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/logging.h" | 10 #include "base/logging.h" |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 void BrowserMainLoop::EarlyInitialization() { | 387 void BrowserMainLoop::EarlyInitialization() { |
388 TRACE_EVENT0("startup", "BrowserMainLoop::EarlyInitialization"); | 388 TRACE_EVENT0("startup", "BrowserMainLoop::EarlyInitialization"); |
389 | 389 |
390 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 390 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
391 // No thread should be created before this call, as SetupSandbox() | 391 // No thread should be created before this call, as SetupSandbox() |
392 // will end-up using fork(). | 392 // will end-up using fork(). |
393 SetupSandbox(parsed_command_line_); | 393 SetupSandbox(parsed_command_line_); |
394 #endif | 394 #endif |
395 | 395 |
396 #if defined(USE_X11) | 396 #if defined(USE_X11) |
397 if (parsed_command_line_.HasSwitch(switches::kSingleProcess) || | 397 if (UsingInProcessGpu()) { |
398 parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { | |
399 if (!gfx::InitializeThreadedX11()) { | 398 if (!gfx::InitializeThreadedX11()) { |
400 LOG(ERROR) << "Failed to put Xlib into threaded mode."; | 399 LOG(ERROR) << "Failed to put Xlib into threaded mode."; |
401 } | 400 } |
402 } | 401 } |
403 #endif | 402 #endif |
404 | 403 |
405 // GLib's spawning of new processes is buggy, so it's important that at this | 404 // GLib's spawning of new processes is buggy, so it's important that at this |
406 // point GLib does not need to start DBUS. Chrome should always start with | 405 // point GLib does not need to start DBUS. Chrome should always start with |
407 // DBUS_SESSION_BUS_ADDRESS properly set. See crbug.com/309093. | 406 // DBUS_SESSION_BUS_ADDRESS properly set. See crbug.com/309093. |
408 #if defined(USE_GLIB) | 407 #if defined(USE_GLIB) |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 PluginService::GetInstance()->Init(); | 609 PluginService::GetInstance()->Init(); |
611 } | 610 } |
612 #endif | 611 #endif |
613 | 612 |
614 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) | 613 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) |
615 // Single-process is an unsupported and not fully tested mode, so | 614 // Single-process is an unsupported and not fully tested mode, so |
616 // don't enable it for official Chrome builds (except on Android). | 615 // don't enable it for official Chrome builds (except on Android). |
617 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) | 616 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
618 RenderProcessHost::SetRunRendererInProcess(true); | 617 RenderProcessHost::SetRunRendererInProcess(true); |
619 #endif | 618 #endif |
619 | |
620 if (UsingInProcessGpu()) { | |
621 InitializeGpuDataManager(); | |
622 } | |
623 | |
620 return result_code_; | 624 return result_code_; |
621 } | 625 } |
622 | 626 |
623 void BrowserMainLoop::CreateStartupTasks() { | 627 void BrowserMainLoop::CreateStartupTasks() { |
624 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); | 628 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); |
625 | 629 |
626 // First time through, we really want to create all the tasks | 630 // First time through, we really want to create all the tasks |
627 if (!startup_task_runner_.get()) { | 631 if (!startup_task_runner_.get()) { |
628 #if defined(OS_ANDROID) | 632 #if defined(OS_ANDROID) |
629 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( | 633 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 // (this thread is UI thread, and io_thread_ is for IPCs). | 1021 // (this thread is UI thread, and io_thread_ is for IPCs). |
1018 io_thread_->SetPriority(base::kThreadPriority_Display); | 1022 io_thread_->SetPriority(base::kThreadPriority_Display); |
1019 base::PlatformThread::SetThreadPriority( | 1023 base::PlatformThread::SetThreadPriority( |
1020 base::PlatformThread::CurrentHandle(), | 1024 base::PlatformThread::CurrentHandle(), |
1021 base::kThreadPriority_Display); | 1025 base::kThreadPriority_Display); |
1022 #endif | 1026 #endif |
1023 | 1027 |
1024 #if !defined(OS_IOS) | 1028 #if !defined(OS_IOS) |
1025 HistogramSynchronizer::GetInstance(); | 1029 HistogramSynchronizer::GetInstance(); |
1026 | 1030 |
1027 bool initialize_gpu_data_manager = true; | 1031 if (!UsingInProcessGpu()) { |
1028 #if defined(OS_ANDROID) | 1032 InitializeGpuDataManager(); |
1029 // On Android, GLSurface::InitializeOneOff() must be called before initalizing | |
boliu
2015/01/26 23:56:09
Pasting your comment over.
On 2015/01/26 19:51:45
| |
1030 // the GpuDataManagerImpl as it uses the GL bindings. crbug.com/326295 | |
1031 if (!gfx::GLSurface::InitializeOneOff()) { | |
1032 LOG(ERROR) << "GLSurface::InitializeOneOff failed"; | |
1033 initialize_gpu_data_manager = false; | |
1034 } | 1033 } |
1035 #endif | |
1036 | |
1037 // Initialize the GpuDataManager before we set up the MessageLoops because | |
1038 // otherwise we'll trigger the assertion about doing IO on the UI thread. | |
1039 if (initialize_gpu_data_manager) | |
1040 GpuDataManagerImpl::GetInstance()->Initialize(); | |
1041 | 1034 |
1042 bool always_uses_gpu = true; | 1035 bool always_uses_gpu = true; |
1043 bool established_gpu_channel = false; | 1036 bool established_gpu_channel = false; |
1044 #if defined(USE_AURA) || defined(OS_MACOSX) | 1037 #if defined(USE_AURA) || defined(OS_MACOSX) |
1045 established_gpu_channel = true; | 1038 established_gpu_channel = true; |
1046 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) { | 1039 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) { |
1047 established_gpu_channel = always_uses_gpu = false; | 1040 established_gpu_channel = always_uses_gpu = false; |
1048 } | 1041 } |
1049 BrowserGpuChannelHostFactory::Initialize(established_gpu_channel); | 1042 BrowserGpuChannelHostFactory::Initialize(established_gpu_channel); |
1050 ImageTransportFactory::Initialize(); | 1043 ImageTransportFactory::Initialize(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 allowed_clipboard_threads.push_back(io_thread_->thread_id()); | 1104 allowed_clipboard_threads.push_back(io_thread_->thread_id()); |
1112 #endif | 1105 #endif |
1113 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); | 1106 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); |
1114 | 1107 |
1115 // When running the GPU thread in-process, avoid optimistically starting it | 1108 // When running the GPU thread in-process, avoid optimistically starting it |
1116 // since creating the GPU thread races against creation of the one-and-only | 1109 // since creating the GPU thread races against creation of the one-and-only |
1117 // ChildProcess instance which is created by the renderer thread. | 1110 // ChildProcess instance which is created by the renderer thread. |
1118 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && | 1111 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && |
1119 !established_gpu_channel && | 1112 !established_gpu_channel && |
1120 always_uses_gpu && | 1113 always_uses_gpu && |
1121 !parsed_command_line_.HasSwitch(switches::kSingleProcess) && | 1114 !UsingInProcessGpu()) { |
1122 !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { | |
1123 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", | 1115 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", |
1124 TRACE_EVENT_SCOPE_THREAD); | 1116 TRACE_EVENT_SCOPE_THREAD); |
1125 BrowserThread::PostTask( | 1117 BrowserThread::PostTask( |
1126 BrowserThread::IO, FROM_HERE, base::Bind( | 1118 BrowserThread::IO, FROM_HERE, base::Bind( |
1127 base::IgnoreResult(&GpuProcessHost::Get), | 1119 base::IgnoreResult(&GpuProcessHost::Get), |
1128 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 1120 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
1129 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); | 1121 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); |
1130 } | 1122 } |
1131 | 1123 |
1132 #if defined(OS_MACOSX) | 1124 #if defined(OS_MACOSX) |
1133 ThemeHelperMac::GetInstance(); | 1125 ThemeHelperMac::GetInstance(); |
1134 SystemHotkeyHelperMac::GetInstance()->DeferredLoadSystemHotkeys(); | 1126 SystemHotkeyHelperMac::GetInstance()->DeferredLoadSystemHotkeys(); |
1135 if (ShouldEnableBootstrapSandbox()) { | 1127 if (ShouldEnableBootstrapSandbox()) { |
1136 TRACE_EVENT0("startup", | 1128 TRACE_EVENT0("startup", |
1137 "BrowserMainLoop::BrowserThreadsStarted:BootstrapSandbox"); | 1129 "BrowserMainLoop::BrowserThreadsStarted:BootstrapSandbox"); |
1138 CHECK(GetBootstrapSandbox()); | 1130 CHECK(GetBootstrapSandbox()); |
1139 } | 1131 } |
1140 #endif // defined(OS_MACOSX) | 1132 #endif // defined(OS_MACOSX) |
1141 | 1133 |
1142 #endif // !defined(OS_IOS) | 1134 #endif // !defined(OS_IOS) |
1143 | 1135 |
1144 return result_code_; | 1136 return result_code_; |
1145 } | 1137 } |
1146 | 1138 |
1139 bool BrowserMainLoop::UsingInProcessGpu() const { | |
1140 return parsed_command_line_.HasSwitch(switches::kSingleProcess) || | |
1141 parsed_command_line_.HasSwitch(switches::kInProcessGPU); | |
1142 } | |
1143 | |
1144 void BrowserMainLoop::InitializeGpuDataManager() { | |
1145 bool initialize_gpu_data_manager = true; | |
1146 #if defined(OS_ANDROID) | |
1147 // On Android, GLSurface::InitializeOneOff() must be called before initalizing | |
1148 // the GpuDataManagerImpl as it uses the GL bindings. crbug.com/326295 | |
1149 if (!gfx::GLSurface::InitializeOneOff()) { | |
1150 LOG(ERROR) << "GLSurface::InitializeOneOff failed"; | |
1151 initialize_gpu_data_manager = false; | |
1152 } | |
1153 #endif | |
1154 | |
1155 // Initialize the GpuDataManager before we set up the MessageLoops because | |
1156 // otherwise we'll trigger the assertion about doing IO on the UI thread. | |
1157 if (initialize_gpu_data_manager) | |
1158 GpuDataManagerImpl::GetInstance()->Initialize(); | |
1159 } | |
1160 | |
1147 bool BrowserMainLoop::InitializeToolkit() { | 1161 bool BrowserMainLoop::InitializeToolkit() { |
1148 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit"); | 1162 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit"); |
1149 // TODO(evan): this function is rather subtle, due to the variety | 1163 // TODO(evan): this function is rather subtle, due to the variety |
1150 // of intersecting ifdefs we have. To keep it easy to follow, there | 1164 // of intersecting ifdefs we have. To keep it easy to follow, there |
1151 // are no #else branches on any #ifs. | 1165 // are no #else branches on any #ifs. |
1152 // TODO(stevenjb): Move platform specific code into platform specific Parts | 1166 // TODO(stevenjb): Move platform specific code into platform specific Parts |
1153 // (Need to add InitializeToolkit stage to BrowserParts). | 1167 // (Need to add InitializeToolkit stage to BrowserParts). |
1154 // See also GTK setup in EarlyInitialization, above, and associated comments. | 1168 // See also GTK setup in EarlyInitialization, above, and associated comments. |
1155 | 1169 |
1156 #if defined(OS_WIN) | 1170 #if defined(OS_WIN) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 | 1254 |
1241 void BrowserMainLoop::EndStartupTracing() { | 1255 void BrowserMainLoop::EndStartupTracing() { |
1242 is_tracing_startup_ = false; | 1256 is_tracing_startup_ = false; |
1243 TracingController::GetInstance()->DisableRecording( | 1257 TracingController::GetInstance()->DisableRecording( |
1244 TracingController::CreateFileSink( | 1258 TracingController::CreateFileSink( |
1245 startup_trace_file_, | 1259 startup_trace_file_, |
1246 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1260 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
1247 } | 1261 } |
1248 | 1262 |
1249 } // namespace content | 1263 } // namespace content |
OLD | NEW |