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

Side by Side Diff: content/renderer/scheduler/deadline_task_runner.cc

Issue 994833003: Prevent multiple pending UpdatePolicy tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change for Ross Created 5 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "content/renderer/scheduler/deadline_task_runner.h"
6
7 #include "base/bind.h"
8
9 namespace content {
10
11 DeadlineTaskRunner::DeadlineTaskRunner(
12 const base::Closure& callback,
13 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
14 : callback_(callback), task_runner_(task_runner) {
15 cancelable_run_internal_.Reset(base::Bind(
16 &DeadlineTaskRunner::RunInternal, base::Unretained(this)));
17 }
18
19 DeadlineTaskRunner::~DeadlineTaskRunner() {
20 }
Sami 2015/03/12 18:15:22 We don't need to cancel the callback here, right?
alex clarke (OOO till 29th) 2015/03/12 18:24:07 No that's done implicitly. There is a test for th
21
22 void DeadlineTaskRunner::SetDeadline(const tracked_objects::Location& from_here,
23 base::TimeDelta delay,
24 base::TimeTicks now) {
25 DCHECK(delay > base::TimeDelta());
26 base::TimeTicks deadline = now + delay;
27 if (deadline_ == base::TimeTicks() || deadline < deadline_) {
Sami 2015/03/12 18:15:22 nit: deadline_.is_null()
alex clarke (OOO till 29th) 2015/03/12 18:24:07 Done.
28 deadline_ = deadline;
29 cancelable_run_internal_.Cancel();
30 task_runner_->PostDelayedTask(
31 from_here, cancelable_run_internal_.callback(), delay);
32 }
33 }
34
35 void DeadlineTaskRunner::RunInternal() {
36 deadline_ = base::TimeTicks();
37 callback_.Run();
38 }
39
40 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698