Page Speed Optimization Libraries  1.8.31.2
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 
00088   virtual GoogleString Name() const = 0;
00089 
00090  private:
00091   bool enable_get_cancellation_;
00092   DISALLOW_COPY_AND_ASSIGN(PropertyStore);
00093 };
00094 
00108 class PropertyStoreGetCallback : public AbstractPropertyStoreGetCallback {
00109  public:
00110   typedef Callback1<bool> BoolCallback;
00111   PropertyStoreGetCallback(
00112       AbstractMutex* mutex,
00113       PropertyPage* page,
00114       bool is_cancellable,
00115       BoolCallback* done,
00116       Timer* timer);
00117   virtual ~PropertyStoreGetCallback();
00118 
00119   static void InitStats(Statistics* statistics);
00120 
00123   virtual void FastFinishLookup();
00125   virtual void DeleteWhenDone();
00130   bool AddPropertyValueProtobufToPropertyPage(
00131       const PropertyCache::Cohort* cohort,
00132       const PropertyValueProtobuf& pcache_value,
00133       int64 min_write_timestamp_ms);
00134 
00137   void Done(bool success);
00138 
00139  protected:
00140   AbstractMutex* mutex() { return mutex_.get(); }
00141   PropertyPage* page() { return page_; }
00142 
00143  private:
00144   scoped_ptr<AbstractMutex> mutex_;
00145   PropertyPage* page_;
00146   const bool is_cancellable_;
00147   BoolCallback* done_;
00148   bool delete_when_done_;
00149   bool done_called_;
00150   Timer* timer_;
00151   int64 fast_finish_time_ms_;
00152 
00153   DISALLOW_COPY_AND_ASSIGN(PropertyStoreGetCallback);
00154 };
00155 
00156 }  
00157 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines