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

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 - respond to Yaron's and jam's comments 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
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 void (*const startup_complete_callback)(int result),
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 startup_complete_callback_(result);
42 }
43 }
44
45 void StartupTaskRunner::WrappedTask() {
46 // Run the current task
47 int result = task_list_.front().Run();
48 task_list_.pop_front();
49 if (result > 0 || task_list_.empty()) {
50 startup_complete_callback_(result);
51 } else {
52 // Queue the next task
53 const base::Closure next_task =
54 base::Bind(&StartupTaskRunner::WrappedTask, this);
55 proxy_->PostNonNestableTask(FROM_HERE, next_task);
56 }
57 }
58
59 StartupTaskRunner::~StartupTaskRunner() {}
60
61 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698