Page Speed Optimization Libraries
1.7.30.2
|
00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_ 00021 00022 #include <vector> 00023 00024 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/property_cache.h" 00027 #include "net/instaweb/util/public/scoped_ptr.h" 00028 #include "net/instaweb/util/public/simple_stats.h" 00029 #include "net/instaweb/util/public/string.h" 00030 #include "net/instaweb/util/public/string_util.h" 00031 00032 namespace net_instaweb { 00033 00034 class CachePropertyStore; 00035 class CountingUrlAsyncFetcher; 00036 class DelayCache; 00037 class FileSystem; 00038 class Hasher; 00039 class HtmlFilter; 00040 class LRUCache; 00041 class MemFileSystem; 00042 class MessageHandler; 00043 class MockHasher; 00044 class MockMessageHandler; 00045 class MockScheduler; 00046 class MockTimer; 00047 class MockTimeCache; 00048 class MockUrlFetcher; 00049 class NonceGenerator; 00050 class RateControllingUrlAsyncFetcher; 00051 class ServerContext; 00052 class RewriteDriver; 00053 class RewriteFilter; 00054 class RewriteOptions; 00055 class Scheduler; 00056 class Statistics; 00057 class TestDistributedFetcher; 00058 class ThreadsafeCache; 00059 class Timer; 00060 class UrlAsyncFetcher; 00061 class UrlNamer; 00062 class WaitUrlAsyncFetcher; 00063 00066 class TestRewriteDriverFactory : public RewriteDriverFactory { 00067 public: 00068 static const int64 kStartTimeMs; 00069 static const char kUrlNamerScheme[]; 00070 00074 static const int kMaxFetchGlobalQueueSize = 500; 00075 static const int kFetchesPerHostOutgoingRequestThreshold = 100; 00076 static const int kFetchesPerHostQueuedRequestThreshold = 500; 00077 00078 class CreateFilterCallback { 00079 public: 00080 CreateFilterCallback() {} 00081 virtual ~CreateFilterCallback(); 00082 virtual HtmlFilter* Done(RewriteDriver* driver) = 0; 00083 00084 private: 00085 DISALLOW_COPY_AND_ASSIGN(CreateFilterCallback); 00086 }; 00087 00088 class CreateRewriterCallback { 00089 public: 00090 CreateRewriterCallback() {} 00091 virtual ~CreateRewriterCallback(); 00092 virtual RewriteFilter* Done(RewriteDriver* driver) = 0; 00093 00094 private: 00095 DISALLOW_COPY_AND_ASSIGN(CreateRewriterCallback); 00096 }; 00097 00098 class PlatformSpecificConfigurationCallback { 00099 public: 00100 PlatformSpecificConfigurationCallback() {} 00101 virtual ~PlatformSpecificConfigurationCallback(); 00102 virtual void Done(RewriteDriver* driver) = 0; 00103 00104 private: 00105 DISALLOW_COPY_AND_ASSIGN(PlatformSpecificConfigurationCallback); 00106 }; 00107 00108 TestRewriteDriverFactory(const StringPiece& temp_dir, 00109 MockUrlFetcher* mock_fetcher, 00110 TestDistributedFetcher* test_distributed_fetcher); 00111 virtual ~TestRewriteDriverFactory(); 00112 00113 static void InitStats(Statistics* statistics); 00114 00115 DelayCache* delay_cache() { return delay_cache_; } 00116 LRUCache* lru_cache() { return lru_cache_.get(); } 00117 MockTimer* mock_timer() { return mock_timer_; } 00118 MockHasher* mock_hasher() { return mock_hasher_; } 00119 MemFileSystem* mem_file_system() { return mem_file_system_; } 00120 MockUrlFetcher* mock_url_async_fetcher() { 00121 return mock_url_fetcher_; 00122 } 00123 WaitUrlAsyncFetcher* wait_url_async_fetcher() { 00124 return wait_url_async_fetcher_.get(); 00125 } 00126 CountingUrlAsyncFetcher* counting_url_async_fetcher() { 00127 return counting_url_async_fetcher_.get(); 00128 } 00129 CountingUrlAsyncFetcher* counting_distributed_async_fetcher() { 00130 return counting_distributed_async_fetcher_; 00131 } 00132 MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); } 00133 00134 void SetupWaitFetcher(); 00135 void CallFetcherCallbacksForDriver(RewriteDriver* driver); 00136 MockMessageHandler* mock_message_handler() { return mock_message_handler_; } 00137 MockScheduler* mock_scheduler() { return mock_scheduler_; } 00138 bool use_test_url_namer() const { return use_test_url_namer_; } 00139 void SetUseTestUrlNamer(bool x); 00140 00142 void AddCreateFilterCallback(CreateFilterCallback* callback) { 00143 filter_callback_vector_.push_back(callback); 00144 } 00145 00146 void ClearFilterCallbackVector() { 00147 filter_callback_vector_.clear(); 00148 } 00149 00151 void AddCreateRewriterCallback(CreateRewriterCallback* callback) { 00152 rewriter_callback_vector_.push_back(callback); 00153 } 00154 00155 void ClearRewriterCallbackVector() { 00156 rewriter_callback_vector_.clear(); 00157 } 00158 00160 virtual bool UseBeaconResultsInFilters() const { 00161 return use_beacon_results_in_filters_; 00162 } 00163 00164 void set_use_beacon_results_in_filters(bool b) { 00165 use_beacon_results_in_filters_ = b; 00166 } 00167 00169 void AddPlatformSpecificConfigurationCallback( 00170 PlatformSpecificConfigurationCallback* callback) { 00171 platform_config_vector_.push_back(callback); 00172 } 00173 00174 void ClearPlatformSpecificConfigurationCallback() { 00175 platform_config_vector_.clear(); 00176 } 00177 00179 virtual RewriteOptions* NewRewriteOptions(); 00180 00182 virtual ServerContext* NewServerContext(); 00183 00184 virtual bool IsDebugClient(const GoogleString& ip) const { 00185 return ip == "127.0.0.1"; 00186 } 00187 00190 void set_add_platform_specific_decoding_passes(bool value) { 00191 add_platform_specific_decoding_passes_ = value; 00192 } 00193 00194 bool add_platform_specific_decoding_passes() const { 00195 return add_platform_specific_decoding_passes_; 00196 } 00197 00199 void AdvanceTimeMs(int64 delta_ms); 00200 00202 const PropertyCache::Cohort* SetupCohort( 00203 PropertyCache* cache, const GoogleString& cohort_name); 00204 00205 CachePropertyStore* cache_property_store() { 00206 return cache_property_store_; 00207 } 00208 00209 protected: 00210 virtual Hasher* NewHasher(); 00211 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00212 virtual MessageHandler* DefaultMessageHandler(); 00213 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00214 virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher(); 00215 virtual FileSystem* DefaultFileSystem(); 00216 virtual NonceGenerator* DefaultNonceGenerator(); 00217 virtual Timer* DefaultTimer(); 00218 virtual void SetupCaches(ServerContext* server_context); 00219 virtual UrlNamer* DefaultUrlNamer(); 00220 virtual Scheduler* CreateScheduler(); 00221 virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver); 00222 virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver); 00223 virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver); 00224 00225 private: 00226 MockTimer* mock_timer_; 00227 MockScheduler* mock_scheduler_; 00228 DelayCache* delay_cache_; 00229 scoped_ptr<ThreadsafeCache> threadsafe_cache_; 00230 scoped_ptr<LRUCache> lru_cache_; 00231 MockUrlFetcher* mock_url_fetcher_; 00232 TestDistributedFetcher* test_distributed_fetcher_; 00233 scoped_ptr<CountingUrlAsyncFetcher> counting_url_async_fetcher_; 00234 RateControllingUrlAsyncFetcher* rate_controlling_url_async_fetcher_; 00235 CountingUrlAsyncFetcher* counting_distributed_async_fetcher_; 00236 scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_; 00237 scoped_ptr<MockTimeCache> mock_time_cache_; 00238 MemFileSystem* mem_file_system_; 00239 MockHasher* mock_hasher_; 00240 SimpleStats simple_stats_; 00241 MockMessageHandler* mock_message_handler_; 00242 MockMessageHandler* mock_html_message_handler_; 00243 bool use_beacon_results_in_filters_; 00244 bool use_test_url_namer_; 00245 bool add_platform_specific_decoding_passes_; 00246 std::vector<CreateFilterCallback*> filter_callback_vector_; 00247 std::vector<CreateRewriterCallback*> rewriter_callback_vector_; 00248 std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_; 00249 CachePropertyStore* cache_property_store_; 00250 }; 00251 00252 } 00253 00254 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_