Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
critical_finder_support_util.h
Go to the documentation of this file.
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 
34 
35 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_FINDER_SUPPORT_UTIL_H_
36 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_FINDER_SUPPORT_UTIL_H_
37 
38 #include "net/instaweb/rewriter/critical_keys.pb.h"
39 #include "net/instaweb/util/public/property_cache.h"
40 #include "pagespeed/kernel/base/basictypes.h"
41 #include "pagespeed/kernel/base/string.h"
42 #include "pagespeed/kernel/base/string_util.h"
43 #include "pagespeed/kernel/base/timer.h"
44 
45 namespace net_instaweb {
46 
50 const int64 kBeaconTimeoutIntervalMs = Timer::kMinuteMs;
51 
54 const int64 kHighFreqBeaconCount = 3;
55 
61 const int64 kLowFreqBeaconMult = 100;
62 
66 const int64 kNonceExpirationLimit = 5;
67 
68 class MessageHandler;
69 class NonceGenerator;
70 class RewriteDriver;
71 
72 enum BeaconStatus {
73  kDoNotBeacon,
74  kBeaconNoNonce,
75  kBeaconWithNonce
76 };
77 
79  BeaconMetadata() : status(kDoNotBeacon) { }
80  BeaconStatus status;
81  GoogleString nonce;
82 };
83 
89 bool ValidateAndExpireNonce(int64 now_ms, StringPiece nonce,
90  CriticalKeys* critical_keys);
91 
98 void GetCriticalKeysFromProto(int64 support_percentage,
99  const CriticalKeys& critical_keys,
100  StringSet* keys);
101 
107 void UpdateCriticalKeys(bool require_prior_support,
108  const StringSet& new_set, int support_value,
109  CriticalKeys* critical_keys);
110 
111 bool ShouldBeacon(const CriticalKeys& proto, const RewriteDriver& driver);
112 
121  const StringSet& new_keys, StringPiece nonce, int support_interval,
122  bool should_replace_prior_result, bool require_prior_support,
123  StringPiece property_name, const PropertyCache* cache,
124  const PropertyCache::Cohort* cohort, AbstractPropertyPage* page,
125  MessageHandler* message_handler, Timer* timer);
126 
140 void PrepareForBeaconInsertionHelper(CriticalKeys* proto,
141  NonceGenerator* nonce_generator,
142  RewriteDriver* driver,
143  bool using_candidate_key_detection,
144  BeaconMetadata* result);
145 
151 bool UpdateCandidateKeys(const StringSet& keys, CriticalKeys* proto,
152  bool clear_rebeacon_timestamp);
153 
156 inline bool IsBeaconDataAvailable(const CriticalKeys& proto) {
157  return (proto.valid_beacons_received() > 0);
158 }
159 
160 }
161 
162 #endif
const int64 kLowFreqBeaconMult
Definition: critical_finder_support_util.h:61
bool UpdateCandidateKeys(const StringSet &keys, CriticalKeys *proto, bool clear_rebeacon_timestamp)
bool IsBeaconDataAvailable(const CriticalKeys &proto)
Definition: critical_finder_support_util.h:156
const int64 kBeaconTimeoutIntervalMs
Definition: critical_finder_support_util.h:50
void UpdateCriticalKeys(bool require_prior_support, const StringSet &new_set, int support_value, CriticalKeys *critical_keys)
Definition: critical_finder_support_util.h:78
const int64 kNonceExpirationLimit
Definition: critical_finder_support_util.h:66
Definition: rewrite_driver.h:98
void PrepareForBeaconInsertionHelper(CriticalKeys *proto, NonceGenerator *nonce_generator, RewriteDriver *driver, bool using_candidate_key_detection, BeaconMetadata *result)
const int64 kHighFreqBeaconCount
Definition: critical_finder_support_util.h:54
void GetCriticalKeysFromProto(int64 support_percentage, const CriticalKeys &critical_keys, StringSet *keys)
bool ValidateAndExpireNonce(int64 now_ms, StringPiece nonce, CriticalKeys *critical_keys)
void WriteCriticalKeysToPropertyCache(const StringSet &new_keys, StringPiece nonce, int support_interval, bool should_replace_prior_result, bool require_prior_support, StringPiece property_name, const PropertyCache *cache, const PropertyCache::Cohort *cohort, AbstractPropertyPage *page, MessageHandler *message_handler, Timer *timer)