Page Speed Optimization Libraries
1.2.24.1
|
00001 // Copyright 2010 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_APACHE_APACHE_CONFIG_H_ 00018 #define NET_INSTAWEB_APACHE_APACHE_CONFIG_H_ 00019 00020 #include "net/instaweb/rewriter/public/rewrite_options.h" 00021 #include "net/instaweb/util/public/basictypes.h" 00022 #include "net/instaweb/util/public/string.h" 00023 #include "net/instaweb/util/public/string_util.h" 00024 00025 namespace net_instaweb { 00026 00027 class Hasher; 00028 00031 class ApacheConfig : public RewriteOptions { 00032 public: 00033 enum RefererStatisticsOutputLevel { 00034 kFast, 00035 kSimple, 00036 kOrganized, 00037 }; 00038 00039 static const char kClassName[]; 00040 00041 static bool ParseRefererStatisticsOutputLevel( 00042 const StringPiece& in, RefererStatisticsOutputLevel* out); 00043 00044 static void Initialize(); 00045 static void Terminate(); 00046 00047 explicit ApacheConfig(const StringPiece& dir); 00048 ApacheConfig(); 00049 ~ApacheConfig() {} 00050 00054 StringPiece description() const { return description_; } 00055 void set_description(const StringPiece& x) { x.CopyToString(&description_); } 00056 00057 int64 file_cache_clean_interval_ms() const { 00058 return file_cache_clean_interval_ms_.value(); 00059 } 00060 void set_file_cache_clean_interval_ms(int64 x) { 00061 set_option(x, &file_cache_clean_interval_ms_); 00062 } 00063 int64 file_cache_clean_size_kb() const { 00064 return file_cache_clean_size_kb_.value(); 00065 } 00066 void set_file_cache_clean_size_kb(int64 x) { 00067 set_option(x, &file_cache_clean_size_kb_); 00068 } 00069 int64 file_cache_clean_inode_limit() const { 00070 return file_cache_clean_inode_limit_.value(); 00071 } 00072 void set_file_cache_clean_inode_limit(int64 x) { 00073 set_option(x, &file_cache_clean_inode_limit_); 00074 } 00075 int64 lru_cache_byte_limit() const { 00076 return lru_cache_byte_limit_.value(); 00077 } 00078 void set_lru_cache_byte_limit(int64 x) { 00079 set_option(x, &lru_cache_byte_limit_); 00080 } 00081 int64 lru_cache_kb_per_process() const { 00082 return lru_cache_kb_per_process_.value(); 00083 } 00084 void set_lru_cache_kb_per_process(int64 x) { 00085 set_option(x, &lru_cache_kb_per_process_); 00086 } 00087 int64 slurp_flush_limit() const { 00088 return slurp_flush_limit_.value(); 00089 } 00090 void set_slurp_flush_limit(int64 x) { 00091 set_option(x, &slurp_flush_limit_); 00092 } 00093 bool use_shared_mem_locking() const { 00094 return use_shared_mem_locking_.value(); 00095 } 00096 void set_use_shared_mem_locking(bool x) { 00097 set_option(x, &use_shared_mem_locking_); 00098 } 00099 bool collect_referer_statistics() const { 00100 return collect_referer_statistics_.value(); 00101 } 00102 void set_collect_referer_statistics(bool x) { 00103 set_option(x, &collect_referer_statistics_); 00104 } 00105 bool hash_referer_statistics() const { 00106 return hash_referer_statistics_.value(); 00107 } 00108 void set_hash_referer_statistics(bool x) { 00109 set_option(x, &hash_referer_statistics_); 00110 } 00111 bool statistics_enabled() const { 00112 return statistics_enabled_.value(); 00113 } 00114 void set_statistics_enabled(bool x) { 00115 set_option(x, &statistics_enabled_); 00116 } 00117 bool statistics_logging_enabled() const { 00118 return statistics_logging_enabled_.value(); 00119 } 00120 void set_statistics_logging_enabled(bool x) { 00121 set_option(x, &statistics_logging_enabled_); 00122 } 00123 const GoogleString& statistics_logging_file() const { 00124 return statistics_logging_file_.value(); 00125 } 00126 const GoogleString& statistics_logging_charts_css() const { 00127 return statistics_logging_charts_css_.value(); 00128 } 00129 const GoogleString& statistics_logging_charts_js() const { 00130 return statistics_logging_charts_js_.value(); 00131 } 00132 void set_statistics_logging_file(GoogleString x) { 00133 set_option(x, &statistics_logging_file_); 00134 } 00135 int64 statistics_logging_interval_ms() const { 00136 return statistics_logging_interval_ms_.value(); 00137 } 00138 void set_statistics_logging_interval_ms(int64 x) { 00139 set_option(x, &statistics_logging_interval_ms_); 00140 } 00141 bool slurp_read_only() const { 00142 return slurp_read_only_.value(); 00143 } 00144 void set_slurp_read_only(bool x) { 00145 set_option(x, &slurp_read_only_); 00146 } 00147 bool rate_limit_background_fetches() const { 00148 return rate_limit_background_fetches_.value(); 00149 } 00150 RefererStatisticsOutputLevel referer_statistics_output_level() const { 00151 return referer_statistics_output_level_.value(); 00152 } 00153 void set_referer_statistics_output_level(RefererStatisticsOutputLevel x) { 00154 set_option(x, &referer_statistics_output_level_); 00155 } 00156 const GoogleString& file_cache_path() const { 00157 return file_cache_path_.value(); 00158 } 00159 void set_file_cache_path(GoogleString x) { 00160 set_option(x, &file_cache_path_); 00161 } 00162 const GoogleString& memcached_servers() const { 00163 return memcached_servers_.value(); 00164 } 00165 void set_memcached_servers(GoogleString x) { 00166 set_option(x, &memcached_servers_); 00167 } 00168 int memcached_threads() const { 00169 return memcached_threads_.value(); 00170 } 00171 void set_memcached_threads(int x) { 00172 set_option(x, &memcached_threads_); 00173 } 00174 int memcached_timeout_us() const { 00175 return memcached_timeout_us_.value(); 00176 } 00177 bool has_memcached_timeout_us() const { 00178 return memcached_timeout_us_.was_set(); 00179 } 00180 void set_memcached_timeout_us(int x) { 00181 set_option(x, &memcached_timeout_us_); 00182 } 00183 const GoogleString& slurp_directory() const { 00184 return slurp_directory_.value(); 00185 } 00186 void set_slurp_directory(GoogleString x) { 00187 set_option(x, &slurp_directory_); 00188 } 00189 const GoogleString& fetcher_proxy() const { 00190 return fetcher_proxy_.value(); 00191 } 00192 void set_fetcher_proxy(GoogleString x) { 00193 set_option(x, &fetcher_proxy_); 00194 } 00195 00197 void set_cache_flush_poll_interval_sec(int64 num_seconds) { 00198 set_option(num_seconds, &cache_flush_poll_interval_sec_); 00199 } 00200 int64 cache_flush_poll_interval_sec() const { 00201 return cache_flush_poll_interval_sec_.value(); 00202 } 00203 void set_cache_flush_filename(const StringPiece& sp) { 00204 set_option(sp.as_string(), &cache_flush_filename_); 00205 } 00206 const GoogleString& cache_flush_filename() const { 00207 return cache_flush_filename_.value(); 00208 } 00209 00212 bool test_proxy() const { 00213 return test_proxy_.value(); 00214 } 00215 void set_test_proxy(bool x) { 00216 set_option(x, &test_proxy_); 00217 } 00218 00220 bool slurping_enabled() const { 00221 return !slurp_directory().empty(); 00222 } 00223 00224 bool slurping_enabled_read_only() const { 00225 return slurping_enabled() && slurp_read_only(); 00226 } 00227 00228 bool experimental_fetch_from_mod_spdy() const { 00229 return experimental_fetch_from_mod_spdy_.value(); 00230 } 00231 00233 virtual ApacheConfig* Clone() const; 00234 00237 static const ApacheConfig* DynamicCast(const RewriteOptions* instance); 00238 static ApacheConfig* DynamicCast(RewriteOptions* instance); 00239 00241 virtual const char* class_name() const; 00242 00243 protected: 00244 template<class T> class ApacheOption : public OptionTemplateBase<T> { 00245 public: 00246 ApacheOption() {} 00247 00249 virtual bool SetFromString(const GoogleString& value_string) { 00250 T value; 00251 bool success = ApacheConfig::ParseFromString(value_string, &value); 00252 if (success) { 00253 this->set(value); 00254 } 00255 return success; 00256 } 00257 00258 virtual GoogleString Signature(const Hasher* hasher) const { 00259 return ApacheConfig::OptionSignature(this->value(), hasher); 00260 } 00261 00262 virtual GoogleString ToString() const { 00263 return ApacheConfig::ToString(this->value()); 00264 } 00265 00266 private: 00267 DISALLOW_COPY_AND_ASSIGN(ApacheOption); 00268 }; 00269 00270 private: 00273 static Properties* apache_properties_; 00274 00281 template<class RewriteOptionsSubclass, class OptionClass> 00282 static void add_option(typename OptionClass::ValueType default_value, 00283 OptionClass RewriteOptionsSubclass::*offset, 00284 const char* id, 00285 OptionEnum option_enum) { 00286 AddProperty(default_value, offset, id, option_enum, apache_properties_); 00287 } 00288 00289 void InitializeSignaturesAndDefaults(); 00290 static void AddProperties(); 00291 void Init(); 00292 00293 static bool ParseFromString(const GoogleString& value_string, 00294 RefererStatisticsOutputLevel* value) { 00295 return ParseRefererStatisticsOutputLevel(value_string, value); 00296 } 00297 00298 static GoogleString OptionSignature(RefererStatisticsOutputLevel x, 00299 const Hasher* hasher) { 00302 return IntegerToString(x); 00303 } 00304 00305 static GoogleString ToString(RefererStatisticsOutputLevel x) { 00308 return IntegerToString(x); 00309 } 00310 00311 GoogleString description_; 00312 RewriteOptions options_; 00313 00314 Option<GoogleString> fetcher_proxy_; 00315 Option<GoogleString> file_cache_path_; 00316 00319 Option<GoogleString> memcached_servers_; 00320 Option<GoogleString> slurp_directory_; 00321 Option<GoogleString> statistics_logging_file_; 00322 Option<GoogleString> statistics_logging_charts_css_; 00323 Option<GoogleString> statistics_logging_charts_js_; 00324 Option<GoogleString> cache_flush_filename_; 00325 00326 ApacheOption<RefererStatisticsOutputLevel> referer_statistics_output_level_; 00327 00328 Option<bool> collect_referer_statistics_; 00329 Option<bool> hash_referer_statistics_; 00330 Option<bool> statistics_enabled_; 00331 Option<bool> statistics_logging_enabled_; 00332 Option<bool> test_proxy_; 00333 Option<bool> use_shared_mem_locking_; 00334 Option<bool> slurp_read_only_; 00335 Option<bool> rate_limit_background_fetches_; 00336 Option<bool> experimental_fetch_from_mod_spdy_; 00337 00338 Option<int> memcached_threads_; 00339 Option<int> memcached_timeout_us_; 00340 00341 Option<int64> file_cache_clean_inode_limit_; 00342 Option<int64> file_cache_clean_interval_ms_; 00343 Option<int64> file_cache_clean_size_kb_; 00344 Option<int64> lru_cache_byte_limit_; 00345 Option<int64> lru_cache_kb_per_process_; 00346 Option<int64> slurp_flush_limit_; 00347 Option<int64> statistics_logging_interval_ms_; 00350 Option<int64> cache_flush_poll_interval_sec_; 00351 00352 DISALLOW_COPY_AND_ASSIGN(ApacheConfig); 00353 }; 00354 00355 } 00356 00357 #endif ///< NET_INSTAWEB_APACHE_APACHE_CONFIG_H_