Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Unified Diff: net/test/fake_time_system.cc

Issue 15733008: Multicast DNS implementation (initial) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mdns_implementation2
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/test/fake_time_system.cc
diff --git a/net/test/fake_time_system.cc b/net/test/fake_time_system.cc
new file mode 100644
index 0000000000000000000000000000000000000000..408ed074d2f4b7b870ec635f61b2c98aa6874f49
--- /dev/null
+++ b/net/test/fake_time_system.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/test/fake_time_system.h"
+
+namespace net {
+
+FakeTimeSystem::Task::Task(base::Time time, base::Closure task)
+ : task_(task), time_(time) {
+}
+
+FakeTimeSystem::Task::~Task() {
+}
+
+bool FakeTimeSystem::Task::operator<(const FakeTimeSystem::Task& other) const {
+ return time_ > other.time_;
+}
+
+base::Time FakeTimeSystem::Now() {
+ return now_;
+}
+
+FakeTimeSystem::FakeTimeSystem() : now_(base::Time()) {
+}
+
+FakeTimeSystem::~FakeTimeSystem() {
+}
+
+void FakeTimeSystem::SetNow(base::Time now) {
+ now_ = now;
+}
+
+bool FakeTimeSystem::RunsTasksOnCurrentThread() const {
+ return true;
+}
+
+bool FakeTimeSystem::PostDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) {
+ base::Time time = now_ + delay;
+ tasks_.push(Task(time, task));
+ return true;
+}
+
+void FakeTimeSystem::RunPendingTasks() {
+ while (!tasks_.empty() && tasks_.top().time() <= now_) {
+ base::Closure to_run = tasks_.top().closure();
+ tasks_.pop();
+ to_run.Run();
+ }
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698