| 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..5eee266a2b6c479651adaf7289dc27e092196351
|
| --- /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_->AllTasksRun();
|
| + }
|
| + }
|
| +}
|
| +
|
| +void StartupTaskRunner::WrappedTask() {
|
| + // Run the current task
|
| + if (task_list_.empty()) {
|
| + // Tell the observer (if any)
|
| + if (observer_ != NULL) {
|
| + observer_->AllTasksRun();
|
| + }
|
| + } 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
|
|
|