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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 reported = true; | 162 reported = true; |
163 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError", | 163 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.ReportedBeaconError", |
164 -beacon.chrome_error); | 164 -beacon.chrome_error); |
165 // TODO(ttuttle): Histogram HTTP response code? | 165 // TODO(ttuttle): Histogram HTTP response code? |
166 } | 166 } |
167 | 167 |
168 UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", reported); | 168 UMA_HISTOGRAM_BOOLEAN("DomainReliability.BeaconReported", reported); |
169 UMA_HISTOGRAM_BOOLEAN("DomainReliability.OnBeaconDidEvict", evicted); | 169 UMA_HISTOGRAM_BOOLEAN("DomainReliability.OnBeaconDidEvict", evicted); |
170 } | 170 } |
171 | 171 |
| 172 void DomainReliabilityContext::ClearBeacons() { |
| 173 ResourceStateVector::iterator it; |
| 174 for (it = states_.begin(); it != states_.end(); ++it) { |
| 175 ResourceState* state = *it; |
| 176 state->beacons.clear(); |
| 177 state->successful_requests = 0; |
| 178 state->failed_requests = 0; |
| 179 state->uploading_beacons_size = 0; |
| 180 state->uploading_successful_requests = 0; |
| 181 state->uploading_failed_requests = 0; |
| 182 } |
| 183 beacon_count_ = 0; |
| 184 uploading_beacon_count_ = 0; |
| 185 } |
| 186 |
172 void DomainReliabilityContext::GetQueuedDataForTesting( | 187 void DomainReliabilityContext::GetQueuedDataForTesting( |
173 size_t resource_index, | 188 size_t resource_index, |
174 std::vector<DomainReliabilityBeacon>* beacons_out, | 189 std::vector<DomainReliabilityBeacon>* beacons_out, |
175 uint32* successful_requests_out, | 190 uint32* successful_requests_out, |
176 uint32* failed_requests_out) const { | 191 uint32* failed_requests_out) const { |
177 DCHECK_NE(DomainReliabilityConfig::kInvalidResourceIndex, resource_index); | 192 DCHECK_NE(DomainReliabilityConfig::kInvalidResourceIndex, resource_index); |
178 DCHECK_GT(states_.size(), resource_index); | 193 DCHECK_GT(states_.size(), resource_index); |
179 const ResourceState& state = *states_[resource_index]; | 194 const ResourceState& state = *states_[resource_index]; |
180 if (beacons_out) | 195 if (beacons_out) |
181 beacons_out->assign(state.beacons.begin(), state.beacons.end()); | 196 beacons_out->assign(state.beacons.begin(), state.beacons.end()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 302 |
288 min_resource->RemoveOldestBeacon(); | 303 min_resource->RemoveOldestBeacon(); |
289 --beacon_count_; | 304 --beacon_count_; |
290 // If that just removed a beacon counted in uploading_beacon_count_, decrement | 305 // If that just removed a beacon counted in uploading_beacon_count_, decrement |
291 // that. | 306 // that. |
292 if (uploading_beacon_count_ > 0) | 307 if (uploading_beacon_count_ > 0) |
293 --uploading_beacon_count_; | 308 --uploading_beacon_count_; |
294 } | 309 } |
295 | 310 |
296 } // namespace domain_reliability | 311 } // namespace domain_reliability |
OLD | NEW |