Page Speed Optimization Libraries
1.3.25.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 virtual ~TestRewriteDriverFactory(); 00101 00102 DelayCache* delay_cache() { return delay_cache_; } 00103 LRUCache* lru_cache() { return lru_cache_; } 00104 MockTimer* mock_timer() { return mock_timer_; } 00105 MockHasher* mock_hasher() { return mock_hasher_; } 00106 MemFileSystem* mem_file_system() { return mem_file_system_; } 00107 FakeUrlAsyncFetcher* mock_url_async_fetcher() { 00108 return mock_url_async_fetcher_.get(); 00109 } 00110 WaitUrlAsyncFetcher* wait_url_async_fetcher() { 00111 return wait_url_async_fetcher_.get(); 00112 } 00113 CountingUrlAsyncFetcher* counting_url_async_fetcher() { 00114 return counting_url_async_fetcher_; 00115 } 00116 MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); } 00117 00118 void SetupWaitFetcher(); 00119 void CallFetcherCallbacksForDriver(RewriteDriver* driver); 00120 MockMessageHandler* mock_message_handler() { return mock_message_handler_; } 00121 MockScheduler* mock_scheduler() { return mock_scheduler_; } 00122 bool use_test_url_namer() const { return use_test_url_namer_; } 00123 void SetUseTestUrlNamer(bool x); 00124 00126 void AddCreateFilterCallback(CreateFilterCallback* callback) { 00127 filter_callback_vector_.push_back(callback); 00128 } 00129 00130 void ClearFilterCallbackVector() { 00131 filter_callback_vector_.clear(); 00132 } 00133 00135 void AddCreateRewriterCallback(CreateRewriterCallback* callback) { 00136 rewriter_callback_vector_.push_back(callback); 00137 } 00138 00139 void ClearRewriterCallbackVector() { 00140 rewriter_callback_vector_.clear(); 00141 } 00142 00144 void AddPlatformSpecificConfigurationCallback( 00145 PlatformSpecificConfigurationCallback* callback) { 00146 platform_config_vector_.push_back(callback); 00147 } 00148 00149 void ClearPlatformSpecificConfigurationCallback() { 00150 platform_config_vector_.clear(); 00151 } 00152 00154 virtual RewriteOptions* NewRewriteOptions(); 00155 00156 virtual bool IsDebugClient(const GoogleString& ip) const { 00157 return ip == "127.0.0.1"; 00158 } 00159 00162 void set_add_platform_specific_decoding_passes(bool value) { 00163 add_platform_specific_decoding_passes_ = value; 00164 } 00165 00166 bool add_platform_specific_decoding_passes() const { 00167 return add_platform_specific_decoding_passes_; 00168 } 00169 00171 void AdvanceTimeMs(int64 delta_ms); 00172 00174 void SetupCohort(PropertyCache* cache, const GoogleString& cohort_name); 00175 00176 protected: 00177 virtual Hasher* NewHasher(); 00178 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00179 virtual MessageHandler* DefaultMessageHandler(); 00180 virtual UrlFetcher* DefaultUrlFetcher(); 00181 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00182 virtual FileSystem* DefaultFileSystem(); 00183 virtual Timer* DefaultTimer(); 00184 virtual void SetupCaches(ServerContext* resource_manager); 00185 virtual UrlNamer* DefaultUrlNamer(); 00186 virtual Scheduler* CreateScheduler(); 00187 virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver); 00188 virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver); 00189 virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver); 00190 00191 private: 00192 MockTimer* mock_timer_; 00193 MockScheduler* mock_scheduler_; 00194 DelayCache* delay_cache_; 00195 scoped_ptr<ThreadsafeCache> threadsafe_cache_; 00196 LRUCache* lru_cache_; 00197 UrlFetcher* proxy_url_fetcher_; 00198 MockUrlFetcher* mock_url_fetcher_; 00199 scoped_ptr<FakeUrlAsyncFetcher> mock_url_async_fetcher_; 00200 CountingUrlAsyncFetcher* counting_url_async_fetcher_; 00201 scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_; 00202 scoped_ptr<MockTimeCache> mock_time_cache_; 00203 MemFileSystem* mem_file_system_; 00204 MockHasher* mock_hasher_; 00205 SimpleStats simple_stats_; 00206 MockMessageHandler* mock_message_handler_; 00207 MockMessageHandler* mock_html_message_handler_; 00208 bool use_test_url_namer_; 00209 bool add_platform_specific_decoding_passes_; 00210 std::vector<CreateFilterCallback*> filter_callback_vector_; 00211 std::vector<CreateRewriterCallback*> rewriter_callback_vector_; 00212 std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_; 00213 }; 00214 00215 } 00216 00217 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_