OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_POLICY_LOGGING_WORK_SCHEDULER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_LOGGING_WORK_SCHEDULER_H_ |
6 #define CHROME_BROWSER_POLICY_LOGGING_WORK_SCHEDULER_H_ | 6 #define CHROME_BROWSER_POLICY_LOGGING_WORK_SCHEDULER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 #include <vector> | 10 #include <vector> |
(...skipping 16 matching lines...) Expand all Loading... | |
27 private: | 27 private: |
28 DISALLOW_COPY_AND_ASSIGN(DummyWorkScheduler); | 28 DISALLOW_COPY_AND_ASSIGN(DummyWorkScheduler); |
29 }; | 29 }; |
30 | 30 |
31 // Helper class for LoggingWorkScheduler. It essentially emulates a real | 31 // Helper class for LoggingWorkScheduler. It essentially emulates a real |
32 // message loop. All the submitted tasks are run with zero delay, but the | 32 // message loop. All the submitted tasks are run with zero delay, but the |
33 // order in which they would run with delays is preserved. | 33 // order in which they would run with delays is preserved. |
34 // All the task posting requests of the schedulers will be channeled through | 34 // All the task posting requests of the schedulers will be channeled through |
35 // a common instance of EventLogger. This makes sure, that this instance can | 35 // a common instance of EventLogger. This makes sure, that this instance can |
36 // keep track of time in the simulation and record logged events with correct | 36 // keep track of time in the simulation and record logged events with correct |
37 // timestamps. | 37 // timestamps. |
zunger
2011/07/19 19:41:46
Again, what's the thread safety? And is this class
gfeher
2011/07/20 16:36:30
This is part of the public API. I've added some ex
| |
38 class EventLogger { | 38 class EventLogger { |
39 public: | 39 public: |
40 EventLogger(); | 40 EventLogger(); |
41 virtual ~EventLogger(); | 41 virtual ~EventLogger(); |
zunger
2011/07/19 19:41:46
Is this meant to be subclassed?
gfeher
2011/07/20 16:36:30
No. Shall I remove virtual then?
gfeher
2011/08/04 10:26:08
Done.
| |
42 | 42 |
43 // Post a task to be executed |delay| milliseconds from now. The task can be | 43 // Post a task to be executed |delay| milliseconds from now. The task can be |
44 // cancelled later by calling Reset() on the callback. | 44 // cancelled later by calling Reset() on the callback. |
45 void PostDelayedWork(linked_ptr<base::Closure> callback, int64 delay); | 45 void PostDelayedWork(linked_ptr<base::Closure> callback, int64 delay); |
46 | 46 |
47 // Register a new event that happened now according to the internal clock. | 47 // Register a new event that happened now according to the internal clock. |
48 void RegisterEvent(); | 48 void RegisterEvent(); |
49 | 49 |
50 // Swap out the internal list of events. | 50 // Swap out the internal list of events. |
51 void Swap(std::vector<int64>* events); | 51 void Swap(std::vector<int64>* events); |
52 | 52 |
53 // Counts the events in a sorted integer array that are >= |start| but | 53 // Counts the events in a sorted integer array that are >= |start| but |
54 // < |start| + |length|. | 54 // < |start| + |length|. |
55 static int CountEvents(const std::vector<int64>& events, | 55 static int CountEvents(const std::vector<int64>& events, |
zunger
2011/07/19 19:41:46
google3 code is using namespace std. (Not sure if
gfeher
2011/07/20 16:36:30
This is interesting because the C++ style guide se
| |
56 int64 start, int64 length); | 56 int64 start, int64 length); |
57 | 57 |
58 private: | 58 private: |
59 class Task { | 59 class Task { |
zunger
2011/07/19 19:41:46
Just declare Task here, and give the full class de
gfeher
2011/07/20 16:36:30
Done.
| |
60 public: | 60 public: |
61 Task(); | 61 Task(); |
62 Task(int64 trigger_time, | 62 Task(int64 trigger_time, |
63 int64 secondary_key, | 63 int64 secondary_key, |
64 linked_ptr<base::Closure> callback); | 64 linked_ptr<base::Closure> callback); |
65 ~Task(); | 65 ~Task(); |
66 | 66 |
67 // Returns true if |this| should be executed before |rhs|. | 67 // Returns true if |this| should be executed before |rhs|. |
68 // Used for sorting by the priority queue. | 68 // Used for sorting by the priority queue. |
69 bool operator< (const Task& rhs) const; | 69 bool operator< (const Task& rhs) const; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 int64 task_counter_; | 108 int64 task_counter_; |
109 | 109 |
110 DISALLOW_COPY_AND_ASSIGN(EventLogger); | 110 DISALLOW_COPY_AND_ASSIGN(EventLogger); |
111 }; | 111 }; |
112 | 112 |
113 // Issues delayed tasks with zero effective delay, but posts them through | 113 // Issues delayed tasks with zero effective delay, but posts them through |
114 // an EventLogger, to make it possible to log events and reconstruct their | 114 // an EventLogger, to make it possible to log events and reconstruct their |
115 // execution time. | 115 // execution time. |
116 class LoggingWorkScheduler : public DelayedWorkScheduler { | 116 class LoggingWorkScheduler : public DelayedWorkScheduler { |
117 public: | 117 public: |
118 explicit LoggingWorkScheduler(EventLogger* logger); | 118 explicit LoggingWorkScheduler(EventLogger* logger); |
zunger
2011/07/19 19:41:46
Does the scheduler take ownership of the logger? N
gfeher
2011/07/20 16:36:30
Done. (I've only talked about thread safety at the
| |
119 virtual ~LoggingWorkScheduler(); | 119 virtual ~LoggingWorkScheduler(); |
120 | 120 |
121 virtual void PostDelayedWork(const base::Closure& callback, int64 delay); | 121 virtual void PostDelayedWork(const base::Closure& callback, int64 delay); |
122 virtual void CancelDelayedWork(); | 122 virtual void CancelDelayedWork(); |
123 | 123 |
124 private: | 124 private: |
125 EventLogger* logger_; | 125 EventLogger* logger_; |
126 linked_ptr<base::Closure> callback_; | 126 linked_ptr<base::Closure> callback_; |
127 | 127 |
128 DISALLOW_COPY_AND_ASSIGN(LoggingWorkScheduler); | 128 DISALLOW_COPY_AND_ASSIGN(LoggingWorkScheduler); |
129 }; | 129 }; |
130 | 130 |
131 } // namespace policy | 131 } // namespace policy |
132 | 132 |
133 #endif // CHROME_BROWSER_POLICY_LOGGING_WORK_SCHEDULER_H_ | 133 #endif // CHROME_BROWSER_POLICY_LOGGING_WORK_SCHEDULER_H_ |
134 | |
OLD | NEW |