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

Unified Diff: content/common/startup_task_runner.cc

Issue 19957002: Run the later parts of startup as UI thread tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run the later parts of startup as UI thread tasks - patch for Yaron's comments Created 7 years, 5 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: content/common/startup_task_runner.cc
diff --git a/content/common/startup_task_runner.cc b/content/common/startup_task_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aca2a8d5e3ec1575785dcdaec87e6cd3343803d3
--- /dev/null
+++ b/content/common/startup_task_runner.cc
@@ -0,0 +1,61 @@
+// 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 "content/public/common/startup_task_runner.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop.h"
+
+namespace content {
+
+StartupTaskRunner::StartupTaskRunner(StartupMode mode, Observer* observer)
+ : startup_mode_(mode), observer_(observer), proxy_(NULL) {}
+
+void StartupTaskRunner::AddTask(base::Closure& callback) {
+ task_list_.push_back(callback);
+}
+
+void StartupTaskRunner::SetProxy(
+ const scoped_refptr<base::SingleThreadTaskRunner>& proxy) {
+ proxy_ = proxy;
+}
+
+void StartupTaskRunner::StartRunningTasks() {
+ CHECK(proxy_);
+ if (startup_mode_ == INCREMENTAL) {
+ const base::Closure next_task =
+ base::Bind(&StartupTaskRunner::WrappedTask, this);
+ proxy_->PostNonNestableTask(FROM_HERE, next_task);
+ } else {
+ for (std::list<base::Closure>::iterator it = task_list_.begin();
+ it != task_list_.end();
+ it++) {
+ it->Run();
+ }
+ if (observer_ != NULL) {
+ observer_->AllStartupTasksRan();
+ }
+ }
+}
+
+void StartupTaskRunner::WrappedTask() {
+ // Run the current task
+ if (task_list_.empty()) {
+ // Tell the observer (if any)
+ if (observer_ != NULL) {
+ observer_->AllStartupTasksRan();
+ }
+ } else {
+ // Run the current task
+ task_list_.front().Run();
+ task_list_.pop_front();
+ // Queue the next task
+ const base::Closure next_task =
+ base::Bind(&StartupTaskRunner::WrappedTask, this);
+ proxy_->PostNonNestableTask(FROM_HERE, next_task);
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698