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

Unified Diff: base/timer/mock_timer.cc

Issue 197243003: base: add MockTimer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix uninitialized variables. Created 6 years, 9 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
« no previous file with comments | « base/timer/mock_timer.h ('k') | base/timer/mock_timer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/timer/mock_timer.cc
diff --git a/base/timer/mock_timer.cc b/base/timer/mock_timer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe7d22278e43bfd02f7598ddd21de7c1d0ab95c3
--- /dev/null
+++ b/base/timer/mock_timer.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2014 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 "base/timer/mock_timer.h"
+
+namespace base {
+
+MockTimer::MockTimer(bool retain_user_task, bool is_repeating)
+ : Timer(retain_user_task, is_repeating),
+ is_running_(false) {
+}
+
+MockTimer::MockTimer(const tracked_objects::Location& posted_from,
+ TimeDelta delay,
+ const base::Closure& user_task,
+ bool is_repeating)
+ : Timer(true, is_repeating),
+ delay_(delay),
+ is_running_(false) {
+}
+
+MockTimer::~MockTimer() {
+}
+
+bool MockTimer::IsRunning() const {
+ return is_running_;
+}
+
+base::TimeDelta MockTimer::GetCurrentDelay() const {
+ return delay_;
+}
+
+void MockTimer::Start(const tracked_objects::Location& posted_from,
+ TimeDelta delay,
+ const base::Closure& user_task) {
+ delay_ = delay;
+ user_task_ = user_task;
+ Reset();
+}
+
+void MockTimer::Stop() {
+ is_running_ = false;
+ if (!retain_user_task())
+ user_task_.Reset();
+}
+
+void MockTimer::Reset() {
+ DCHECK(!user_task_.is_null());
+ is_running_ = true;
+}
+
+void MockTimer::Fire() {
+ DCHECK(is_running_);
+ base::Closure old_task = user_task_;
+ if (is_repeating())
+ Reset();
+ else
+ Stop();
+ old_task.Run();
+}
+
+} // namespace base
« no previous file with comments | « base/timer/mock_timer.h ('k') | base/timer/mock_timer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698