| OLD | NEW |
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 DISALLOW_COPY_AND_ASSIGN(ResourceState); | 94 DISALLOW_COPY_AND_ASSIGN(ResourceState); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 const size_t DomainReliabilityContext::kMaxQueuedBeacons = 150; | 98 const size_t DomainReliabilityContext::kMaxQueuedBeacons = 150; |
| 99 | 99 |
| 100 DomainReliabilityContext::DomainReliabilityContext( | 100 DomainReliabilityContext::DomainReliabilityContext( |
| 101 MockableTime* time, | 101 MockableTime* time, |
| 102 const DomainReliabilityScheduler::Params& scheduler_params, | 102 const DomainReliabilityScheduler::Params& scheduler_params, |
| 103 const std::string& upload_reporter_string, | 103 const std::string& upload_reporter_string, |
| 104 const base::TimeTicks& last_network_change_time, |
| 104 DomainReliabilityDispatcher* dispatcher, | 105 DomainReliabilityDispatcher* dispatcher, |
| 105 DomainReliabilityUploader* uploader, | 106 DomainReliabilityUploader* uploader, |
| 106 scoped_ptr<const DomainReliabilityConfig> config) | 107 scoped_ptr<const DomainReliabilityConfig> config) |
| 107 : config_(config.Pass()), | 108 : config_(config.Pass()), |
| 108 time_(time), | 109 time_(time), |
| 109 upload_reporter_string_(upload_reporter_string), | 110 upload_reporter_string_(upload_reporter_string), |
| 110 scheduler_(time, | 111 scheduler_(time, |
| 111 config_->collectors.size(), | 112 config_->collectors.size(), |
| 112 scheduler_params, | 113 scheduler_params, |
| 113 base::Bind(&DomainReliabilityContext::ScheduleUpload, | 114 base::Bind(&DomainReliabilityContext::ScheduleUpload, |
| 114 base::Unretained(this))), | 115 base::Unretained(this))), |
| 115 dispatcher_(dispatcher), | 116 dispatcher_(dispatcher), |
| 116 uploader_(uploader), | 117 uploader_(uploader), |
| 117 uploading_beacons_size_(0), | 118 uploading_beacons_size_(0), |
| 119 last_network_change_time_(last_network_change_time), |
| 118 weak_factory_(this) { | 120 weak_factory_(this) { |
| 119 InitializeResourceStates(); | 121 InitializeResourceStates(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 DomainReliabilityContext::~DomainReliabilityContext() {} | 124 DomainReliabilityContext::~DomainReliabilityContext() {} |
| 123 | 125 |
| 124 void DomainReliabilityContext::OnBeacon(const GURL& url, | 126 void DomainReliabilityContext::OnBeacon(const GURL& url, |
| 125 const DomainReliabilityBeacon& beacon) { | 127 const DomainReliabilityBeacon& beacon) { |
| 126 size_t index = config_->GetResourceIndexForUrl(url); | 128 size_t index = config_->GetResourceIndexForUrl(url); |
| 127 if (index == DomainReliabilityConfig::kInvalidResourceIndex) | 129 if (index == DomainReliabilityConfig::kInvalidResourceIndex) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 UMA_HISTOGRAM_MEDIUM_TIMES("DomainReliability.UploadDuration", | 255 UMA_HISTOGRAM_MEDIUM_TIMES("DomainReliability.UploadDuration", |
| 254 time_->NowTicks() - upload_time_); | 256 time_->NowTicks() - upload_time_); |
| 255 last_upload_time_ = upload_time_; | 257 last_upload_time_ = upload_time_; |
| 256 upload_time_ = base::TimeTicks(); | 258 upload_time_ = base::TimeTicks(); |
| 257 } | 259 } |
| 258 | 260 |
| 259 scoped_ptr<const Value> DomainReliabilityContext::CreateReport( | 261 scoped_ptr<const Value> DomainReliabilityContext::CreateReport( |
| 260 base::TimeTicks upload_time) const { | 262 base::TimeTicks upload_time) const { |
| 261 scoped_ptr<ListValue> beacons_value(new ListValue()); | 263 scoped_ptr<ListValue> beacons_value(new ListValue()); |
| 262 for (BeaconConstIterator it = beacons_.begin(); it != beacons_.end(); ++it) | 264 for (BeaconConstIterator it = beacons_.begin(); it != beacons_.end(); ++it) |
| 263 beacons_value->Append(it->ToValue(upload_time)); | 265 beacons_value->Append(it->ToValue(upload_time, last_network_change_time_)); |
| 264 | 266 |
| 265 scoped_ptr<ListValue> resources_value(new ListValue()); | 267 scoped_ptr<ListValue> resources_value(new ListValue()); |
| 266 for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it) { | 268 for (ResourceStateIterator it = states_.begin(); it != states_.end(); ++it) { |
| 267 scoped_ptr<Value> resource_report = (*it)->ToValue(upload_time); | 269 scoped_ptr<Value> resource_report = (*it)->ToValue(upload_time); |
| 268 if (resource_report) | 270 if (resource_report) |
| 269 resources_value->Append(resource_report.release()); | 271 resources_value->Append(resource_report.release()); |
| 270 } | 272 } |
| 271 | 273 |
| 272 DictionaryValue* report_value = new DictionaryValue(); | 274 DictionaryValue* report_value = new DictionaryValue(); |
| 273 if (!config().version.empty()) | 275 if (!config().version.empty()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 315 |
| 314 beacons_.pop_front(); | 316 beacons_.pop_front(); |
| 315 | 317 |
| 316 // If that just removed a beacon counted in uploading_beacons_size_, decrement | 318 // If that just removed a beacon counted in uploading_beacons_size_, decrement |
| 317 // that. | 319 // that. |
| 318 if (uploading_beacons_size_ > 0) | 320 if (uploading_beacons_size_ > 0) |
| 319 --uploading_beacons_size_; | 321 --uploading_beacons_size_; |
| 320 } | 322 } |
| 321 | 323 |
| 322 } // namespace domain_reliability | 324 } // namespace domain_reliability |
| OLD | NEW |