Page Speed Optimization Libraries  1.8.31.3
net/instaweb/rewriter/public/critical_finder_support_util.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 
00034 
00035 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_FINDER_SUPPORT_UTIL_H_
00036 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_FINDER_SUPPORT_UTIL_H_
00037 
00038 #include "net/instaweb/rewriter/critical_keys.pb.h"
00039 #include "net/instaweb/util/public/basictypes.h"
00040 #include "net/instaweb/util/public/property_cache.h"
00041 #include "net/instaweb/util/public/string.h"
00042 #include "net/instaweb/util/public/string_util.h"
00043 #include "net/instaweb/util/public/timer.h"
00044 
00045 namespace net_instaweb {
00046 
00050 const int64 kBeaconTimeoutIntervalMs = Timer::kMinuteMs;
00051 
00054 const int64 kHighFreqBeaconCount = 3;
00055 
00061 const int64 kLowFreqBeaconMult = 100;
00062 
00066 const int64 kNonceExpirationLimit = 5;
00067 
00068 class MessageHandler;
00069 class NonceGenerator;
00070 class RewriteDriver;
00071 
00072 enum BeaconStatus {
00073   kDoNotBeacon,
00074   kBeaconNoNonce,
00075   kBeaconWithNonce
00076 };
00077 
00078 struct BeaconMetadata {
00079   BeaconMetadata() : status(kDoNotBeacon) { }
00080   BeaconStatus status;
00081   GoogleString nonce;
00082 };
00083 
00089 bool ValidateAndExpireNonce(int64 now_ms, StringPiece nonce,
00090                             CriticalKeys* critical_keys);
00091 
00098 void GetCriticalKeysFromProto(int64 support_percentage,
00099                               const CriticalKeys& critical_keys,
00100                               StringSet* keys);
00101 
00107 void UpdateCriticalKeys(bool require_prior_support,
00108                         const StringSet& new_set, int support_value,
00109                         CriticalKeys* critical_keys);
00110 
00111 bool ShouldBeacon(const CriticalKeys& proto, const RewriteDriver& driver);
00112 
00120 void WriteCriticalKeysToPropertyCache(
00121     const StringSet& new_keys, StringPiece nonce, int support_interval,
00122     bool should_replace_prior_result, bool require_prior_support,
00123     StringPiece property_name, const PropertyCache* cache,
00124     const PropertyCache::Cohort* cohort, AbstractPropertyPage* page,
00125     MessageHandler* message_handler, Timer* timer);
00126 
00140 void PrepareForBeaconInsertionHelper(CriticalKeys* proto,
00141                                      NonceGenerator* nonce_generator,
00142                                      RewriteDriver* driver,
00143                                      bool using_candidate_key_detection,
00144                                      BeaconMetadata* result);
00145 
00151 bool UpdateCandidateKeys(const StringSet& keys, CriticalKeys* proto,
00152                          bool clear_rebeacon_timestamp);
00153 
00156 inline bool IsBeaconDataAvailable(const CriticalKeys& proto) {
00157   return (proto.valid_beacons_received() > 0);
00158 }
00159 
00160 }  
00161 
00162 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_FINDER_SUPPORT_UTIL_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines