Page Speed Optimization Libraries
1.5.27.2
|
#include "critical_images_finder.h"
Public Member Functions | |
CriticalImagesFinder (Statistics *stats) | |
virtual bool | IsMeaningful (const RewriteDriver *driver) const =0 |
virtual int | PercentSeenForCritical () const |
virtual int | NumSetsToKeep () const |
virtual bool | IsHtmlCriticalImage (const GoogleString &image_url, RewriteDriver *driver) |
virtual bool | IsCssCriticalImage (const GoogleString &image_url, RewriteDriver *driver) |
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 (StringPiece url, RewriteDriver *driver)=0 |
Compute the critical images for the given url. | |
virtual const char * | GetCriticalImagesCohort () const =0 |
bool | UpdateCriticalImagesCacheEntryFromDriver (const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, RewriteDriver *driver) |
bool | UpdateCriticalImagesCacheEntry (const StringSet *html_critical_images_set, const StringSet *css_critical_images_set, AbstractPropertyPage *page, PropertyCache *page_property_cache) |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
Static Public Attributes | |
static const char | kCriticalImagesValidCount [] |
static const char | kCriticalImagesExpiredCount [] |
static const char | kCriticalImagesNotFoundCount [] |
static const char | kCriticalImagesPropertyName [] |
Protected Member Functions | |
virtual void | UpdateCriticalImagesSetInDriver (RewriteDriver *driver) |
CriticalImagesInfo * | ExtractCriticalImagesFromCache (RewriteDriver *driver, const PropertyValue *property_value) |
Friends | |
class | CriticalImagesFinderTestBase |
Finds critical images i.e. images which are above the fold for a given url. This information may be used by DelayImagesFilter.
CriticalImagesInfo* net_instaweb::CriticalImagesFinder::ExtractCriticalImagesFromCache | ( | RewriteDriver * | driver, |
const PropertyValue * | property_value | ||
) | [protected] |
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.
virtual const char* net_instaweb::CriticalImagesFinder::GetCriticalImagesCohort | ( | ) | const [pure virtual] |
Identifies which cohort in the PropertyCache the critical image information is located in.
Implemented in net_instaweb::BeaconCriticalImagesFinder.
const StringSet& net_instaweb::CriticalImagesFinder::GetHtmlCriticalImages | ( | RewriteDriver * | driver | ) |
Get the critical image sets. Returns an empty set if there is no critical image information.
virtual bool net_instaweb::CriticalImagesFinder::IsHtmlCriticalImage | ( | const GoogleString & | image_url, |
RewriteDriver * | driver | ||
) | [virtual] |
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).
Reimplemented in net_instaweb::BeaconCriticalImagesFinder.
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.
StringSet* net_instaweb::CriticalImagesFinder::mutable_html_critical_images | ( | RewriteDriver * | driver | ) |
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::NumSetsToKeep | ( | ) | const [inline, virtual] |
The number of past critical image sets to keep. By default, we only keep the most recent one. The beacon critical image finder should override this to store a larger number of sets.
Reimplemented in net_instaweb::BeaconCriticalImagesFinder.
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.
bool net_instaweb::CriticalImagesFinder::UpdateCriticalImagesCacheEntry | ( | const StringSet * | html_critical_images_set, |
const StringSet * | css_critical_images_set, | ||
AbstractPropertyPage * | page, | ||
PropertyCache * | page_property_cache | ||
) |
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.
virtual void net_instaweb::CriticalImagesFinder::UpdateCriticalImagesSetInDriver | ( | RewriteDriver * | driver | ) | [protected, virtual] |
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.