blob: 821da8727553536aa5fb45abc8ec66f595057d56 [file] [log] [blame]
[email protected]60b122d2012-01-09 23:00:071// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b48c9182011-10-26 18:03:302// 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]b48c9182011-10-26 18:03:307
[email protected]b48c9182011-10-26 18:03:308#include "base/basictypes.h"
[email protected]57624ab2013-08-01 16:01:519#include "base/memory/ref_counted.h"
[email protected]b48c9182011-10-26 18:03:3010#include "base/memory/scoped_ptr.h"
[email protected]2e5b60a22011-11-28 15:56:4111#include "content/browser/browser_process_sub_thread.h"
[email protected]57624ab2013-08-01 16:01:5112#include "content/public/browser/browser_main_runner.h"
[email protected]b48c9182011-10-26 18:03:3013
[email protected]b48c9182011-10-26 18:03:3014class CommandLine;
[email protected]b48c9182011-10-26 18:03:3015
[email protected]b48c9182011-10-26 18:03:3016namespace base {
[email protected]89bf27e2013-06-27 18:04:5617class HighResolutionTimerManager;
[email protected]5e9e96a2013-03-31 02:29:2018class MessageLoop;
[email protected]6c5905b72013-04-03 19:06:5119class PowerMonitor;
[email protected]b48c9182011-10-26 18:03:3020class SystemMonitor;
[email protected]111494e2013-07-24 18:38:2921namespace debug {
22class TraceMemoryController;
[email protected]e5a631a2013-09-18 07:33:2723class TraceEventSystemStatsMonitor;
[email protected]111494e2013-07-24 18:38:2924} // namespace debug
25} // namespace base
[email protected]b48c9182011-10-26 18:03:3026
[email protected]67dfea902012-04-03 01:49:0927namespace media {
28class AudioManager;
[email protected]a9875152013-06-22 04:03:0329class MIDIManager;
[email protected]61f697f2013-08-15 22:02:4030class UserInputMonitor;
[email protected]111494e2013-07-24 18:38:2931} // namespace media
[email protected]67dfea902012-04-03 01:49:0932
[email protected]b48c9182011-10-26 18:03:3033namespace net {
34class NetworkChangeNotifier;
[email protected]111494e2013-07-24 18:38:2935} // namespace net
[email protected]b48c9182011-10-26 18:03:3036
37namespace content {
[email protected]f8d17372013-01-11 09:31:4738class AudioMirroringManager;
[email protected]b48c9182011-10-26 18:03:3039class BrowserMainParts;
[email protected]2208a74d2012-10-29 17:09:4440class BrowserOnlineStateObserver;
[email protected]2e5b60a22011-11-28 15:56:4141class BrowserShutdownImpl;
[email protected]c38831a12011-10-28 12:44:4942class BrowserThreadImpl;
[email protected]1d232b92012-10-29 17:39:0743class MediaStreamManager;
[email protected]ea114722012-03-12 01:11:2544class ResourceDispatcherHostImpl;
[email protected]fcb8e0212012-10-29 11:57:1845class SpeechRecognitionManagerImpl;
[email protected]232e09d2013-08-27 15:29:5646class StartupTaskRunner;
[email protected]46488322012-10-30 03:22:2047class SystemMessageWindowWin;
[email protected]97646c92012-07-31 20:30:0848struct MainFunctionParams;
49
50#if defined(OS_LINUX)
51class DeviceMonitorLinux;
[email protected]14625442012-08-15 12:51:4252#elif defined(OS_MACOSX)
53class DeviceMonitorMac;
[email protected]97646c92012-07-31 20:30:0854#endif
[email protected]b48c9182011-10-26 18:03:3055
[email protected]53ab4802012-04-12 22:14:3556// Implements the main browser loop stages called from BrowserMainRunner.
[email protected]b48c9182011-10-26 18:03:3057// See comments in browser_main_parts.h for additional info.
[email protected]89acda82013-06-25 20:52:5058class CONTENT_EXPORT BrowserMainLoop {
[email protected]b48c9182011-10-26 18:03:3059 public:
[email protected]aa445462013-06-21 17:12:3660 // 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]46488322012-10-30 03:22:2064 explicit BrowserMainLoop(const MainFunctionParams& parameters);
[email protected]b48c9182011-10-26 18:03:3065 virtual ~BrowserMainLoop();
66
67 void Init();
68
69 void EarlyInitialization();
70 void InitializeToolkit();
71 void MainMessageLoopStart();
[email protected]f573ed6b2012-02-10 15:58:5272
[email protected]232e09d2013-08-27 15:29:5673 // 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]57624ab2013-08-01 16:01:5177 void CreateStartupTasks();
[email protected]f573ed6b2012-02-10 15:58:5278
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]b48c9182011-10-26 18:03:3085
86 int GetResultCode() const { return result_code_; }
87
[email protected]aa445462013-06-21 17:12:3688 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]61f697f2013-08-15 22:02:4095 media::UserInputMonitor* user_input_monitor() const {
96 return user_input_monitor_.get();
97 }
[email protected]a9875152013-06-22 04:03:0398 media::MIDIManager* midi_manager() const { return midi_manager_.get(); }
[email protected]89acda82013-06-25 20:52:5099 base::Thread* indexed_db_thread() const { return indexed_db_thread_.get(); }
[email protected]52e456b92012-02-23 17:13:18100
[email protected]b48c9182011-10-26 18:03:30101 private:
[email protected]aa445462013-06-21 17:12:36102 class MemoryObserver;
[email protected]2e5b60a22011-11-28 15:56:41103 // For ShutdownThreadsAndCleanUp.
104 friend class BrowserShutdownImpl;
105
[email protected]b48c9182011-10-26 18:03:30106 void InitializeMainThread();
107
[email protected]57624ab2013-08-01 16:01:51108 // Called just before creating the threads
109 int PreCreateThreads();
110
111 // Create all secondary threads.
112 int CreateThreads();
113
[email protected]99907362012-01-11 05:41:40114 // Called right after the browser threads have been started.
[email protected]57624ab2013-08-01 16:01:51115 int BrowserThreadsStarted();
116
117 int PreMainMessageLoopRun();
[email protected]99907362012-01-11 05:41:40118
[email protected]f573ed6b2012-02-10 15:58:52119 void MainMessageLoopRun();
120
[email protected]b48c9182011-10-26 18:03:30121 // Members initialized on construction ---------------------------------------
[email protected]46488322012-10-30 03:22:20122 const MainFunctionParams& parameters_;
[email protected]b48c9182011-10-26 18:03:30123 const CommandLine& parsed_command_line_;
124 int result_code_;
[email protected]57624ab2013-08-01 16:01:51125 // True if the non-UI threads were created.
126 bool created_threads_;
[email protected]b48c9182011-10-26 18:03:30127
[email protected]b48c9182011-10-26 18:03:30128 // Members initialized in |MainMessageLoopStart()| ---------------------------
[email protected]5e9e96a2013-03-31 02:29:20129 scoped_ptr<base::MessageLoop> main_message_loop_;
[email protected]b48c9182011-10-26 18:03:30130 scoped_ptr<base::SystemMonitor> system_monitor_;
[email protected]6c5905b72013-04-03 19:06:51131 scoped_ptr<base::PowerMonitor> power_monitor_;
[email protected]89bf27e2013-06-27 18:04:56132 scoped_ptr<base::HighResolutionTimerManager> hi_res_timer_manager_;
[email protected]b48c9182011-10-26 18:03:30133 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
[email protected]61f697f2013-08-15 22:02:40134 // user_input_monitor_ has to outlive audio_manager_, so declared first.
135 scoped_ptr<media::UserInputMonitor> user_input_monitor_;
[email protected]67dfea902012-04-03 01:49:09136 scoped_ptr<media::AudioManager> audio_manager_;
[email protected]a9875152013-06-22 04:03:03137 scoped_ptr<media::MIDIManager> midi_manager_;
[email protected]f8d17372013-01-11 09:31:47138 scoped_ptr<AudioMirroringManager> audio_mirroring_manager_;
[email protected]1d232b92012-10-29 17:39:07139 scoped_ptr<MediaStreamManager> media_stream_manager_;
[email protected]bff327f2012-03-11 22:17:19140 // Per-process listener for online state changes.
141 scoped_ptr<BrowserOnlineStateObserver> online_state_observer_;
[email protected]cd1cd4c02011-11-15 01:59:49142#if defined(OS_WIN)
143 scoped_ptr<SystemMessageWindowWin> system_message_window_;
[email protected]97646c92012-07-31 20:30:08144#elif defined(OS_LINUX)
145 scoped_ptr<DeviceMonitorLinux> device_monitor_linux_;
[email protected]759a86a2012-09-10 14:42:54146#elif defined(OS_MACOSX) && !defined(OS_IOS)
[email protected]14625442012-08-15 12:51:42147 scoped_ptr<DeviceMonitorMac> device_monitor_mac_;
[email protected]cd1cd4c02011-11-15 01:59:49148#endif
[email protected]232e09d2013-08-27 15:29:56149 // The startup task runner is created by CreateStartupTasks()
150 scoped_ptr<StartupTaskRunner> startup_task_runner_;
[email protected]50462bf02011-11-21 19:13:31151
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]c38831a12011-10-28 12:44:49158 scoped_ptr<BrowserThreadImpl> main_thread_;
[email protected]60b122d2012-01-09 23:00:07159
[email protected]99907362012-01-11 05:41:40160 // Members initialized in |BrowserThreadsStarted()| --------------------------
[email protected]ea114722012-03-12 01:11:25161 scoped_ptr<ResourceDispatcherHostImpl> resource_dispatcher_host_;
[email protected]fcb8e0212012-10-29 11:57:18162 scoped_ptr<SpeechRecognitionManagerImpl> speech_recognition_manager_;
[email protected]99907362012-01-11 05:41:40163
[email protected]60b122d2012-01-09 23:00:07164 // Members initialized in |RunMainMessageLoopParts()| ------------------------
[email protected]2e5b60a22011-11-28 15:56:41165 scoped_ptr<BrowserProcessSubThread> db_thread_;
[email protected]31dbf9d2011-12-07 01:25:30166 scoped_ptr<BrowserProcessSubThread> file_user_blocking_thread_;
[email protected]c2b77b2392011-12-02 13:00:16167 scoped_ptr<BrowserProcessSubThread> file_thread_;
[email protected]2e5b60a22011-11-28 15:56:41168 scoped_ptr<BrowserProcessSubThread> process_launcher_thread_;
169 scoped_ptr<BrowserProcessSubThread> cache_thread_;
[email protected]c2b77b2392011-12-02 13:00:16170 scoped_ptr<BrowserProcessSubThread> io_thread_;
[email protected]89acda82013-06-25 20:52:50171 scoped_ptr<base::Thread> indexed_db_thread_;
[email protected]ee57f332013-01-31 18:13:54172 scoped_ptr<MemoryObserver> memory_observer_;
[email protected]111494e2013-07-24 18:38:29173 scoped_ptr<base::debug::TraceMemoryController> trace_memory_controller_;
[email protected]e5a631a2013-09-18 07:33:27174 scoped_ptr<base::debug::TraceEventSystemStatsMonitor> system_stats_monitor_;
[email protected]b48c9182011-10-26 18:03:30175
[email protected]b48c9182011-10-26 18:03:30176 DISALLOW_COPY_AND_ASSIGN(BrowserMainLoop);
177};
178
179} // namespace content
180
181#endif // CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_