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

Side by Side Diff: components/domain_reliability/context.cc

Issue 2464163003: Domain Reliability: Expire queued beacons after 1 hour. (Closed)
Patch Set: Created 4 years, 1 month 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
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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 base::TimeDelta max_delay) { 147 base::TimeDelta max_delay) {
148 dispatcher_->ScheduleTask( 148 dispatcher_->ScheduleTask(
149 base::Bind( 149 base::Bind(
150 &DomainReliabilityContext::StartUpload, 150 &DomainReliabilityContext::StartUpload,
151 weak_factory_.GetWeakPtr()), 151 weak_factory_.GetWeakPtr()),
152 min_delay, 152 min_delay,
153 max_delay); 153 max_delay);
154 } 154 }
155 155
156 void DomainReliabilityContext::StartUpload() { 156 void DomainReliabilityContext::StartUpload() {
157 RemoveExpiredBeacons();
158 if (beacons_.empty())
159 return;
160
157 MarkUpload(); 161 MarkUpload();
158 162
159 size_t collector_index = scheduler_.OnUploadStart(); 163 size_t collector_index = scheduler_.OnUploadStart();
160 const GURL& collector_url = *config().collectors[collector_index]; 164 const GURL& collector_url = *config().collectors[collector_index];
161 165
162 DCHECK(upload_time_.is_null()); 166 DCHECK(upload_time_.is_null());
163 upload_time_ = time_->NowTicks(); 167 upload_time_ = time_->NowTicks();
164 std::string report_json = "{}"; 168 std::string report_json = "{}";
165 int max_upload_depth = -1; 169 int max_upload_depth = -1;
166 bool wrote = base::JSONWriter::Write( 170 bool wrote = base::JSONWriter::Write(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 << "removing oldest beacon"; 263 << "removing oldest beacon";
260 264
261 beacons_.pop_front(); 265 beacons_.pop_front();
262 266
263 // If that just removed a beacon counted in uploading_beacons_size_, decrement 267 // If that just removed a beacon counted in uploading_beacons_size_, decrement
264 // that. 268 // that.
265 if (uploading_beacons_size_ > 0) 269 if (uploading_beacons_size_ > 0)
266 --uploading_beacons_size_; 270 --uploading_beacons_size_;
267 } 271 }
268 272
273 void DomainReliabilityContext::RemoveExpiredBeacons() {
274 base::TimeTicks now = time_->NowTicks();
275 const base::TimeDelta kMaxAge = base::TimeDelta::FromHours(1);
Randy Smith (Not in Mondays) 2016/11/04 16:06:29 Defined constant somewhere?
276 while (!beacons_.empty() && now - beacons_.front()->start_time >= kMaxAge)
277 beacons_.pop_front();
278 }
279
269 } // namespace domain_reliability 280 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/context.h ('k') | components/domain_reliability/context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698