Page Speed Optimization Libraries
1.7.30.2
|
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 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FINDER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FINDER_H_ 00021 00022 #include "net/instaweb/rewriter/critical_keys.pb.h" 00023 #include "net/instaweb/rewriter/public/critical_finder_support_util.h" 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/property_cache.h" 00026 #include "net/instaweb/util/public/string_util.h" 00027 #include "pagespeed/kernel/base/string.h" 00028 00029 namespace net_instaweb { 00030 00031 class MessageHandler; 00032 class NonceGenerator; 00033 class RewriteDriver; 00034 class Statistics; 00035 class TimedVariable; 00036 class Timer; 00037 00043 struct CriticalSelectorInfo { 00044 StringSet critical_selectors; 00045 CriticalKeys proto; 00046 }; 00047 00051 class CriticalSelectorFinder { 00052 public: 00053 static const char kCriticalSelectorsValidCount[]; 00054 static const char kCriticalSelectorsExpiredCount[]; 00055 static const char kCriticalSelectorsNotFoundCount[]; 00056 static const char kCriticalSelectorsPropertyName[]; 00057 00062 CriticalSelectorFinder(const PropertyCache::Cohort* cohort, 00063 NonceGenerator* nonce_generator, Statistics* stats); 00064 virtual ~CriticalSelectorFinder(); 00065 00066 static void InitStats(Statistics* statistics); 00067 00068 bool IsCriticalSelector(RewriteDriver* driver, const GoogleString& selector); 00069 00070 const StringSet& GetCriticalSelectors(RewriteDriver* driver); 00071 00077 virtual void WriteCriticalSelectorsToPropertyCache( 00078 const StringSet& selector_set, StringPiece nonce, 00079 RewriteDriver* driver); 00080 00083 static void WriteCriticalSelectorsToPropertyCacheStatic( 00084 const StringSet& selector_set, StringPiece nonce, int support_interval, 00085 bool should_replace_prior_result, const PropertyCache* cache, 00086 const PropertyCache::Cohort* cohort, AbstractPropertyPage* page, 00087 MessageHandler* message_handler, Timer* timer); 00088 00094 BeaconMetadata PrepareForBeaconInsertion( 00095 const StringSet& selector_set, RewriteDriver* driver); 00096 00098 virtual int SupportInterval() const = 0; 00099 00100 protected: 00102 virtual bool ShouldReplacePriorResult() const { return false; } 00103 00106 00107 private: 00111 void UpdateCriticalSelectorInfoInDriver(RewriteDriver* driver); 00112 00113 const PropertyCache::Cohort* cohort_; 00114 NonceGenerator* nonce_generator_; 00115 00116 TimedVariable* critical_selectors_valid_count_; 00117 TimedVariable* critical_selectors_expired_count_; 00118 TimedVariable* critical_selectors_not_found_count_; 00119 00120 DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFinder); 00121 }; 00122 00123 class BeaconCriticalSelectorFinder : public CriticalSelectorFinder { 00124 public: 00125 BeaconCriticalSelectorFinder(const PropertyCache::Cohort* cohort, 00126 NonceGenerator* nonce_generator, 00127 Statistics* stats) 00128 : CriticalSelectorFinder(cohort, nonce_generator, stats) {} 00129 00130 static void WriteCriticalSelectorsToPropertyCacheFromBeacon( 00131 const StringSet& selector_set, StringPiece nonce, 00132 const PropertyCache* cache, const PropertyCache::Cohort* cohort, 00133 AbstractPropertyPage* page, MessageHandler* message_handler, 00134 Timer* timer); 00135 00136 private: 00138 static const int kDefaultSupportInterval = 10; 00139 00141 virtual int SupportInterval() const { return kDefaultSupportInterval; } 00142 }; 00143 00144 } 00145 00146 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FINDER_H_