OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 #ifndef NET_TEST_FAKE_TIME_SYSTEM_H_ | |
6 #define NET_TEST_FAKE_TIME_SYSTEM_H_ | |
7 | |
8 #include <queue> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/task_runner.h" | |
12 #include "base/time/clock.h" | |
13 | |
14 namespace net { | |
15 | |
16 class FakeTimeSystem : public base::Clock, public base::TaskRunner { | |
szym
2013/05/24 15:32:22
Needs class-level comment. Not sure you need this.
Noam Samuel
2013/05/29 21:25:16
Done.
| |
17 public: | |
18 class Task { | |
19 public: | |
20 Task(base::Time time, base::Closure task); | |
21 ~Task(); | |
22 | |
23 bool operator<(const Task &other) const; | |
24 | |
25 const base::Closure& closure() const { return task_; } | |
26 const base::Time time() const { return time_; } | |
27 | |
28 private: | |
29 base::Closure task_; | |
30 base::Time time_; | |
31 }; | |
32 | |
33 | |
34 FakeTimeSystem(); | |
35 | |
36 void SetNow(base::Time now); | |
37 | |
38 // Runs pending tasks until the queue is empty. Runs only tasks | |
39 // that are supposed to be run after |now_|. | |
40 void RunPendingTasks(); | |
41 | |
42 virtual base::Time Now() OVERRIDE; | |
43 | |
44 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
45 const base::Closure& task, | |
46 base::TimeDelta delay) OVERRIDE; | |
47 | |
48 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | |
49 | |
50 private: | |
51 virtual ~FakeTimeSystem(); | |
52 | |
53 base::Time now_; | |
54 std::priority_queue<Task> tasks_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(FakeTimeSystem); | |
57 }; | |
58 } | |
59 | |
60 #endif // NET_TEST_FAKE_TIME_SYSTEM_H_ | |
OLD | NEW |