Page Speed Optimization Libraries  1.7.30.1
net/instaweb/util/public/property_store.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2013 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 
00021 #ifndef NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_
00022 #define NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_
00023 
00024 #include "net/instaweb/util/public/abstract_property_store_get_callback.h"
00025 #include "net/instaweb/util/public/property_cache.h"
00026 #include "net/instaweb/util/public/string.h"
00027 #include "pagespeed/kernel/base/basictypes.h"
00028 #include "pagespeed/kernel/base/callback.h"
00029 #include "pagespeed/kernel/base/scoped_ptr.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class AbstractMutex;
00034 class PropertyCacheValues;
00035 class PropertyValueProtobuf;
00036 class Statistics;
00037 class Timer;
00038 
00041 class PropertyStore {
00042  public:
00043   typedef Callback1<bool> BoolCallback;
00044   PropertyStore();
00045   virtual ~PropertyStore();
00046 
00056   virtual void Get(
00057       const GoogleString& url,
00058       const GoogleString& options_signature_hash,
00059       const GoogleString& cache_key_suffix,
00060       const PropertyCache::CohortVector& cohort_list,
00061       PropertyPage* page,
00062       BoolCallback* done,
00063       AbstractPropertyStoreGetCallback** callback) = 0;
00064 
00069   virtual void Put(
00070       const GoogleString& url,
00071       const GoogleString& options_signature_hash,
00072       const GoogleString& cache_key_suffix,
00073       const PropertyCache::Cohort* cohort,
00074       const PropertyCacheValues* values,
00075       BoolCallback* done) = 0;
00076 
00080   bool enable_get_cancellation() { return enable_get_cancellation_; }
00081   void set_enable_get_cancellation(bool x) { enable_get_cancellation_ = x; }
00082 
00083  private:
00084   bool enable_get_cancellation_;
00085   DISALLOW_COPY_AND_ASSIGN(PropertyStore);
00086 };
00087 
00101 class PropertyStoreGetCallback : public AbstractPropertyStoreGetCallback {
00102  public:
00103   typedef Callback1<bool> BoolCallback;
00104   PropertyStoreGetCallback(
00105       AbstractMutex* mutex,
00106       PropertyPage* page,
00107       bool is_cancellable,
00108       BoolCallback* done,
00109       Timer* timer);
00110   virtual ~PropertyStoreGetCallback();
00111 
00112   static void InitStats(Statistics* statistics);
00113 
00116   virtual void FastFinishLookup();
00118   virtual void DeleteWhenDone();
00123   bool AddPropertyValueProtobufToPropertyPage(
00124       const PropertyCache::Cohort* cohort,
00125       const PropertyValueProtobuf& pcache_value,
00126       int64 min_write_timestamp_ms);
00127 
00130   void Done(bool success);
00131 
00132  protected:
00133   AbstractMutex* mutex() { return mutex_.get(); }
00134   PropertyPage* page() { return page_; }
00135 
00136  private:
00137   scoped_ptr<AbstractMutex> mutex_;
00138   PropertyPage* page_;
00139   const bool is_cancellable_;
00140   BoolCallback* done_;
00141   bool delete_when_done_;
00142   bool done_called_;
00143   Timer* timer_;
00144   int64 fast_finish_time_ms_;
00145 
00146   DISALLOW_COPY_AND_ASSIGN(PropertyStoreGetCallback);
00147 };
00148 
00149 }  
00150 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines