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

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: tweak 2 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), weak_factory_(this) {
15 InitializeRunInternal();
16 }
17
18 DeadlineTaskRunner::~DeadlineTaskRunner() {
19 }
20
21 void DeadlineTaskRunner::SetDeadline(const tracked_objects::Location& from_here,
22 base::TimeTicks deadline,
23 base::TimeTicks now) {
24 DCHECK(deadline > now);
25 if (deadline_ != base::TimeTicks()) {
26 if (deadline >= deadline_)
27 return;
rmcilroy 2015/03/12 15:45:30 This might be clearer with a non-nested early out
alex clarke (OOO till 29th) 2015/03/12 17:01:49 Unfortunately that will always early out if we use
28
29 Cancel();
30 }
31 deadline_ = deadline;
32 task_runner_->PostDelayedTask(from_here, run_internal_, deadline - now);
33 }
34
35 void DeadlineTaskRunner::RunInternal() {
36 deadline_ = base::TimeTicks();
37 callback_.Run();
38 }
39
40 void DeadlineTaskRunner::Cancel() {
41 weak_factory_.InvalidateWeakPtrs();
42 InitializeRunInternal();
43 }
44
45 void DeadlineTaskRunner::InitializeRunInternal() {
46 run_internal_ =
47 base::Bind(&DeadlineTaskRunner::RunInternal, weak_factory_.GetWeakPtr());
rmcilroy 2015/03/12 15:45:30 Just use a CancelableClosureHolder for the interna
alex clarke (OOO till 29th) 2015/03/12 17:01:49 I thought about doing it that way but I think we'd
48 }
49
50 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698