Page Speed Optimization Libraries
1.6.29.3
|
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 00026 00027 #ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIME_CACHE_H_ 00028 #define NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIME_CACHE_H_ 00029 00030 #include "net/instaweb/util/public/cache_interface.h" 00031 #include "pagespeed/kernel/base/basictypes.h" 00032 #include "pagespeed/kernel/base/string.h" 00033 #include "pagespeed/kernel/base/string_util.h" 00034 00035 namespace net_instaweb { 00036 00037 class Scheduler; 00038 class SharedString; 00039 00041 class MockTimeCache : public CacheInterface { 00042 public: 00044 MockTimeCache(Scheduler* scheduler, CacheInterface* cache); 00045 virtual ~MockTimeCache(); 00046 00048 virtual void Get(const GoogleString& key, Callback* callback); 00049 virtual void Put(const GoogleString& key, SharedString* value); 00050 virtual void Delete(const GoogleString& key); 00051 00055 void set_delay_us(int64 delay_us) { delay_us_ = delay_us; } 00056 int64 delay_us() const { return delay_us_; } 00057 00058 Scheduler* scheduler() { return scheduler_; } 00059 00060 virtual GoogleString Name() const { return FormatName(cache_->Name()); } 00061 static GoogleString FormatName(StringPiece name); 00062 virtual bool IsBlocking() const { return cache_->IsBlocking(); } 00063 virtual bool IsHealthy() const { return cache_->IsHealthy(); } 00064 virtual void ShutDown() { cache_->ShutDown(); } 00065 00066 private: 00067 class DelayCallback; 00068 00069 Scheduler* scheduler_; 00070 CacheInterface* cache_; 00071 int64 delay_us_; 00072 GoogleString name_; 00073 00074 DISALLOW_COPY_AND_ASSIGN(MockTimeCache); 00075 }; 00076 00077 } 00078 00079 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIME_CACHE_H_