~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/util/public/property_store.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Google Inc.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
// Author: pulkitg@google.com (Pulkit Goyal)
18
 
//
19
 
// Retrieves property values stored in the storage system and populate them
20
 
// in PropertyPage after validation of the properties.
21
 
#ifndef NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_
22
 
#define NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_
23
 
 
24
 
#include "net/instaweb/util/public/abstract_property_store_get_callback.h"
25
 
#include "net/instaweb/util/public/property_cache.h"
26
 
#include "net/instaweb/util/public/string.h"
27
 
#include "pagespeed/kernel/base/basictypes.h"
28
 
#include "pagespeed/kernel/base/callback.h"
29
 
#include "pagespeed/kernel/base/scoped_ptr.h"
30
 
 
31
 
namespace net_instaweb {
32
 
 
33
 
class AbstractMutex;
34
 
class PropertyCacheValues;
35
 
class PropertyValueProtobuf;
36
 
class Statistics;
37
 
class Timer;
38
 
 
39
 
// Abstract interface for implementing PropertyStore which helps to
40
 
// retrieve and put properties into the storage system.
41
 
class PropertyStore {
42
 
 public:
43
 
  typedef Callback1<bool> BoolCallback;
44
 
  PropertyStore();
45
 
  virtual ~PropertyStore();
46
 
 
47
 
  // Populates the values field for all the cohorts present in the cohort_list
48
 
  // and call the BoolCallback after lookup of all the cohorts are done.
49
 
  // BoolCallback is called with true if at least one of the cohorts lookup is
50
 
  // succeeded.
51
 
  // PropertyPage object is used to validate the entries looked up from cache.
52
 
  // AbstractPropertyStoreGetCallback is set in callback parameter and can be
53
 
  // used to fast finish the lookup. Client must call DeleteWhenDone() on this
54
 
  // callback after that it is no more usable. This parameter can be set to
55
 
  // NULL.
56
 
  virtual void Get(
57
 
      const GoogleString& url,
58
 
      const GoogleString& options_signature_hash,
59
 
      const GoogleString& cache_key_suffix,
60
 
      const PropertyCache::CohortVector& cohort_list,
61
 
      PropertyPage* page,
62
 
      BoolCallback* done,
63
 
      AbstractPropertyStoreGetCallback** callback) = 0;
64
 
 
65
 
  // Write to storage system for the given key.
66
 
  // Callback done can be NULL. BoolCallback done will be called with true if
67
 
  // Insert operation is successful.
68
 
  // TODO(pulkitg): Remove UserAgentMatcher dependency.
69
 
  virtual void Put(
70
 
      const GoogleString& url,
71
 
      const GoogleString& options_signature_hash,
72
 
      const GoogleString& cache_key_suffix,
73
 
      const PropertyCache::Cohort* cohort,
74
 
      const PropertyCacheValues* values,
75
 
      BoolCallback* done) = 0;
76
 
 
77
 
  // PropertyStore::Get can be cancelled if enable_get_cancellation is true
78
 
  // i.e. input done callback will be called as soon as FastFinishLookup() is
79
 
  // called on the AbstractPropertyStoreGetCallback callback.
80
 
  bool enable_get_cancellation() { return enable_get_cancellation_; }
81
 
  void set_enable_get_cancellation(bool x) { enable_get_cancellation_ = x; }
82
 
 
83
 
  // The name of this PropertyStore -- used for logging and debugging.
84
 
  //
85
 
  // It is strongly recommended that you provide a static GoogleString
86
 
  // FormatName(...) method for use in formatting the Name() return,
87
 
  // and in testing, e.g. in net/instaweb/system/system_caches_test.cc.
88
 
  virtual GoogleString Name() const = 0;
89
 
 
90
 
 private:
91
 
  bool enable_get_cancellation_;
92
 
  DISALLOW_COPY_AND_ASSIGN(PropertyStore);
93
 
};
94
 
 
95
 
// This class manages the lookup for the properties in PropertyStore. It works
96
 
// in two mode: Cancellable mode and Non-Cancellable mode.
97
 
// Non-Cancellable Mode:
98
 
//   - FastFinishLookup() has no-op in this mode.
99
 
//   - Done() will be called whenever lookup finishes and calls the
100
 
//     done callback based on sucess of the lookup.
101
 
//   - DeleteWhenDone() will delete the callback if Done() is already called or
102
 
//     set the bit so that callback delete itself after executing Done().
103
 
// Cancellable Mode:
104
 
//   - FastFinishLookup() will call the done callback if its not yet called.
105
 
//   - Done() is same as that in non-cancellable mode but if FastFinishLookup()
106
 
//     is called then it will not call the done callback.
107
 
//   - DeleteWhenDone() works same as it works in non-cancellable mode.
108
 
class PropertyStoreGetCallback : public AbstractPropertyStoreGetCallback {
109
 
 public:
110
 
  typedef Callback1<bool> BoolCallback;
111
 
  PropertyStoreGetCallback(
112
 
      AbstractMutex* mutex,
113
 
      PropertyPage* page,
114
 
      bool is_cancellable,
115
 
      BoolCallback* done,
116
 
      Timer* timer);
117
 
  virtual ~PropertyStoreGetCallback();
118
 
 
119
 
  static void InitStats(Statistics* statistics);
120
 
 
121
 
  // Try to finish all the pending lookups if possible and call Done as soon as
122
 
  // possible.
123
 
  virtual void FastFinishLookup();
124
 
  // Deletes the callback after done finishes.
125
 
  virtual void DeleteWhenDone();
126
 
  // Add the given property cache value to the PropertyPage if PropertyPage is
127
 
  // not NULL.
128
 
  // Returns true if PropertyValueProtobuf is successfully added to
129
 
  // PropertyPage.
130
 
  bool AddPropertyValueProtobufToPropertyPage(
131
 
      const PropertyCache::Cohort* cohort,
132
 
      const PropertyValueProtobuf& pcache_value,
133
 
      int64 min_write_timestamp_ms);
134
 
 
135
 
  // Done is called when lookup is finished. This method is made public so that
136
 
  // PropertyStore implementations may call it.
137
 
  void Done(bool success);
138
 
 
139
 
 protected:
140
 
  AbstractMutex* mutex() { return mutex_.get(); }
141
 
  PropertyPage* page() { return page_; }
142
 
 
143
 
 private:
144
 
  scoped_ptr<AbstractMutex> mutex_;
145
 
  PropertyPage* page_;
146
 
  const bool is_cancellable_;
147
 
  BoolCallback* done_;
148
 
  bool delete_when_done_;
149
 
  bool done_called_;
150
 
  Timer* timer_;
151
 
  int64 fast_finish_time_ms_;
152
 
 
153
 
  DISALLOW_COPY_AND_ASSIGN(PropertyStoreGetCallback);
154
 
};
155
 
 
156
 
}  // namespace net_instaweb
157
 
#endif  // NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_STORE_H_