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

Side by Side Diff: chrome/browser/safe_browsing/delayed_callback_runner.cc

Issue 441453002: Support for process-wide incidents in the safe browsing incident reporting service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/safe_browsing/delayed_callback_runner.h"
6
7 #include "base/location.h"
8
9 namespace safe_browsing {
10
11 DelayedCallbackRunner::DelayedCallbackRunner(
12 base::TimeDelta delay,
13 base::TaskRunner* task_runner)
14 : task_runner_(task_runner),
15 next_callback_(callbacks_.end()),
16 timer_(FROM_HERE, delay, this, &DelayedCallbackRunner::OnTimer) {
17 }
18
19 DelayedCallbackRunner::~DelayedCallbackRunner() {
20 }
21
22 void DelayedCallbackRunner::RegisterCallback(const base::Closure& callback) {
23 callbacks_.push_back(callback);
24 }
25
26 void DelayedCallbackRunner::Start() {
27 // Nothing to do if the runner is already running or nothing has been added.
28 if (next_callback_ != callbacks_.end() || callbacks_.empty())
29 return;
30
31 // Prime the system with the first callback.
32 next_callback_ = callbacks_.begin();
33
34 // Point the starter pistol in the air and pull the trigger.
35 timer_.Reset();
36 }
37
38 void DelayedCallbackRunner::OnTimer() {
39 // Run the next callback on the task runner.
40 task_runner_->PostTask(FROM_HERE, *next_callback_);
41
42 // Get ready for the next callback if there is one.
43 if (++next_callback_ != callbacks_.end())
44 timer_.Reset();
45 }
46
47 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698