OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/public/common/startup_task_runner.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 StartupTaskRunner::StartupTaskRunner(StartupMode mode, Observer* observer) |
| 14 : startup_mode_(mode), observer_(observer), proxy_(NULL) {} |
| 15 |
| 16 void StartupTaskRunner::AddTask(base::Closure& callback) { |
| 17 task_list_.push_back(callback); |
| 18 } |
| 19 |
| 20 void StartupTaskRunner::SetProxy( |
| 21 const scoped_refptr<base::SingleThreadTaskRunner>& proxy) { |
| 22 proxy_ = proxy; |
| 23 } |
| 24 |
| 25 void StartupTaskRunner::StartRunningTasks() { |
| 26 CHECK(proxy_); |
| 27 if (startup_mode_ == INCREMENTAL) { |
| 28 const base::Closure next_task = |
| 29 base::Bind(&StartupTaskRunner::WrappedTask, this); |
| 30 proxy_->PostNonNestableTask(FROM_HERE, next_task); |
| 31 } else { |
| 32 for (std::list<base::Closure>::iterator it = task_list_.begin(); |
| 33 it != task_list_.end(); |
| 34 it++) { |
| 35 it->Run(); |
| 36 } |
| 37 if (observer_ != NULL) { |
| 38 observer_->AllStartupTasksRan(); |
| 39 } |
| 40 } |
| 41 } |
| 42 |
| 43 void StartupTaskRunner::WrappedTask() { |
| 44 // Run the current task |
| 45 if (task_list_.empty()) { |
| 46 // Tell the observer (if any) |
| 47 if (observer_ != NULL) { |
| 48 observer_->AllStartupTasksRan(); |
| 49 } |
| 50 } else { |
| 51 // Run the current task |
| 52 task_list_.front().Run(); |
| 53 task_list_.pop_front(); |
| 54 // Queue the next task |
| 55 const base::Closure next_task = |
| 56 base::Bind(&StartupTaskRunner::WrappedTask, this); |
| 57 proxy_->PostNonNestableTask(FROM_HERE, next_task); |
| 58 } |
| 59 } |
| 60 |
| 61 } // namespace content |
OLD | NEW |