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..d6650de84509e502fcfa325ef8ab5e69949de256 |
--- /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(); |
+ task_.Run(); |
mmenke
2014/03/07 15:46:17
temp_task.Run();
There were no unit tests to chec
Elly Fong-Jones
2014/03/10 19:46:51
Fixed.
I don't see how one could write a unit tes
mmenke
2014/03/10 19:49:57
See base/timer/timer_unittest.cc
Elly Fong-Jones
2014/03/11 17:06:17
Done.
|
+} |
+ |
+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))); |
+} |
+ |
+void MockableOneShotTimer::Stop() { |
+ timer_.Stop(); |
+} |
+ |
+bool MockableOneShotTimer::IsRunning() const { |
+ return timer_.IsRunning(); |
+} |