Page Speed Optimization Libraries
1.8.31.3
|
00001 // Copyright 2013 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_SERVER_CONTEXT_H_ 00018 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_SERVER_CONTEXT_H_ 00019 00020 #include "net/instaweb/rewriter/public/server_context.h" 00021 00022 #include "net/instaweb/http/public/request_context.h" 00023 #include "net/instaweb/util/public/basictypes.h" 00024 #include "net/instaweb/util/public/scoped_ptr.h" 00025 #include "pagespeed/kernel/base/string_util.h" 00026 #include "pagespeed/kernel/base/string.h" 00027 00028 namespace net_instaweb { 00029 00030 class AbstractMutex; 00031 class AsyncFetch; 00032 class GoogleUrl; 00033 class Histogram; 00034 class QueryParams; 00035 class RewriteDriver; 00036 class RewriteDriverFactory; 00037 class RewriteOptions; 00038 class RewriteStats; 00039 class SharedMemStatistics; 00040 class Statistics; 00041 class SystemCaches; 00042 class SystemRewriteDriverFactory; 00043 class SystemRewriteOptions; 00044 class UpDownCounter; 00045 class UrlAsyncFetcherStats; 00046 class Variable; 00047 class Writer; 00048 00050 class SystemServerContext : public ServerContext { 00051 public: 00058 enum AdminSource { kPageSpeedAdmin, kStatistics, kOther }; 00059 00060 SystemServerContext(RewriteDriverFactory* factory, 00061 StringPiece hostname, int port); 00062 virtual ~SystemServerContext(); 00063 00072 void FlushCacheIfNecessary(); 00073 00074 SystemRewriteOptions* global_system_rewrite_options(); 00075 GoogleString hostname_identifier() { return hostname_identifier_; } 00076 00077 static void InitStats(Statistics* statistics); 00078 00080 virtual void ChildInit(SystemRewriteDriverFactory* factory); 00081 00085 void CreateLocalStatistics(Statistics* global_statistics, 00086 SystemRewriteDriverFactory* factory); 00087 00090 bool initialized() const { return initialized_; } 00091 00103 virtual void ApplySessionFetchers(const RequestContextPtr& req, 00104 RewriteDriver* driver); 00105 00108 void AddHtmlRewriteTimeUs(int64 rewrite_time_us); 00109 00114 virtual void CollapseConfigOverlaysAndComputeSignatures(); 00115 00118 virtual const SystemRewriteOptions* SpdyGlobalConfig() const; 00119 00122 void ConsoleHandler(const SystemRewriteOptions& options, AdminSource source, 00123 const QueryParams& query_params, AsyncFetch* fetch); 00124 00126 void MessageHistoryHandler(AdminSource source, AsyncFetch* fetch); 00127 00129 void StatisticsGraphsHandler(Writer* writer); 00130 00134 void AdminPage(bool is_global, const GoogleUrl& stripped_gurl, 00135 const QueryParams& query_params, const RewriteOptions* options, 00136 AsyncFetch* fetch); 00137 00143 void StatisticsPage(bool is_global, const QueryParams& query_params, 00144 const RewriteOptions* options, 00145 AsyncFetch* fetch); 00146 00147 protected: 00160 virtual bool UpdateCacheFlushTimestampMs(int64 timestamp_ms); 00161 00163 virtual void MaybeApplySpdySessionFetcher(const RequestContextPtr& request, 00164 RewriteDriver* driver) {} 00165 00167 void ConsoleJsonHandler(const QueryParams& params, AsyncFetch* fetch); 00168 00180 void StatisticsHandler(bool is_global_request, AdminSource source, 00181 AsyncFetch* fetch); 00182 00184 void PrintSpdyConfig(AdminSource source, AsyncFetch* fetch); 00185 00187 void PrintNormalConfig(AdminSource source, AsyncFetch* fetch); 00188 00191 void PrintCaches(bool is_global, AdminSource source, 00192 const QueryParams& query_params, 00193 const RewriteOptions* options, 00194 AsyncFetch* fetch); 00195 00197 void PrintHistograms(bool is_global_request, AdminSource source, 00198 AsyncFetch* fetch); 00199 00200 Variable* statistics_404_count(); 00201 00202 private: 00203 bool initialized_; 00204 bool use_per_vhost_statistics_; 00205 00209 scoped_ptr<AbstractMutex> cache_flush_mutex_; 00210 int64 last_cache_flush_check_sec_; 00211 00212 Variable* cache_flush_count_; 00213 UpDownCounter* cache_flush_timestamp_ms_; 00214 00215 Histogram* html_rewrite_time_us_histogram_; 00216 00218 scoped_ptr<Statistics> split_statistics_; 00219 00221 SharedMemStatistics* local_statistics_; 00222 00224 scoped_ptr<RewriteStats> local_rewrite_stats_; 00225 scoped_ptr<UrlAsyncFetcherStats> stats_fetcher_; 00226 00230 GoogleString hostname_identifier_; 00231 00232 SystemCaches* system_caches_; 00233 00234 DISALLOW_COPY_AND_ASSIGN(SystemServerContext); 00235 }; 00236 00237 } 00238 00239 #endif ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_SERVER_CONTEXT_H_