Page Speed Optimization Libraries
1.5.27.2
|
00001 // Copyright 2010 Google Inc. 00017 00018 #ifndef NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_ 00019 #define NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_ 00020 00021 #include <map> 00022 #include <set> 00023 00024 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h" 00025 #include "net/instaweb/system/public/system_rewrite_driver_factory.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/cache_interface.h" 00028 #include "net/instaweb/util/public/scoped_ptr.h" 00029 #include "net/instaweb/util/public/shared_mem_cache.h" 00030 #include "net/instaweb/util/public/string.h" 00031 #include "net/instaweb/util/public/string_util.h" 00032 00033 struct apr_pool_t; 00034 struct server_rec; 00035 00036 namespace net_instaweb { 00037 00038 class AbstractSharedMem; 00039 class ApacheConfig; 00040 class ApacheMessageHandler; 00041 class ApacheServerContext; 00042 class FileSystem; 00043 class Hasher; 00044 class MessageHandler; 00045 class ModSpdyFetchController; 00046 class NamedLockManager; 00047 class QueuedWorkerPool; 00048 class RewriteOptions; 00049 class SerfUrlAsyncFetcher; 00050 class ServerContext; 00051 class SharedCircularBuffer; 00052 class SharedMemStatistics; 00053 class SlowWorker; 00054 class StaticAssetManager; 00055 class Statistics; 00056 class SystemCaches; 00057 class Timer; 00058 class UrlAsyncFetcher; 00059 class UrlFetcher; 00060 class UrlPollableAsyncFetcher; 00061 00063 class ApacheRewriteDriverFactory : public SystemRewriteDriverFactory { 00064 public: 00067 static const char kStaticAssetPrefix[]; 00068 00069 ApacheRewriteDriverFactory(server_rec* server, const StringPiece& version); 00070 virtual ~ApacheRewriteDriverFactory(); 00071 00072 virtual Hasher* NewHasher(); 00073 00079 UrlPollableAsyncFetcher* SubResourceFetcher(); 00080 00081 GoogleString hostname_identifier() { return hostname_identifier_; } 00082 00083 AbstractSharedMem* shared_mem_runtime() const { 00084 return shared_mem_runtime_.get(); 00085 } 00090 ApacheMessageHandler* apache_message_handler() { 00091 return apache_message_handler_; 00092 } 00114 bool is_root_process() const { return is_root_process_; } 00115 void RootInit(); 00116 void ChildInit(); 00117 00120 Statistics* MakeGlobalSharedMemStatistics(const ApacheConfig* options); 00121 00123 SharedMemStatistics* AllocateAndInitSharedMemStatistics( 00124 const StringPiece& name, const ApacheConfig* options); 00125 00126 virtual ApacheServerContext* MakeApacheServerContext(server_rec* server); 00127 ServerContext* NewServerContext(); 00128 00129 00133 void set_fetch_with_gzip(bool x) { fetch_with_gzip_ = x; } 00134 bool fetch_with_gzip() const { return fetch_with_gzip_; } 00135 00138 void set_track_original_content_length(bool x) { 00139 track_original_content_length_ = x; 00140 } 00141 bool track_original_content_length() const { 00142 return track_original_content_length_; 00143 } 00144 00145 void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; } 00146 int num_rewrite_threads() const { return num_rewrite_threads_; } 00147 void set_num_expensive_rewrite_threads(int x) { 00148 num_expensive_rewrite_threads_ = x; 00149 } 00150 int num_expensive_rewrite_threads() const { 00151 return num_expensive_rewrite_threads_; 00152 } 00153 00154 void set_message_buffer_size(int x) { 00155 message_buffer_size_ = x; 00156 } 00157 00162 void list_outstanding_urls_on_error(bool x) { 00163 list_outstanding_urls_on_error_ = x; 00164 } 00165 00166 bool use_per_vhost_statistics() const { 00167 return use_per_vhost_statistics_; 00168 } 00169 00170 void set_use_per_vhost_statistics(bool x) { 00171 use_per_vhost_statistics_ = x; 00172 } 00173 00174 bool enable_property_cache() const { 00175 return enable_property_cache_; 00176 } 00177 00178 void set_enable_property_cache(bool x) { 00179 enable_property_cache_ = x; 00180 } 00181 00183 bool inherit_vhost_config() const { 00184 return inherit_vhost_config_; 00185 } 00186 00187 void set_inherit_vhost_config(bool x) { 00188 inherit_vhost_config_ = x; 00189 } 00190 00191 bool disable_loopback_routing() const { 00192 return disable_loopback_routing_; 00193 } 00194 00195 void set_disable_loopback_routing(bool x) { 00196 disable_loopback_routing_ = x; 00197 } 00198 00199 bool install_crash_handler() const { 00200 return install_crash_handler_; 00201 } 00202 00203 void set_install_crash_handler(bool x) { 00204 install_crash_handler_ = x; 00205 } 00206 00207 SystemCaches* caches() { return caches_.get(); } 00208 00211 virtual bool UseBeaconResultsInFilters() const { 00212 return true; 00213 } 00214 00218 UrlAsyncFetcher* GetFetcher(ApacheConfig* config); 00219 00222 SerfUrlAsyncFetcher* GetSerfFetcher(ApacheConfig* config); 00223 00227 bool PoolDestroyed(ApacheServerContext* rm); 00228 00231 virtual RewriteOptions* NewRewriteOptions(); 00232 00235 virtual RewriteOptions* NewRewriteOptionsForQuery(); 00236 00240 static void InitStats(Statistics* statistics); 00241 static void Initialize(); 00242 static void Terminate(); 00243 00251 bool SetHttpsOptions(StringPiece directive, GoogleString* error_message); 00252 00253 ModSpdyFetchController* mod_spdy_fetch_controller() { 00254 return mod_spdy_fetch_controller_.get(); 00255 } 00256 00257 protected: 00258 virtual UrlFetcher* DefaultUrlFetcher(); 00259 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00260 virtual void StopCacheActivity(); 00261 00263 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00264 virtual MessageHandler* DefaultMessageHandler(); 00265 virtual FileSystem* DefaultFileSystem(); 00266 virtual Timer* DefaultTimer(); 00267 virtual void SetupCaches(ServerContext* server_context); 00268 virtual NamedLockManager* DefaultLockManager(); 00269 virtual QueuedWorkerPool* CreateWorkerPool(WorkerPoolCategory pool, 00270 StringPiece name); 00271 00274 virtual bool ShouldWriteResourcesToFileSystem() { return false; } 00275 00278 void ParentOrChildInit(); 00282 void SharedCircularBufferInit(bool is_root); 00283 00286 virtual void ShutDown(); 00287 00289 virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager); 00290 00291 private: 00292 typedef SharedMemCache<64> MetadataShmCache; 00293 struct MetadataShmCacheInfo { 00294 MetadataShmCacheInfo() : cache_backend(NULL) {} 00295 00297 scoped_ptr<CacheInterface> cache_to_use; 00298 MetadataShmCache* cache_backend; 00299 }; 00300 00303 void AutoDetectThreadCounts(); 00304 00305 apr_pool_t* pool_; 00306 server_rec* server_rec_; 00307 scoped_ptr<SharedMemStatistics> shared_mem_statistics_; 00308 scoped_ptr<AbstractSharedMem> shared_mem_runtime_; 00309 scoped_ptr<SharedCircularBuffer> shared_circular_buffer_; 00310 scoped_ptr<SlowWorker> slow_worker_; 00311 00316 GoogleString version_; 00317 00318 bool statistics_frozen_; 00319 bool is_root_process_; 00320 bool fetch_with_gzip_; 00321 bool track_original_content_length_; 00322 bool list_outstanding_urls_on_error_; 00323 00327 const GoogleString hostname_identifier_; 00333 ApacheMessageHandler* apache_message_handler_; 00338 ApacheMessageHandler* apache_html_parse_message_handler_; 00339 00347 typedef std::set<ApacheServerContext*> ApacheServerContextSet; 00348 ApacheServerContextSet uninitialized_server_contexts_; 00349 00353 bool use_per_vhost_statistics_; 00354 00356 bool enable_property_cache_; 00357 00359 bool inherit_vhost_config_; 00360 00363 bool disable_loopback_routing_; 00364 00366 bool install_crash_handler_; 00367 00369 bool thread_counts_finalized_; 00370 00372 int num_rewrite_threads_; 00373 int num_expensive_rewrite_threads_; 00374 00375 int max_mod_spdy_fetch_threads_; 00376 00379 int message_buffer_size_; 00380 00384 typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap; 00385 FetcherMap fetcher_map_; 00386 typedef std::map<GoogleString, SerfUrlAsyncFetcher*> SerfFetcherMap; 00387 SerfFetcherMap serf_fetcher_map_; 00388 00390 scoped_ptr<ModSpdyFetchController> mod_spdy_fetch_controller_; 00391 00392 GoogleString https_options_; 00393 00395 scoped_ptr<SystemCaches> caches_; 00396 00397 DISALLOW_COPY_AND_ASSIGN(ApacheRewriteDriverFactory); 00398 }; 00399 00400 } 00401 00402 #endif ///< NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_