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

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

Issue 252613002: Domain Reliability: More security review. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ;_; 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 #ifndef COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_ 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_ 6 #define COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 #include "components/domain_reliability/domain_reliability_export.h" 12 #include "components/domain_reliability/domain_reliability_export.h"
14 #include "components/domain_reliability/util.h" 13 #include "components/domain_reliability/util.h"
15 14
16 namespace tracked_objects { 15 namespace tracked_objects {
17 class Location; 16 class Location;
18 } // namespace tracked_objects 17 } // namespace tracked_objects
19 18
20 namespace domain_reliability { 19 namespace domain_reliability {
21 20
22 // Runs tasks during a specified interval. Calling |RunEligibleTasks| gives any 21 // Runs tasks during a specified interval. Calling |RunEligibleTasks| gives any
23 // task a chance to run early (if the minimum delay has already passed); tasks 22 // task a chance to run early (if the minimum delay has already passed); tasks
24 // that aren't run early will be run once their maximum delay has passed. 23 // that aren't run early will be run once their maximum delay has passed.
25 // 24 //
26 // (See scheduler.h for an explanation of how the intervals are chosen.) 25 // (See scheduler.h for an explanation of how the intervals are chosen.)
27 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityDispatcher { 26 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityDispatcher {
28 public: 27 public:
29 DomainReliabilityDispatcher(MockableTime* time); 28 explicit DomainReliabilityDispatcher(MockableTime* time);
30 ~DomainReliabilityDispatcher(); 29 ~DomainReliabilityDispatcher();
31 30
32 void ScheduleTask( 31 // Schedules |task| to be executed between |min_delay| and |max_delay| from
33 const base::Closure& task, 32 // now. The task will be run at most |max_delay| from now; once |min_delay|
34 base::TimeDelta min_delay, 33 // has passed, any call to |RunEligibleTasks| will run the task earlier than
35 base::TimeDelta max_delay); 34 // that.
35 void ScheduleTask(const base::Closure& task,
36 base::TimeDelta min_delay,
37 base::TimeDelta max_delay);
36 38
39 // Runs all tasks whose minimum delay has already passed.
37 void RunEligibleTasks(); 40 void RunEligibleTasks();
38 41
39 private: 42 private:
40 struct Task { 43 struct Task;
41 Task(const base::Closure& closure_p,
42 scoped_ptr<MockableTime::Timer> timer_p,
43 base::TimeDelta min_delay_p,
44 base::TimeDelta max_delay_p);
45 ~Task();
46 44
47 base::Closure closure; 45 // Adds |task| to the set of all tasks, but not the set of eligible tasks.
48 scoped_ptr<MockableTime::Timer> timer; 46 void MakeTaskWaiting(Task* task);
49 base::TimeDelta min_delay;
50 base::TimeDelta max_delay;
51 bool eligible;
52 };
53 47
54 void MakeTaskWaiting(Task* task); 48 // Adds |task| to the set of eligible tasks, and also the set of all tasks
49 // if not already there.
55 void MakeTaskEligible(Task* task); 50 void MakeTaskEligible(Task* task);
51
52 // Runs |task|'s callback, removes it from both sets, and deletes it.
56 void RunAndDeleteTask(Task* task); 53 void RunAndDeleteTask(Task* task);
57 54
58 MockableTime* time_; 55 MockableTime* time_;
59 std::set<Task*> tasks_; 56 std::set<Task*> tasks_;
60 std::set<Task*> eligible_tasks_; 57 std::set<Task*> eligible_tasks_;
61 }; 58 };
62 59
63 } // namespace domain_reliability 60 } // namespace domain_reliability
64 61
65 #endif 62 #endif
OLDNEW
« no previous file with comments | « components/domain_reliability/context_unittest.cc ('k') | components/domain_reliability/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698