Page Speed Optimization Libraries
1.8.31.3
|
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 StaticAssetManager; 00042 class Statistics; 00043 class SystemCaches; 00044 class SystemRewriteOptions; 00045 class SystemServerContext; 00046 class SystemThreadSystem; 00047 class Timer; 00048 class UrlAsyncFetcher; 00049 00051 class SystemRewriteDriverFactory : public RewriteDriverFactory { 00052 public: 00061 SystemRewriteDriverFactory(const ProcessContext& process_context, 00062 SystemThreadSystem* thread_system, 00063 AbstractSharedMem* shared_mem_runtime, 00064 StringPiece hostname, int port); 00065 virtual ~SystemRewriteDriverFactory(); 00066 00069 static void InitApr(); 00070 00071 AbstractSharedMem* shared_mem_runtime() const { 00072 return shared_mem_runtime_.get(); 00073 } 00074 00076 SharedMemStatistics* AllocateAndInitSharedMemStatistics( 00077 bool local, const StringPiece& name, const SystemRewriteOptions& options); 00078 00081 virtual void NonStaticInitStats(Statistics* statistics) = 0; 00082 00084 NonceGenerator* DefaultNonceGenerator(); 00085 00109 bool is_root_process() const { return is_root_process_; } 00110 virtual void RootInit(); 00111 virtual void ChildInit(); 00112 00115 virtual void ParentOrChildInit(); 00116 00124 void PostConfig(const std::vector<SystemServerContext*>& server_contexts, 00125 GoogleString* error_message, 00126 int* error_index, 00127 Statistics** global_statistics); 00128 00132 void SharedCircularBufferInit(bool is_root); 00133 00134 virtual Hasher* NewHasher(); 00135 virtual Timer* DefaultTimer(); 00136 virtual ServerContext* NewServerContext(); 00137 00139 virtual bool enable_property_cache() const { 00140 return true; 00141 } 00142 00143 GoogleString hostname_identifier() { return hostname_identifier_; } 00144 00147 virtual void ShutDown(); 00148 00149 virtual void StopCacheActivity(); 00150 00151 SystemCaches* caches() { return caches_.get(); } 00152 00153 virtual void set_message_buffer_size(int x) { 00154 message_buffer_size_ = x; 00155 } 00156 00160 UrlAsyncFetcher* GetFetcher(SystemRewriteOptions* config); 00161 00164 void set_track_original_content_length(bool x) { 00165 track_original_content_length_ = x; 00166 } 00167 bool track_original_content_length() const { 00168 return track_original_content_length_; 00169 } 00170 00175 void list_outstanding_urls_on_error(bool x) { 00176 list_outstanding_urls_on_error_ = x; 00177 } 00178 00182 virtual int requests_per_host() { return 4; } 00183 virtual int max_queue_size() { return 500 * requests_per_host(); } 00184 virtual int queued_per_host() { return 500 * requests_per_host(); } 00185 00188 virtual bool use_per_vhost_statistics() const { return true; } 00189 00190 void set_static_asset_prefix(StringPiece s) { 00191 s.CopyToString(&static_asset_prefix_); 00192 } 00193 const GoogleString& static_asset_prefix() { return static_asset_prefix_; } 00194 00195 protected: 00198 static void InitStats(Statistics* statistics); 00199 00201 virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager); 00202 00203 virtual void SetupCaches(ServerContext* server_context); 00204 00206 virtual void SetupMessageHandlers() {} 00207 virtual void ShutDownMessageHandlers() {} 00208 virtual void SetCircularBuffer(SharedCircularBuffer* buffer) {} 00209 00212 virtual void ShutDownFetchers() {} 00213 00221 typedef std::set<SystemServerContext*> SystemServerContextSet; 00222 SystemServerContextSet uninitialized_server_contexts_; 00223 00227 virtual UrlAsyncFetcher* AllocateFetcher(SystemRewriteOptions* config); 00228 00229 virtual FileSystem* DefaultFileSystem(); 00230 virtual NamedLockManager* DefaultLockManager(); 00231 00232 private: 00235 Statistics* SetUpGlobalSharedMemStatistics( 00236 const SystemRewriteOptions& options); 00237 00241 GoogleString GetFetcherKey(bool include_slurping_config, 00242 const SystemRewriteOptions* config); 00243 00248 UrlAsyncFetcher* GetBaseFetcher(SystemRewriteOptions* config); 00249 00250 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00251 00252 scoped_ptr<SharedMemStatistics> shared_mem_statistics_; 00255 StringVector local_shm_stats_segment_names_; 00256 scoped_ptr<AbstractSharedMem> shared_mem_runtime_; 00257 scoped_ptr<SharedCircularBuffer> shared_circular_buffer_; 00258 00259 bool statistics_frozen_; 00260 bool is_root_process_; 00261 00265 const GoogleString hostname_identifier_; 00266 00269 int message_buffer_size_; 00270 00272 scoped_ptr<SystemCaches> caches_; 00273 00274 bool track_original_content_length_; 00275 bool list_outstanding_urls_on_error_; 00276 00289 typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap; 00290 FetcherMap base_fetcher_map_; 00291 FetcherMap fetcher_map_; 00292 00294 GoogleString static_asset_prefix_; 00295 00297 SystemThreadSystem* system_thread_system_; 00298 00299 DISALLOW_COPY_AND_ASSIGN(SystemRewriteDriverFactory); 00300 }; 00301 00302 } 00303 00304 #endif ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_