[email protected] | 60b122d | 2012-01-09 23:00:07 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ | ||||
6 | #define CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 7 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 8 | #include "base/basictypes.h" |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 11 | #include "content/browser/browser_process_sub_thread.h" |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 12 | #include "content/public/browser/browser_main_runner.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 13 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 14 | class CommandLine; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 15 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 16 | namespace base { |
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 17 | class HighResolutionTimerManager; |
[email protected] | 5e9e96a | 2013-03-31 02:29:20 | [diff] [blame] | 18 | class MessageLoop; |
[email protected] | 6c5905b7 | 2013-04-03 19:06:51 | [diff] [blame] | 19 | class PowerMonitor; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 20 | class SystemMonitor; |
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 21 | namespace debug { |
22 | class TraceMemoryController; | ||||
[email protected] | e5a631a | 2013-09-18 07:33:27 | [diff] [blame] | 23 | class TraceEventSystemStatsMonitor; |
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 24 | } // namespace debug |
25 | } // namespace base | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 26 | |
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 27 | namespace media { |
28 | class AudioManager; | ||||
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 29 | class MIDIManager; |
[email protected] | 61f697f | 2013-08-15 22:02:40 | [diff] [blame] | 30 | class UserInputMonitor; |
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 31 | } // namespace media |
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 32 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 33 | namespace net { |
34 | class NetworkChangeNotifier; | ||||
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 35 | } // namespace net |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 36 | |
37 | namespace content { | ||||
[email protected] | f8d1737 | 2013-01-11 09:31:47 | [diff] [blame] | 38 | class AudioMirroringManager; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 39 | class BrowserMainParts; |
[email protected] | 2208a74d | 2012-10-29 17:09:44 | [diff] [blame] | 40 | class BrowserOnlineStateObserver; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 41 | class BrowserShutdownImpl; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 42 | class BrowserThreadImpl; |
[email protected] | 1d232b9 | 2012-10-29 17:39:07 | [diff] [blame] | 43 | class MediaStreamManager; |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 44 | class ResourceDispatcherHostImpl; |
[email protected] | fcb8e021 | 2012-10-29 11:57:18 | [diff] [blame] | 45 | class SpeechRecognitionManagerImpl; |
[email protected] | 232e09d | 2013-08-27 15:29:56 | [diff] [blame] | 46 | class StartupTaskRunner; |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 47 | class SystemMessageWindowWin; |
[email protected] | 97646c9 | 2012-07-31 20:30:08 | [diff] [blame] | 48 | struct MainFunctionParams; |
49 | |||||
50 | #if defined(OS_LINUX) | ||||
51 | class DeviceMonitorLinux; | ||||
[email protected] | 1462544 | 2012-08-15 12:51:42 | [diff] [blame] | 52 | #elif defined(OS_MACOSX) |
53 | class DeviceMonitorMac; | ||||
[email protected] | 97646c9 | 2012-07-31 20:30:08 | [diff] [blame] | 54 | #endif |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 55 | |
[email protected] | 53ab480 | 2012-04-12 22:14:35 | [diff] [blame] | 56 | // Implements the main browser loop stages called from BrowserMainRunner. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 57 | // See comments in browser_main_parts.h for additional info. |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 58 | class CONTENT_EXPORT BrowserMainLoop { |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 59 | public: |
[email protected] | aa44546 | 2013-06-21 17:12:36 | [diff] [blame] | 60 | // Returns the current instance. This is used to get access to the getters |
61 | // that return objects which are owned by this class. | ||||
62 | static BrowserMainLoop* GetInstance(); | ||||
63 | |||||
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 64 | explicit BrowserMainLoop(const MainFunctionParams& parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 65 | virtual ~BrowserMainLoop(); |
66 | |||||
67 | void Init(); | ||||
68 | |||||
69 | void EarlyInitialization(); | ||||
70 | void InitializeToolkit(); | ||||
71 | void MainMessageLoopStart(); | ||||
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 72 | |
[email protected] | 232e09d | 2013-08-27 15:29:56 | [diff] [blame] | 73 | // Create and start running the tasks we need to complete startup. Note that |
74 | // this can be called more than once (currently only on Android) if we get a | ||||
75 | // request for synchronous startup while the tasks created by asynchronous | ||||
76 | // startup are still running. | ||||
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 77 | void CreateStartupTasks(); |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 78 | |
79 | // Perform the default message loop run logic. | ||||
80 | void RunMainMessageLoopParts(); | ||||
81 | |||||
82 | // Performs the shutdown sequence, starting with PostMainMessageLoopRun | ||||
83 | // through stopping threads to PostDestroyThreads. | ||||
84 | void ShutdownThreadsAndCleanUp(); | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 85 | |
86 | int GetResultCode() const { return result_code_; } | ||||
87 | |||||
[email protected] | aa44546 | 2013-06-21 17:12:36 | [diff] [blame] | 88 | media::AudioManager* audio_manager() const { return audio_manager_.get(); } |
89 | AudioMirroringManager* audio_mirroring_manager() const { | ||||
90 | return audio_mirroring_manager_.get(); | ||||
91 | } | ||||
92 | MediaStreamManager* media_stream_manager() const { | ||||
93 | return media_stream_manager_.get(); | ||||
94 | } | ||||
[email protected] | 61f697f | 2013-08-15 22:02:40 | [diff] [blame] | 95 | media::UserInputMonitor* user_input_monitor() const { |
96 | return user_input_monitor_.get(); | ||||
97 | } | ||||
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 98 | media::MIDIManager* midi_manager() const { return midi_manager_.get(); } |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 99 | base::Thread* indexed_db_thread() const { return indexed_db_thread_.get(); } |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 100 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 101 | private: |
[email protected] | aa44546 | 2013-06-21 17:12:36 | [diff] [blame] | 102 | class MemoryObserver; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 103 | // For ShutdownThreadsAndCleanUp. |
104 | friend class BrowserShutdownImpl; | ||||
105 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 106 | void InitializeMainThread(); |
107 | |||||
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 108 | // Called just before creating the threads |
109 | int PreCreateThreads(); | ||||
110 | |||||
111 | // Create all secondary threads. | ||||
112 | int CreateThreads(); | ||||
113 | |||||
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 114 | // Called right after the browser threads have been started. |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 115 | int BrowserThreadsStarted(); |
116 | |||||
117 | int PreMainMessageLoopRun(); | ||||
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 118 | |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 119 | void MainMessageLoopRun(); |
120 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 121 | // Members initialized on construction --------------------------------------- |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 122 | const MainFunctionParams& parameters_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 123 | const CommandLine& parsed_command_line_; |
124 | int result_code_; | ||||
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 125 | // True if the non-UI threads were created. |
126 | bool created_threads_; | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 127 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 128 | // Members initialized in |MainMessageLoopStart()| --------------------------- |
[email protected] | 5e9e96a | 2013-03-31 02:29:20 | [diff] [blame] | 129 | scoped_ptr<base::MessageLoop> main_message_loop_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 130 | scoped_ptr<base::SystemMonitor> system_monitor_; |
[email protected] | 6c5905b7 | 2013-04-03 19:06:51 | [diff] [blame] | 131 | scoped_ptr<base::PowerMonitor> power_monitor_; |
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 132 | scoped_ptr<base::HighResolutionTimerManager> hi_res_timer_manager_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 133 | scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
[email protected] | 61f697f | 2013-08-15 22:02:40 | [diff] [blame] | 134 | // user_input_monitor_ has to outlive audio_manager_, so declared first. |
135 | scoped_ptr<media::UserInputMonitor> user_input_monitor_; | ||||
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 136 | scoped_ptr<media::AudioManager> audio_manager_; |
[email protected] | a987515 | 2013-06-22 04:03:03 | [diff] [blame] | 137 | scoped_ptr<media::MIDIManager> midi_manager_; |
[email protected] | f8d1737 | 2013-01-11 09:31:47 | [diff] [blame] | 138 | scoped_ptr<AudioMirroringManager> audio_mirroring_manager_; |
[email protected] | 1d232b9 | 2012-10-29 17:39:07 | [diff] [blame] | 139 | scoped_ptr<MediaStreamManager> media_stream_manager_; |
[email protected] | bff327f | 2012-03-11 22:17:19 | [diff] [blame] | 140 | // Per-process listener for online state changes. |
141 | scoped_ptr<BrowserOnlineStateObserver> online_state_observer_; | ||||
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 142 | #if defined(OS_WIN) |
143 | scoped_ptr<SystemMessageWindowWin> system_message_window_; | ||||
[email protected] | 97646c9 | 2012-07-31 20:30:08 | [diff] [blame] | 144 | #elif defined(OS_LINUX) |
145 | scoped_ptr<DeviceMonitorLinux> device_monitor_linux_; | ||||
[email protected] | 759a86a | 2012-09-10 14:42:54 | [diff] [blame] | 146 | #elif defined(OS_MACOSX) && !defined(OS_IOS) |
[email protected] | 1462544 | 2012-08-15 12:51:42 | [diff] [blame] | 147 | scoped_ptr<DeviceMonitorMac> device_monitor_mac_; |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 148 | #endif |
[email protected] | 232e09d | 2013-08-27 15:29:56 | [diff] [blame] | 149 | // The startup task runner is created by CreateStartupTasks() |
150 | scoped_ptr<StartupTaskRunner> startup_task_runner_; | ||||
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 151 | |
152 | // Destroy parts_ before main_message_loop_ (required) and before other | ||||
153 | // classes constructed in content (but after main_thread_). | ||||
154 | scoped_ptr<BrowserMainParts> parts_; | ||||
155 | |||||
156 | // Members initialized in |InitializeMainThread()| --------------------------- | ||||
157 | // This must get destroyed before other threads that are created in parts_. | ||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 158 | scoped_ptr<BrowserThreadImpl> main_thread_; |
[email protected] | 60b122d | 2012-01-09 23:00:07 | [diff] [blame] | 159 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 160 | // Members initialized in |BrowserThreadsStarted()| -------------------------- |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 161 | scoped_ptr<ResourceDispatcherHostImpl> resource_dispatcher_host_; |
[email protected] | fcb8e021 | 2012-10-29 11:57:18 | [diff] [blame] | 162 | scoped_ptr<SpeechRecognitionManagerImpl> speech_recognition_manager_; |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 163 | |
[email protected] | 60b122d | 2012-01-09 23:00:07 | [diff] [blame] | 164 | // Members initialized in |RunMainMessageLoopParts()| ------------------------ |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 165 | scoped_ptr<BrowserProcessSubThread> db_thread_; |
[email protected] | 31dbf9d | 2011-12-07 01:25:30 | [diff] [blame] | 166 | scoped_ptr<BrowserProcessSubThread> file_user_blocking_thread_; |
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 167 | scoped_ptr<BrowserProcessSubThread> file_thread_; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 168 | scoped_ptr<BrowserProcessSubThread> process_launcher_thread_; |
169 | scoped_ptr<BrowserProcessSubThread> cache_thread_; | ||||
[email protected] | c2b77b239 | 2011-12-02 13:00:16 | [diff] [blame] | 170 | scoped_ptr<BrowserProcessSubThread> io_thread_; |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 171 | scoped_ptr<base::Thread> indexed_db_thread_; |
[email protected] | ee57f33 | 2013-01-31 18:13:54 | [diff] [blame] | 172 | scoped_ptr<MemoryObserver> memory_observer_; |
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 173 | scoped_ptr<base::debug::TraceMemoryController> trace_memory_controller_; |
[email protected] | e5a631a | 2013-09-18 07:33:27 | [diff] [blame] | 174 | scoped_ptr<base::debug::TraceEventSystemStatsMonitor> system_stats_monitor_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 175 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 176 | DISALLOW_COPY_AND_ASSIGN(BrowserMainLoop); |
177 | }; | ||||
178 | |||||
179 | } // namespace content | ||||
180 | |||||
181 | #endif // CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ |