Page Speed Optimization Libraries  1.6.29.3
net/instaweb/rewriter/public/critical_selector_finder.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 
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/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/property_cache.h"
00025 #include "net/instaweb/util/public/string_util.h"
00026 #include "pagespeed/kernel/base/string.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class MessageHandler;
00031 class NonceGenerator;
00032 class RewriteDriver;
00033 class Statistics;
00034 class TimedVariable;
00035 class Timer;
00036 
00042 struct CriticalSelectorInfo {
00043   StringSet critical_selectors;
00044   CriticalKeys proto;
00045 };
00046 
00050 class CriticalSelectorFinder {
00051  public:
00052   static const char kCriticalSelectorsValidCount[];
00053   static const char kCriticalSelectorsExpiredCount[];
00054   static const char kCriticalSelectorsNotFoundCount[];
00055   static const char kCriticalSelectorsPropertyName[];
00056 
00061   CriticalSelectorFinder(
00062       const PropertyCache::Cohort* cohort, Timer* timer,
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 
00095   GoogleString PrepareForBeaconInsertion(
00096       const StringSet& selector_set, RewriteDriver* driver);
00097 
00099   virtual int SupportInterval() const = 0;
00100 
00101  protected:
00103   virtual bool ShouldReplacePriorResult() const { return false; }
00104 
00107 
00108  private:
00112   void UpdateCriticalSelectorInfoInDriver(RewriteDriver* driver);
00113 
00114   const PropertyCache::Cohort* cohort_;
00115   Timer* timer_;
00116   NonceGenerator* nonce_generator_;
00117 
00118   TimedVariable* critical_selectors_valid_count_;
00119   TimedVariable* critical_selectors_expired_count_;
00120   TimedVariable* critical_selectors_not_found_count_;
00121 
00122   DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFinder);
00123 };
00124 
00125 class BeaconCriticalSelectorFinder : public CriticalSelectorFinder {
00126  public:
00127   BeaconCriticalSelectorFinder(const PropertyCache::Cohort* cohort,
00128                                Timer* timer, NonceGenerator* nonce_generator,
00129                                Statistics* stats)
00130       : CriticalSelectorFinder(cohort, timer, nonce_generator, stats) {}
00131 
00132   static void WriteCriticalSelectorsToPropertyCacheFromBeacon(
00133       const StringSet& selector_set, StringPiece none,
00134       const PropertyCache* cache, const PropertyCache::Cohort* cohort,
00135       AbstractPropertyPage* page, MessageHandler* message_handler,
00136       Timer* timer);
00137 
00138  private:
00140   static const int kDefaultSupportInterval = 10;
00141 
00143   virtual int SupportInterval() const { return kDefaultSupportInterval; }
00144 };
00145 
00146 }  
00147 
00148 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FINDER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines