Commit 90c03338 authored by ttuttle@chromium.org's avatar ttuttle@chromium.org

Domain Reliability: Omit empty, 0-count resources from uploads

Don't waste space including resources with empty beacons and 0 counters
in uploads.

BUG=356791

Review URL: https://codereview.chromium.org/284283002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271045 0039d316-1c4b-4281-b951-d872f2087c98
parent 04412a00
......@@ -39,7 +39,13 @@ class DomainReliabilityContext::ResourceState {
failed_requests(0) {}
~ResourceState() {}
// Serializes the resource state into a Value to be included in an upload.
// If there is nothing to report (no beacons and all request counters are 0),
// returns a scoped_ptr to NULL instead so the resource can be omitted.
scoped_ptr<base::Value> ToValue(base::TimeTicks upload_time) const {
if (beacons.empty() && successful_requests == 0 && failed_requests == 0)
return scoped_ptr<base::Value>();
ListValue* beacons_value = new ListValue();
for (BeaconConstIterator it = beacons.begin(); it != beacons.end(); ++it)
beacons_value->Append(it->ToValue(upload_time));
......@@ -259,8 +265,11 @@ void DomainReliabilityContext::OnUploadComplete(bool success) {
scoped_ptr<const Value> DomainReliabilityContext::CreateReport(
base::TimeTicks upload_time) const {
ListValue* resources_value = new ListValue();
for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it)
resources_value->Append((*it)->ToValue(upload_time).release());
for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it) {
scoped_ptr<Value> resource_report = (*it)->ToValue(upload_time);
if (resource_report)
resources_value->Append(resource_report.release());
}
DictionaryValue* report_value = new DictionaryValue();
report_value->SetString("reporter", upload_reporter_string_);
......
......@@ -162,9 +162,7 @@ TEST_F(DomainReliabilityContextTest, ReportUpload) {
"\"resource_reports\":[{\"beacons\":[{\"http_response_code\":200,"
"\"request_age_ms\":300250,\"request_elapsed_ms\":250,\"server_ip\":"
"\"127.0.0.1\",\"status\":\"ok\"}],\"failed_requests\":0,"
"\"resource_name\":\"always_report\",\"successful_requests\":1},"
"{\"beacons\":[],\"failed_requests\":0,\"resource_name\":"
"\"never_report\",\"successful_requests\":0}]}";
"\"resource_name\":\"always_report\",\"successful_requests\":1}]}";
time_.Advance(max_delay());
EXPECT_TRUE(upload_pending());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment