Page Speed Optimization Libraries  1.2.24.1
net/instaweb/automatic/public/resource_fetch.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 
00023 #ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_RESOURCE_FETCH_H_
00024 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_RESOURCE_FETCH_H_
00025 
00026 #include "net/instaweb/http/public/async_fetch.h"
00027 #include "net/instaweb/http/public/request_context.h"
00028 #include "net/instaweb/util/public/basictypes.h"
00029 #include "net/instaweb/util/public/google_url.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class MessageHandler;
00034 class ServerContext;
00035 class RewriteDriver;
00036 class RewriteDriverPool;
00037 class RewriteOptions;
00038 class SyncFetcherAdapterCallback;
00039 class Timer;
00040 
00045 class ResourceFetch : public SharedAsyncFetch {
00046  public:
00051   static void Start(const GoogleUrl& url,
00052                     RewriteOptions* custom_options,
00056                     bool using_spdy,
00057                     ServerContext* server_context,
00058                     AsyncFetch* async_fetch);
00059 
00070   static bool BlockingFetch(const GoogleUrl& url,
00071                             ServerContext* server_context,
00072                             RewriteDriver* driver,
00073                             SyncFetcherAdapterCallback* async_fetch);
00074 
00082   static RewriteDriver* GetDriver(const GoogleUrl& url,
00083                                   RewriteOptions* custom_options,
00084                                   RewriteDriverPool* driver_pool,
00085                                   bool using_spdy,
00086                                   ServerContext* server_context,
00087                                   const RequestContextPtr& request_ctx);
00088 
00089  protected:
00091   virtual void HandleHeadersComplete();
00092   virtual void HandleDone(bool success);
00093 
00094  private:
00095   enum CleanupMode {
00096     kAutoCleanupDriver,
00097     kDontAutoCleanupDriver
00098   };
00099 
00100   ResourceFetch(const GoogleUrl& url, CleanupMode cleanup_mode,
00101                 RewriteDriver* driver, Timer* timer,
00102                 MessageHandler* handler, AsyncFetch* async_fetch);
00103   virtual ~ResourceFetch();
00104 
00110   static void StartWithDriver(const GoogleUrl& url,
00111                               CleanupMode cleanup_mode,
00112                               ServerContext* manager,
00113                               RewriteDriver* driver,
00114                               AsyncFetch* async_fetch);
00115 
00119   static void ApplyFuriousOptions(const ServerContext* server_context,
00120                                   const GoogleUrl& url,
00121                                   RewriteDriverPool* driver_pool,
00122                                   RewriteOptions** custom_options);
00123 
00124   GoogleUrl resource_url_;
00125   RewriteDriver* driver_;
00126   Timer* timer_;
00127   MessageHandler* message_handler_;
00128 
00129   int64 start_time_ms_;
00130   int redirect_count_;
00131   CleanupMode cleanup_mode_;
00132 
00133   DISALLOW_COPY_AND_ASSIGN(ResourceFetch);
00134 };
00135 
00136 }  
00137 
00138 #endif  ///< NET_INSTAWEB_AUTOMATIC_PUBLIC_RESOURCE_FETCH_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines