| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 reported = true; | 88 reported = true; |
| 89 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError", | 89 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError", |
| 90 -beacon.chrome_error); | 90 -beacon.chrome_error); |
| 91 // TODO(ttuttle): Histogram HTTP response code? | 91 // TODO(ttuttle): Histogram HTTP response code? |
| 92 } | 92 } |
| 93 | 93 |
| 94 UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", reported); | 94 UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", reported); |
| 95 UMA_HISTOGRAM_BOOLEAN("DomainReliability.AddBeaconDidEvict", evicted); | 95 UMA_HISTOGRAM_BOOLEAN("DomainReliability.AddBeaconDidEvict", evicted); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void DomainReliabilityContext::ClearBeacons() { |
| 99 ResourceStateVector::iterator it; |
| 100 for (it = states_.begin(); it != states_.end(); ++it) { |
| 101 ResourceState* state = *it; |
| 102 state->beacons.clear(); |
| 103 state->successful_requests = 0; |
| 104 state->failed_requests = 0; |
| 105 state->uploading_beacons_size = 0; |
| 106 state->uploading_successful_requests = 0; |
| 107 state->uploading_failed_requests = 0; |
| 108 } |
| 109 beacon_count_ = 0; |
| 110 uploading_beacon_count_ = 0; |
| 111 } |
| 112 |
| 98 void DomainReliabilityContext::GetQueuedDataForTesting( | 113 void DomainReliabilityContext::GetQueuedDataForTesting( |
| 99 int resource_index, | 114 int resource_index, |
| 100 std::vector<DomainReliabilityBeacon>* beacons_out, | 115 std::vector<DomainReliabilityBeacon>* beacons_out, |
| 101 int* successful_requests_out, | 116 int* successful_requests_out, |
| 102 int* failed_requests_out) const { | 117 int* failed_requests_out) const { |
| 103 DCHECK_LE(0, resource_index); | 118 DCHECK_LE(0, resource_index); |
| 104 DCHECK_GT(static_cast<int>(states_.size()), resource_index); | 119 DCHECK_GT(static_cast<int>(states_.size()), resource_index); |
| 105 const ResourceState& state = *states_[resource_index]; | 120 const ResourceState& state = *states_[resource_index]; |
| 106 if (beacons_out) { | 121 if (beacons_out) { |
| 107 beacons_out->resize(state.beacons.size()); | 122 beacons_out->resize(state.beacons.size()); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 287 |
| 273 min_resource->RemoveOldestBeacon(); | 288 min_resource->RemoveOldestBeacon(); |
| 274 --beacon_count_; | 289 --beacon_count_; |
| 275 // If that just removed a beacon counted in uploading_beacon_count_, decrement | 290 // If that just removed a beacon counted in uploading_beacon_count_, decrement |
| 276 // that. | 291 // that. |
| 277 if (uploading_beacon_count_ > 0) | 292 if (uploading_beacon_count_ > 0) |
| 278 --uploading_beacon_count_; | 293 --uploading_beacon_count_; |
| 279 } | 294 } |
| 280 | 295 |
| 281 } // namespace domain_reliability | 296 } // namespace domain_reliability |
| OLD | NEW |