Page Speed Optimization Libraries
1.8.31.3
|
00001 /* 00002 * Copyright 2014 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_HTTP_PUBLIC_SIMULATED_DELAY_FETCHER_H_ 00020 #define NET_INSTAWEB_HTTP_PUBLIC_SIMULATED_DELAY_FETCHER_H_ 00021 00022 #include <map> 00023 00024 #include "net/instaweb/http/public/url_async_fetcher.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 #include "pagespeed/kernel/base/file_system.h" 00029 #include "pagespeed/kernel/base/scoped_ptr.h" 00030 #include "pagespeed/kernel/base/thread_annotations.h" 00031 00032 namespace net_instaweb { 00033 00034 class AbstractMutex; 00035 class AsyncFetch; 00036 class MessageHandler; 00037 class Scheduler; 00038 class ThreadSystem; 00039 class Timer; 00040 00044 class SimulatedDelayFetcher : public UrlAsyncFetcher { 00045 public: 00047 static const char kPayload[]; 00048 00055 SimulatedDelayFetcher(ThreadSystem* thread_system, 00056 Timer* timer, 00057 Scheduler* scheduler, 00058 MessageHandler* handler, 00059 FileSystem* file_system, 00060 StringPiece delay_map_path, 00061 StringPiece request_log_path, 00062 int request_log_flush_frequency); 00063 00064 virtual ~SimulatedDelayFetcher(); 00065 00066 virtual void Fetch(const GoogleString& url, 00067 MessageHandler* message_handler, 00068 AsyncFetch* fetch); 00069 00070 private: 00071 typedef std::map<GoogleString, int> DelayMap; 00072 void ProduceReply(AsyncFetch* fetch); 00073 void ParseDelayMap(StringPiece delay_map_path); 00074 00075 Timer* timer_; 00076 Scheduler* scheduler_; 00077 MessageHandler* message_handler_; 00078 FileSystem* file_system_; 00079 DelayMap delays_ms_; 00080 int request_log_flush_frequency_; 00081 00082 scoped_ptr<AbstractMutex> mutex_; 00083 int request_log_outstanding_ GUARDED_BY(mutex_.get()); 00084 FileSystem::OutputFile* request_log_ PT_GUARDED_BY(mutex_.get()); 00085 00086 DISALLOW_COPY_AND_ASSIGN(SimulatedDelayFetcher); 00087 }; 00088 00089 } 00090 00091 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_SIMULATED_DELAY_FETCHER_H_