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

Unified Diff: chrome/renderer/net/mockable_one_shot_timer.cc

Issue 136203009: Support auto-reload on errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: placate clang 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
Index: chrome/renderer/net/mockable_one_shot_timer.cc
diff --git a/chrome/renderer/net/mockable_one_shot_timer.cc b/chrome/renderer/net/mockable_one_shot_timer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9c882328df005b9b3d71390a7f971a30774e2de8
--- /dev/null
+++ b/chrome/renderer/net/mockable_one_shot_timer.cc
@@ -0,0 +1,34 @@
+// Copyright 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 "chrome/renderer/net/mockable_one_shot_timer.h"
+
+MockableOneShotTimer::MockableOneShotTimer() {}
+MockableOneShotTimer::~MockableOneShotTimer() {}
+
+void MockableOneShotTimer::Fired() {
+ // Store the task in a temporary across Run() to prevent its closure (and
+ // hence maybe arguments to the callback function or similar) from going out
+ // of scope while Run() is still executing if Run() calls Start().
+ base::Closure temp_task = task_;
+ task_.Reset();
+ temp_task.Run();
+}
+
+void MockableOneShotTimer::Start(
+ const tracked_objects::Location& posted_from, base::TimeDelta delay,
+ const base::Closure& task) {
+ DCHECK(!task.is_null());
+ task_ = task;
+ timer_.Start(posted_from, delay,
+ base::Bind(&MockableOneShotTimer::Fired, base::Unretained(this)));
mmenke 2014/03/12 19:02:42 Should we include bind.h? callback.h doesn't dire
Elly Fong-Jones 2014/03/12 20:10:53 Done.
+}
+
+void MockableOneShotTimer::Stop() {
+ timer_.Stop();
+}
+
+bool MockableOneShotTimer::IsRunning() const {
+ return timer_.IsRunning();
+}

Powered by Google App Engine
This is Rietveld 408576698