OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/hi_res_timer_manager.h" | 10 #include "base/hi_res_timer_manager.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 #if defined(USE_X11) | 85 #if defined(USE_X11) |
86 #include <X11/Xlib.h> | 86 #include <X11/Xlib.h> |
87 #endif | 87 #endif |
88 | 88 |
89 // One of the linux specific headers defines this as a macro. | 89 // One of the linux specific headers defines this as a macro. |
90 #ifdef DestroyAll | 90 #ifdef DestroyAll |
91 #undef DestroyAll | 91 #undef DestroyAll |
92 #endif | 92 #endif |
93 | 93 |
94 using content::TraceControllerImpl; | 94 namespace content { |
95 | |
96 namespace { | 95 namespace { |
97 | 96 |
98 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 97 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
99 void SetupSandbox(const CommandLine& parsed_command_line) { | 98 void SetupSandbox(const CommandLine& parsed_command_line) { |
100 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this | 99 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this |
101 // code en masse out of chrome_main for now. | 100 // code en masse out of chrome_main for now. |
102 const char* sandbox_binary = NULL; | 101 const char* sandbox_binary = NULL; |
103 struct stat st; | 102 struct stat st; |
104 | 103 |
105 // In Chromium branded builds, developers can set an environment variable to | 104 // In Chromium branded builds, developers can set an environment variable to |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 G_LOG_LEVEL_CRITICAL | | 177 G_LOG_LEVEL_CRITICAL | |
179 G_LOG_LEVEL_WARNING), | 178 G_LOG_LEVEL_WARNING), |
180 GLibLogHandler, | 179 GLibLogHandler, |
181 NULL); | 180 NULL); |
182 } | 181 } |
183 } | 182 } |
184 #endif | 183 #endif |
185 | 184 |
186 } // namespace | 185 } // namespace |
187 | 186 |
188 namespace content { | |
189 | |
190 // The currently-running BrowserMainLoop. There can be one or zero. | 187 // The currently-running BrowserMainLoop. There can be one or zero. |
191 BrowserMainLoop* g_current_browser_main_loop = NULL; | 188 BrowserMainLoop* g_current_browser_main_loop = NULL; |
192 | 189 |
193 // This is just to be able to keep ShutdownThreadsAndCleanUp out of | 190 // This is just to be able to keep ShutdownThreadsAndCleanUp out of |
194 // the public interface of BrowserMainLoop. | 191 // the public interface of BrowserMainLoop. |
195 class BrowserShutdownImpl { | 192 class BrowserShutdownImpl { |
196 public: | 193 public: |
197 static void ImmediateShutdownAndExitProcess() { | 194 static void ImmediateShutdownAndExitProcess() { |
198 DCHECK(g_current_browser_main_loop); | 195 DCHECK(g_current_browser_main_loop); |
199 g_current_browser_main_loop->ShutdownThreadsAndCleanUp(); | 196 g_current_browser_main_loop->ShutdownThreadsAndCleanUp(); |
200 | 197 |
201 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
202 // At this point the message loop is still running yet we've shut everything | 199 // At this point the message loop is still running yet we've shut everything |
203 // down. If any messages are processed we'll likely crash. Exit now. | 200 // down. If any messages are processed we'll likely crash. Exit now. |
204 ExitProcess(content::RESULT_CODE_NORMAL_EXIT); | 201 ExitProcess(RESULT_CODE_NORMAL_EXIT); |
205 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 202 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
206 _exit(content::RESULT_CODE_NORMAL_EXIT); | 203 _exit(RESULT_CODE_NORMAL_EXIT); |
207 #else | 204 #else |
208 NOTIMPLEMENTED(); | 205 NOTIMPLEMENTED(); |
209 #endif | 206 #endif |
210 } | 207 } |
211 }; | 208 }; |
212 | 209 |
213 void ImmediateShutdownAndExitProcess() { | 210 void ImmediateShutdownAndExitProcess() { |
214 BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); | 211 BrowserShutdownImpl::ImmediateShutdownAndExitProcess(); |
215 } | 212 } |
216 | 213 |
217 // static | 214 // static |
218 media::AudioManager* BrowserMainLoop::GetAudioManager() { | 215 media::AudioManager* BrowserMainLoop::GetAudioManager() { |
219 return g_current_browser_main_loop->audio_manager_.get(); | 216 return g_current_browser_main_loop->audio_manager_.get(); |
220 } | 217 } |
221 | 218 |
222 // static | 219 // static |
223 media_stream::MediaStreamManager* BrowserMainLoop::GetMediaStreamManager() { | 220 media_stream::MediaStreamManager* BrowserMainLoop::GetMediaStreamManager() { |
224 return g_current_browser_main_loop->media_stream_manager_.get(); | 221 return g_current_browser_main_loop->media_stream_manager_.get(); |
225 } | 222 } |
226 // BrowserMainLoop construction / destruction ============================= | 223 // BrowserMainLoop construction / destruction ============================= |
227 | 224 |
228 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) | 225 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) |
229 : parameters_(parameters), | 226 : parameters_(parameters), |
230 parsed_command_line_(parameters.command_line), | 227 parsed_command_line_(parameters.command_line), |
231 result_code_(content::RESULT_CODE_NORMAL_EXIT) { | 228 result_code_(RESULT_CODE_NORMAL_EXIT) { |
232 DCHECK(!g_current_browser_main_loop); | 229 DCHECK(!g_current_browser_main_loop); |
233 g_current_browser_main_loop = this; | 230 g_current_browser_main_loop = this; |
234 } | 231 } |
235 | 232 |
236 BrowserMainLoop::~BrowserMainLoop() { | 233 BrowserMainLoop::~BrowserMainLoop() { |
237 DCHECK_EQ(this, g_current_browser_main_loop); | 234 DCHECK_EQ(this, g_current_browser_main_loop); |
238 #if !defined(OS_IOS) | 235 #if !defined(OS_IOS) |
239 ui::Clipboard::DestroyClipboardForCurrentThread(); | 236 ui::Clipboard::DestroyClipboardForCurrentThread(); |
240 #endif // !defined(OS_IOS) | 237 #endif // !defined(OS_IOS) |
241 g_current_browser_main_loop = NULL; | 238 g_current_browser_main_loop = NULL; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // seem dependent on SSL initialization(). | 294 // seem dependent on SSL initialization(). |
298 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) | 295 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) |
299 net::set_tcp_fastopen_enabled(true); | 296 net::set_tcp_fastopen_enabled(true); |
300 | 297 |
301 #if !defined(OS_IOS) | 298 #if !defined(OS_IOS) |
302 if (parsed_command_line_.HasSwitch(switches::kRendererProcessLimit)) { | 299 if (parsed_command_line_.HasSwitch(switches::kRendererProcessLimit)) { |
303 std::string limit_string = parsed_command_line_.GetSwitchValueASCII( | 300 std::string limit_string = parsed_command_line_.GetSwitchValueASCII( |
304 switches::kRendererProcessLimit); | 301 switches::kRendererProcessLimit); |
305 size_t process_limit; | 302 size_t process_limit; |
306 if (base::StringToSizeT(limit_string, &process_limit)) { | 303 if (base::StringToSizeT(limit_string, &process_limit)) { |
307 content::RenderProcessHost::SetMaxRendererProcessCount(process_limit); | 304 RenderProcessHost::SetMaxRendererProcessCount(process_limit); |
308 } | 305 } |
309 } | 306 } |
310 #endif // !defined(OS_IOS) | 307 #endif // !defined(OS_IOS) |
311 | 308 |
312 if (parts_.get()) | 309 if (parts_.get()) |
313 parts_->PostEarlyInitialization(); | 310 parts_->PostEarlyInitialization(); |
314 } | 311 } |
315 | 312 |
316 void BrowserMainLoop::MainMessageLoopStart() { | 313 void BrowserMainLoop::MainMessageLoopStart() { |
317 if (parts_.get()) | 314 if (parts_.get()) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 // ChildProcess instance which is created by the renderer thread. | 450 // ChildProcess instance which is created by the renderer thread. |
454 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed() && | 451 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed() && |
455 !parsed_command_line_.HasSwitch(switches::kDisableGpuProcessPrelaunch) && | 452 !parsed_command_line_.HasSwitch(switches::kDisableGpuProcessPrelaunch) && |
456 !parsed_command_line_.HasSwitch(switches::kSingleProcess) && | 453 !parsed_command_line_.HasSwitch(switches::kSingleProcess) && |
457 !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { | 454 !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { |
458 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process"); | 455 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process"); |
459 BrowserThread::PostTask( | 456 BrowserThread::PostTask( |
460 BrowserThread::IO, FROM_HERE, base::Bind( | 457 BrowserThread::IO, FROM_HERE, base::Bind( |
461 base::IgnoreResult(&GpuProcessHost::Get), | 458 base::IgnoreResult(&GpuProcessHost::Get), |
462 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 459 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
463 content::CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); | 460 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); |
464 } | 461 } |
465 #endif // !defined(OS_IOS) | 462 #endif // !defined(OS_IOS) |
466 | 463 |
467 // If the UI thread blocks, the whole UI is unresponsive. | 464 // If the UI thread blocks, the whole UI is unresponsive. |
468 // Do not allow disk IO from the UI thread. | 465 // Do not allow disk IO from the UI thread. |
469 base::ThreadRestrictions::SetIOAllowed(false); | 466 base::ThreadRestrictions::SetIOAllowed(false); |
470 base::ThreadRestrictions::DisallowWaiting(); | 467 base::ThreadRestrictions::DisallowWaiting(); |
471 } | 468 } |
472 | 469 |
473 void BrowserMainLoop::RunMainMessageLoopParts() { | 470 void BrowserMainLoop::RunMainMessageLoopParts() { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 // Register the main thread by instantiating it, but don't call any methods. | 629 // Register the main thread by instantiating it, but don't call any methods. |
633 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 630 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
634 MessageLoop::current())); | 631 MessageLoop::current())); |
635 } | 632 } |
636 | 633 |
637 | 634 |
638 void BrowserMainLoop::BrowserThreadsStarted() { | 635 void BrowserMainLoop::BrowserThreadsStarted() { |
639 #if !defined(OS_IOS) | 636 #if !defined(OS_IOS) |
640 HistogramSynchronizer::GetInstance(); | 637 HistogramSynchronizer::GetInstance(); |
641 | 638 |
642 content::BrowserGpuChannelHostFactory::Initialize(); | 639 BrowserGpuChannelHostFactory::Initialize(); |
643 #if defined(USE_AURA) | 640 #if defined(USE_AURA) |
644 ImageTransportFactory::Initialize(); | 641 ImageTransportFactory::Initialize(); |
645 #endif | 642 #endif |
646 | 643 |
647 #if defined(OS_LINUX) | 644 #if defined(OS_LINUX) |
648 device_monitor_linux_.reset(new DeviceMonitorLinux()); | 645 device_monitor_linux_.reset(new DeviceMonitorLinux()); |
649 #elif defined(OS_MACOSX) | 646 #elif defined(OS_MACOSX) |
650 device_monitor_mac_.reset(new DeviceMonitorMac()); | 647 device_monitor_mac_.reset(new DeviceMonitorMac()); |
651 #endif | 648 #endif |
652 | 649 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); | 722 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
726 if (parameters_.ui_task) | 723 if (parameters_.ui_task) |
727 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); | 724 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); |
728 | 725 |
729 base::RunLoop run_loop; | 726 base::RunLoop run_loop; |
730 run_loop.Run(); | 727 run_loop.Run(); |
731 #endif | 728 #endif |
732 } | 729 } |
733 | 730 |
734 } // namespace content | 731 } // namespace content |
OLD | NEW |