Page Speed Optimization Libraries  1.6.29.3
net/instaweb/rewriter/public/test_rewrite_driver_factory.h
Go to the documentation of this file.
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/property_cache.h"
00027 #include "net/instaweb/util/public/scoped_ptr.h"
00028 #include "net/instaweb/util/public/simple_stats.h"
00029 #include "net/instaweb/util/public/string.h"
00030 #include "net/instaweb/util/public/string_util.h"
00031 
00032 namespace net_instaweb {
00033 
00034 class CountingUrlAsyncFetcher;
00035 class DelayCache;
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 NonceGenerator;
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 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                            TestDistributedFetcher* test_distributed_fetcher);
00101   virtual ~TestRewriteDriverFactory();
00102 
00103   DelayCache* delay_cache() { return delay_cache_; }
00104   LRUCache* lru_cache() { return lru_cache_.get(); }
00105   MockTimer* mock_timer() { return mock_timer_; }
00106   MockHasher* mock_hasher() { return mock_hasher_; }
00107   MemFileSystem* mem_file_system() { return mem_file_system_; }
00108   MockUrlFetcher* mock_url_async_fetcher() {
00109     return mock_url_fetcher_;
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   const PropertyCache::Cohort*  SetupCohort(
00191       PropertyCache* cache, const GoogleString& cohort_name);
00192 
00193  protected:
00194   virtual Hasher* NewHasher();
00195   virtual MessageHandler* DefaultHtmlParseMessageHandler();
00196   virtual MessageHandler* DefaultMessageHandler();
00197   virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
00198   virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher();
00199   virtual FileSystem* DefaultFileSystem();
00200   virtual NonceGenerator* DefaultNonceGenerator();
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   MockUrlFetcher* mock_url_fetcher_;
00216   TestDistributedFetcher* test_distributed_fetcher_;
00217   CountingUrlAsyncFetcher* counting_url_async_fetcher_;
00218   CountingUrlAsyncFetcher* counting_distributed_async_fetcher_;
00219   scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_;
00220   scoped_ptr<MockTimeCache> mock_time_cache_;
00221   MemFileSystem* mem_file_system_; 
00222   MockHasher* mock_hasher_;
00223   SimpleStats simple_stats_;
00224   MockMessageHandler* mock_message_handler_;
00225   MockMessageHandler* mock_html_message_handler_;
00226   bool use_beacon_results_in_filters_;
00227   bool use_test_url_namer_;
00228   bool add_platform_specific_decoding_passes_;
00229   std::vector<CreateFilterCallback*> filter_callback_vector_;
00230   std::vector<CreateRewriterCallback*> rewriter_callback_vector_;
00231   std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_;
00232 };
00233 
00234 }  
00235 
00236 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines