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 { |
| 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 FakeTimeSystem(); |
| 34 |
| 35 void SetNow(base::Time now); |
| 36 |
| 37 // Runs pending tasks until the queue is empty. Runs only tasks |
| 38 // that are supposed to be run after |now_|. |
| 39 void RunPendingTasks(); |
| 40 |
| 41 virtual base::Time Now() OVERRIDE; |
| 42 |
| 43 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 44 const base::Closure& task, |
| 45 base::TimeDelta delay) OVERRIDE; |
| 46 |
| 47 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| 48 |
| 49 private: |
| 50 virtual ~FakeTimeSystem(); |
| 51 |
| 52 base::Time now_; |
| 53 std::priority_queue<Task> tasks_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(FakeTimeSystem); |
| 56 }; |
| 57 } |
| 58 |
| 59 #endif // NET_TEST_FAKE_TIME_SYSTEM_H_ |
OLD | NEW |