Page Speed Optimization Libraries  1.8.31.2
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 CachePropertyStore;
00035 class CountingUrlAsyncFetcher;
00036 class DelayCache;
00037 class FileSystem;
00038 class Hasher;
00039 class HtmlFilter;
00040 class LRUCache;
00041 class MemFileSystem;
00042 class MessageHandler;
00043 class MockHasher;
00044 class MockMessageHandler;
00045 class MockScheduler;
00046 class MockTimer;
00047 class MockTimeCache;
00048 class MockUrlFetcher;
00049 class NonceGenerator;
00050 class ProcessContext;
00051 class RateControllingUrlAsyncFetcher;
00052 class ServerContext;
00053 class RewriteDriver;
00054 class RewriteFilter;
00055 class RewriteOptions;
00056 class Scheduler;
00057 class Statistics;
00058 class TestDistributedFetcher;
00059 class ThreadsafeCache;
00060 class Timer;
00061 class UrlAsyncFetcher;
00062 class UrlNamer;
00063 class WaitUrlAsyncFetcher;
00064 
00067 class TestRewriteDriverFactory : public RewriteDriverFactory {
00068  public:
00069   static const int64 kStartTimeMs; 
00070   static const char kUrlNamerScheme[]; 
00071 
00075   static const int kMaxFetchGlobalQueueSize = 500;
00076   static const int kFetchesPerHostOutgoingRequestThreshold = 100;
00077   static const int kFetchesPerHostQueuedRequestThreshold = 500;
00078 
00079   class CreateFilterCallback {
00080    public:
00081     CreateFilterCallback() {}
00082     virtual ~CreateFilterCallback();
00083     virtual HtmlFilter* Done(RewriteDriver* driver) = 0;
00084 
00085    private:
00086     DISALLOW_COPY_AND_ASSIGN(CreateFilterCallback);
00087   };
00088 
00089   class CreateRewriterCallback {
00090    public:
00091     CreateRewriterCallback() {}
00092     virtual ~CreateRewriterCallback();
00093     virtual RewriteFilter* Done(RewriteDriver* driver) = 0;
00094 
00095    private:
00096     DISALLOW_COPY_AND_ASSIGN(CreateRewriterCallback);
00097   };
00098 
00099   class PlatformSpecificConfigurationCallback {
00100    public:
00101     PlatformSpecificConfigurationCallback() {}
00102     virtual ~PlatformSpecificConfigurationCallback();
00103     virtual void Done(RewriteDriver* driver) = 0;
00104 
00105    private:
00106     DISALLOW_COPY_AND_ASSIGN(PlatformSpecificConfigurationCallback);
00107   };
00108 
00109   TestRewriteDriverFactory(const ProcessContext& process_context,
00110                            const StringPiece& temp_dir,
00111                            MockUrlFetcher* mock_fetcher,
00112                            TestDistributedFetcher* test_distributed_fetcher);
00113   virtual ~TestRewriteDriverFactory();
00114 
00115   static void InitStats(Statistics* statistics);
00116 
00117   DelayCache* delay_cache() { return delay_cache_; }
00118   LRUCache* lru_cache() { return lru_cache_.get(); }
00119   MockTimer* mock_timer() { return mock_timer_; }
00120   MockHasher* mock_hasher() { return mock_hasher_; }
00121   MemFileSystem* mem_file_system() { return mem_file_system_; }
00122   MockUrlFetcher* mock_url_async_fetcher() {
00123     return mock_url_fetcher_;
00124   }
00125   WaitUrlAsyncFetcher* wait_url_async_fetcher() {
00126     return wait_url_async_fetcher_.get();
00127   }
00128   CountingUrlAsyncFetcher* counting_url_async_fetcher() {
00129     return counting_url_async_fetcher_.get();
00130   }
00131   CountingUrlAsyncFetcher* counting_distributed_async_fetcher() {
00132     return counting_distributed_async_fetcher_;
00133   }
00134   MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); }
00135 
00136   void SetupWaitFetcher();
00137   void CallFetcherCallbacksForDriver(RewriteDriver* driver);
00138   MockMessageHandler* mock_message_handler() { return mock_message_handler_; }
00139   MockScheduler* mock_scheduler() { return mock_scheduler_; }
00140   bool use_test_url_namer() const { return use_test_url_namer_; }
00141   void SetUseTestUrlNamer(bool x);
00142 
00144   void AddCreateFilterCallback(CreateFilterCallback* callback) {
00145     filter_callback_vector_.push_back(callback);
00146   }
00147 
00148   void ClearFilterCallbackVector() {
00149     filter_callback_vector_.clear();
00150   }
00151 
00153   void AddCreateRewriterCallback(CreateRewriterCallback* callback) {
00154     rewriter_callback_vector_.push_back(callback);
00155   }
00156 
00157   void ClearRewriterCallbackVector() {
00158     rewriter_callback_vector_.clear();
00159   }
00160 
00162   virtual bool UseBeaconResultsInFilters() const {
00163     return use_beacon_results_in_filters_;
00164   }
00165 
00166   void set_use_beacon_results_in_filters(bool b) {
00167     use_beacon_results_in_filters_ = b;
00168   }
00169 
00171   void AddPlatformSpecificConfigurationCallback(
00172       PlatformSpecificConfigurationCallback* callback) {
00173     platform_config_vector_.push_back(callback);
00174   }
00175 
00176   void ClearPlatformSpecificConfigurationCallback() {
00177     platform_config_vector_.clear();
00178   }
00179 
00181   virtual RewriteOptions* NewRewriteOptions();
00182 
00184   virtual ServerContext* NewServerContext();
00185 
00186   virtual ServerContext* NewDecodingServerContext();
00187 
00188   virtual bool IsDebugClient(const GoogleString& ip) const {
00189     return ip == "127.0.0.1";
00190   }
00191 
00195   void set_add_platform_specific_decoding_passes(bool value) {
00196     add_platform_specific_decoding_passes_ = value;
00197   }
00198 
00199   bool add_platform_specific_decoding_passes() const {
00200     return add_platform_specific_decoding_passes_;
00201   }
00202 
00204   using RewriteDriverFactory::RebuildDecodingDriverForTests;
00205 
00207   void AdvanceTimeMs(int64 delta_ms);
00208 
00210   const PropertyCache::Cohort*  SetupCohort(
00211       PropertyCache* cache, const GoogleString& cohort_name);
00212 
00213   CachePropertyStore* cache_property_store() {
00214     return cache_property_store_;
00215   }
00216 
00217  protected:
00218   virtual Hasher* NewHasher();
00219   virtual MessageHandler* DefaultHtmlParseMessageHandler();
00220   virtual MessageHandler* DefaultMessageHandler();
00221   virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
00222   virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher();
00223   virtual FileSystem* DefaultFileSystem();
00224   virtual NonceGenerator* DefaultNonceGenerator();
00225   virtual Timer* DefaultTimer();
00226   virtual void SetupCaches(ServerContext* server_context);
00227   virtual UrlNamer* DefaultUrlNamer();
00228   virtual Scheduler* CreateScheduler();
00229   virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver);
00230   virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver);
00231   virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver);
00232 
00233  private:
00234   MockTimer* mock_timer_; 
00235   MockScheduler* mock_scheduler_; 
00236   DelayCache* delay_cache_;
00237   scoped_ptr<ThreadsafeCache> threadsafe_cache_;
00238   scoped_ptr<LRUCache> lru_cache_;
00239   MockUrlFetcher* mock_url_fetcher_;
00240   TestDistributedFetcher* test_distributed_fetcher_;
00241   scoped_ptr<CountingUrlAsyncFetcher> counting_url_async_fetcher_;
00242   RateControllingUrlAsyncFetcher* rate_controlling_url_async_fetcher_;
00243   CountingUrlAsyncFetcher* counting_distributed_async_fetcher_;
00244   scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_;
00245   scoped_ptr<MockTimeCache> mock_time_cache_;
00246   MemFileSystem* mem_file_system_; 
00247   MockHasher* mock_hasher_;
00248   SimpleStats simple_stats_;
00249   MockMessageHandler* mock_message_handler_;
00250   MockMessageHandler* mock_html_message_handler_;
00251   bool use_beacon_results_in_filters_;
00252   bool use_test_url_namer_;
00253   bool add_platform_specific_decoding_passes_;
00254   std::vector<CreateFilterCallback*> filter_callback_vector_;
00255   std::vector<CreateRewriterCallback*> rewriter_callback_vector_;
00256   std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_;
00257   CachePropertyStore* cache_property_store_;
00258 };
00259 
00260 }  
00261 
00262 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines