Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Unified Diff: components/domain_reliability/context.cc

Issue 284283002: Domain Reliability: Omit empty, 0-count resources from uploads (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/domain_reliability/context_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/domain_reliability/context.cc
diff --git a/components/domain_reliability/context.cc b/components/domain_reliability/context.cc
index 18a37555baae515f59070cc890103874d5d08956..7acc8e67fe257d468623193956fbba6ae3efac26 100644
--- a/components/domain_reliability/context.cc
+++ b/components/domain_reliability/context.cc
@@ -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_);
« no previous file with comments | « no previous file | components/domain_reliability/context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698