Chromium Code Reviews| 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 // Need to initialize in-process GpuDataManager before creating threads | |
| 621 // since it's unsafe to manipulate the global CommandLine after. | |
|
no sievers
2015/01/27 19:43:58
nit: I'd say more specifically that we need to app
boliu
2015/01/27 20:06:35
Done.
| |
| 622 if (UsingInProcessGpu()) { | |
| 623 bool initialize_gpu_data_manager = true; | |
| 624 #if defined(OS_ANDROID) | |
| 625 if (!gfx::GLSurface::InitializeOneOff()) { | |
| 626 LOG(ERROR) << "GLSurface::InitializeOneOff failed"; | |
| 627 initialize_gpu_data_manager = false; | |
|
no sievers
2015/01/27 19:43:58
Do we really support this or is this fatal?
boliu
2015/01/27 20:06:35
Webview supports this!
This used be fatal and the
| |
| 628 } | |
| 629 #endif | |
| 630 | |
| 631 // Initialize the GpuDataManager before we set up the MessageLoops because | |
| 632 // otherwise we'll trigger the assertion about doing IO on the UI thread. | |
| 633 if (initialize_gpu_data_manager) | |
| 634 GpuDataManagerImpl::GetInstance()->Initialize(); | |
| 635 } | |
| 636 | |
| 620 return result_code_; | 637 return result_code_; |
| 621 } | 638 } |
| 622 | 639 |
| 623 void BrowserMainLoop::CreateStartupTasks() { | 640 void BrowserMainLoop::CreateStartupTasks() { |
| 624 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); | 641 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); |
| 625 | 642 |
| 626 // First time through, we really want to create all the tasks | 643 // First time through, we really want to create all the tasks |
| 627 if (!startup_task_runner_.get()) { | 644 if (!startup_task_runner_.get()) { |
| 628 #if defined(OS_ANDROID) | 645 #if defined(OS_ANDROID) |
| 629 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( | 646 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 } | 1022 } |
| 1006 | 1023 |
| 1007 int BrowserMainLoop::BrowserThreadsStarted() { | 1024 int BrowserMainLoop::BrowserThreadsStarted() { |
| 1008 TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted"); | 1025 TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted"); |
| 1009 | 1026 |
| 1010 #if !defined(OS_IOS) | 1027 #if !defined(OS_IOS) |
| 1011 indexed_db_thread_.reset(new base::Thread("IndexedDB")); | 1028 indexed_db_thread_.reset(new base::Thread("IndexedDB")); |
| 1012 indexed_db_thread_->Start(); | 1029 indexed_db_thread_->Start(); |
| 1013 #endif | 1030 #endif |
| 1014 | 1031 |
| 1032 #if !defined(OS_IOS) | |
| 1033 HistogramSynchronizer::GetInstance(); | |
| 1034 | |
| 1035 | |
| 1036 // GpuDataManager for in-process initialized in PreCreateThreads. | |
| 1037 bool initialize_gpu_data_manager = !UsingInProcessGpu(); | |
| 1015 #if defined(OS_ANDROID) | 1038 #if defined(OS_ANDROID) |
| 1016 // Up the priority of anything that touches with display tasks | 1039 // Up the priority of anything that touches with display tasks |
| 1017 // (this thread is UI thread, and io_thread_ is for IPCs). | 1040 // (this thread is UI thread, and io_thread_ is for IPCs). |
| 1018 io_thread_->SetPriority(base::kThreadPriority_Display); | 1041 io_thread_->SetPriority(base::kThreadPriority_Display); |
| 1019 base::PlatformThread::SetThreadPriority( | 1042 base::PlatformThread::SetThreadPriority( |
| 1020 base::PlatformThread::CurrentHandle(), | 1043 base::PlatformThread::CurrentHandle(), |
| 1021 base::kThreadPriority_Display); | 1044 base::kThreadPriority_Display); |
| 1022 #endif | |
| 1023 | 1045 |
| 1024 #if !defined(OS_IOS) | 1046 if (!UsingInProcessGpu() && !gfx::GLSurface::InitializeOneOff()) { |
|
no sievers
2015/01/27 19:43:58
nit: use |initialize_gpu_data_manager|
boliu
2015/01/27 20:06:35
Done.
| |
| 1025 HistogramSynchronizer::GetInstance(); | 1047 // On Android, GLSurface::InitializeOneOff() must be called before |
| 1026 | 1048 // initalizing the GpuDataManagerImpl as it uses the GL bindings. |
| 1027 bool initialize_gpu_data_manager = true; | 1049 // crbug.com/326295 |
|
no sievers
2015/01/27 19:43:58
Pull this comment out to line 1045 and can you add
boliu
2015/01/27 20:06:35
Done.
| |
| 1028 #if defined(OS_ANDROID) | |
| 1029 // On Android, GLSurface::InitializeOneOff() must be called before initalizing | |
| 1030 // the GpuDataManagerImpl as it uses the GL bindings. crbug.com/326295 | |
| 1031 if (!gfx::GLSurface::InitializeOneOff()) { | |
| 1032 LOG(ERROR) << "GLSurface::InitializeOneOff failed"; | 1050 LOG(ERROR) << "GLSurface::InitializeOneOff failed"; |
| 1033 initialize_gpu_data_manager = false; | 1051 initialize_gpu_data_manager = false; |
| 1034 } | 1052 } |
| 1035 #endif | 1053 #endif |
| 1036 | 1054 |
| 1037 // Initialize the GpuDataManager before we set up the MessageLoops because | 1055 // Initialize the GpuDataManager before we set up the MessageLoops because |
| 1038 // otherwise we'll trigger the assertion about doing IO on the UI thread. | 1056 // otherwise we'll trigger the assertion about doing IO on the UI thread. |
| 1039 if (initialize_gpu_data_manager) | 1057 if (initialize_gpu_data_manager) |
| 1040 GpuDataManagerImpl::GetInstance()->Initialize(); | 1058 GpuDataManagerImpl::GetInstance()->Initialize(); |
| 1041 | 1059 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 allowed_clipboard_threads.push_back(io_thread_->thread_id()); | 1129 allowed_clipboard_threads.push_back(io_thread_->thread_id()); |
| 1112 #endif | 1130 #endif |
| 1113 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); | 1131 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); |
| 1114 | 1132 |
| 1115 // When running the GPU thread in-process, avoid optimistically starting it | 1133 // 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 | 1134 // since creating the GPU thread races against creation of the one-and-only |
| 1117 // ChildProcess instance which is created by the renderer thread. | 1135 // ChildProcess instance which is created by the renderer thread. |
| 1118 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && | 1136 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && |
| 1119 !established_gpu_channel && | 1137 !established_gpu_channel && |
| 1120 always_uses_gpu && | 1138 always_uses_gpu && |
| 1121 !parsed_command_line_.HasSwitch(switches::kSingleProcess) && | 1139 !UsingInProcessGpu()) { |
| 1122 !parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { | |
| 1123 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", | 1140 TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", |
| 1124 TRACE_EVENT_SCOPE_THREAD); | 1141 TRACE_EVENT_SCOPE_THREAD); |
| 1125 BrowserThread::PostTask( | 1142 BrowserThread::PostTask( |
| 1126 BrowserThread::IO, FROM_HERE, base::Bind( | 1143 BrowserThread::IO, FROM_HERE, base::Bind( |
| 1127 base::IgnoreResult(&GpuProcessHost::Get), | 1144 base::IgnoreResult(&GpuProcessHost::Get), |
| 1128 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 1145 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| 1129 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); | 1146 CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); |
| 1130 } | 1147 } |
| 1131 | 1148 |
| 1132 #if defined(OS_MACOSX) | 1149 #if defined(OS_MACOSX) |
| 1133 ThemeHelperMac::GetInstance(); | 1150 ThemeHelperMac::GetInstance(); |
| 1134 SystemHotkeyHelperMac::GetInstance()->DeferredLoadSystemHotkeys(); | 1151 SystemHotkeyHelperMac::GetInstance()->DeferredLoadSystemHotkeys(); |
| 1135 if (ShouldEnableBootstrapSandbox()) { | 1152 if (ShouldEnableBootstrapSandbox()) { |
| 1136 TRACE_EVENT0("startup", | 1153 TRACE_EVENT0("startup", |
| 1137 "BrowserMainLoop::BrowserThreadsStarted:BootstrapSandbox"); | 1154 "BrowserMainLoop::BrowserThreadsStarted:BootstrapSandbox"); |
| 1138 CHECK(GetBootstrapSandbox()); | 1155 CHECK(GetBootstrapSandbox()); |
| 1139 } | 1156 } |
| 1140 #endif // defined(OS_MACOSX) | 1157 #endif // defined(OS_MACOSX) |
| 1141 | 1158 |
| 1142 #endif // !defined(OS_IOS) | 1159 #endif // !defined(OS_IOS) |
| 1143 | 1160 |
| 1144 return result_code_; | 1161 return result_code_; |
| 1145 } | 1162 } |
| 1146 | 1163 |
| 1164 bool BrowserMainLoop::UsingInProcessGpu() const { | |
| 1165 return parsed_command_line_.HasSwitch(switches::kSingleProcess) || | |
| 1166 parsed_command_line_.HasSwitch(switches::kInProcessGPU); | |
| 1167 } | |
| 1168 | |
| 1147 bool BrowserMainLoop::InitializeToolkit() { | 1169 bool BrowserMainLoop::InitializeToolkit() { |
| 1148 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit"); | 1170 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit"); |
| 1149 // TODO(evan): this function is rather subtle, due to the variety | 1171 // TODO(evan): this function is rather subtle, due to the variety |
| 1150 // of intersecting ifdefs we have. To keep it easy to follow, there | 1172 // of intersecting ifdefs we have. To keep it easy to follow, there |
| 1151 // are no #else branches on any #ifs. | 1173 // are no #else branches on any #ifs. |
| 1152 // TODO(stevenjb): Move platform specific code into platform specific Parts | 1174 // TODO(stevenjb): Move platform specific code into platform specific Parts |
| 1153 // (Need to add InitializeToolkit stage to BrowserParts). | 1175 // (Need to add InitializeToolkit stage to BrowserParts). |
| 1154 // See also GTK setup in EarlyInitialization, above, and associated comments. | 1176 // See also GTK setup in EarlyInitialization, above, and associated comments. |
| 1155 | 1177 |
| 1156 #if defined(OS_WIN) | 1178 #if defined(OS_WIN) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1240 | 1262 |
| 1241 void BrowserMainLoop::EndStartupTracing() { | 1263 void BrowserMainLoop::EndStartupTracing() { |
| 1242 is_tracing_startup_ = false; | 1264 is_tracing_startup_ = false; |
| 1243 TracingController::GetInstance()->DisableRecording( | 1265 TracingController::GetInstance()->DisableRecording( |
| 1244 TracingController::CreateFileSink( | 1266 TracingController::CreateFileSink( |
| 1245 startup_trace_file_, | 1267 startup_trace_file_, |
| 1246 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1268 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
| 1247 } | 1269 } |
| 1248 | 1270 |
| 1249 } // namespace content | 1271 } // namespace content |
| OLD | NEW |