Page Speed Optimization Libraries
1.7.30.4
|
00001 // Copyright 2013 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_ 00018 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_ 00019 00020 #include <map> 00021 #include <set> 00022 #include <vector> 00023 00024 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "pagespeed/kernel/base/scoped_ptr.h" 00027 #include "pagespeed/kernel/base/string.h" 00028 #include "pagespeed/kernel/base/string_util.h" 00029 00030 namespace net_instaweb { 00031 00032 class AbstractSharedMem; 00033 class FileSystem; 00034 class Hasher; 00035 class NamedLockManager; 00036 class NonceGenerator; 00037 class ProcessContext; 00038 class ServerContext; 00039 class SharedCircularBuffer; 00040 class SharedMemStatistics; 00041 class Statistics; 00042 class SystemCaches; 00043 class SystemRewriteOptions; 00044 class SystemServerContext; 00045 class SystemThreadSystem; 00046 class Timer; 00047 class UrlAsyncFetcher; 00048 00050 class SystemRewriteDriverFactory : public RewriteDriverFactory { 00051 public: 00060 SystemRewriteDriverFactory(const ProcessContext& process_context, 00061 SystemThreadSystem* thread_system, 00062 AbstractSharedMem* shared_mem_runtime, 00063 StringPiece hostname, int port); 00064 virtual ~SystemRewriteDriverFactory(); 00065 00068 static void InitApr(); 00069 00070 AbstractSharedMem* shared_mem_runtime() const { 00071 return shared_mem_runtime_.get(); 00072 } 00073 00075 SharedMemStatistics* AllocateAndInitSharedMemStatistics( 00076 bool local, const StringPiece& name, const SystemRewriteOptions& options); 00077 00080 virtual void NonStaticInitStats(Statistics* statistics) = 0; 00081 00083 NonceGenerator* DefaultNonceGenerator(); 00084 00108 bool is_root_process() const { return is_root_process_; } 00109 virtual void RootInit(); 00110 virtual void ChildInit(); 00111 00114 virtual void ParentOrChildInit(); 00115 00123 void PostConfig(const std::vector<SystemServerContext*>& server_contexts, 00124 GoogleString* error_message, 00125 int* error_index, 00126 Statistics** global_statistics); 00127 00131 void SharedCircularBufferInit(bool is_root); 00132 00133 virtual Hasher* NewHasher(); 00134 virtual Timer* DefaultTimer(); 00135 virtual ServerContext* NewServerContext(); 00136 00138 virtual bool enable_property_cache() const { 00139 return true; 00140 } 00141 00142 GoogleString hostname_identifier() { return hostname_identifier_; } 00143 00146 virtual void ShutDown(); 00147 00148 virtual void StopCacheActivity(); 00149 00150 SystemCaches* caches() { return caches_.get(); } 00151 00152 virtual void set_message_buffer_size(int x) { 00153 message_buffer_size_ = x; 00154 } 00155 00159 UrlAsyncFetcher* GetFetcher(SystemRewriteOptions* config); 00160 00163 void set_track_original_content_length(bool x) { 00164 track_original_content_length_ = x; 00165 } 00166 bool track_original_content_length() const { 00167 return track_original_content_length_; 00168 } 00169 00174 void list_outstanding_urls_on_error(bool x) { 00175 list_outstanding_urls_on_error_ = x; 00176 } 00177 00181 virtual int requests_per_host() { return 4; } 00182 virtual int max_queue_size() { return 500 * requests_per_host(); } 00183 virtual int queued_per_host() { return 500 * requests_per_host(); } 00184 00187 virtual bool use_per_vhost_statistics() const { return true; } 00188 00189 protected: 00192 static void InitStats(Statistics* statistics); 00193 00194 virtual void SetupCaches(ServerContext* server_context); 00195 00197 virtual void SetupMessageHandlers() {} 00198 virtual void ShutDownMessageHandlers() {} 00199 virtual void SetCircularBuffer(SharedCircularBuffer* buffer) {} 00200 00203 virtual void ShutDownFetchers() {} 00204 00212 typedef std::set<SystemServerContext*> SystemServerContextSet; 00213 SystemServerContextSet uninitialized_server_contexts_; 00214 00218 virtual UrlAsyncFetcher* AllocateFetcher(SystemRewriteOptions* config); 00219 00220 virtual FileSystem* DefaultFileSystem(); 00221 virtual NamedLockManager* DefaultLockManager(); 00222 00223 private: 00226 Statistics* SetUpGlobalSharedMemStatistics( 00227 const SystemRewriteOptions& options); 00228 00232 GoogleString GetFetcherKey(bool include_slurping_config, 00233 const SystemRewriteOptions* config); 00234 00239 UrlAsyncFetcher* GetBaseFetcher(SystemRewriteOptions* config); 00240 00241 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00242 00243 scoped_ptr<SharedMemStatistics> shared_mem_statistics_; 00246 StringVector local_shm_stats_segment_names_; 00247 scoped_ptr<AbstractSharedMem> shared_mem_runtime_; 00248 scoped_ptr<SharedCircularBuffer> shared_circular_buffer_; 00249 00250 bool statistics_frozen_; 00251 bool is_root_process_; 00252 00256 const GoogleString hostname_identifier_; 00257 00260 int message_buffer_size_; 00261 00263 scoped_ptr<SystemCaches> caches_; 00264 00265 bool track_original_content_length_; 00266 bool list_outstanding_urls_on_error_; 00267 00280 typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap; 00281 FetcherMap base_fetcher_map_; 00282 FetcherMap fetcher_map_; 00283 00285 SystemThreadSystem* system_thread_system_; 00286 00287 DISALLOW_COPY_AND_ASSIGN(SystemRewriteDriverFactory); 00288 }; 00289 00290 } 00291 00292 #endif ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_