1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_
6 #define CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/browser/browser_process_sub_thread.h"
13 class HighResolutionTimerManager
;
25 class NetworkChangeNotifier
;
29 class AudioMirroringManager
;
30 class BrowserMainParts
;
31 class BrowserOnlineStateObserver
;
32 class BrowserShutdownImpl
;
33 class BrowserThreadImpl
;
34 class MediaStreamManager
;
35 class ResourceDispatcherHostImpl
;
36 class SpeechRecognitionManagerImpl
;
37 class SystemMessageWindowWin
;
39 struct MainFunctionParams
;
42 class DeviceMonitorLinux
;
43 #elif defined(OS_MACOSX)
44 class DeviceMonitorMac
;
47 // Implements the main browser loop stages called from BrowserMainRunner.
48 // See comments in browser_main_parts.h for additional info.
49 // All functions are to be called only on the UI thread unless otherwise noted.
50 class BrowserMainLoop
{
53 explicit BrowserMainLoop(const MainFunctionParams
& parameters
);
54 virtual ~BrowserMainLoop();
58 void EarlyInitialization();
59 void InitializeToolkit();
60 void MainMessageLoopStart();
62 // Create all secondary threads.
65 // Perform the default message loop run logic.
66 void RunMainMessageLoopParts();
68 // Performs the shutdown sequence, starting with PostMainMessageLoopRun
69 // through stopping threads to PostDestroyThreads.
70 void ShutdownThreadsAndCleanUp();
72 int GetResultCode() const { return result_code_
; }
74 // Can be called on any thread.
75 static media::AudioManager
* GetAudioManager();
76 static AudioMirroringManager
* GetAudioMirroringManager();
77 static MediaStreamManager
* GetMediaStreamManager();
80 // For ShutdownThreadsAndCleanUp.
81 friend class BrowserShutdownImpl
;
83 void InitializeMainThread();
85 // Called right after the browser threads have been started.
86 void BrowserThreadsStarted();
88 void MainMessageLoopRun();
90 // Members initialized on construction ---------------------------------------
91 const MainFunctionParams
& parameters_
;
92 const CommandLine
& parsed_command_line_
;
95 // Members initialized in |MainMessageLoopStart()| ---------------------------
96 scoped_ptr
<MessageLoop
> main_message_loop_
;
97 scoped_ptr
<base::SystemMonitor
> system_monitor_
;
98 scoped_ptr
<HighResolutionTimerManager
> hi_res_timer_manager_
;
99 scoped_ptr
<net::NetworkChangeNotifier
> network_change_notifier_
;
100 scoped_ptr
<media::AudioManager
> audio_manager_
;
101 scoped_ptr
<AudioMirroringManager
> audio_mirroring_manager_
;
102 scoped_ptr
<MediaStreamManager
> media_stream_manager_
;
103 // Per-process listener for online state changes.
104 scoped_ptr
<BrowserOnlineStateObserver
> online_state_observer_
;
106 scoped_ptr
<SystemMessageWindowWin
> system_message_window_
;
107 #elif defined(OS_LINUX)
108 scoped_ptr
<DeviceMonitorLinux
> device_monitor_linux_
;
109 #elif defined(OS_MACOSX) && !defined(OS_IOS)
110 scoped_ptr
<DeviceMonitorMac
> device_monitor_mac_
;
113 // Destroy parts_ before main_message_loop_ (required) and before other
114 // classes constructed in content (but after main_thread_).
115 scoped_ptr
<BrowserMainParts
> parts_
;
117 // Members initialized in |InitializeMainThread()| ---------------------------
118 // This must get destroyed before other threads that are created in parts_.
119 scoped_ptr
<BrowserThreadImpl
> main_thread_
;
121 // Members initialized in |BrowserThreadsStarted()| --------------------------
122 scoped_ptr
<ResourceDispatcherHostImpl
> resource_dispatcher_host_
;
123 scoped_ptr
<SpeechRecognitionManagerImpl
> speech_recognition_manager_
;
125 // Members initialized in |RunMainMessageLoopParts()| ------------------------
126 scoped_ptr
<BrowserProcessSubThread
> db_thread_
;
128 scoped_ptr
<WebKitThread
> webkit_thread_
;
130 scoped_ptr
<BrowserProcessSubThread
> file_user_blocking_thread_
;
131 scoped_ptr
<BrowserProcessSubThread
> file_thread_
;
132 scoped_ptr
<BrowserProcessSubThread
> process_launcher_thread_
;
133 scoped_ptr
<BrowserProcessSubThread
> cache_thread_
;
134 scoped_ptr
<BrowserProcessSubThread
> io_thread_
;
135 scoped_ptr
<MemoryObserver
> memory_observer_
;
137 DISALLOW_COPY_AND_ASSIGN(BrowserMainLoop
);
140 } // namespace content
142 #endif // CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_