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

Side by Side Diff: content/browser/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 - Jam's nits Created 7 years, 4 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 unified diff | Download patch
« no previous file with comments | « content/browser/startup_task_runner.h ('k') | content/browser/startup_task_runner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/browser/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(
14 bool browser_may_start_asynchronously,
15 base::Callback<void(int)> const startup_complete_callback,
16 scoped_refptr<base::SingleThreadTaskRunner> proxy)
17 : asynchronous_startup_(browser_may_start_asynchronously),
18 startup_complete_callback_(startup_complete_callback),
19 proxy_(proxy) {}
20
21 void StartupTaskRunner::AddTask(StartupTask& callback) {
22 task_list_.push_back(callback);
23 }
24
25 void StartupTaskRunner::StartRunningTasks() {
26 DCHECK(proxy_);
27 int result = 0;
28 if (asynchronous_startup_ && !task_list_.empty()) {
29 const base::Closure next_task =
30 base::Bind(&StartupTaskRunner::WrappedTask, this);
31 proxy_->PostNonNestableTask(FROM_HERE, next_task);
32 } else {
33 for (std::list<StartupTask>::iterator it = task_list_.begin();
34 it != task_list_.end();
35 it++) {
36 result = it->Run();
37 if (result > 0) {
38 break;
39 }
40 }
41 if (!startup_complete_callback_.is_null()) {
42 startup_complete_callback_.Run(result);
43 }
44 }
45 }
46
47 void StartupTaskRunner::WrappedTask() {
48 int result = task_list_.front().Run();
49 task_list_.pop_front();
50 if (result > 0 || task_list_.empty()) {
51 if (!startup_complete_callback_.is_null()) {
52 startup_complete_callback_.Run(result);
53 }
54 } else {
55 const base::Closure next_task =
56 base::Bind(&StartupTaskRunner::WrappedTask, this);
57 proxy_->PostNonNestableTask(FROM_HERE, next_task);
58 }
59 }
60
61 StartupTaskRunner::~StartupTaskRunner() {}
62
63 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/startup_task_runner.h ('k') | content/browser/startup_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698