Index: components/gcm_driver/gcm_delayed_task_controller.cc |
diff --git a/components/gcm_driver/gcm_delayed_task_controller.cc b/components/gcm_driver/gcm_delayed_task_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0506a34848d3b4bb2700905d0c8583fb7244c1e4 |
--- /dev/null |
+++ b/components/gcm_driver/gcm_delayed_task_controller.cc |
@@ -0,0 +1,38 @@ |
+// 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 "components/gcm_driver/gcm_delayed_task_controller.h" |
+ |
+#include "base/logging.h" |
+ |
+namespace gcm { |
+ |
+GCMDelayedTaskController::GCMDelayedTaskController() : ready_(false) { |
+} |
+ |
+GCMDelayedTaskController::~GCMDelayedTaskController() { |
+} |
+ |
+void GCMDelayedTaskController::AddTask(const base::Closure& task) { |
+ delayed_tasks_.push_back(task); |
+} |
+ |
+void GCMDelayedTaskController::SetReady() { |
+ ready_ = true; |
+ RunTasks(); |
+} |
+ |
+bool GCMDelayedTaskController::CanRunTaskWithoutDelay() const { |
+ return ready_; |
+} |
+ |
+void GCMDelayedTaskController::RunTasks() { |
+ DCHECK(ready_); |
+ |
+ for (size_t i = 0; i < delayed_tasks_.size(); ++i) |
+ delayed_tasks_[i].Run(); |
+ delayed_tasks_.clear(); |
+} |
+ |
+} // namespace gcm |