Page Speed Optimization Libraries
1.8.31.3
|
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_REWRITER_PUBLIC_RESOURCE_FETCH_H_ 00024 #define NET_INSTAWEB_REWRITER_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 RewriteOptions; 00037 class SyncFetcherAdapterCallback; 00038 class Timer; 00039 00044 class ResourceFetch : public SharedAsyncFetch { 00045 public: 00047 enum CleanupMode { 00048 kAutoCleanupDriver, 00049 kDontAutoCleanupDriver 00050 }; 00051 00056 static void Start(const GoogleUrl& url, 00057 RewriteOptions* custom_options, 00061 bool using_spdy, 00062 ServerContext* server_context, 00063 AsyncFetch* async_fetch); 00064 00070 static void StartWithDriver(const GoogleUrl& url, 00071 CleanupMode cleanup_mode, 00072 ServerContext* server_context, 00073 RewriteDriver* driver, 00074 AsyncFetch* async_fetch); 00075 00086 static bool BlockingFetch(const GoogleUrl& url, 00087 ServerContext* server_context, 00088 RewriteDriver* driver, 00089 SyncFetcherAdapterCallback* async_fetch); 00090 00098 static RewriteDriver* GetDriver(const GoogleUrl& url, 00099 RewriteOptions* custom_options, 00100 ServerContext* server_context, 00101 const RequestContextPtr& request_ctx); 00102 00103 protected: 00105 virtual void HandleHeadersComplete(); 00106 virtual void HandleDone(bool success); 00107 00108 private: 00109 ResourceFetch(const GoogleUrl& url, CleanupMode cleanup_mode, 00110 RewriteDriver* driver, Timer* timer, 00111 MessageHandler* handler, AsyncFetch* async_fetch); 00112 virtual ~ResourceFetch(); 00113 00117 static void ApplyExperimentOptions(const GoogleUrl& url, 00118 const RequestContextPtr& request_ctx, 00119 ServerContext* server_context, 00120 RewriteOptions** custom_options); 00121 00122 GoogleUrl resource_url_; 00123 RewriteDriver* driver_; 00124 Timer* timer_; 00125 MessageHandler* message_handler_; 00126 00127 int64 start_time_ms_; 00128 int redirect_count_; 00129 CleanupMode cleanup_mode_; 00130 00131 DISALLOW_COPY_AND_ASSIGN(ResourceFetch); 00132 }; 00133 00134 } 00135 00136 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_FETCH_H_