Be more defensive about examining protobuf fields that might not be initialized.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "net/instaweb/rewriter/critical_images.pb.h"
|
||||
#include "net/instaweb/rewriter/critical_keys.pb.h"
|
||||
#include "net/instaweb/rewriter/public/critical_finder_support_util.h"
|
||||
#include "net/instaweb/rewriter/public/property_cache_util.h"
|
||||
#include "net/instaweb/rewriter/public/rewrite_driver.h"
|
||||
@@ -26,6 +27,8 @@
|
||||
#include "net/instaweb/rewriter/public/rewrite_options.h"
|
||||
#include "net/instaweb/rewriter/public/server_context.h"
|
||||
#include "net/instaweb/util/public/fallback_property_page.h"
|
||||
#include "pagespeed/kernel/base/basictypes.h"
|
||||
#include "pagespeed/kernel/base/statistics.h"
|
||||
#include "pagespeed/kernel/base/string.h"
|
||||
#include "pagespeed/kernel/base/string_hash.h"
|
||||
#include "pagespeed/kernel/base/timer.h"
|
||||
@@ -87,9 +90,18 @@ CriticalImagesFinder::Availability BeaconCriticalImagesFinder::Available(
|
||||
|
||||
bool BeaconCriticalImagesFinder::ShouldBeacon(RewriteDriver* driver) {
|
||||
UpdateCriticalImagesSetInDriver(driver);
|
||||
return ::net_instaweb::ShouldBeacon(
|
||||
driver->critical_images_info()->proto.html_critical_image_support(),
|
||||
*driver);
|
||||
int64 next_beacon_timestamp_ms = 0;
|
||||
CriticalImagesInfo* critical_images = driver->critical_images_info();
|
||||
DCHECK(critical_images != NULL)
|
||||
<< "UpdateCriticalImagesSetInDriver must be called before ShouldBeacon";
|
||||
if (critical_images != NULL) {
|
||||
const CriticalImages& proto = critical_images->proto;
|
||||
if (proto.has_html_critical_image_support()) {
|
||||
next_beacon_timestamp_ms =
|
||||
proto.html_critical_image_support().next_beacon_timestamp_ms();
|
||||
}
|
||||
}
|
||||
return net_instaweb::ShouldBeacon(next_beacon_timestamp_ms, *driver);
|
||||
}
|
||||
|
||||
BeaconMetadata BeaconCriticalImagesFinder::PrepareForBeaconInsertion(
|
||||
|
||||
@@ -327,7 +327,7 @@ void WriteCriticalKeysToPropertyCache(
|
||||
}
|
||||
}
|
||||
|
||||
bool ShouldBeacon(const CriticalKeys& proto, const RewriteDriver& driver) {
|
||||
bool ShouldBeacon(int64 next_beacon_timestamp_ms, const RewriteDriver& driver) {
|
||||
// When downstream cache integration is enabled, and there is a rebeaconing
|
||||
// key already specified in the config, we should only rebeacon when there
|
||||
// is a matching key in the beacon requesting header.
|
||||
@@ -337,7 +337,7 @@ bool ShouldBeacon(const CriticalKeys& proto, const RewriteDriver& driver) {
|
||||
driver.request_headers()->Lookup1(kPsaShouldBeacon));
|
||||
}
|
||||
int64 now_ms = driver.timer()->NowMs();
|
||||
return now_ms >= proto.next_beacon_timestamp_ms();
|
||||
return now_ms >= next_beacon_timestamp_ms;
|
||||
}
|
||||
|
||||
void PrepareForBeaconInsertionHelper(CriticalKeys* proto,
|
||||
@@ -346,7 +346,8 @@ void PrepareForBeaconInsertionHelper(CriticalKeys* proto,
|
||||
bool using_candidate_key_detection,
|
||||
BeaconMetadata* result) {
|
||||
result->status = kDoNotBeacon;
|
||||
if (!ShouldBeacon(*proto, *driver)) {
|
||||
CHECK(proto);
|
||||
if (!ShouldBeacon(proto->next_beacon_timestamp_ms(), *driver)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ void UpdateCriticalKeys(bool require_prior_support,
|
||||
const StringSet& new_set, int support_value,
|
||||
CriticalKeys* critical_keys);
|
||||
|
||||
bool ShouldBeacon(const CriticalKeys& proto, const RewriteDriver& driver);
|
||||
bool ShouldBeacon(int64 next_beacon_timestamp_ms, const RewriteDriver& driver);
|
||||
|
||||
enum CriticalKeysWriteFlags {
|
||||
kNoRequirementsOnPriorResult = 0, // Nice name for lack of next two flags.
|
||||
|
||||
Reference in New Issue
Block a user