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 #include "net/test/fake_time_system.h" |
| 6 |
| 7 namespace net { |
| 8 |
| 9 FakeTimeSystem::Task::Task(base::Time time, base::Closure task) |
| 10 : task_(task), time_(time) { |
| 11 } |
| 12 |
| 13 FakeTimeSystem::Task::~Task() { |
| 14 } |
| 15 |
| 16 bool FakeTimeSystem::Task::operator<(const FakeTimeSystem::Task& other) const { |
| 17 return time_ > other.time_; |
| 18 } |
| 19 |
| 20 base::Time FakeTimeSystem::Now() { |
| 21 return now_; |
| 22 } |
| 23 |
| 24 FakeTimeSystem::FakeTimeSystem() : now_(base::Time()) { |
| 25 } |
| 26 |
| 27 FakeTimeSystem::~FakeTimeSystem() { |
| 28 } |
| 29 |
| 30 void FakeTimeSystem::SetNow(base::Time now) { |
| 31 now_ = now; |
| 32 } |
| 33 |
| 34 bool FakeTimeSystem::RunsTasksOnCurrentThread() const { |
| 35 return true; |
| 36 } |
| 37 |
| 38 bool FakeTimeSystem::PostDelayedTask(const tracked_objects::Location& from_here, |
| 39 const base::Closure& task, |
| 40 base::TimeDelta delay) { |
| 41 base::Time time = now_ + delay; |
| 42 tasks_.push(Task(time, task)); |
| 43 return true; |
| 44 } |
| 45 |
| 46 void FakeTimeSystem::RunPendingTasks() { |
| 47 while (!tasks_.empty() && tasks_.top().time() <= now_) { |
| 48 base::Closure to_run = tasks_.top().closure(); |
| 49 tasks_.pop(); |
| 50 to_run.Run(); |
| 51 } |
| 52 } |
| 53 |
| 54 } // namespace net |
OLD | NEW |