Page Speed Optimization Libraries
1.4.26.1
|
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/scoped_ptr.h" 00027 #include "net/instaweb/util/public/simple_stats.h" 00028 #include "net/instaweb/util/public/string.h" 00029 #include "net/instaweb/util/public/string_util.h" 00030 00031 namespace net_instaweb { 00032 00033 class CountingUrlAsyncFetcher; 00034 class DelayCache; 00035 class FakeUrlAsyncFetcher; 00036 class FileSystem; 00037 class Hasher; 00038 class HtmlFilter; 00039 class LRUCache; 00040 class MemFileSystem; 00041 class MessageHandler; 00042 class MockHasher; 00043 class MockMessageHandler; 00044 class MockScheduler; 00045 class MockTimer; 00046 class MockTimeCache; 00047 class MockUrlFetcher; 00048 class PropertyCache; 00049 class ServerContext; 00050 class RewriteDriver; 00051 class RewriteFilter; 00052 class RewriteOptions; 00053 class Scheduler; 00054 class ThreadsafeCache; 00055 class Timer; 00056 class UrlAsyncFetcher; 00057 class UrlFetcher; 00058 class UrlNamer; 00059 class WaitUrlAsyncFetcher; 00060 00063 class TestRewriteDriverFactory : public RewriteDriverFactory { 00064 public: 00065 static const int64 kStartTimeMs; 00066 static const char kUrlNamerScheme[]; 00067 00068 class CreateFilterCallback { 00069 public: 00070 CreateFilterCallback() {} 00071 virtual ~CreateFilterCallback(); 00072 virtual HtmlFilter* Done(RewriteDriver* driver) = 0; 00073 00074 private: 00075 DISALLOW_COPY_AND_ASSIGN(CreateFilterCallback); 00076 }; 00077 00078 class CreateRewriterCallback { 00079 public: 00080 CreateRewriterCallback() {} 00081 virtual ~CreateRewriterCallback(); 00082 virtual RewriteFilter* Done(RewriteDriver* driver) = 0; 00083 00084 private: 00085 DISALLOW_COPY_AND_ASSIGN(CreateRewriterCallback); 00086 }; 00087 00088 class PlatformSpecificConfigurationCallback { 00089 public: 00090 PlatformSpecificConfigurationCallback() {} 00091 virtual ~PlatformSpecificConfigurationCallback(); 00092 virtual void Done(RewriteDriver* driver) = 0; 00093 00094 private: 00095 DISALLOW_COPY_AND_ASSIGN(PlatformSpecificConfigurationCallback); 00096 }; 00097 00098 TestRewriteDriverFactory(const StringPiece& temp_dir, 00099 MockUrlFetcher* mock_fetcher, 00100 MockUrlFetcher* mock_distributed_fetcher); 00101 virtual ~TestRewriteDriverFactory(); 00102 00103 DelayCache* delay_cache() { return delay_cache_; } 00104 LRUCache* lru_cache() { return lru_cache_; } 00105 MockTimer* mock_timer() { return mock_timer_; } 00106 MockHasher* mock_hasher() { return mock_hasher_; } 00107 MemFileSystem* mem_file_system() { return mem_file_system_; } 00108 FakeUrlAsyncFetcher* mock_url_async_fetcher() { 00109 return mock_url_async_fetcher_.get(); 00110 } 00111 WaitUrlAsyncFetcher* wait_url_async_fetcher() { 00112 return wait_url_async_fetcher_.get(); 00113 } 00114 CountingUrlAsyncFetcher* counting_url_async_fetcher() { 00115 return counting_url_async_fetcher_; 00116 } 00117 CountingUrlAsyncFetcher* counting_distributed_async_fetcher() { 00118 return counting_distributed_async_fetcher_; 00119 } 00120 MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); } 00121 00122 void SetupWaitFetcher(); 00123 void CallFetcherCallbacksForDriver(RewriteDriver* driver); 00124 MockMessageHandler* mock_message_handler() { return mock_message_handler_; } 00125 MockScheduler* mock_scheduler() { return mock_scheduler_; } 00126 bool use_test_url_namer() const { return use_test_url_namer_; } 00127 void SetUseTestUrlNamer(bool x); 00128 00130 void AddCreateFilterCallback(CreateFilterCallback* callback) { 00131 filter_callback_vector_.push_back(callback); 00132 } 00133 00134 void ClearFilterCallbackVector() { 00135 filter_callback_vector_.clear(); 00136 } 00137 00139 void AddCreateRewriterCallback(CreateRewriterCallback* callback) { 00140 rewriter_callback_vector_.push_back(callback); 00141 } 00142 00143 void ClearRewriterCallbackVector() { 00144 rewriter_callback_vector_.clear(); 00145 } 00146 00148 virtual bool UseBeaconResultsInFilters() const { 00149 return use_beacon_results_in_filters_; 00150 } 00151 00152 void set_use_beacon_results_in_filters(bool b) { 00153 use_beacon_results_in_filters_ = b; 00154 } 00155 00157 void AddPlatformSpecificConfigurationCallback( 00158 PlatformSpecificConfigurationCallback* callback) { 00159 platform_config_vector_.push_back(callback); 00160 } 00161 00162 void ClearPlatformSpecificConfigurationCallback() { 00163 platform_config_vector_.clear(); 00164 } 00165 00167 virtual RewriteOptions* NewRewriteOptions(); 00168 00170 virtual ServerContext* NewServerContext(); 00171 00172 virtual bool IsDebugClient(const GoogleString& ip) const { 00173 return ip == "127.0.0.1"; 00174 } 00175 00178 void set_add_platform_specific_decoding_passes(bool value) { 00179 add_platform_specific_decoding_passes_ = value; 00180 } 00181 00182 bool add_platform_specific_decoding_passes() const { 00183 return add_platform_specific_decoding_passes_; 00184 } 00185 00187 void AdvanceTimeMs(int64 delta_ms); 00188 00190 void SetupCohort(PropertyCache* cache, const GoogleString& cohort_name); 00191 00192 protected: 00193 virtual Hasher* NewHasher(); 00194 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00195 virtual MessageHandler* DefaultMessageHandler(); 00196 virtual UrlFetcher* DefaultUrlFetcher(); 00197 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00198 virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher(); 00199 virtual FileSystem* DefaultFileSystem(); 00200 virtual Timer* DefaultTimer(); 00201 virtual void SetupCaches(ServerContext* resource_manager); 00202 virtual UrlNamer* DefaultUrlNamer(); 00203 virtual Scheduler* CreateScheduler(); 00204 virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver); 00205 virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver); 00206 virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver); 00207 00208 private: 00209 MockTimer* mock_timer_; 00210 MockScheduler* mock_scheduler_; 00211 DelayCache* delay_cache_; 00212 scoped_ptr<ThreadsafeCache> threadsafe_cache_; 00213 LRUCache* lru_cache_; 00214 UrlFetcher* proxy_url_fetcher_; 00215 MockUrlFetcher* mock_url_fetcher_; 00216 MockUrlFetcher* mock_distributed_fetcher_; 00217 scoped_ptr<FakeUrlAsyncFetcher> mock_url_async_fetcher_; 00218 scoped_ptr<FakeUrlAsyncFetcher> mock_distributed_async_fetcher_; 00219 CountingUrlAsyncFetcher* counting_url_async_fetcher_; 00220 CountingUrlAsyncFetcher* counting_distributed_async_fetcher_; 00221 scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_; 00222 scoped_ptr<MockTimeCache> mock_time_cache_; 00223 MemFileSystem* mem_file_system_; 00224 MockHasher* mock_hasher_; 00225 SimpleStats simple_stats_; 00226 MockMessageHandler* mock_message_handler_; 00227 MockMessageHandler* mock_html_message_handler_; 00228 bool use_beacon_results_in_filters_; 00229 bool use_test_url_namer_; 00230 bool add_platform_specific_decoding_passes_; 00231 std::vector<CreateFilterCallback*> filter_callback_vector_; 00232 std::vector<CreateRewriterCallback*> rewriter_callback_vector_; 00233 std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_; 00234 }; 00235 00236 } 00237 00238 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_