Page Speed Optimization Libraries
1.6.29.3
|
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 00061 class ApacheRewriteDriverFactory : public SystemRewriteDriverFactory { 00062 public: 00065 static const char kStaticAssetPrefix[]; 00066 00067 ApacheRewriteDriverFactory(server_rec* server, const StringPiece& version); 00068 virtual ~ApacheRewriteDriverFactory(); 00069 00070 virtual Hasher* NewHasher(); 00071 00072 GoogleString hostname_identifier() { return hostname_identifier_; } 00073 00074 AbstractSharedMem* shared_mem_runtime() const { 00075 return shared_mem_runtime_.get(); 00076 } 00081 ApacheMessageHandler* apache_message_handler() { 00082 return apache_message_handler_; 00083 } 00105 bool is_root_process() const { return is_root_process_; } 00106 void RootInit(); 00107 void ChildInit(); 00108 00111 Statistics* MakeGlobalSharedMemStatistics(const ApacheConfig* options); 00112 00114 SharedMemStatistics* AllocateAndInitSharedMemStatistics( 00115 const StringPiece& name, const ApacheConfig* options); 00116 00117 virtual ApacheServerContext* MakeApacheServerContext(server_rec* server); 00118 ServerContext* NewServerContext(); 00119 00120 00124 void set_fetch_with_gzip(bool x) { fetch_with_gzip_ = x; } 00125 bool fetch_with_gzip() const { return fetch_with_gzip_; } 00126 00129 void set_track_original_content_length(bool x) { 00130 track_original_content_length_ = x; 00131 } 00132 bool track_original_content_length() const { 00133 return track_original_content_length_; 00134 } 00135 00136 void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; } 00137 int num_rewrite_threads() const { return num_rewrite_threads_; } 00138 void set_num_expensive_rewrite_threads(int x) { 00139 num_expensive_rewrite_threads_ = x; 00140 } 00141 int num_expensive_rewrite_threads() const { 00142 return num_expensive_rewrite_threads_; 00143 } 00144 00145 void set_message_buffer_size(int x) { 00146 message_buffer_size_ = x; 00147 } 00148 00153 void list_outstanding_urls_on_error(bool x) { 00154 list_outstanding_urls_on_error_ = x; 00155 } 00156 00157 bool use_per_vhost_statistics() const { 00158 return use_per_vhost_statistics_; 00159 } 00160 00161 void set_use_per_vhost_statistics(bool x) { 00162 use_per_vhost_statistics_ = x; 00163 } 00164 00165 bool enable_property_cache() const { 00166 return enable_property_cache_; 00167 } 00168 00169 void set_enable_property_cache(bool x) { 00170 enable_property_cache_ = x; 00171 } 00172 00174 bool inherit_vhost_config() const { 00175 return inherit_vhost_config_; 00176 } 00177 00178 void set_inherit_vhost_config(bool x) { 00179 inherit_vhost_config_ = x; 00180 } 00181 00182 bool disable_loopback_routing() const { 00183 return disable_loopback_routing_; 00184 } 00185 00186 void set_disable_loopback_routing(bool x) { 00187 disable_loopback_routing_ = x; 00188 } 00189 00190 bool install_crash_handler() const { 00191 return install_crash_handler_; 00192 } 00193 00194 void set_install_crash_handler(bool x) { 00195 install_crash_handler_ = x; 00196 } 00197 00198 SystemCaches* caches() { return caches_.get(); } 00199 00202 virtual bool UseBeaconResultsInFilters() const { 00203 return true; 00204 } 00205 00209 UrlAsyncFetcher* GetFetcher(ApacheConfig* config); 00210 00213 SerfUrlAsyncFetcher* GetSerfFetcher(ApacheConfig* config); 00214 00218 bool PoolDestroyed(ApacheServerContext* rm); 00219 00222 virtual RewriteOptions* NewRewriteOptions(); 00223 00226 virtual RewriteOptions* NewRewriteOptionsForQuery(); 00227 00231 static void InitStats(Statistics* statistics); 00232 static void Initialize(); 00233 static void Terminate(); 00234 00242 bool SetHttpsOptions(StringPiece directive, GoogleString* error_message); 00243 00244 ModSpdyFetchController* mod_spdy_fetch_controller() { 00245 return mod_spdy_fetch_controller_.get(); 00246 } 00247 00248 protected: 00249 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00250 virtual void StopCacheActivity(); 00251 00253 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00254 virtual MessageHandler* DefaultMessageHandler(); 00255 virtual FileSystem* DefaultFileSystem(); 00256 virtual Timer* DefaultTimer(); 00257 virtual void SetupCaches(ServerContext* server_context); 00258 virtual NamedLockManager* DefaultLockManager(); 00259 virtual QueuedWorkerPool* CreateWorkerPool(WorkerPoolCategory pool, 00260 StringPiece name); 00261 00264 virtual bool ShouldWriteResourcesToFileSystem() { return false; } 00265 00268 void ParentOrChildInit(); 00272 void SharedCircularBufferInit(bool is_root); 00273 00276 virtual void ShutDown(); 00277 00279 virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager); 00280 00281 private: 00282 typedef SharedMemCache<64> MetadataShmCache; 00283 struct MetadataShmCacheInfo { 00284 MetadataShmCacheInfo() : cache_backend(NULL) {} 00285 00287 scoped_ptr<CacheInterface> cache_to_use; 00288 MetadataShmCache* cache_backend; 00289 }; 00290 00293 void AutoDetectThreadCounts(); 00294 00295 apr_pool_t* pool_; 00296 server_rec* server_rec_; 00297 scoped_ptr<SharedMemStatistics> shared_mem_statistics_; 00298 scoped_ptr<AbstractSharedMem> shared_mem_runtime_; 00299 scoped_ptr<SharedCircularBuffer> shared_circular_buffer_; 00300 scoped_ptr<SlowWorker> slow_worker_; 00301 00306 GoogleString version_; 00307 00308 bool statistics_frozen_; 00309 bool is_root_process_; 00310 bool fetch_with_gzip_; 00311 bool track_original_content_length_; 00312 bool list_outstanding_urls_on_error_; 00313 00317 const GoogleString hostname_identifier_; 00323 ApacheMessageHandler* apache_message_handler_; 00328 ApacheMessageHandler* apache_html_parse_message_handler_; 00329 00337 typedef std::set<ApacheServerContext*> ApacheServerContextSet; 00338 ApacheServerContextSet uninitialized_server_contexts_; 00339 00343 bool use_per_vhost_statistics_; 00344 00346 bool enable_property_cache_; 00347 00349 bool inherit_vhost_config_; 00350 00353 bool disable_loopback_routing_; 00354 00356 bool install_crash_handler_; 00357 00359 bool thread_counts_finalized_; 00360 00362 int num_rewrite_threads_; 00363 int num_expensive_rewrite_threads_; 00364 00365 int max_mod_spdy_fetch_threads_; 00366 00369 int message_buffer_size_; 00370 00374 typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap; 00375 FetcherMap fetcher_map_; 00376 typedef std::map<GoogleString, SerfUrlAsyncFetcher*> SerfFetcherMap; 00377 SerfFetcherMap serf_fetcher_map_; 00378 00380 scoped_ptr<ModSpdyFetchController> mod_spdy_fetch_controller_; 00381 00382 GoogleString https_options_; 00383 00385 scoped_ptr<SystemCaches> caches_; 00386 00387 DISALLOW_COPY_AND_ASSIGN(ApacheRewriteDriverFactory); 00388 }; 00389 00390 } 00391 00392 #endif ///< NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_