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

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

Issue 252613002: Domain Reliability: More security review. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix one unittest Created 6 years, 7 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
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/dispatcher.h" 5 #include "components/domain_reliability/dispatcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
11 #include "components/domain_reliability/util.h" 11 #include "components/domain_reliability/util.h"
12 12
13 namespace domain_reliability { 13 namespace domain_reliability {
14 14
15 struct DomainReliabilityDispatcher::Task {
16 Task(const base::Closure& closure,
17 scoped_ptr<MockableTime::Timer> timer,
18 base::TimeDelta min_delay,
19 base::TimeDelta max_delay);
20 ~Task();
21
22 base::Closure closure;
23 scoped_ptr<MockableTime::Timer> timer;
24 base::TimeDelta min_delay;
25 base::TimeDelta max_delay;
26 bool eligible;
27 };
28
15 DomainReliabilityDispatcher::DomainReliabilityDispatcher(MockableTime* time) 29 DomainReliabilityDispatcher::DomainReliabilityDispatcher(MockableTime* time)
16 : time_(time) {} 30 : time_(time) {}
17 31
18 DomainReliabilityDispatcher::~DomainReliabilityDispatcher() { 32 DomainReliabilityDispatcher::~DomainReliabilityDispatcher() {
19 // TODO(ttuttle): STLElementDeleter? 33 // TODO(ttuttle): STLElementDeleter?
20 STLDeleteElements(&tasks_); 34 STLDeleteElements(&tasks_);
21 } 35 }
22 36
23 void DomainReliabilityDispatcher::ScheduleTask( 37 void DomainReliabilityDispatcher::ScheduleTask(
24 const base::Closure& closure, 38 const base::Closure& closure,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 DomainReliabilityDispatcher::Task::Task(const base::Closure& closure, 73 DomainReliabilityDispatcher::Task::Task(const base::Closure& closure,
60 scoped_ptr<MockableTime::Timer> timer, 74 scoped_ptr<MockableTime::Timer> timer,
61 base::TimeDelta min_delay, 75 base::TimeDelta min_delay,
62 base::TimeDelta max_delay) 76 base::TimeDelta max_delay)
63 : closure(closure), 77 : closure(closure),
64 timer(timer.Pass()), 78 timer(timer.Pass()),
65 min_delay(min_delay), 79 min_delay(min_delay),
66 max_delay(max_delay), 80 max_delay(max_delay),
67 eligible(false) {} 81 eligible(false) {}
68 82
69 DomainReliabilityDispatcher::Task::~Task() {} 83 DomainReliabilityDispatcher::Task::~Task() {}
Ryan Sleevi 2014/04/30 23:58:11 Seems like you should move 73-83 up to 28, to matc
Deprecated (see juliatuttle) 2014/05/02 19:23:40 Done.
70 84
71 void DomainReliabilityDispatcher::MakeTaskWaiting(Task* task) { 85 void DomainReliabilityDispatcher::MakeTaskWaiting(Task* task) {
72 DCHECK(task); 86 DCHECK(task);
73 DCHECK(!task->eligible); 87 DCHECK(!task->eligible);
74 DCHECK(!task->timer->IsRunning()); 88 DCHECK(!task->timer->IsRunning());
75 task->timer->Start( 89 task->timer->Start(FROM_HERE,
76 FROM_HERE, 90 task->min_delay,
77 task->min_delay, 91 base::Bind(&DomainReliabilityDispatcher::MakeTaskEligible,
78 base::Bind( 92 base::Unretained(this),
79 &DomainReliabilityDispatcher::MakeTaskEligible, 93 task));
80 base::Unretained(this),
81 task));
82 } 94 }
83 95
84 void 96 void
85 DomainReliabilityDispatcher::MakeTaskEligible(Task* task) { 97 DomainReliabilityDispatcher::MakeTaskEligible(Task* task) {
86 DCHECK(task); 98 DCHECK(task);
87 DCHECK(!task->eligible); 99 DCHECK(!task->eligible);
88 task->eligible = true; 100 task->eligible = true;
89 eligible_tasks_.insert(task); 101 eligible_tasks_.insert(task);
90 task->timer->Start( 102 task->timer->Start(FROM_HERE,
91 FROM_HERE, 103 task->max_delay - task->min_delay,
92 task->max_delay - task->min_delay, 104 base::Bind(&DomainReliabilityDispatcher::RunAndDeleteTask,
93 base::Bind( 105 base::Unretained(this),
94 &DomainReliabilityDispatcher::RunAndDeleteTask, 106 task));
Ryan Sleevi 2014/04/30 23:58:11 DESIGN: Not something for now, but I'm wondering i
Deprecated (see juliatuttle) 2014/05/02 19:23:40 I added two layers of indirection: MockableTime: L
95 base::Unretained(this),
96 task));
97 } 107 }
98 108
99 void DomainReliabilityDispatcher::RunAndDeleteTask(Task* task) { 109 void DomainReliabilityDispatcher::RunAndDeleteTask(Task* task) {
100 DCHECK(task); 110 DCHECK(task);
101 DCHECK(!task->closure.is_null()); 111 DCHECK(!task->closure.is_null());
102 task->closure.Run(); 112 task->closure.Run();
103 if (task->eligible) 113 if (task->eligible)
104 eligible_tasks_.erase(task); 114 eligible_tasks_.erase(task);
105 tasks_.erase(task); 115 tasks_.erase(task);
106 delete task; 116 delete task;
107 } 117 }
108 118
109 } // namespace domain_reliability 119 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698