Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
net_instaweb::BeaconCriticalImagesFinder Class Reference

#include "beacon_critical_images_finder.h"

Inheritance diagram for net_instaweb::BeaconCriticalImagesFinder:

Public Member Functions

 BeaconCriticalImagesFinder (const PropertyCache::Cohort *cohort, NonceGenerator *nonce_generator, Statistics *stats)
 All constructor args are owned by the caller.
virtual Availability Available (RewriteDriver *driver)
virtual int PercentSeenForCritical () const
virtual int SupportInterval () const
virtual void ComputeCriticalImages (RewriteDriver *driver)
 Compute the critical images for the driver's url.
virtual bool ShouldBeacon (RewriteDriver *driver)
virtual BeaconMetadata PrepareForBeaconInsertion (RewriteDriver *driver)
virtual void UpdateCandidateImagesForBeaconing (const StringSet &images, RewriteDriver *driver, bool beaconing)
- Public Member Functions inherited from net_instaweb::CriticalImagesFinder
 CriticalImagesFinder (const PropertyCache::Cohort *cohort, Statistics *stats)
bool IsHtmlCriticalImage (StringPiece image_url, RewriteDriver *driver)
bool IsCssCriticalImage (StringPiece image_url, RewriteDriver *driver)
bool GetRenderedImageDimensions (RewriteDriver *driver, const GoogleUrl &image_src_gurl, std::pair< int32, int32 > *dimensions)
const StringSet & GetHtmlCriticalImages (RewriteDriver *driver)
const StringSet & GetCssCriticalImages (RewriteDriver *driver)
StringSet * mutable_html_critical_images (RewriteDriver *driver)
StringSet * mutable_css_critical_images (RewriteDriver *driver)
const PropertyCache::Cohortcohort () const
bool UpdateCriticalImagesCacheEntryFromDriver (const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, RewriteDriver *driver)
virtual bool IsCriticalImageInfoPresent (RewriteDriver *driver)
virtual RenderedImages * ExtractRenderedImageDimensionsFromCache (RewriteDriver *driver)
 Extracts rendered images' dimensions from property cache.
void AddHtmlCriticalImage (const GoogleString &url, RewriteDriver *driver)
 Adds the given url to the html critical image set for the driver.
RenderedImages * JsonMapToRenderedImagesMap (const GoogleString &str, const RewriteOptions *options)

Static Public Member Functions

static bool UpdateCriticalImagesCacheEntry (const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, const RenderedImages *rendered_images_set, const StringPiece &nonce, const PropertyCache::Cohort *cohort, AbstractPropertyPage *page, Timer *timer)
- Static Public Member Functions inherited from net_instaweb::CriticalImagesFinder
static void InitStats (Statistics *statistics)
static bool PopulateCriticalImagesFromPropertyValue (const PropertyValue *property_value, CriticalImages *critical_images)
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)

Additional Inherited Members

- Public Types inherited from net_instaweb::CriticalImagesFinder
enum  Availability { kDisabled, kNoDataYet, kAvailable }
- Static Public Attributes inherited from net_instaweb::CriticalImagesFinder
static const char kCriticalImagesValidCount []
static const char kCriticalImagesExpiredCount []
static const char kCriticalImagesNotFoundCount []
static const char kCriticalImagesPropertyName []
static const char kRenderedImageDimensionsProperty []
- Protected Member Functions inherited from net_instaweb::CriticalImagesFinder
virtual void UpdateCriticalImagesSetInDriver (RewriteDriver *driver)
CriticalImagesInfoExtractCriticalImagesFromCache (RewriteDriver *driver, const PropertyValue *property_value)
- Static Protected Member Functions inherited from net_instaweb::CriticalImagesFinder
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)

Detailed Description

Support critical (above the fold) image detection through a javascript beacon on the client.

Member Function Documentation

virtual Availability net_instaweb::BeaconCriticalImagesFinder::Available ( RewriteDriver driver)

Checks whether IsHtmlCriticalImage will return meaningful results about critical images. Users of IsHtmlCriticalImage should check this function and supply default behaviors when Available != kAvailable.

Reimplemented from net_instaweb::CriticalImagesFinder.

virtual int net_instaweb::BeaconCriticalImagesFinder::PercentSeenForCritical ( ) const

In order to handle varying critical image sets returned by the beacon, we store a history of the last N critical images, and only declare an image critical if it appears critical in the last M out of N sets reported. This function returns what percentage of the sets need to include the image for it be considered critical.

Reimplemented from net_instaweb::CriticalImagesFinder.

virtual BeaconMetadata net_instaweb::BeaconCriticalImagesFinder::PrepareForBeaconInsertion ( RewriteDriver driver)

Check beacon interval and nonce state, and return appropriate BeaconMetadata; result.status indicates whether beaconing should occur, and result.nonce contains the nonce (if required).

Reimplemented from net_instaweb::CriticalImagesFinder.

virtual bool net_instaweb::BeaconCriticalImagesFinder::ShouldBeacon ( RewriteDriver driver)

Returns true if it's time to inject a beacon onto the page. The default finder doesn't use beaconing, so it always returns false.

Reimplemented from net_instaweb::CriticalImagesFinder.

virtual int net_instaweb::BeaconCriticalImagesFinder::SupportInterval ( ) const

Minimum interval to store support for critical image results. This affects how long we keep around evidence that an image might be critical; we'll remember the fact for at least SupportInterval beacon insertions if it only occurs once, and we'll remember it longer if multiple beacons support image criticality. By default, SupportInteval() = 1 and we only store one beacon result. The beacon critical image finder should override this to store a larger number of sets.

Reimplemented from net_instaweb::CriticalImagesFinder.

virtual void net_instaweb::BeaconCriticalImagesFinder::UpdateCandidateImagesForBeaconing ( const StringSet &  images,
RewriteDriver driver,
bool  beaconing 

For implementations that use beaconing, update the candidate images in the property cache. New images are a signal that we should beacon more often for a few requests. The beaconing argument should indicate if the current request is injecting a beacon. If so, we don't need to trigger a beacon on the next request even if the candidate images have changed.

Reimplemented from net_instaweb::CriticalImagesFinder.

static bool net_instaweb::BeaconCriticalImagesFinder::UpdateCriticalImagesCacheEntry ( const StringSet *  html_critical_images_set,
const StringSet *  css_critical_images_set,
const RenderedImages *  rendered_images_set,
const StringPiece &  nonce,
const PropertyCache::Cohort cohort,
AbstractPropertyPage page,
Timer timer 

Update the critical image entry in the property cache. This is meant to be called in the beacon handler, where there is no RewriteDriver available.

The documentation for this class was generated from the following file: