Page Speed Optimization Libraries  1.13.35.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 
25 #include "net/instaweb/util/public/property_cache.h"
32 
33 namespace net_instaweb {
34 
35 class CachePropertyStore;
36 class CountingUrlAsyncFetcher;
37 class DelayCache;
38 class FileSystem;
39 class Hasher;
40 class HtmlFilter;
41 class LRUCache;
42 class MemFileSystem;
43 class MessageHandler;
44 class MockHasher;
45 class MockMessageHandler;
46 class MockScheduler;
47 class MockTimer;
48 class MockTimeCache;
49 class MockUrlFetcher;
50 class NamedLockManager;
51 class NonceGenerator;
52 class ProcessContext;
53 class RateControllingUrlAsyncFetcher;
54 class ServerContext;
55 class RewriteDriver;
56 class RewriteFilter;
57 class RewriteOptions;
58 class Scheduler;
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 
87  };
88 
90  public:
92  virtual ~CreateRewriterCallback();
93  virtual RewriteFilter* Done(RewriteDriver* driver) = 0;
94 
95  private:
96 
97  };
98 
100  public:
103  virtual void Done(RewriteDriver* driver) = 0;
104 
105  private:
106 
107  };
108 
109  TestRewriteDriverFactory(const ProcessContext& process_context,
110  const StringPiece& temp_dir,
111  MockUrlFetcher* mock_fetcher);
112  virtual ~TestRewriteDriverFactory();
113 
114  static void InitStats(Statistics* statistics);
115 
116  DelayCache* delay_cache() { return delay_cache_; }
117  LRUCache* lru_cache() { return lru_cache_.get(); }
118  MockTimer* mock_timer() { return mock_timer_; }
119  MockHasher* mock_hasher() { return mock_hasher_; }
120  MemFileSystem* mem_file_system() { return mem_file_system_; }
121  MockUrlFetcher* mock_url_async_fetcher() {
122  return mock_url_fetcher_;
123  }
124  WaitUrlAsyncFetcher* wait_url_async_fetcher() {
125  return wait_url_async_fetcher_.get();
126  }
127  CountingUrlAsyncFetcher* counting_url_async_fetcher() {
128  return counting_url_async_fetcher_.get();
129  }
130  MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); }
131 
132  void SetupWaitFetcher();
133  void CallFetcherCallbacksForDriver(RewriteDriver* driver);
134  MockMessageHandler* mock_message_handler() { return mock_message_handler_; }
135  MockScheduler* mock_scheduler() { return mock_scheduler_; }
136  bool use_test_url_namer() const { return use_test_url_namer_; }
137  void SetUseTestUrlNamer(bool x);
138 
141  filter_callback_vector_.push_back(callback);
142  }
143 
144  void ClearFilterCallbackVector() {
145  filter_callback_vector_.clear();
146  }
147 
150  rewriter_callback_vector_.push_back(callback);
151  }
152 
153  void ClearRewriterCallbackVector() {
154  rewriter_callback_vector_.clear();
155  }
156 
158  virtual bool UseBeaconResultsInFilters() const {
159  return use_beacon_results_in_filters_;
160  }
161 
162  void set_use_beacon_results_in_filters(bool b) {
163  use_beacon_results_in_filters_ = b;
164  }
165 
169  platform_config_vector_.push_back(callback);
170  }
171 
172  void ClearPlatformSpecificConfigurationCallback() {
173  platform_config_vector_.clear();
174  }
175 
177  virtual RewriteOptions* NewRewriteOptions();
178 
180  virtual ServerContext* NewServerContext();
181 
182  virtual ServerContext* NewDecodingServerContext();
183 
184  virtual bool IsDebugClient(const GoogleString& ip) const {
185  return ip == "127.0.0.1";
186  }
187 
192  add_platform_specific_decoding_passes_ = value;
193  }
194 
195  bool add_platform_specific_decoding_passes() const {
196  return add_platform_specific_decoding_passes_;
197  }
198 
201 
203  void AdvanceTimeMs(int64 delta_ms);
204 
206  const PropertyCache::Cohort* SetupCohort(
207  PropertyCache* cache, const GoogleString& cohort_name);
208 
209  CachePropertyStore* cache_property_store() {
210  return cache_property_store_;
211  }
212 
213  protected:
214  virtual Hasher* NewHasher();
215  virtual MessageHandler* DefaultHtmlParseMessageHandler();
216  virtual MessageHandler* DefaultMessageHandler();
217  virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
218  virtual FileSystem* DefaultFileSystem();
219  virtual NonceGenerator* DefaultNonceGenerator();
220  virtual Timer* DefaultTimer();
221  virtual void SetupCaches(ServerContext* server_context);
222  virtual UrlNamer* DefaultUrlNamer();
223  virtual Scheduler* CreateScheduler();
224  virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver);
225  virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver);
226  virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver);
227  virtual NamedLockManager* DefaultLockManager();
228 
229  private:
230  MockTimer* mock_timer_;
231  MockScheduler* mock_scheduler_;
232  DelayCache* delay_cache_;
233  scoped_ptr<ThreadsafeCache> threadsafe_cache_;
234  scoped_ptr<LRUCache> lru_cache_;
235  MockUrlFetcher* mock_url_fetcher_;
236  scoped_ptr<CountingUrlAsyncFetcher> counting_url_async_fetcher_;
237  RateControllingUrlAsyncFetcher* rate_controlling_url_async_fetcher_;
238  scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_;
239  scoped_ptr<MockTimeCache> mock_time_cache_;
240  MemFileSystem* mem_file_system_;
241  MockHasher* mock_hasher_;
242  SimpleStats simple_stats_;
243  MockMessageHandler* mock_message_handler_;
244  MockMessageHandler* mock_html_message_handler_;
245  bool use_beacon_results_in_filters_;
246  bool use_test_url_namer_;
247  bool add_platform_specific_decoding_passes_;
248  std::vector<CreateFilterCallback*> filter_callback_vector_;
249  std::vector<CreateRewriterCallback*> rewriter_callback_vector_;
250  std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_;
251  CachePropertyStore* cache_property_store_;
252 };
253 
254 }
255 
256 #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
Definition: html_filter.h:35
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:184
See file comment.
Definition: delay_cache.h:47
Definition: test_rewrite_driver_factory.h:79
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
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:167
virtual NamedLockManager * DefaultLockManager()
void set_add_platform_specific_decoding_passes(bool value)
Definition: test_rewrite_driver_factory.h:191
virtual void AddPlatformSpecificDecodingPasses(RewriteDriver *driver)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static const int64 kStartTimeMs
Arbitrary time to start MockTimer.
Definition: test_rewrite_driver_factory.h:69
Definition: lru_cache.h:44
virtual bool UseBeaconResultsInFilters() const
By default this is false, but can be reset.
Definition: test_rewrite_driver_factory.h:158
virtual void AddPlatformSpecificRewritePasses(RewriteDriver *driver)
Definition: rewrite_filter.h:35
Definition: mock_url_fetcher.h:41
void AddCreateRewriterCallback(CreateRewriterCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:149
Definition: rewrite_driver.h:100
Definition: process_context.h:35
static const int kMaxFetchGlobalQueueSize
Definition: test_rewrite_driver_factory.h:75
Statistics * statistics()
Definition: rewrite_driver_factory.h:247
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:140
Definition: rewrite_driver_factory.h:70