Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_rewrite_driver_factory.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
21 
22 #include <vector>
23 
28 #include "net/instaweb/util/public/simple_stats.h"
31 
32 namespace net_instaweb {
33 
34 class CachePropertyStore;
35 class CountingUrlAsyncFetcher;
36 class DelayCache;
37 class FileSystem;
38 class Hasher;
39 class HtmlFilter;
40 class LRUCache;
41 class MemFileSystem;
42 class MessageHandler;
43 class MockHasher;
44 class MockMessageHandler;
45 class MockScheduler;
46 class MockTimer;
47 class MockTimeCache;
48 class MockUrlFetcher;
49 class NonceGenerator;
50 class ProcessContext;
51 class RateControllingUrlAsyncFetcher;
52 class ServerContext;
53 class RewriteDriver;
54 class RewriteFilter;
55 class RewriteOptions;
56 class Scheduler;
57 class Statistics;
58 class TestDistributedFetcher;
59 class ThreadsafeCache;
60 class Timer;
61 class UrlAsyncFetcher;
62 class UrlNamer;
63 class WaitUrlAsyncFetcher;
64 
68  public:
69  static const int64 kStartTimeMs;
70  static const char kUrlNamerScheme[];
71 
75  static const int kMaxFetchGlobalQueueSize = 500;
76  static const int kFetchesPerHostOutgoingRequestThreshold = 100;
77  static const int kFetchesPerHostQueuedRequestThreshold = 500;
78 
80  public:
82  virtual ~CreateFilterCallback();
83  virtual HtmlFilter* Done(RewriteDriver* driver) = 0;
84 
85  private:
86  DISALLOW_COPY_AND_ASSIGN(CreateFilterCallback);
87  };
88 
90  public:
92  virtual ~CreateRewriterCallback();
93  virtual RewriteFilter* Done(RewriteDriver* driver) = 0;
94 
95  private:
96  DISALLOW_COPY_AND_ASSIGN(CreateRewriterCallback);
97  };
98 
100  public:
103  virtual void Done(RewriteDriver* driver) = 0;
104 
105  private:
106  DISALLOW_COPY_AND_ASSIGN(PlatformSpecificConfigurationCallback);
107  };
108 
109  TestRewriteDriverFactory(const ProcessContext& process_context,
110  const StringPiece& temp_dir,
111  MockUrlFetcher* mock_fetcher,
112  TestDistributedFetcher* test_distributed_fetcher);
113  virtual ~TestRewriteDriverFactory();
114 
115  static void InitStats(Statistics* statistics);
116 
117  DelayCache* delay_cache() { return delay_cache_; }
118  LRUCache* lru_cache() { return lru_cache_.get(); }
119  MockTimer* mock_timer() { return mock_timer_; }
120  MockHasher* mock_hasher() { return mock_hasher_; }
121  MemFileSystem* mem_file_system() { return mem_file_system_; }
122  MockUrlFetcher* mock_url_async_fetcher() {
123  return mock_url_fetcher_;
124  }
125  WaitUrlAsyncFetcher* wait_url_async_fetcher() {
126  return wait_url_async_fetcher_.get();
127  }
128  CountingUrlAsyncFetcher* counting_url_async_fetcher() {
129  return counting_url_async_fetcher_.get();
130  }
131  CountingUrlAsyncFetcher* counting_distributed_async_fetcher() {
132  return counting_distributed_async_fetcher_;
133  }
134  MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); }
135 
136  void SetupWaitFetcher();
137  void CallFetcherCallbacksForDriver(RewriteDriver* driver);
138  MockMessageHandler* mock_message_handler() { return mock_message_handler_; }
139  MockScheduler* mock_scheduler() { return mock_scheduler_; }
140  bool use_test_url_namer() const { return use_test_url_namer_; }
141  void SetUseTestUrlNamer(bool x);
142 
145  filter_callback_vector_.push_back(callback);
146  }
147 
148  void ClearFilterCallbackVector() {
149  filter_callback_vector_.clear();
150  }
151 
154  rewriter_callback_vector_.push_back(callback);
155  }
156 
157  void ClearRewriterCallbackVector() {
158  rewriter_callback_vector_.clear();
159  }
160 
162  virtual bool UseBeaconResultsInFilters() const {
163  return use_beacon_results_in_filters_;
164  }
165 
166  void set_use_beacon_results_in_filters(bool b) {
167  use_beacon_results_in_filters_ = b;
168  }
169 
173  platform_config_vector_.push_back(callback);
174  }
175 
176  void ClearPlatformSpecificConfigurationCallback() {
177  platform_config_vector_.clear();
178  }
179 
181  virtual RewriteOptions* NewRewriteOptions();
182 
184  virtual ServerContext* NewServerContext();
185 
186  virtual ServerContext* NewDecodingServerContext();
187 
188  virtual bool IsDebugClient(const GoogleString& ip) const {
189  return ip == "127.0.0.1";
190  }
191 
196  add_platform_specific_decoding_passes_ = value;
197  }
198 
199  bool add_platform_specific_decoding_passes() const {
200  return add_platform_specific_decoding_passes_;
201  }
202 
205 
207  void AdvanceTimeMs(int64 delta_ms);
208 
210  const PropertyCache::Cohort* SetupCohort(
211  PropertyCache* cache, const GoogleString& cohort_name);
212 
213  CachePropertyStore* cache_property_store() {
214  return cache_property_store_;
215  }
216 
217  protected:
218  virtual Hasher* NewHasher();
219  virtual MessageHandler* DefaultHtmlParseMessageHandler();
220  virtual MessageHandler* DefaultMessageHandler();
221  virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
222  virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher();
223  virtual FileSystem* DefaultFileSystem();
224  virtual NonceGenerator* DefaultNonceGenerator();
225  virtual Timer* DefaultTimer();
226  virtual void SetupCaches(ServerContext* server_context);
227  virtual UrlNamer* DefaultUrlNamer();
228  virtual Scheduler* CreateScheduler();
229  virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver);
230  virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver);
231  virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver);
232 
233  private:
234  MockTimer* mock_timer_;
235  MockScheduler* mock_scheduler_;
236  DelayCache* delay_cache_;
237  scoped_ptr<ThreadsafeCache> threadsafe_cache_;
238  scoped_ptr<LRUCache> lru_cache_;
239  MockUrlFetcher* mock_url_fetcher_;
240  TestDistributedFetcher* test_distributed_fetcher_;
241  scoped_ptr<CountingUrlAsyncFetcher> counting_url_async_fetcher_;
242  RateControllingUrlAsyncFetcher* rate_controlling_url_async_fetcher_;
243  CountingUrlAsyncFetcher* counting_distributed_async_fetcher_;
244  scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_;
245  scoped_ptr<MockTimeCache> mock_time_cache_;
246  MemFileSystem* mem_file_system_;
247  MockHasher* mock_hasher_;
248  SimpleStats simple_stats_;
249  MockMessageHandler* mock_message_handler_;
250  MockMessageHandler* mock_html_message_handler_;
251  bool use_beacon_results_in_filters_;
252  bool use_test_url_namer_;
253  bool add_platform_specific_decoding_passes_;
254  std::vector<CreateFilterCallback*> filter_callback_vector_;
255  std::vector<CreateRewriterCallback*> rewriter_callback_vector_;
256  std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_;
257  CachePropertyStore* cache_property_store_;
258 };
259 
260 }
261 
262 #endif
Definition: test_rewrite_driver_factory.h:67
virtual ServerContext * NewServerContext()
Note that this enables html proxying.
static const char kUrlNamerScheme[]
Env.var URL_NAMER_SCHEME.
Definition: test_rewrite_driver_factory.h:70
virtual void ApplyPlatformSpecificConfiguration(RewriteDriver *driver)
virtual void SetupCaches(ServerContext *server_context)
void RebuildDecodingDriverForTests(ServerContext *server_context)
For use in tests.
virtual bool IsDebugClient(const GoogleString &ip) const
Base method that returns true if the given ip is a debug ip.
Definition: test_rewrite_driver_factory.h:188
Definition: test_rewrite_driver_factory.h:79
Definition: test_rewrite_driver_factory.h:89
virtual Scheduler * CreateScheduler()
void AddPlatformSpecificConfigurationCallback(PlatformSpecificConfigurationCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:171
void set_add_platform_specific_decoding_passes(bool value)
Definition: test_rewrite_driver_factory.h:195
virtual void AddPlatformSpecificDecodingPasses(RewriteDriver *driver)
Definition: test_distributed_fetcher.h:37
static const int64 kStartTimeMs
Arbitrary time to start MockTimer.
Definition: test_rewrite_driver_factory.h:69
virtual bool UseBeaconResultsInFilters() const
By default this is false, but can be reset.
Definition: test_rewrite_driver_factory.h:162
virtual void AddPlatformSpecificRewritePasses(RewriteDriver *driver)
Definition: rewrite_filter.h:37
Definition: mock_url_fetcher.h:41
void AddCreateRewriterCallback(CreateRewriterCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:153
Definition: rewrite_driver.h:98
Definition: process_context.h:35
static const int kMaxFetchGlobalQueueSize
Definition: test_rewrite_driver_factory.h:75
Statistics * statistics()
Definition: rewrite_driver_factory.h:242
virtual ServerContext * NewDecodingServerContext()
virtual RewriteOptions * NewRewriteOptions()
Note that this disables ajax rewriting by default.
virtual UrlAsyncFetcher * DefaultAsyncUrlFetcher()
const PropertyCache::Cohort * SetupCohort(PropertyCache *cache, const GoogleString &cohort_name)
Sets up the cohort in the PropertyCache provided.
void AdvanceTimeMs(int64 delta_ms)
Advances the mock scheduler by delta_ms.
void AddCreateFilterCallback(CreateFilterCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:144
Definition: rewrite_driver_factory.h:73