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/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), | |
jam
2013/07/31 21:26:53
nit: use callbacks instead of c function pointers
aberent
2013/08/01 13:56:37
Done.
| |
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_ != NULL) { | |
jam
2013/07/31 21:26:53
nit: if (startup_complete_callback)
aberent
2013/08/01 13:56:37
Done.
| |
42 startup_complete_callback_(result); | |
jam
2013/07/31 21:26:53
nit: spacing
aberent
2013/08/01 13:56:37
Done.
| |
43 } | |
44 } | |
45 } | |
46 | |
47 void StartupTaskRunner::WrappedTask() { | |
48 // Run the current task | |
jam
2013/07/31 21:26:53
nit: this comment and below are just describing th
aberent
2013/08/01 13:56:37
Done.
| |
49 int result = task_list_.front().Run(); | |
50 task_list_.pop_front(); | |
51 if (result > 0 || task_list_.empty()) { | |
52 if(startup_complete_callback_ != NULL) { | |
jam
2013/07/31 21:26:53
nit if (startup_complete_callback_)
aberent
2013/08/01 13:56:37
Done.
| |
53 startup_complete_callback_(result); | |
54 } | |
55 } else { | |
56 // Queue the next task | |
57 const base::Closure next_task = | |
58 base::Bind(&StartupTaskRunner::WrappedTask, this); | |
59 proxy_->PostNonNestableTask(FROM_HERE, next_task); | |
60 } | |
61 } | |
62 | |
63 StartupTaskRunner::~StartupTaskRunner() {} | |
64 | |
65 } // namespace content | |
OLD | NEW |