Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
critical_images_finder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_IMAGES_FINDER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_IMAGES_FINDER_H_
21 
22 #include <map>
23 #include <utility>
24 
25 #include "net/instaweb/rewriter/critical_images.pb.h"
27 #include "net/instaweb/util/public/property_cache.h"
31 
32 namespace net_instaweb {
33 
34 class GoogleUrl;
35 class RenderedImages;
36 class RewriteDriver;
37 class RewriteOptions;
38 class Statistics;
39 class Variable;
40 
41 typedef std::map<GoogleString, std::pair<int32, int32> >
42  RenderedImageDimensionsMap;
43 
54  : is_critical_image_info_present(false) {}
55  StringSet html_critical_images;
56  StringSet css_critical_images;
57  CriticalImages proto;
58  bool is_critical_image_info_present;
59  RenderedImageDimensionsMap rendered_images_map;
60 };
61 
62 
66  public:
67  enum Availability {
71  };
72  static const char kCriticalImagesValidCount[];
73  static const char kCriticalImagesExpiredCount[];
74  static const char kCriticalImagesNotFoundCount[];
75  static const char kCriticalImagesPropertyName[];
78  static const char kRenderedImageDimensionsProperty[];
79 
81  virtual ~CriticalImagesFinder();
82 
83  static void InitStats(Statistics* statistics);
84 
88  virtual Availability Available(RewriteDriver* driver);
89 
95  virtual int PercentSeenForCritical() const {
96  return kDefaultPercentSeenForCritical;
97  }
98 
106  virtual int SupportInterval() const {
107  return kDefaultImageSupportInterval;
108  }
109 
120  bool IsHtmlCriticalImage(StringPiece image_url, RewriteDriver* driver);
121 
122  bool IsCssCriticalImage(StringPiece image_url, RewriteDriver* driver);
123 
127  RewriteDriver* driver,
128  const GoogleUrl& image_src_gurl,
129  std::pair<int32, int32>* dimensions);
130 
133  const StringSet& GetHtmlCriticalImages(RewriteDriver* driver);
134  const StringSet& GetCssCriticalImages(RewriteDriver* driver);
135 
142  StringSet* mutable_html_critical_images(RewriteDriver* driver);
143  StringSet* mutable_css_critical_images(RewriteDriver* driver);
144 
146  virtual void ComputeCriticalImages(RewriteDriver* driver) = 0;
147 
152  const PropertyCache::Cohort* cohort() const { return cohort_; }
153 
160  const StringSet* html_critical_images_set,
161  const StringSet* css_critical_images_set,
162  RewriteDriver* driver);
163 
169  const PropertyValue* property_value, CriticalImages* critical_images);
170 
174  static bool UpdateCriticalImagesCacheEntry(
175  const StringSet* html_critical_images_set,
176  const StringSet* css_critical_images_set,
177  const RenderedImages* rendered_images_set,
178  int support_interval,
180  AbstractPropertyPage* page);
181 
184  virtual bool IsCriticalImageInfoPresent(RewriteDriver* driver);
185 
187  virtual RenderedImages* ExtractRenderedImageDimensionsFromCache(
188  RewriteDriver* driver);
189 
191  void AddHtmlCriticalImage(const GoogleString& url,
192  RewriteDriver* driver);
193 
196  RenderedImages* JsonMapToRenderedImagesMap(const GoogleString& str,
197  const RewriteOptions* options);
198 
201  virtual bool ShouldBeacon(RewriteDriver* driver) { return false; }
202 
208  BeaconMetadata result;
209  result.status = kBeaconNoNonce;
210  return result;
211  }
212 
218  virtual void UpdateCandidateImagesForBeaconing(const StringSet& images,
219  RewriteDriver* driver,
220  bool beaconing) {}
221 
222  protected:
226  const StringSet* html_critical_images_set,
227  const StringSet* css_critical_images_set,
228  const RenderedImages* rendered_images_set,
229  int support_interval,
231  AbstractPropertyPage* page,
232  CriticalImages* critical_images);
233 
238  virtual void UpdateCriticalImagesSetInDriver(RewriteDriver* driver);
239 
240  virtual GoogleString GetKeyForUrl(StringPiece url) { return url.as_string(); }
241 
245  CriticalImagesInfo* ExtractCriticalImagesFromCache(
246  RewriteDriver* driver,
247  const PropertyValue* property_value);
248 
249  private:
250  friend class CriticalImagesFinderTestBase;
251 
256  static bool UpdateCriticalImages(const StringSet* html_critical_images,
257  const StringSet* css_critical_images,
258  int support_interval,
259  CriticalImages* critical_images);
260 
263  static const int kDefaultPercentSeenForCritical = 100;
264  static const int kDefaultImageSupportInterval = 1;
265 
266  const PropertyCache::Cohort* cohort_;
267 
268  Variable* critical_images_valid_count_;
269  Variable* critical_images_expired_count_;
270  Variable* critical_images_not_found_count_;
271 
272 
273 };
274 
275 }
276 
277 #endif
class GoogleUrl
Definition: google_url.h:58
Abstract interface for implementing a PropertyPage.
Definition: property_cache.h:291
Data is expected but we don't have it yet.
Definition: critical_images_finder.h:69
Holds the value & stability-metadata for a property.
Definition: property_cache.h:122
virtual int SupportInterval() const
Definition: critical_images_finder.h:106
Definition: property_cache.h:186
Definition: critical_images_finder.h:65
virtual bool ShouldBeacon(RewriteDriver *driver)
Definition: critical_images_finder.h:201
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
static bool UpdateCriticalImagesCacheEntry(const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, const RenderedImages *rendered_images_set, int support_interval, const PropertyCache::Cohort *cohort, AbstractPropertyPage *page)
const PropertyCache::Cohort * cohort() const
Definition: critical_images_finder.h:152
virtual void ComputeCriticalImages(RewriteDriver *driver)=0
Compute the critical images for the driver's url.
bool GetRenderedImageDimensions(RewriteDriver *driver, const GoogleUrl &image_src_gurl, std::pair< int32, int32 > *dimensions)
virtual BeaconMetadata PrepareForBeaconInsertion(RewriteDriver *driver)
Definition: critical_images_finder.h:207
const StringSet & GetHtmlCriticalImages(RewriteDriver *driver)
static bool PopulateCriticalImagesFromPropertyValue(const PropertyValue *property_value, CriticalImages *critical_images)
void AddHtmlCriticalImage(const GoogleString &url, RewriteDriver *driver)
Adds the given url to the html critical image set for the driver.
virtual void UpdateCandidateImagesForBeaconing(const StringSet &images, RewriteDriver *driver, bool beaconing)
Definition: critical_images_finder.h:218
Availability
Definition: critical_images_finder.h:67
static bool UpdateAndWriteBackCriticalImagesCacheEntry(const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, const RenderedImages *rendered_images_set, int support_interval, const PropertyCache::Cohort *cohort, AbstractPropertyPage *page, CriticalImages *critical_images)
Definition: critical_finder_support_util.h:78
RenderedImages * JsonMapToRenderedImagesMap(const GoogleString &str, const RewriteOptions *options)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
StringSet * mutable_html_critical_images(RewriteDriver *driver)
Data will never be forthcoming.
Definition: critical_images_finder.h:68
Data is available.
Definition: critical_images_finder.h:70
virtual bool IsCriticalImageInfoPresent(RewriteDriver *driver)
Definition: rewrite_driver.h:100
virtual void UpdateCriticalImagesSetInDriver(RewriteDriver *driver)
virtual int PercentSeenForCritical() const
Definition: critical_images_finder.h:95
CriticalImagesInfo * ExtractCriticalImagesFromCache(RewriteDriver *driver, const PropertyValue *property_value)
bool UpdateCriticalImagesCacheEntryFromDriver(const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, RewriteDriver *driver)
bool IsHtmlCriticalImage(StringPiece image_url, RewriteDriver *driver)
Definition: rewrite_options.h:84
virtual RenderedImages * ExtractRenderedImageDimensionsFromCache(RewriteDriver *driver)
Extracts rendered images' dimensions from property cache.
virtual Availability Available(RewriteDriver *driver)
Definition: critical_images_finder.h:52
static const char kRenderedImageDimensionsProperty[]
Definition: critical_images_finder.h:78