Page Speed Optimization Libraries
1.5.27.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/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 TestDistributedFetcher; 00055 class ThreadsafeCache; 00056 class Timer; 00057 class UrlAsyncFetcher; 00058 class UrlFetcher; 00059 class UrlNamer; 00060 class WaitUrlAsyncFetcher; 00061 00064 class TestRewriteDriverFactory : public RewriteDriverFactory { 00065 public: 00066 static const int64 kStartTimeMs; 00067 static const char kUrlNamerScheme[]; 00068 00069 class CreateFilterCallback { 00070 public: 00071 CreateFilterCallback() {} 00072 virtual ~CreateFilterCallback(); 00073 virtual HtmlFilter* Done(RewriteDriver* driver) = 0; 00074 00075 private: 00076 DISALLOW_COPY_AND_ASSIGN(CreateFilterCallback); 00077 }; 00078 00079 class CreateRewriterCallback { 00080 public: 00081 CreateRewriterCallback() {} 00082 virtual ~CreateRewriterCallback(); 00083 virtual RewriteFilter* Done(RewriteDriver* driver) = 0; 00084 00085 private: 00086 DISALLOW_COPY_AND_ASSIGN(CreateRewriterCallback); 00087 }; 00088 00089 class PlatformSpecificConfigurationCallback { 00090 public: 00091 PlatformSpecificConfigurationCallback() {} 00092 virtual ~PlatformSpecificConfigurationCallback(); 00093 virtual void Done(RewriteDriver* driver) = 0; 00094 00095 private: 00096 DISALLOW_COPY_AND_ASSIGN(PlatformSpecificConfigurationCallback); 00097 }; 00098 00099 TestRewriteDriverFactory(const StringPiece& temp_dir, 00100 MockUrlFetcher* mock_fetcher, 00101 TestDistributedFetcher* test_distributed_fetcher); 00102 virtual ~TestRewriteDriverFactory(); 00103 00104 DelayCache* delay_cache() { return delay_cache_; } 00105 LRUCache* lru_cache() { return lru_cache_.get(); } 00106 MockTimer* mock_timer() { return mock_timer_; } 00107 MockHasher* mock_hasher() { return mock_hasher_; } 00108 MemFileSystem* mem_file_system() { return mem_file_system_; } 00109 FakeUrlAsyncFetcher* mock_url_async_fetcher() { 00110 return mock_url_async_fetcher_.get(); 00111 } 00112 WaitUrlAsyncFetcher* wait_url_async_fetcher() { 00113 return wait_url_async_fetcher_.get(); 00114 } 00115 CountingUrlAsyncFetcher* counting_url_async_fetcher() { 00116 return counting_url_async_fetcher_; 00117 } 00118 CountingUrlAsyncFetcher* counting_distributed_async_fetcher() { 00119 return counting_distributed_async_fetcher_; 00120 } 00121 MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); } 00122 00123 void SetupWaitFetcher(); 00124 void CallFetcherCallbacksForDriver(RewriteDriver* driver); 00125 MockMessageHandler* mock_message_handler() { return mock_message_handler_; } 00126 MockScheduler* mock_scheduler() { return mock_scheduler_; } 00127 bool use_test_url_namer() const { return use_test_url_namer_; } 00128 void SetUseTestUrlNamer(bool x); 00129 00131 void AddCreateFilterCallback(CreateFilterCallback* callback) { 00132 filter_callback_vector_.push_back(callback); 00133 } 00134 00135 void ClearFilterCallbackVector() { 00136 filter_callback_vector_.clear(); 00137 } 00138 00140 void AddCreateRewriterCallback(CreateRewriterCallback* callback) { 00141 rewriter_callback_vector_.push_back(callback); 00142 } 00143 00144 void ClearRewriterCallbackVector() { 00145 rewriter_callback_vector_.clear(); 00146 } 00147 00149 virtual bool UseBeaconResultsInFilters() const { 00150 return use_beacon_results_in_filters_; 00151 } 00152 00153 void set_use_beacon_results_in_filters(bool b) { 00154 use_beacon_results_in_filters_ = b; 00155 } 00156 00158 void AddPlatformSpecificConfigurationCallback( 00159 PlatformSpecificConfigurationCallback* callback) { 00160 platform_config_vector_.push_back(callback); 00161 } 00162 00163 void ClearPlatformSpecificConfigurationCallback() { 00164 platform_config_vector_.clear(); 00165 } 00166 00168 virtual RewriteOptions* NewRewriteOptions(); 00169 00171 virtual ServerContext* NewServerContext(); 00172 00173 virtual bool IsDebugClient(const GoogleString& ip) const { 00174 return ip == "127.0.0.1"; 00175 } 00176 00179 void set_add_platform_specific_decoding_passes(bool value) { 00180 add_platform_specific_decoding_passes_ = value; 00181 } 00182 00183 bool add_platform_specific_decoding_passes() const { 00184 return add_platform_specific_decoding_passes_; 00185 } 00186 00188 void AdvanceTimeMs(int64 delta_ms); 00189 00191 void SetupCohort(PropertyCache* cache, const GoogleString& cohort_name); 00192 00193 protected: 00194 virtual Hasher* NewHasher(); 00195 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00196 virtual MessageHandler* DefaultMessageHandler(); 00197 virtual UrlFetcher* DefaultUrlFetcher(); 00198 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00199 virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher(); 00200 virtual FileSystem* DefaultFileSystem(); 00201 virtual Timer* DefaultTimer(); 00202 virtual void SetupCaches(ServerContext* server_context); 00203 virtual UrlNamer* DefaultUrlNamer(); 00204 virtual Scheduler* CreateScheduler(); 00205 virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver); 00206 virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver); 00207 virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver); 00208 00209 private: 00210 MockTimer* mock_timer_; 00211 MockScheduler* mock_scheduler_; 00212 DelayCache* delay_cache_; 00213 scoped_ptr<ThreadsafeCache> threadsafe_cache_; 00214 scoped_ptr<LRUCache> lru_cache_; 00215 UrlFetcher* proxy_url_fetcher_; 00216 MockUrlFetcher* mock_url_fetcher_; 00217 TestDistributedFetcher* test_distributed_fetcher_; 00218 scoped_ptr<FakeUrlAsyncFetcher> mock_url_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_