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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 scheduler_.OnBeaconAdded(); | 99 scheduler_.OnBeaconAdded(); |
100 beacons_.push_back(beacon.release()); | 100 beacons_.push_back(beacon.release()); |
101 bool should_evict = beacons_.size() > kMaxQueuedBeacons; | 101 bool should_evict = beacons_.size() > kMaxQueuedBeacons; |
102 if (should_evict) | 102 if (should_evict) |
103 RemoveOldestBeacon(); | 103 RemoveOldestBeacon(); |
104 | 104 |
105 LogOnBeaconDidEvictHistogram(should_evict); | 105 LogOnBeaconDidEvictHistogram(should_evict); |
106 } | 106 } |
107 | 107 |
108 void DomainReliabilityContext::ClearBeacons() { | 108 void DomainReliabilityContext::ClearBeacons() { |
109 STLDeleteElements(&beacons_); | 109 base::STLDeleteElements(&beacons_); |
110 beacons_.clear(); | 110 beacons_.clear(); |
111 uploading_beacons_size_ = 0; | 111 uploading_beacons_size_ = 0; |
112 } | 112 } |
113 | 113 |
114 std::unique_ptr<Value> DomainReliabilityContext::GetWebUIData() const { | 114 std::unique_ptr<Value> DomainReliabilityContext::GetWebUIData() const { |
115 DictionaryValue* context_value = new DictionaryValue(); | 115 DictionaryValue* context_value = new DictionaryValue(); |
116 | 116 |
117 context_value->SetString("origin", config().origin.spec()); | 117 context_value->SetString("origin", config().origin.spec()); |
118 context_value->SetInteger("beacon_count", static_cast<int>(beacons_.size())); | 118 context_value->SetInteger("beacon_count", static_cast<int>(beacons_.size())); |
119 context_value->SetInteger("uploading_beacon_count", | 119 context_value->SetInteger("uploading_beacon_count", |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 void DomainReliabilityContext::MarkUpload() { | 224 void DomainReliabilityContext::MarkUpload() { |
225 DCHECK_EQ(0u, uploading_beacons_size_); | 225 DCHECK_EQ(0u, uploading_beacons_size_); |
226 uploading_beacons_size_ = beacons_.size(); | 226 uploading_beacons_size_ = beacons_.size(); |
227 DCHECK_NE(0u, uploading_beacons_size_); | 227 DCHECK_NE(0u, uploading_beacons_size_); |
228 } | 228 } |
229 | 229 |
230 void DomainReliabilityContext::CommitUpload() { | 230 void DomainReliabilityContext::CommitUpload() { |
231 auto begin = beacons_.begin(); | 231 auto begin = beacons_.begin(); |
232 auto end = begin + uploading_beacons_size_; | 232 auto end = begin + uploading_beacons_size_; |
233 STLDeleteContainerPointers(begin, end); | 233 base::STLDeleteContainerPointers(begin, end); |
234 beacons_.erase(begin, end); | 234 beacons_.erase(begin, end); |
235 DCHECK_NE(0u, uploading_beacons_size_); | 235 DCHECK_NE(0u, uploading_beacons_size_); |
236 uploading_beacons_size_ = 0; | 236 uploading_beacons_size_ = 0; |
237 } | 237 } |
238 | 238 |
239 void DomainReliabilityContext::RollbackUpload() { | 239 void DomainReliabilityContext::RollbackUpload() { |
240 DCHECK_NE(0u, uploading_beacons_size_); | 240 DCHECK_NE(0u, uploading_beacons_size_); |
241 uploading_beacons_size_ = 0; | 241 uploading_beacons_size_ = 0; |
242 } | 242 } |
243 | 243 |
244 void DomainReliabilityContext::RemoveOldestBeacon() { | 244 void DomainReliabilityContext::RemoveOldestBeacon() { |
245 DCHECK(!beacons_.empty()); | 245 DCHECK(!beacons_.empty()); |
246 | 246 |
247 VLOG(1) << "Beacon queue for " << config().origin << " full; " | 247 VLOG(1) << "Beacon queue for " << config().origin << " full; " |
248 << "removing oldest beacon"; | 248 << "removing oldest beacon"; |
249 | 249 |
250 delete beacons_.front(); | 250 delete beacons_.front(); |
251 beacons_.pop_front(); | 251 beacons_.pop_front(); |
252 | 252 |
253 // If that just removed a beacon counted in uploading_beacons_size_, decrement | 253 // If that just removed a beacon counted in uploading_beacons_size_, decrement |
254 // that. | 254 // that. |
255 if (uploading_beacons_size_ > 0) | 255 if (uploading_beacons_size_ > 0) |
256 --uploading_beacons_size_; | 256 --uploading_beacons_size_; |
257 } | 257 } |
258 | 258 |
259 } // namespace domain_reliability | 259 } // namespace domain_reliability |
OLD | NEW |