Page Speed Optimization Libraries  1.7.30.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends
net_instaweb::CriticalImagesFinder Class Reference

#include "critical_images_finder.h"

Inheritance diagram for net_instaweb::CriticalImagesFinder:
net_instaweb::BeaconCriticalImagesFinder net_instaweb::TestCriticalImagesFinder net_instaweb::MockCriticalImagesFinder

List of all members.

Public Member Functions

 CriticalImagesFinder (const PropertyCache::Cohort *cohort, Statistics *stats)
virtual bool IsMeaningful (const RewriteDriver *driver) const =0
virtual int PercentSeenForCritical () const
virtual int SupportInterval () const
bool IsHtmlCriticalImage (const GoogleString &image_url, RewriteDriver *driver)
bool IsCssCriticalImage (const GoogleString &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)
virtual void ComputeCriticalImages (RewriteDriver *driver)=0
 Compute the critical images for the driver's url.
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)
virtual BeaconMetadata PrepareForBeaconInsertion (RewriteDriver *driver)

Static Public Member Functions

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)

Static Public Attributes

static const char kCriticalImagesValidCount []
static const char kCriticalImagesExpiredCount []
static const char kCriticalImagesNotFoundCount []
static const char kCriticalImagesPropertyName []
static const char kRenderedImageDimensionsProperty []

Protected Member Functions

virtual void UpdateCriticalImagesSetInDriver (RewriteDriver *driver)
virtual GoogleString GetKeyForUrl (const GoogleString &url)
CriticalImagesInfoExtractCriticalImagesFromCache (RewriteDriver *driver, const PropertyValue *property_value)

Static Protected Member Functions

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)

Friends

class CriticalImagesFinderTestBase

Detailed Description

Finds critical images i.e. images which are above the fold for a given url. This information may be used by DelayImagesFilter.


Member Function Documentation

Identifies which cohort in the PropertyCache the critical image information is located in.

Todo:
TODO(jud): Make this protected. There is a lingering public usage in critical_images_beacon_filter.cc.

Extracts the critical images from the given property_value into critical_images_info, after checking if the property value is still valid using the provided TTL. It also updates stats variables.

Get the critical image sets. Returns an empty set if there is no critical image information.

bool net_instaweb::CriticalImagesFinder::GetRenderedImageDimensions ( RewriteDriver driver,
const GoogleUrl &  image_src_gurl,
std::pair< int32, int32 > *  dimensions 
)

Returns true if rendered dimensions exist for the image_src_url and populates dimensions in the std::pair.

Returns true if the critical images are available, false otherwise. This is virtual only to be overridden in tests.

Reimplemented in net_instaweb::MockCriticalImagesFinder.

bool net_instaweb::CriticalImagesFinder::IsHtmlCriticalImage ( const GoogleString &  image_url,
RewriteDriver driver 
)

Checks whether the requested image is present in the critical set or not. Users of this function should also check IsMeaningful() to see if the implementation of this function returns meaningful results and provide a default behavior if it does not. If no critical set value has been obtained, returns false (not critical).

virtual bool net_instaweb::CriticalImagesFinder::IsMeaningful ( const RewriteDriver driver) const [pure virtual]

Checks whether IsHtmlCriticalImage will return meaningful results about critical images. Users of IsHtmlCriticalImage should check this function and supply a default behavior if IsMeaningful returns false.

Implemented in net_instaweb::BeaconCriticalImagesFinder, net_instaweb::MockCriticalImagesFinder, and net_instaweb::TestCriticalImagesFinder.

RenderedImages* net_instaweb::CriticalImagesFinder::JsonMapToRenderedImagesMap ( const GoogleString &  str,
const RewriteOptions options 
)

Parses Json map returned from beacon js and populates RenderedImages proto. Caller takes ownership of the returned pointer.

Utility functions for manually setting the critical image sets. These should only be used by unit tests that need to setup a specific set of critical images. For normal users of CriticalImagesFinder, the critical images will be populated from entries in the property cache. Note that these always return a non-NULL StringSet value (implying "beacon result received").

virtual int net_instaweb::CriticalImagesFinder::PercentSeenForCritical ( ) const [inline, virtual]

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 in net_instaweb::BeaconCriticalImagesFinder.

static bool net_instaweb::CriticalImagesFinder::PopulateCriticalImagesFromPropertyValue ( const PropertyValue property_value,
CriticalImages *  critical_images 
) [static]

Setup the HTML and CSS critical image sets in critical_images_info from the property_value. Return true if property_value had a value, and deserialization of it succeeded. Here because helper code needs access to it.

Check property cache state and prepare to insert beacon. Returns the metadata where result.status == kDoNotBeacon if no beaconing should occur, and result.nonce contains the nonce if required (default implementation always beacons without a nonce).

Reimplemented in net_instaweb::BeaconCriticalImagesFinder.

virtual int net_instaweb::CriticalImagesFinder::SupportInterval ( ) const [inline, virtual]

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 in net_instaweb::BeaconCriticalImagesFinder.

static bool net_instaweb::CriticalImagesFinder::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 
) [static, protected]

Completes a critical image set update operation and writes the data back to the property cache.

static bool net_instaweb::CriticalImagesFinder::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 
) [static]

Alternative interface to update the critical images cache entry. This is useful in contexts like the beacon handler where the RewriteDriver for the original request no longer exists.

bool net_instaweb::CriticalImagesFinder::UpdateCriticalImagesCacheEntryFromDriver ( const StringSet *  html_critical_images_set,
const StringSet *  css_critical_images_set,
RewriteDriver driver 
)

Updates the critical images property cache entry. Returns whether the update succeeded or not. Note that this base implementation does not call WriteCohort. This should be called in the subclass if the cohort is not written elsewhere. NULL is permitted for the critical image sets if only one of the html or css sets is being updated, but not the other.

Gets critical images if present in the property cache and updates the critical_images set in RewriteDriver with the obtained set. If you override this method, driver->critical_images_info() must not return NULL after this function has been called.

Reimplemented in net_instaweb::MockCriticalImagesFinder.


Member Data Documentation

Property name for the rendered image dimensions retreived from webkit render response for the page.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines