Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / browser / startup_task_runner.cc
blobd1fc904d5266b1f7dcc48a913a1827578b158c8a
1 // Copyright 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.
5 #include "content/browser/startup_task_runner.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h"
11 namespace content {
13 StartupTaskRunner::StartupTaskRunner(
14 base::Callback<void(int)> const startup_complete_callback,
15 scoped_refptr<base::SingleThreadTaskRunner> proxy)
16 : startup_complete_callback_(startup_complete_callback), proxy_(proxy) {}
18 StartupTaskRunner::~StartupTaskRunner() {}
20 void StartupTaskRunner::AddTask(StartupTask& callback) {
21 task_list_.push_back(callback);
24 void StartupTaskRunner::StartRunningTasksAsync() {
25 DCHECK(proxy_);
26 int result = 0;
27 if (task_list_.empty()) {
28 if (!startup_complete_callback_.is_null()) {
29 startup_complete_callback_.Run(result);
31 } else {
32 const base::Closure next_task =
33 base::Bind(&StartupTaskRunner::WrappedTask, base::Unretained(this));
34 proxy_->PostNonNestableTask(FROM_HERE, next_task);
38 void StartupTaskRunner::RunAllTasksNow() {
39 int result = 0;
40 for (std::list<StartupTask>::iterator it = task_list_.begin();
41 it != task_list_.end();
42 it++) {
43 result = it->Run();
44 if (result > 0) break;
46 if (!startup_complete_callback_.is_null()) {
47 startup_complete_callback_.Run(result);
51 void StartupTaskRunner::WrappedTask() {
52 if (task_list_.empty()) {
53 // This will happen if the remaining tasks have been run synchronously since
54 // the WrappedTask was created. Any callback will already have been called,
55 // so there is nothing to do
56 return;
58 int result = task_list_.front().Run();
59 task_list_.pop_front();
60 if (result > 0 || task_list_.empty()) {
61 if (!startup_complete_callback_.is_null()) {
62 startup_complete_callback_.Run(result);
64 } else {
65 const base::Closure next_task =
66 base::Bind(&StartupTaskRunner::WrappedTask, base::Unretained(this));
67 proxy_->PostNonNestableTask(FROM_HERE, next_task);
71 } // namespace content