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

Side by Side Diff: content/browser/startup_task_runner.cc

Issue 22691002: Allow overlapping sync and async startup requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow multiple overlapping startup requests - update to merge with nyquist@'s patch 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/startup_task_runner.h" 5 #include "content/browser/startup_task_runner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 StartupTaskRunner::StartupTaskRunner( 13 StartupTaskRunner::StartupTaskRunner(
14 bool browser_may_start_asynchronously,
15 base::Callback<void(int)> const startup_complete_callback, 14 base::Callback<void(int)> const startup_complete_callback,
16 scoped_refptr<base::SingleThreadTaskRunner> proxy) 15 scoped_refptr<base::SingleThreadTaskRunner> proxy)
17 : asynchronous_startup_(browser_may_start_asynchronously), 16 : startup_complete_callback_(startup_complete_callback), proxy_(proxy) {}
18 startup_complete_callback_(startup_complete_callback), 17
19 proxy_(proxy) {} 18 // This is needed to satisfy the coding style checks done by the Mac compiler,
Yaron 2013/08/22 06:00:26 Nit: comment is unnecessary. It's standard style f
aberent 2013/08/23 11:40:21 Done.
19 // but doesn't need to do anything.
20 StartupTaskRunner::~StartupTaskRunner() {}
20 21
21 void StartupTaskRunner::AddTask(StartupTask& callback) { 22 void StartupTaskRunner::AddTask(StartupTask& callback) {
22 task_list_.push_back(callback); 23 task_list_.push_back(callback);
23 } 24 }
24 25
25 void StartupTaskRunner::StartRunningTasks() { 26 void StartupTaskRunner::StartRunningTasksAsync() {
26 DCHECK(proxy_); 27 DCHECK(proxy_);
27 int result = 0; 28 int result = 0;
28 if (asynchronous_startup_ && !task_list_.empty()) { 29 if (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()) { 30 if (!startup_complete_callback_.is_null()) {
nyquist 2013/08/23 06:28:32 Nit: curly braces unnecessary.
aberent 2013/08/23 11:40:21 Not done. The style guide is explicitly neutral
42 startup_complete_callback_.Run(result); 31 startup_complete_callback_.Run(result);
43 } 32 }
33 } else {
34 const base::Closure next_task =
35 base::Bind(&StartupTaskRunner::WrappedTask, base::Unretained(this));
36 proxy_->PostNonNestableTask(FROM_HERE, next_task);
37 }
38 }
39
40 void StartupTaskRunner::RunAllTasksNow() {
41 int result = 0;
42 for (std::list<StartupTask>::iterator it = task_list_.begin();
43 it != task_list_.end();
44 it++) {
45 result = it->Run();
46 if (result > 0) {
nyquist 2013/08/23 06:28:32 Nit: curly braces unnecessary.
aberent 2013/08/23 11:40:21 Done and break moved to line with if.
47 break;
48 }
49 }
50 if (!startup_complete_callback_.is_null()) {
nyquist 2013/08/23 06:28:32 Nit: curly braces unnecessary.
aberent 2013/08/23 11:40:21 Not done. See comment on line 30.
51 startup_complete_callback_.Run(result);
44 } 52 }
45 } 53 }
46 54
47 void StartupTaskRunner::WrappedTask() { 55 void StartupTaskRunner::WrappedTask() {
56 if (task_list_.empty()) {
57 // This will happen if the remaining tasks have been run synchronously since
58 // the WrappedTask was created. Any callback will already have been called,
59 // so there is nothing to do
60 return;
61 }
48 int result = task_list_.front().Run(); 62 int result = task_list_.front().Run();
49 task_list_.pop_front(); 63 task_list_.pop_front();
50 if (result > 0 || task_list_.empty()) { 64 if (result > 0 || task_list_.empty()) {
51 if (!startup_complete_callback_.is_null()) { 65 if (!startup_complete_callback_.is_null()) {
52 startup_complete_callback_.Run(result); 66 startup_complete_callback_.Run(result);
53 } 67 }
54 } else { 68 } else {
55 const base::Closure next_task = 69 const base::Closure next_task =
56 base::Bind(&StartupTaskRunner::WrappedTask, this); 70 base::Bind(&StartupTaskRunner::WrappedTask, base::Unretained(this));
57 proxy_->PostNonNestableTask(FROM_HERE, next_task); 71 proxy_->PostNonNestableTask(FROM_HERE, next_task);
58 } 72 }
59 } 73 }
60 74
61 StartupTaskRunner::~StartupTaskRunner() {}
62
63 } // namespace content 75 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698