Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: content/app/content_main_runner.cc

Issue 1815563004: Remove iOS ifdefs in src/content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/browser_child_process_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/app/content_main_runner.h" 5 #include "content/public/app/content_main_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <string> 10 #include <string>
(...skipping 20 matching lines...) Expand all
31 #include "base/process/process_handle.h" 31 #include "base/process/process_handle.h"
32 #include "base/profiler/scoped_tracker.h" 32 #include "base/profiler/scoped_tracker.h"
33 #include "base/strings/string_number_conversions.h" 33 #include "base/strings/string_number_conversions.h"
34 #include "base/strings/string_util.h" 34 #include "base/strings/string_util.h"
35 #include "base/strings/stringprintf.h" 35 #include "base/strings/stringprintf.h"
36 #include "base/trace_event/trace_event.h" 36 #include "base/trace_event/trace_event.h"
37 #include "build/build_config.h" 37 #include "build/build_config.h"
38 #include "components/tracing/trace_config_file.h" 38 #include "components/tracing/trace_config_file.h"
39 #include "components/tracing/trace_to_console.h" 39 #include "components/tracing/trace_to_console.h"
40 #include "components/tracing/tracing_switches.h" 40 #include "components/tracing/tracing_switches.h"
41 #include "content/app/mojo/mojo_init.h"
41 #include "content/browser/browser_main.h" 42 #include "content/browser/browser_main.h"
43 #include "content/browser/gpu/gpu_process_host.h"
44 #include "content/browser/renderer_host/render_process_host_impl.h"
45 #include "content/browser/utility_process_host_impl.h"
42 #include "content/common/set_process_title.h" 46 #include "content/common/set_process_title.h"
43 #include "content/common/url_schemes.h" 47 #include "content/common/url_schemes.h"
44 #include "content/gpu/in_process_gpu_thread.h" 48 #include "content/gpu/in_process_gpu_thread.h"
45 #include "content/public/app/content_main.h" 49 #include "content/public/app/content_main.h"
46 #include "content/public/app/content_main_delegate.h" 50 #include "content/public/app/content_main_delegate.h"
47 #include "content/public/browser/content_browser_client.h" 51 #include "content/public/browser/content_browser_client.h"
48 #include "content/public/common/content_client.h" 52 #include "content/public/common/content_client.h"
49 #include "content/public/common/content_constants.h" 53 #include "content/public/common/content_constants.h"
50 #include "content/public/common/content_paths.h" 54 #include "content/public/common/content_paths.h"
51 #include "content/public/common/content_switches.h" 55 #include "content/public/common/content_switches.h"
52 #include "content/public/common/main_function_params.h" 56 #include "content/public/common/main_function_params.h"
53 #include "content/public/common/sandbox_init.h" 57 #include "content/public/common/sandbox_init.h"
58 #include "content/public/gpu/content_gpu_client.h"
59 #include "content/public/plugin/content_plugin_client.h"
60 #include "content/public/renderer/content_renderer_client.h"
61 #include "content/public/utility/content_utility_client.h"
54 #include "content/renderer/in_process_renderer_thread.h" 62 #include "content/renderer/in_process_renderer_thread.h"
55 #include "content/utility/in_process_utility_thread.h" 63 #include "content/utility/in_process_utility_thread.h"
56 #include "ipc/ipc_descriptors.h" 64 #include "ipc/ipc_descriptors.h"
57 #include "ipc/ipc_switches.h" 65 #include "ipc/ipc_switches.h"
58 #include "media/base/media.h" 66 #include "media/base/media.h"
59 #include "sandbox/win/src/sandbox_types.h" 67 #include "sandbox/win/src/sandbox_types.h"
60 #include "ui/base/ui_base_paths.h" 68 #include "ui/base/ui_base_paths.h"
61 #include "ui/base/ui_base_switches.h" 69 #include "ui/base/ui_base_switches.h"
62 70
63 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 71 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
64 #include "gin/v8_initializer.h" 72 #include "gin/v8_initializer.h"
65 #endif 73 #endif
66 74
67 #if !defined(OS_IOS)
68 #include "content/app/mojo/mojo_init.h"
69 #include "content/browser/gpu/gpu_process_host.h"
70 #include "content/browser/renderer_host/render_process_host_impl.h"
71 #include "content/browser/utility_process_host_impl.h"
72 #include "content/public/gpu/content_gpu_client.h"
73 #include "content/public/plugin/content_plugin_client.h"
74 #include "content/public/renderer/content_renderer_client.h"
75 #include "content/public/utility/content_utility_client.h"
76 #endif
77
78 #if defined(OS_WIN) 75 #if defined(OS_WIN)
79 #include <malloc.h> 76 #include <malloc.h>
80 #include <cstring> 77 #include <cstring>
81 78
82 #include "base/trace_event/trace_event_etw_export_win.h" 79 #include "base/trace_event/trace_event_etw_export_win.h"
83 #include "base/win/process_startup_helper.h" 80 #include "base/win/process_startup_helper.h"
84 #include "ui/base/win/atl_module.h" 81 #include "ui/base/win/atl_module.h"
85 #include "ui/gfx/win/dpi.h" 82 #include "ui/gfx/win/dpi.h"
86 #elif defined(OS_MACOSX) 83 #elif defined(OS_MACOSX)
87 #include "base/mac/scoped_nsautorelease_pool.h" 84 #include "base/mac/scoped_nsautorelease_pool.h"
88 #if !defined(OS_IOS)
89 #include "base/power_monitor/power_monitor_device_source.h" 85 #include "base/power_monitor/power_monitor_device_source.h"
90 #include "content/app/mac/mac_init.h" 86 #include "content/app/mac/mac_init.h"
91 #include "content/browser/mach_broker_mac.h" 87 #include "content/browser/mach_broker_mac.h"
92 #include "content/common/sandbox_init_mac.h" 88 #include "content/common/sandbox_init_mac.h"
93 #endif // !OS_IOS
94 #endif // OS_WIN 89 #endif // OS_WIN
95 90
96 #if defined(OS_POSIX) 91 #if defined(OS_POSIX)
97 #include <signal.h> 92 #include <signal.h>
98 93
99 #include "base/posix/global_descriptors.h" 94 #include "base/posix/global_descriptors.h"
100 #include "content/public/common/content_descriptors.h" 95 #include "content/public/common/content_descriptors.h"
101 96
102 #if !defined(OS_MACOSX) 97 #if !defined(OS_MACOSX)
103 #include "content/public/common/zygote_fork_delegate_linux.h" 98 #include "content/public/common/zygote_fork_delegate_linux.h"
(...skipping 22 matching lines...) Expand all
126 #if defined(OS_ANDROID) 121 #if defined(OS_ANDROID)
127 extern int DownloadMain(const MainFunctionParams&); 122 extern int DownloadMain(const MainFunctionParams&);
128 #endif 123 #endif
129 } // namespace content 124 } // namespace content
130 125
131 namespace content { 126 namespace content {
132 127
133 #if !defined(CHROME_MULTIPLE_DLL_CHILD) 128 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
134 base::LazyInstance<ContentBrowserClient> 129 base::LazyInstance<ContentBrowserClient>
135 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; 130 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER;
136 #endif // !CHROME_MULTIPLE_DLL_CHILD
137
138 #if !defined(OS_IOS) && !defined(CHROME_MULTIPLE_DLL_BROWSER)
139 base::LazyInstance<ContentGpuClient> 131 base::LazyInstance<ContentGpuClient>
scottmg 2016/03/18 23:07:39 I think this should be !defined(CHROME_MULTIPLE_DL
jam 2016/03/19 03:22:17 oops, fixed. serves me right for sending before wa
140 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; 132 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER;
141 base::LazyInstance<ContentPluginClient> 133 base::LazyInstance<ContentPluginClient>
142 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; 134 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER;
143 base::LazyInstance<ContentRendererClient> 135 base::LazyInstance<ContentRendererClient>
144 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; 136 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
145 base::LazyInstance<ContentUtilityClient> 137 base::LazyInstance<ContentUtilityClient>
146 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; 138 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER;
147 #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER 139 #endif // !CHROME_MULTIPLE_DLL_BROWSER
148 140
149 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) 141 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID)
150 #if defined __LP64__ 142 #if defined __LP64__
151 #define kV8NativesDataDescriptor kV8NativesDataDescriptor64 143 #define kV8NativesDataDescriptor kV8NativesDataDescriptor64
152 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 144 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64
153 #else 145 #else
154 #define kV8NativesDataDescriptor kV8NativesDataDescriptor32 146 #define kV8NativesDataDescriptor kV8NativesDataDescriptor32
155 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 147 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32
156 #endif 148 #endif
157 #endif 149 #endif
158 150
159 #if defined(OS_POSIX) && !defined(OS_IOS) 151 #if defined(OS_POSIX)
160 152
161 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. 153 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE.
162 void SetupSignalHandlers() { 154 void SetupSignalHandlers() {
163 // Sanitise our signal handling state. Signals that were ignored by our 155 // Sanitise our signal handling state. Signals that were ignored by our
164 // parent will also be ignored by us. We also inherit our parent's sigmask. 156 // parent will also be ignored by us. We also inherit our parent's sigmask.
165 sigset_t empty_signal_set; 157 sigset_t empty_signal_set;
166 CHECK_EQ(0, sigemptyset(&empty_signal_set)); 158 CHECK_EQ(0, sigemptyset(&empty_signal_set));
167 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); 159 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL));
168 160
169 struct sigaction sigact; 161 struct sigaction sigact;
170 memset(&sigact, 0, sizeof(sigact)); 162 memset(&sigact, 0, sizeof(sigact));
171 sigact.sa_handler = SIG_DFL; 163 sigact.sa_handler = SIG_DFL;
172 static const int signals_to_reset[] = 164 static const int signals_to_reset[] =
173 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, 165 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV,
174 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. 166 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below.
175 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { 167 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) {
176 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL)); 168 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL));
177 } 169 }
178 170
179 // Always ignore SIGPIPE. We check the return value of write(). 171 // Always ignore SIGPIPE. We check the return value of write().
180 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN)); 172 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN));
181 } 173 }
182 174
183 #endif // OS_POSIX && !OS_IOS 175 #endif // OS_POSIX
184 176
185 void CommonSubprocessInit(const std::string& process_type) { 177 void CommonSubprocessInit(const std::string& process_type) {
186 #if defined(OS_WIN) 178 #if defined(OS_WIN)
187 // HACK: Let Windows know that we have started. This is needed to suppress 179 // HACK: Let Windows know that we have started. This is needed to suppress
188 // the IDC_APPSTARTING cursor from being displayed for a prolonged period 180 // the IDC_APPSTARTING cursor from being displayed for a prolonged period
189 // while a subprocess is starting. 181 // while a subprocess is starting.
190 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); 182 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0);
191 MSG msg; 183 MSG msg;
192 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); 184 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
193 #endif 185 #endif
(...skipping 20 matching lines...) Expand all
214 base::RouteStdioToConsole(false); 206 base::RouteStdioToConsole(false);
215 LoadLibraryA("dbghelp.dll"); 207 LoadLibraryA("dbghelp.dll");
216 #endif 208 #endif
217 #endif 209 #endif
218 } 210 }
219 211
220 class ContentClientInitializer { 212 class ContentClientInitializer {
221 public: 213 public:
222 static void Set(const std::string& process_type, 214 static void Set(const std::string& process_type,
223 ContentMainDelegate* delegate) { 215 ContentMainDelegate* delegate) {
216 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
224 ContentClient* content_client = GetContentClient(); 217 ContentClient* content_client = GetContentClient();
225 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
226 if (process_type.empty()) { 218 if (process_type.empty()) {
227 if (delegate) 219 if (delegate)
228 content_client->browser_ = delegate->CreateContentBrowserClient(); 220 content_client->browser_ = delegate->CreateContentBrowserClient();
229 if (!content_client->browser_) 221 if (!content_client->browser_)
230 content_client->browser_ = &g_empty_content_browser_client.Get(); 222 content_client->browser_ = &g_empty_content_browser_client.Get();
231 } 223 }
232 #endif // !CHROME_MULTIPLE_DLL_CHILD
233
234 #if !defined(OS_IOS) && !defined(CHROME_MULTIPLE_DLL_BROWSER)
scottmg 2016/03/18 23:07:39 same
235 if (process_type == switches::kGpuProcess || 224 if (process_type == switches::kGpuProcess ||
236 base::CommandLine::ForCurrentProcess()->HasSwitch( 225 base::CommandLine::ForCurrentProcess()->HasSwitch(
237 switches::kSingleProcess)) { 226 switches::kSingleProcess)) {
238 if (delegate) 227 if (delegate)
239 content_client->gpu_ = delegate->CreateContentGpuClient(); 228 content_client->gpu_ = delegate->CreateContentGpuClient();
240 if (!content_client->gpu_) 229 if (!content_client->gpu_)
241 content_client->gpu_ = &g_empty_content_gpu_client.Get(); 230 content_client->gpu_ = &g_empty_content_gpu_client.Get();
242 } 231 }
243 232
244 if (process_type == switches::kPluginProcess || 233 if (process_type == switches::kPluginProcess ||
(...skipping 14 matching lines...) Expand all
259 248
260 if (process_type == switches::kUtilityProcess || 249 if (process_type == switches::kUtilityProcess ||
261 base::CommandLine::ForCurrentProcess()->HasSwitch( 250 base::CommandLine::ForCurrentProcess()->HasSwitch(
262 switches::kSingleProcess)) { 251 switches::kSingleProcess)) {
263 if (delegate) 252 if (delegate)
264 content_client->utility_ = delegate->CreateContentUtilityClient(); 253 content_client->utility_ = delegate->CreateContentUtilityClient();
265 // TODO(scottmg): http://crbug.com/237249 Should be in _child. 254 // TODO(scottmg): http://crbug.com/237249 Should be in _child.
266 if (!content_client->utility_) 255 if (!content_client->utility_)
267 content_client->utility_ = &g_empty_content_utility_client.Get(); 256 content_client->utility_ = &g_empty_content_utility_client.Get();
268 } 257 }
269 #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER 258 #endif // !CHROME_MULTIPLE_DLL_BROWSER
270 } 259 }
271 }; 260 };
272 261
273 // We dispatch to a process-type-specific FooMain() based on a command-line 262 // We dispatch to a process-type-specific FooMain() based on a command-line
274 // flag. This struct is used to build a table of (flag, main function) pairs. 263 // flag. This struct is used to build a table of (flag, main function) pairs.
275 struct MainFunction { 264 struct MainFunction {
276 const char* name; 265 const char* name;
277 int (*function)(const MainFunctionParams&); 266 int (*function)(const MainFunctionParams&);
278 }; 267 };
279 268
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 310 }
322 311
323 if (delegate) 312 if (delegate)
324 return delegate->RunProcess(process_type, main_params); 313 return delegate->RunProcess(process_type, main_params);
325 314
326 NOTREACHED() << "Unknown zygote process type: " << process_type; 315 NOTREACHED() << "Unknown zygote process type: " << process_type;
327 return 1; 316 return 1;
328 } 317 }
329 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 318 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
330 319
331 #if !defined(OS_IOS)
332 static void RegisterMainThreadFactories() { 320 static void RegisterMainThreadFactories() {
333 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) && !defined(CHROME_MULTIPLE_DLL_CHILD) 321 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) && !defined(CHROME_MULTIPLE_DLL_CHILD)
334 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( 322 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(
335 CreateInProcessUtilityThread); 323 CreateInProcessUtilityThread);
336 RenderProcessHostImpl::RegisterRendererMainThreadFactory( 324 RenderProcessHostImpl::RegisterRendererMainThreadFactory(
337 CreateInProcessRendererThread); 325 CreateInProcessRendererThread);
338 GpuProcessHost::RegisterGpuMainThreadFactory( 326 GpuProcessHost::RegisterGpuMainThreadFactory(
339 CreateInProcessGpuThread); 327 CreateInProcessGpuThread);
340 #else 328 #else
341 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); 329 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 return RunZygote(main_function_params, delegate); 395 return RunZygote(main_function_params, delegate);
408 #endif 396 #endif
409 397
410 // If it's a process we don't know about, the embedder should know. 398 // If it's a process we don't know about, the embedder should know.
411 if (delegate) 399 if (delegate)
412 return delegate->RunProcess(process_type, main_function_params); 400 return delegate->RunProcess(process_type, main_function_params);
413 401
414 NOTREACHED() << "Unknown process type: " << process_type; 402 NOTREACHED() << "Unknown process type: " << process_type;
415 return 1; 403 return 1;
416 } 404 }
417 #endif // !OS_IOS
418 405
419 class ContentMainRunnerImpl : public ContentMainRunner { 406 class ContentMainRunnerImpl : public ContentMainRunner {
420 public: 407 public:
421 ContentMainRunnerImpl() 408 ContentMainRunnerImpl()
422 : is_initialized_(false), 409 : is_initialized_(false),
423 is_shutdown_(false), 410 is_shutdown_(false),
424 completed_basic_startup_(false), 411 completed_basic_startup_(false),
425 delegate_(NULL), 412 delegate_(NULL),
426 ui_task_(NULL) { 413 ui_task_(NULL) {
427 #if defined(OS_WIN) 414 #if defined(OS_WIN)
(...skipping 17 matching lines...) Expand all
445 sandbox_info_ = *params.sandbox_info; 432 sandbox_info_ = *params.sandbox_info;
446 #else // !OS_WIN 433 #else // !OS_WIN
447 434
448 #if defined(OS_ANDROID) 435 #if defined(OS_ANDROID)
449 // See note at the initialization of ExitManager, below; basically, 436 // See note at the initialization of ExitManager, below; basically,
450 // only Android builds have the ctor/dtor handlers set up to use 437 // only Android builds have the ctor/dtor handlers set up to use
451 // TRACE_EVENT right away. 438 // TRACE_EVENT right away.
452 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); 439 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
453 #endif // OS_ANDROID 440 #endif // OS_ANDROID
454 441
455 #if !defined(OS_IOS)
456 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); 442 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
457 #endif
458 443
459 // On Android, 444 // On Android,
460 // - setlocale() is not supported. 445 // - setlocale() is not supported.
461 // - We do not override the signal handlers so that we can get 446 // - We do not override the signal handlers so that we can get
462 // stack trace when crashing. 447 // stack trace when crashing.
463 // - The ipc_fd is passed through the Java service. 448 // - The ipc_fd is passed through the Java service.
464 // Thus, these are all disabled. 449 // Thus, these are all disabled.
465 #if !defined(OS_ANDROID) && !defined(OS_IOS) 450 #if !defined(OS_ANDROID)
466 // Set C library locale to make sure CommandLine can parse argument values 451 // Set C library locale to make sure CommandLine can parse argument values
467 // in correct encoding. 452 // in correct encoding.
468 setlocale(LC_ALL, ""); 453 setlocale(LC_ALL, "");
469 454
470 SetupSignalHandlers(); 455 SetupSignalHandlers();
471 g_fds->Set(kPrimaryIPCChannel, 456 g_fds->Set(kPrimaryIPCChannel,
472 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 457 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
473 g_fds->Set(kMojoIPCChannel, 458 g_fds->Set(kMojoIPCChannel,
474 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 459 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
475 #endif // !OS_ANDROID && !OS_IOS 460 #endif // !OS_ANDROID
476 461
477 #if defined(OS_LINUX) || defined(OS_OPENBSD) 462 #if defined(OS_LINUX) || defined(OS_OPENBSD)
478 g_fds->Set(kCrashDumpSignal, 463 g_fds->Set(kCrashDumpSignal,
479 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); 464 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
480 #endif // OS_LINUX || OS_OPENBSD 465 #endif // OS_LINUX || OS_OPENBSD
481 466
482 467
483 #endif // !OS_WIN 468 #endif // !OS_WIN
484 469
485 is_initialized_ = true; 470 is_initialized_ = true;
486 delegate_ = params.delegate; 471 delegate_ = params.delegate;
487 472
488 // The exit manager is in charge of calling the dtors of singleton objects. 473 // The exit manager is in charge of calling the dtors of singleton objects.
489 // On Android, AtExitManager is set up when library is loaded. 474 // On Android, AtExitManager is set up when library is loaded.
490 // On iOS, it's set up in main(), which can't call directly through to here.
491 // A consequence of this is that you can't use the ctor/dtor-based 475 // A consequence of this is that you can't use the ctor/dtor-based
492 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. 476 // TRACE_EVENT methods on Linux or iOS builds till after we set this up.
493 #if !defined(OS_ANDROID) && !defined(OS_IOS) 477 #if !defined(OS_ANDROID)
494 if (!ui_task_) { 478 if (!ui_task_) {
495 // When running browser tests, don't create a second AtExitManager as that 479 // When running browser tests, don't create a second AtExitManager as that
496 // interfers with shutdown when objects created before ContentMain is 480 // interfers with shutdown when objects created before ContentMain is
497 // called are destructed when it returns. 481 // called are destructed when it returns.
498 exit_manager_.reset(new base::AtExitManager); 482 exit_manager_.reset(new base::AtExitManager);
499 } 483 }
500 #endif // !OS_ANDROID && !OS_IOS 484 #endif // !OS_ANDROID
501 485
502 // Don't create this loop on iOS, since the outer loop is already handled 486 #if defined(OS_MACOSX)
503 // and a loop that's destroyed in shutdown interleaves badly with the event
504 // loop pool on iOS.
505 #if defined(OS_MACOSX) && !defined(OS_IOS)
506 // We need this pool for all the objects created before we get to the 487 // We need this pool for all the objects created before we get to the
507 // event loop, but we don't want to leave them hanging around until the 488 // event loop, but we don't want to leave them hanging around until the
508 // app quits. Each "main" needs to flush this pool right before it goes into 489 // app quits. Each "main" needs to flush this pool right before it goes into
509 // its main event loop to get rid of the cruft. 490 // its main event loop to get rid of the cruft.
510 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 491 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
511 InitializeMac(); 492 InitializeMac();
512 #endif 493 #endif
513 494
514 // On Android, the command line is initialized when library is loaded and 495 // On Android, the command line is initialized when library is loaded and
515 // we have already started our TRACE_EVENT0. 496 // we have already started our TRACE_EVENT0.
(...skipping 11 matching lines...) Expand all
527 base::CommandLine::Init(argc, argv); 508 base::CommandLine::Init(argc, argv);
528 509
529 base::EnableTerminationOnHeapCorruption(); 510 base::EnableTerminationOnHeapCorruption();
530 511
531 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. 512 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
532 // Enable profiler recording right after command line is initialized so that 513 // Enable profiler recording right after command line is initialized so that
533 // browser startup can be instrumented. 514 // browser startup can be instrumented.
534 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) 515 if (delegate_ && delegate_->ShouldEnableProfilerRecording())
535 tracked_objects::ScopedTracker::Enable(); 516 tracked_objects::ScopedTracker::Enable();
536 517
537 #if !defined(OS_IOS)
538 SetProcessTitleFromCommandLine(argv); 518 SetProcessTitleFromCommandLine(argv);
539 #endif
540 #endif // !OS_ANDROID 519 #endif // !OS_ANDROID
541 520
542 int exit_code = 0; 521 int exit_code = 0;
543 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) 522 if (delegate_ && delegate_->BasicStartupComplete(&exit_code))
544 return exit_code; 523 return exit_code;
545 524
546 completed_basic_startup_ = true; 525 completed_basic_startup_ = true;
547 526
548 const base::CommandLine& command_line = 527 const base::CommandLine& command_line =
549 *base::CommandLine::ForCurrentProcess(); 528 *base::CommandLine::ForCurrentProcess();
550 std::string process_type = 529 std::string process_type =
551 command_line.GetSwitchValueASCII(switches::kProcessType); 530 command_line.GetSwitchValueASCII(switches::kProcessType);
552 531
553 #if !defined(OS_IOS)
554 // Initialize mojo here so that services can be registered. 532 // Initialize mojo here so that services can be registered.
555 InitializeMojo(); 533 InitializeMojo();
556 #endif
557 534
558 #if defined(OS_WIN) 535 #if defined(OS_WIN)
559 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) { 536 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) {
560 std::string scale_factor_string = command_line.GetSwitchValueASCII( 537 std::string scale_factor_string = command_line.GetSwitchValueASCII(
561 switches::kDeviceScaleFactor); 538 switches::kDeviceScaleFactor);
562 double scale_factor = 0; 539 double scale_factor = 0;
563 if (base::StringToDouble(scale_factor_string, &scale_factor)) 540 if (base::StringToDouble(scale_factor_string, &scale_factor))
564 gfx::SetDefaultDeviceScaleFactor(scale_factor); 541 gfx::SetDefaultDeviceScaleFactor(scale_factor);
565 } 542 }
566 #endif 543 #endif
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 base::trace_event::TraceEventETWExport::EnableETWExport(); 589 base::trace_event::TraceEventETWExport::EnableETWExport();
613 #endif // OS_WIN 590 #endif // OS_WIN
614 591
615 #if !defined(OS_ANDROID) 592 #if !defined(OS_ANDROID)
616 // Android tracing started at the beginning of the method. 593 // Android tracing started at the beginning of the method.
617 // Other OSes have to wait till we get here in order for all the memory 594 // Other OSes have to wait till we get here in order for all the memory
618 // management setup to be completed. 595 // management setup to be completed.
619 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); 596 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
620 #endif // !OS_ANDROID 597 #endif // !OS_ANDROID
621 598
622 #if defined(OS_MACOSX) && !defined(OS_IOS) 599 #if defined(OS_MACOSX)
623 // We need to allocate the IO Ports before the Sandbox is initialized or 600 // We need to allocate the IO Ports before the Sandbox is initialized or
624 // the first instance of PowerMonitor is created. 601 // the first instance of PowerMonitor is created.
625 // It's important not to allocate the ports for processes which don't 602 // It's important not to allocate the ports for processes which don't
626 // register with the power monitor - see crbug.com/88867. 603 // register with the power monitor - see crbug.com/88867.
627 if (process_type.empty() || 604 if (process_type.empty() ||
628 (delegate_ && 605 (delegate_ &&
629 delegate_->ProcessRegistersWithSystemProcess(process_type))) { 606 delegate_->ProcessRegistersWithSystemProcess(process_type))) {
630 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); 607 base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
631 } 608 }
632 609
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 #endif // V8_USE_EXTERNAL_STARTUP_DATA 702 #endif // V8_USE_EXTERNAL_STARTUP_DATA
726 703
727 if (delegate_) 704 if (delegate_)
728 delegate_->PreSandboxStartup(); 705 delegate_->PreSandboxStartup();
729 706
730 if (!process_type.empty()) 707 if (!process_type.empty())
731 CommonSubprocessInit(process_type); 708 CommonSubprocessInit(process_type);
732 709
733 #if defined(OS_WIN) 710 #if defined(OS_WIN)
734 CHECK(InitializeSandbox(params.sandbox_info)); 711 CHECK(InitializeSandbox(params.sandbox_info));
735 #elif defined(OS_MACOSX) && !defined(OS_IOS) 712 #elif defined(OS_MACOSX)
736 if (process_type == switches::kRendererProcess || 713 if (process_type == switches::kRendererProcess ||
737 process_type == switches::kPpapiPluginProcess || 714 process_type == switches::kPpapiPluginProcess ||
738 (delegate_ && delegate_->DelaySandboxInitialization(process_type))) { 715 (delegate_ && delegate_->DelaySandboxInitialization(process_type))) {
739 // On OS X the renderer sandbox needs to be initialized later in the 716 // On OS X the renderer sandbox needs to be initialized later in the
740 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). 717 // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
741 } else { 718 } else {
742 CHECK(InitializeSandbox()); 719 CHECK(InitializeSandbox());
743 } 720 }
744 #endif 721 #endif
745 722
(...skipping 15 matching lines...) Expand all
761 base::HistogramBase::EnableActivityReportHistogram(process_type); 738 base::HistogramBase::EnableActivityReportHistogram(process_type);
762 739
763 MainFunctionParams main_params(command_line); 740 MainFunctionParams main_params(command_line);
764 main_params.ui_task = ui_task_; 741 main_params.ui_task = ui_task_;
765 #if defined(OS_WIN) 742 #if defined(OS_WIN)
766 main_params.sandbox_info = &sandbox_info_; 743 main_params.sandbox_info = &sandbox_info_;
767 #elif defined(OS_MACOSX) 744 #elif defined(OS_MACOSX)
768 main_params.autorelease_pool = autorelease_pool_.get(); 745 main_params.autorelease_pool = autorelease_pool_.get();
769 #endif 746 #endif
770 747
771 #if !defined(OS_IOS)
772 return RunNamedProcessTypeMain(process_type, main_params, delegate_); 748 return RunNamedProcessTypeMain(process_type, main_params, delegate_);
773 #else
774 return 1;
775 #endif
776 } 749 }
777 750
778 void Shutdown() override { 751 void Shutdown() override {
779 DCHECK(is_initialized_); 752 DCHECK(is_initialized_);
780 DCHECK(!is_shutdown_); 753 DCHECK(!is_shutdown_);
781 754
782 if (completed_basic_startup_ && delegate_) { 755 if (completed_basic_startup_ && delegate_) {
783 const base::CommandLine& command_line = 756 const base::CommandLine& command_line =
784 *base::CommandLine::ForCurrentProcess(); 757 *base::CommandLine::ForCurrentProcess();
785 std::string process_type = 758 std::string process_type =
786 command_line.GetSwitchValueASCII(switches::kProcessType); 759 command_line.GetSwitchValueASCII(switches::kProcessType);
787 760
788 delegate_->ProcessExiting(process_type); 761 delegate_->ProcessExiting(process_type);
789 } 762 }
790 763
791 #if defined(OS_WIN) 764 #if defined(OS_WIN)
792 #ifdef _CRTDBG_MAP_ALLOC 765 #ifdef _CRTDBG_MAP_ALLOC
793 _CrtDumpMemoryLeaks(); 766 _CrtDumpMemoryLeaks();
794 #endif // _CRTDBG_MAP_ALLOC 767 #endif // _CRTDBG_MAP_ALLOC
795 #endif // OS_WIN 768 #endif // OS_WIN
796 769
797 #if defined(OS_MACOSX) && !defined(OS_IOS) 770 #if defined(OS_MACOSX)
798 autorelease_pool_.reset(NULL); 771 autorelease_pool_.reset(NULL);
799 #endif 772 #endif
800 773
801 exit_manager_.reset(NULL); 774 exit_manager_.reset(NULL);
802 775
803 delegate_ = NULL; 776 delegate_ = NULL;
804 is_shutdown_ = true; 777 is_shutdown_ = true;
805 } 778 }
806 779
807 private: 780 private:
(...skipping 23 matching lines...) Expand all
831 804
832 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 805 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
833 }; 806 };
834 807
835 // static 808 // static
836 ContentMainRunner* ContentMainRunner::Create() { 809 ContentMainRunner* ContentMainRunner::Create() {
837 return new ContentMainRunnerImpl(); 810 return new ContentMainRunnerImpl();
838 } 811 }
839 812
840 } // namespace content 813 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/browser_child_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698