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 #include "chrome/browser/policy/logging_work_scheduler.h" | 5 #include "chrome/browser/policy/logging_work_scheduler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
11 | 11 |
12 namespace policy { | 12 namespace policy { |
13 | 13 |
| 14 // Objects of this class are used in the priority-queue of future tasks |
| 15 // in EventLogger. |
| 16 class EventLogger::Task { |
| 17 public: |
| 18 Task(); |
| 19 Task(int64 trigger_time, |
| 20 int64 secondary_key, |
| 21 linked_ptr<base::Closure> callback); |
| 22 ~Task(); |
| 23 |
| 24 // Returns true if |this| should be executed before |rhs|. |
| 25 // Used for sorting by the priority queue. |
| 26 bool operator< (const Task& rhs) const; |
| 27 |
| 28 int64 trigger_time() const; |
| 29 |
| 30 // Returns a copy of the callback object of this task, and resets the |
| 31 // original callback object. (LoggingTaskScheduler owns a linked_ptr to |
| 32 // its task's callback objects and it only allows firing new tasks if the |
| 33 // previous task's callback object has been reset.) |
| 34 base::Closure GetAndResetCallback(); |
| 35 |
| 36 private: |
| 37 // The virtual time when this task will trigger. |
| 38 // Smaller times win. |
| 39 int64 trigger_time_; |
| 40 // Used for sorting tasks that have the same trigger_time. |
| 41 // Bigger keys win. |
| 42 int64 secondary_key_; |
| 43 |
| 44 linked_ptr<base::Closure> callback_; |
| 45 }; |
| 46 |
14 EventLogger::Task::Task() { | 47 EventLogger::Task::Task() { |
15 } | 48 } |
16 | 49 |
17 EventLogger::Task::Task(int64 trigger_time, | 50 EventLogger::Task::Task(int64 trigger_time, |
18 int64 secondary_key, | 51 int64 secondary_key, |
19 linked_ptr<base::Closure> callback) | 52 linked_ptr<base::Closure> callback) |
20 : trigger_time_(trigger_time), | 53 : trigger_time_(trigger_time), |
21 secondary_key_(secondary_key), | 54 secondary_key_(secondary_key), |
22 callback_(callback) { | 55 callback_(callback) { |
23 } | 56 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 logger_->PostDelayedWork(callback_, delay); | 174 logger_->PostDelayedWork(callback_, delay); |
142 } | 175 } |
143 | 176 |
144 void LoggingWorkScheduler::CancelDelayedWork() { | 177 void LoggingWorkScheduler::CancelDelayedWork() { |
145 if (!callback_.get()) return; | 178 if (!callback_.get()) return; |
146 callback_->Reset(); // Erase the callback to the delayed work. | 179 callback_->Reset(); // Erase the callback to the delayed work. |
147 callback_.reset(NULL); // Erase the pointer to the callback. | 180 callback_.reset(NULL); // Erase the pointer to the callback. |
148 } | 181 } |
149 | 182 |
150 } // namespace policy | 183 } // namespace policy |
OLD | NEW |