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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/domain_reliability/context_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/domain_reliability/context.h" 5 #include "components/domain_reliability/context.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 21 matching lines...) Expand all
32 class DomainReliabilityContext::ResourceState { 32 class DomainReliabilityContext::ResourceState {
33 public: 33 public:
34 ResourceState(DomainReliabilityContext* context, 34 ResourceState(DomainReliabilityContext* context,
35 const DomainReliabilityConfig::Resource* config) 35 const DomainReliabilityConfig::Resource* config)
36 : context(context), 36 : context(context),
37 config(config), 37 config(config),
38 successful_requests(0), 38 successful_requests(0),
39 failed_requests(0) {} 39 failed_requests(0) {}
40 ~ResourceState() {} 40 ~ResourceState() {}
41 41
42 // Serializes the resource state into a Value to be included in an upload.
43 // If there is nothing to report (no beacons and all request counters are 0),
44 // returns a scoped_ptr to NULL instead so the resource can be omitted.
42 scoped_ptr<base::Value> ToValue(base::TimeTicks upload_time) const { 45 scoped_ptr<base::Value> ToValue(base::TimeTicks upload_time) const {
46 if (beacons.empty() && successful_requests == 0 && failed_requests == 0)
47 return scoped_ptr<base::Value>();
48
43 ListValue* beacons_value = new ListValue(); 49 ListValue* beacons_value = new ListValue();
44 for (BeaconConstIterator it = beacons.begin(); it != beacons.end(); ++it) 50 for (BeaconConstIterator it = beacons.begin(); it != beacons.end(); ++it)
45 beacons_value->Append(it->ToValue(upload_time)); 51 beacons_value->Append(it->ToValue(upload_time));
46 52
47 DictionaryValue* resource_value = new DictionaryValue(); 53 DictionaryValue* resource_value = new DictionaryValue();
48 resource_value->SetString("resource_name", config->name); 54 resource_value->SetString("resource_name", config->name);
49 resource_value->SetInteger("successful_requests", successful_requests); 55 resource_value->SetInteger("successful_requests", successful_requests);
50 resource_value->SetInteger("failed_requests", failed_requests); 56 resource_value->SetInteger("failed_requests", failed_requests);
51 resource_value->Set("beacons", beacons_value); 57 resource_value->Set("beacons", beacons_value);
52 58
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 DCHECK(!upload_time_.is_null()); 258 DCHECK(!upload_time_.is_null());
253 UMA_HISTOGRAM_MEDIUM_TIMES("DomainReliability.UploadDuration", 259 UMA_HISTOGRAM_MEDIUM_TIMES("DomainReliability.UploadDuration",
254 time_->NowTicks() - upload_time_); 260 time_->NowTicks() - upload_time_);
255 last_upload_time_ = upload_time_; 261 last_upload_time_ = upload_time_;
256 upload_time_ = base::TimeTicks(); 262 upload_time_ = base::TimeTicks();
257 } 263 }
258 264
259 scoped_ptr<const Value> DomainReliabilityContext::CreateReport( 265 scoped_ptr<const Value> DomainReliabilityContext::CreateReport(
260 base::TimeTicks upload_time) const { 266 base::TimeTicks upload_time) const {
261 ListValue* resources_value = new ListValue(); 267 ListValue* resources_value = new ListValue();
262 for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it) 268 for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it) {
263 resources_value->Append((*it)->ToValue(upload_time).release()); 269 scoped_ptr<Value> resource_report = (*it)->ToValue(upload_time);
270 if (resource_report)
271 resources_value->Append(resource_report.release());
272 }
264 273
265 DictionaryValue* report_value = new DictionaryValue(); 274 DictionaryValue* report_value = new DictionaryValue();
266 report_value->SetString("reporter", upload_reporter_string_); 275 report_value->SetString("reporter", upload_reporter_string_);
267 report_value->Set("resource_reports", resources_value); 276 report_value->Set("resource_reports", resources_value);
268 277
269 return scoped_ptr<const Value>(report_value); 278 return scoped_ptr<const Value>(report_value);
270 } 279 }
271 280
272 void DomainReliabilityContext::MarkUpload() { 281 void DomainReliabilityContext::MarkUpload() {
273 for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it) 282 for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it)
(...skipping 28 matching lines...) Expand all
302 311
303 min_resource->RemoveOldestBeacon(); 312 min_resource->RemoveOldestBeacon();
304 --beacon_count_; 313 --beacon_count_;
305 // If that just removed a beacon counted in uploading_beacon_count_, decrement 314 // If that just removed a beacon counted in uploading_beacon_count_, decrement
306 // that. 315 // that.
307 if (uploading_beacon_count_ > 0) 316 if (uploading_beacon_count_ > 0)
308 --uploading_beacon_count_; 317 --uploading_beacon_count_;
309 } 318 }
310 319
311 } // namespace domain_reliability 320 } // namespace domain_reliability
OLDNEW
« 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