OLD | NEW |
---|---|
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 #ifndef CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ | 5 #ifndef CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ |
6 #define CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ | 6 #define CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
Yaron
2013/08/22 06:00:26
Not needed anymore
aberent
2013/08/23 11:40:21
Done.
| |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 | 13 |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 | 15 |
16 #include "content/public/browser/browser_main_runner.h" | 16 #include "content/public/browser/browser_main_runner.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 // A startup task is a void function returning the status on completion. | 20 // A startup task is a void function returning the status on completion. |
21 // a status of > 0 indicates a failure, and that no further startup tasks should | 21 // a status of > 0 indicates a failure, and that no further startup tasks should |
22 // be run. | 22 // be run. |
23 typedef base::Callback<int(void)> StartupTask; | 23 typedef base::Callback<int(void)> StartupTask; |
24 | 24 |
25 // This class runs startup tasks. The tasks are either run immediately inline, | 25 // This class runs startup tasks. The tasks are either run immediately inline, |
26 // or are queued one at a time on the UI thread's message loop. If the events | 26 // or are queued one at a time on the UI thread's message loop. If the events |
27 // are queued, UI events that are received during startup will be acted upon | 27 // are queued, UI events that are received during startup will be acted upon |
28 // between startup tasks. The motivation for this is that, on targets where the | 28 // between startup tasks. The motivation for this is that, on targets where the |
29 // UI is already started, it allows us to keep the UI responsive during startup. | 29 // UI is already started, it allows us to keep the UI responsive during startup. |
30 // | 30 // |
31 // Note that this differs from a SingleThreadedTaskRunner in that there may be | 31 // Note that this differs from a SingleThreadedTaskRunner in that there may be |
32 // no opportunity to handle UI events between the tasks of a | 32 // no opportunity to handle UI events between the tasks of a |
33 // SingleThreadedTaskRunner. | 33 // SingleThreadedTaskRunner. |
34 | 34 |
35 class CONTENT_EXPORT StartupTaskRunner | 35 class StartupTaskRunner { |
36 : public base::RefCounted<StartupTaskRunner> { | |
37 | 36 |
38 public: | 37 public: |
39 // Constructor: Note that |startup_complete_callback| is optional. If it is | 38 // Constructor: Note that |startup_complete_callback| is optional. If it is |
40 // not null it will be called once all the startup tasks have run. | 39 // not null it will be called once all the startup tasks have run. |
41 StartupTaskRunner(bool browser_may_start_asynchronously, | 40 StartupTaskRunner(base::Callback<void(int)> startup_complete_callback, |
42 base::Callback<void(int)> startup_complete_callback, | |
43 scoped_refptr<base::SingleThreadTaskRunner> proxy); | 41 scoped_refptr<base::SingleThreadTaskRunner> proxy); |
44 | 42 |
43 ~StartupTaskRunner(); | |
44 | |
45 // Add a task to the queue of startup tasks to be run. | 45 // Add a task to the queue of startup tasks to be run. |
46 virtual void AddTask(StartupTask& callback); | 46 void AddTask(StartupTask& callback); |
47 | 47 |
48 // Start running the tasks. | 48 // Start running the tasks asynchronously. |
49 virtual void StartRunningTasks(); | 49 void StartRunningTasksAsync(); |
50 | |
51 // Run all tasks, or all remaining tasks, synchronously | |
52 void RunAllTasksNow(); | |
50 | 53 |
51 private: | 54 private: |
52 friend class base::RefCounted<StartupTaskRunner>; | 55 friend class base::RefCounted<StartupTaskRunner>; |
53 virtual ~StartupTaskRunner(); | |
54 | 56 |
55 std::list<StartupTask> task_list_; | 57 std::list<StartupTask> task_list_; |
56 void WrappedTask(); | 58 void WrappedTask(); |
57 | 59 |
58 const bool asynchronous_startup_; | |
59 base::Callback<void(int)> startup_complete_callback_; | 60 base::Callback<void(int)> startup_complete_callback_; |
60 scoped_refptr<base::SingleThreadTaskRunner> proxy_; | 61 scoped_refptr<base::SingleThreadTaskRunner> proxy_; |
61 | 62 |
62 DISALLOW_COPY_AND_ASSIGN(StartupTaskRunner); | 63 DISALLOW_COPY_AND_ASSIGN(StartupTaskRunner); |
63 }; | 64 }; |
64 | 65 |
65 } // namespace content | 66 } // namespace content |
66 #endif // CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ | 67 #endif // CONTENT_BROWSER_STARTUP_TASK_RUNNER_H_ |
OLD | NEW |