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

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: fix 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 24 matching lines...) Expand all
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 131 #endif // !CHROME_MULTIPLE_DLL_CHILD
137 132
138 #if !defined(OS_IOS) && !defined(CHROME_MULTIPLE_DLL_BROWSER) 133 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
139 base::LazyInstance<ContentGpuClient> 134 base::LazyInstance<ContentGpuClient>
140 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; 135 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER;
141 base::LazyInstance<ContentPluginClient> 136 base::LazyInstance<ContentPluginClient>
142 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; 137 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER;
143 base::LazyInstance<ContentRendererClient> 138 base::LazyInstance<ContentRendererClient>
144 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; 139 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
145 base::LazyInstance<ContentUtilityClient> 140 base::LazyInstance<ContentUtilityClient>
146 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; 141 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER;
147 #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER 142 #endif // !CHROME_MULTIPLE_DLL_BROWSER
148 143
149 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) 144 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID)
150 #if defined __LP64__ 145 #if defined __LP64__
151 #define kV8NativesDataDescriptor kV8NativesDataDescriptor64 146 #define kV8NativesDataDescriptor kV8NativesDataDescriptor64
152 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 147 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64
153 #else 148 #else
154 #define kV8NativesDataDescriptor kV8NativesDataDescriptor32 149 #define kV8NativesDataDescriptor kV8NativesDataDescriptor32
155 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 150 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32
156 #endif 151 #endif
157 #endif 152 #endif
158 153
159 #if defined(OS_POSIX) && !defined(OS_IOS) 154 #if defined(OS_POSIX)
160 155
161 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. 156 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE.
162 void SetupSignalHandlers() { 157 void SetupSignalHandlers() {
163 // Sanitise our signal handling state. Signals that were ignored by our 158 // 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. 159 // parent will also be ignored by us. We also inherit our parent's sigmask.
165 sigset_t empty_signal_set; 160 sigset_t empty_signal_set;
166 CHECK_EQ(0, sigemptyset(&empty_signal_set)); 161 CHECK_EQ(0, sigemptyset(&empty_signal_set));
167 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); 162 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL));
168 163
169 struct sigaction sigact; 164 struct sigaction sigact;
170 memset(&sigact, 0, sizeof(sigact)); 165 memset(&sigact, 0, sizeof(sigact));
171 sigact.sa_handler = SIG_DFL; 166 sigact.sa_handler = SIG_DFL;
172 static const int signals_to_reset[] = 167 static const int signals_to_reset[] =
173 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, 168 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV,
174 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. 169 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below.
175 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { 170 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) {
176 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL)); 171 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL));
177 } 172 }
178 173
179 // Always ignore SIGPIPE. We check the return value of write(). 174 // Always ignore SIGPIPE. We check the return value of write().
180 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN)); 175 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN));
181 } 176 }
182 177
183 #endif // OS_POSIX && !OS_IOS 178 #endif // OS_POSIX
184 179
185 void CommonSubprocessInit(const std::string& process_type) { 180 void CommonSubprocessInit(const std::string& process_type) {
186 #if defined(OS_WIN) 181 #if defined(OS_WIN)
187 // HACK: Let Windows know that we have started. This is needed to suppress 182 // 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 183 // the IDC_APPSTARTING cursor from being displayed for a prolonged period
189 // while a subprocess is starting. 184 // while a subprocess is starting.
190 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); 185 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0);
191 MSG msg; 186 MSG msg;
192 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); 187 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
193 #endif 188 #endif
(...skipping 30 matching lines...) Expand all
224 ContentClient* content_client = GetContentClient(); 219 ContentClient* content_client = GetContentClient();
225 #if !defined(CHROME_MULTIPLE_DLL_CHILD) 220 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
226 if (process_type.empty()) { 221 if (process_type.empty()) {
227 if (delegate) 222 if (delegate)
228 content_client->browser_ = delegate->CreateContentBrowserClient(); 223 content_client->browser_ = delegate->CreateContentBrowserClient();
229 if (!content_client->browser_) 224 if (!content_client->browser_)
230 content_client->browser_ = &g_empty_content_browser_client.Get(); 225 content_client->browser_ = &g_empty_content_browser_client.Get();
231 } 226 }
232 #endif // !CHROME_MULTIPLE_DLL_CHILD 227 #endif // !CHROME_MULTIPLE_DLL_CHILD
233 228
234 #if !defined(OS_IOS) && !defined(CHROME_MULTIPLE_DLL_BROWSER) 229 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
235 if (process_type == switches::kGpuProcess || 230 if (process_type == switches::kGpuProcess ||
236 base::CommandLine::ForCurrentProcess()->HasSwitch( 231 base::CommandLine::ForCurrentProcess()->HasSwitch(
237 switches::kSingleProcess)) { 232 switches::kSingleProcess)) {
238 if (delegate) 233 if (delegate)
239 content_client->gpu_ = delegate->CreateContentGpuClient(); 234 content_client->gpu_ = delegate->CreateContentGpuClient();
240 if (!content_client->gpu_) 235 if (!content_client->gpu_)
241 content_client->gpu_ = &g_empty_content_gpu_client.Get(); 236 content_client->gpu_ = &g_empty_content_gpu_client.Get();
242 } 237 }
243 238
244 if (process_type == switches::kPluginProcess || 239 if (process_type == switches::kPluginProcess ||
(...skipping 14 matching lines...) Expand all
259 254
260 if (process_type == switches::kUtilityProcess || 255 if (process_type == switches::kUtilityProcess ||
261 base::CommandLine::ForCurrentProcess()->HasSwitch( 256 base::CommandLine::ForCurrentProcess()->HasSwitch(
262 switches::kSingleProcess)) { 257 switches::kSingleProcess)) {
263 if (delegate) 258 if (delegate)
264 content_client->utility_ = delegate->CreateContentUtilityClient(); 259 content_client->utility_ = delegate->CreateContentUtilityClient();
265 // TODO(scottmg): http://crbug.com/237249 Should be in _child. 260 // TODO(scottmg): http://crbug.com/237249 Should be in _child.
266 if (!content_client->utility_) 261 if (!content_client->utility_)
267 content_client->utility_ = &g_empty_content_utility_client.Get(); 262 content_client->utility_ = &g_empty_content_utility_client.Get();
268 } 263 }
269 #endif // !OS_IOS && !CHROME_MULTIPLE_DLL_BROWSER 264 #endif // !CHROME_MULTIPLE_DLL_BROWSER
270 } 265 }
271 }; 266 };
272 267
273 // We dispatch to a process-type-specific FooMain() based on a command-line 268 // 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. 269 // flag. This struct is used to build a table of (flag, main function) pairs.
275 struct MainFunction { 270 struct MainFunction {
276 const char* name; 271 const char* name;
277 int (*function)(const MainFunctionParams&); 272 int (*function)(const MainFunctionParams&);
278 }; 273 };
279 274
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 316 }
322 317
323 if (delegate) 318 if (delegate)
324 return delegate->RunProcess(process_type, main_params); 319 return delegate->RunProcess(process_type, main_params);
325 320
326 NOTREACHED() << "Unknown zygote process type: " << process_type; 321 NOTREACHED() << "Unknown zygote process type: " << process_type;
327 return 1; 322 return 1;
328 } 323 }
329 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 324 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
330 325
331 #if !defined(OS_IOS)
332 static void RegisterMainThreadFactories() { 326 static void RegisterMainThreadFactories() {
333 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) && !defined(CHROME_MULTIPLE_DLL_CHILD) 327 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) && !defined(CHROME_MULTIPLE_DLL_CHILD)
334 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( 328 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(
335 CreateInProcessUtilityThread); 329 CreateInProcessUtilityThread);
336 RenderProcessHostImpl::RegisterRendererMainThreadFactory( 330 RenderProcessHostImpl::RegisterRendererMainThreadFactory(
337 CreateInProcessRendererThread); 331 CreateInProcessRendererThread);
338 GpuProcessHost::RegisterGpuMainThreadFactory( 332 GpuProcessHost::RegisterGpuMainThreadFactory(
339 CreateInProcessGpuThread); 333 CreateInProcessGpuThread);
340 #else 334 #else
341 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); 335 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); 401 return RunZygote(main_function_params, delegate);
408 #endif 402 #endif
409 403
410 // If it's a process we don't know about, the embedder should know. 404 // If it's a process we don't know about, the embedder should know.
411 if (delegate) 405 if (delegate)
412 return delegate->RunProcess(process_type, main_function_params); 406 return delegate->RunProcess(process_type, main_function_params);
413 407
414 NOTREACHED() << "Unknown process type: " << process_type; 408 NOTREACHED() << "Unknown process type: " << process_type;
415 return 1; 409 return 1;
416 } 410 }
417 #endif // !OS_IOS
418 411
419 class ContentMainRunnerImpl : public ContentMainRunner { 412 class ContentMainRunnerImpl : public ContentMainRunner {
420 public: 413 public:
421 ContentMainRunnerImpl() 414 ContentMainRunnerImpl()
422 : is_initialized_(false), 415 : is_initialized_(false),
423 is_shutdown_(false), 416 is_shutdown_(false),
424 completed_basic_startup_(false), 417 completed_basic_startup_(false),
425 delegate_(NULL), 418 delegate_(NULL),
426 ui_task_(NULL) { 419 ui_task_(NULL) {
427 #if defined(OS_WIN) 420 #if defined(OS_WIN)
(...skipping 17 matching lines...) Expand all
445 sandbox_info_ = *params.sandbox_info; 438 sandbox_info_ = *params.sandbox_info;
446 #else // !OS_WIN 439 #else // !OS_WIN
447 440
448 #if defined(OS_ANDROID) 441 #if defined(OS_ANDROID)
449 // See note at the initialization of ExitManager, below; basically, 442 // See note at the initialization of ExitManager, below; basically,
450 // only Android builds have the ctor/dtor handlers set up to use 443 // only Android builds have the ctor/dtor handlers set up to use
451 // TRACE_EVENT right away. 444 // TRACE_EVENT right away.
452 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); 445 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
453 #endif // OS_ANDROID 446 #endif // OS_ANDROID
454 447
455 #if !defined(OS_IOS)
456 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); 448 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
457 #endif
458 449
459 // On Android, 450 // On Android,
460 // - setlocale() is not supported. 451 // - setlocale() is not supported.
461 // - We do not override the signal handlers so that we can get 452 // - We do not override the signal handlers so that we can get
462 // stack trace when crashing. 453 // stack trace when crashing.
463 // - The ipc_fd is passed through the Java service. 454 // - The ipc_fd is passed through the Java service.
464 // Thus, these are all disabled. 455 // Thus, these are all disabled.
465 #if !defined(OS_ANDROID) && !defined(OS_IOS) 456 #if !defined(OS_ANDROID)
466 // Set C library locale to make sure CommandLine can parse argument values 457 // Set C library locale to make sure CommandLine can parse argument values
467 // in correct encoding. 458 // in correct encoding.
468 setlocale(LC_ALL, ""); 459 setlocale(LC_ALL, "");
469 460
470 SetupSignalHandlers(); 461 SetupSignalHandlers();
471 g_fds->Set(kPrimaryIPCChannel, 462 g_fds->Set(kPrimaryIPCChannel,
472 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 463 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
473 g_fds->Set(kMojoIPCChannel, 464 g_fds->Set(kMojoIPCChannel,
474 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 465 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
475 #endif // !OS_ANDROID && !OS_IOS 466 #endif // !OS_ANDROID
476 467
477 #if defined(OS_LINUX) || defined(OS_OPENBSD) 468 #if defined(OS_LINUX) || defined(OS_OPENBSD)
478 g_fds->Set(kCrashDumpSignal, 469 g_fds->Set(kCrashDumpSignal,
479 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); 470 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
480 #endif // OS_LINUX || OS_OPENBSD 471 #endif // OS_LINUX || OS_OPENBSD
481 472
482 473
483 #endif // !OS_WIN 474 #endif // !OS_WIN
484 475
485 is_initialized_ = true; 476 is_initialized_ = true;
486 delegate_ = params.delegate; 477 delegate_ = params.delegate;
487 478
488 // The exit manager is in charge of calling the dtors of singleton objects. 479 // The exit manager is in charge of calling the dtors of singleton objects.
489 // On Android, AtExitManager is set up when library is loaded. 480 // 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 481 // 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. 482 // TRACE_EVENT methods on Linux or iOS builds till after we set this up.
493 #if !defined(OS_ANDROID) && !defined(OS_IOS) 483 #if !defined(OS_ANDROID)
494 if (!ui_task_) { 484 if (!ui_task_) {
495 // When running browser tests, don't create a second AtExitManager as that 485 // When running browser tests, don't create a second AtExitManager as that
496 // interfers with shutdown when objects created before ContentMain is 486 // interfers with shutdown when objects created before ContentMain is
497 // called are destructed when it returns. 487 // called are destructed when it returns.
498 exit_manager_.reset(new base::AtExitManager); 488 exit_manager_.reset(new base::AtExitManager);
499 } 489 }
500 #endif // !OS_ANDROID && !OS_IOS 490 #endif // !OS_ANDROID
501 491
502 // Don't create this loop on iOS, since the outer loop is already handled 492 #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 493 // 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 494 // 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 495 // 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. 496 // its main event loop to get rid of the cruft.
510 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 497 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
511 InitializeMac(); 498 InitializeMac();
512 #endif 499 #endif
513 500
514 // On Android, the command line is initialized when library is loaded and 501 // On Android, the command line is initialized when library is loaded and
515 // we have already started our TRACE_EVENT0. 502 // we have already started our TRACE_EVENT0.
(...skipping 11 matching lines...) Expand all
527 base::CommandLine::Init(argc, argv); 514 base::CommandLine::Init(argc, argv);
528 515
529 base::EnableTerminationOnHeapCorruption(); 516 base::EnableTerminationOnHeapCorruption();
530 517
531 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. 518 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
532 // Enable profiler recording right after command line is initialized so that 519 // Enable profiler recording right after command line is initialized so that
533 // browser startup can be instrumented. 520 // browser startup can be instrumented.
534 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) 521 if (delegate_ && delegate_->ShouldEnableProfilerRecording())
535 tracked_objects::ScopedTracker::Enable(); 522 tracked_objects::ScopedTracker::Enable();
536 523
537 #if !defined(OS_IOS)
538 SetProcessTitleFromCommandLine(argv); 524 SetProcessTitleFromCommandLine(argv);
539 #endif
540 #endif // !OS_ANDROID 525 #endif // !OS_ANDROID
541 526
542 int exit_code = 0; 527 int exit_code = 0;
543 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) 528 if (delegate_ && delegate_->BasicStartupComplete(&exit_code))
544 return exit_code; 529 return exit_code;
545 530
546 completed_basic_startup_ = true; 531 completed_basic_startup_ = true;
547 532
548 const base::CommandLine& command_line = 533 const base::CommandLine& command_line =
549 *base::CommandLine::ForCurrentProcess(); 534 *base::CommandLine::ForCurrentProcess();
550 std::string process_type = 535 std::string process_type =
551 command_line.GetSwitchValueASCII(switches::kProcessType); 536 command_line.GetSwitchValueASCII(switches::kProcessType);
552 537
553 #if !defined(OS_IOS)
554 // Initialize mojo here so that services can be registered. 538 // Initialize mojo here so that services can be registered.
555 InitializeMojo(); 539 InitializeMojo();
556 #endif
557 540
558 #if defined(OS_WIN) 541 #if defined(OS_WIN)
559 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) { 542 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) {
560 std::string scale_factor_string = command_line.GetSwitchValueASCII( 543 std::string scale_factor_string = command_line.GetSwitchValueASCII(
561 switches::kDeviceScaleFactor); 544 switches::kDeviceScaleFactor);
562 double scale_factor = 0; 545 double scale_factor = 0;
563 if (base::StringToDouble(scale_factor_string, &scale_factor)) 546 if (base::StringToDouble(scale_factor_string, &scale_factor))
564 gfx::SetDefaultDeviceScaleFactor(scale_factor); 547 gfx::SetDefaultDeviceScaleFactor(scale_factor);
565 } 548 }
566 #endif 549 #endif
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 base::trace_event::TraceEventETWExport::EnableETWExport(); 595 base::trace_event::TraceEventETWExport::EnableETWExport();
613 #endif // OS_WIN 596 #endif // OS_WIN
614 597
615 #if !defined(OS_ANDROID) 598 #if !defined(OS_ANDROID)
616 // Android tracing started at the beginning of the method. 599 // 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 600 // Other OSes have to wait till we get here in order for all the memory
618 // management setup to be completed. 601 // management setup to be completed.
619 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); 602 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
620 #endif // !OS_ANDROID 603 #endif // !OS_ANDROID
621 604
622 #if defined(OS_MACOSX) && !defined(OS_IOS) 605 #if defined(OS_MACOSX)
623 // We need to allocate the IO Ports before the Sandbox is initialized or 606 // We need to allocate the IO Ports before the Sandbox is initialized or
624 // the first instance of PowerMonitor is created. 607 // the first instance of PowerMonitor is created.
625 // It's important not to allocate the ports for processes which don't 608 // It's important not to allocate the ports for processes which don't
626 // register with the power monitor - see crbug.com/88867. 609 // register with the power monitor - see crbug.com/88867.
627 if (process_type.empty() || 610 if (process_type.empty() ||
628 (delegate_ && 611 (delegate_ &&
629 delegate_->ProcessRegistersWithSystemProcess(process_type))) { 612 delegate_->ProcessRegistersWithSystemProcess(process_type))) {
630 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); 613 base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
631 } 614 }
632 615
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 #endif // V8_USE_EXTERNAL_STARTUP_DATA 708 #endif // V8_USE_EXTERNAL_STARTUP_DATA
726 709
727 if (delegate_) 710 if (delegate_)
728 delegate_->PreSandboxStartup(); 711 delegate_->PreSandboxStartup();
729 712
730 if (!process_type.empty()) 713 if (!process_type.empty())
731 CommonSubprocessInit(process_type); 714 CommonSubprocessInit(process_type);
732 715
733 #if defined(OS_WIN) 716 #if defined(OS_WIN)
734 CHECK(InitializeSandbox(params.sandbox_info)); 717 CHECK(InitializeSandbox(params.sandbox_info));
735 #elif defined(OS_MACOSX) && !defined(OS_IOS) 718 #elif defined(OS_MACOSX)
736 if (process_type == switches::kRendererProcess || 719 if (process_type == switches::kRendererProcess ||
737 process_type == switches::kPpapiPluginProcess || 720 process_type == switches::kPpapiPluginProcess ||
738 (delegate_ && delegate_->DelaySandboxInitialization(process_type))) { 721 (delegate_ && delegate_->DelaySandboxInitialization(process_type))) {
739 // On OS X the renderer sandbox needs to be initialized later in the 722 // On OS X the renderer sandbox needs to be initialized later in the
740 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). 723 // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
741 } else { 724 } else {
742 CHECK(InitializeSandbox()); 725 CHECK(InitializeSandbox());
743 } 726 }
744 #endif 727 #endif
745 728
(...skipping 15 matching lines...) Expand all
761 base::HistogramBase::EnableActivityReportHistogram(process_type); 744 base::HistogramBase::EnableActivityReportHistogram(process_type);
762 745
763 MainFunctionParams main_params(command_line); 746 MainFunctionParams main_params(command_line);
764 main_params.ui_task = ui_task_; 747 main_params.ui_task = ui_task_;
765 #if defined(OS_WIN) 748 #if defined(OS_WIN)
766 main_params.sandbox_info = &sandbox_info_; 749 main_params.sandbox_info = &sandbox_info_;
767 #elif defined(OS_MACOSX) 750 #elif defined(OS_MACOSX)
768 main_params.autorelease_pool = autorelease_pool_.get(); 751 main_params.autorelease_pool = autorelease_pool_.get();
769 #endif 752 #endif
770 753
771 #if !defined(OS_IOS)
772 return RunNamedProcessTypeMain(process_type, main_params, delegate_); 754 return RunNamedProcessTypeMain(process_type, main_params, delegate_);
773 #else
774 return 1;
775 #endif
776 } 755 }
777 756
778 void Shutdown() override { 757 void Shutdown() override {
779 DCHECK(is_initialized_); 758 DCHECK(is_initialized_);
780 DCHECK(!is_shutdown_); 759 DCHECK(!is_shutdown_);
781 760
782 if (completed_basic_startup_ && delegate_) { 761 if (completed_basic_startup_ && delegate_) {
783 const base::CommandLine& command_line = 762 const base::CommandLine& command_line =
784 *base::CommandLine::ForCurrentProcess(); 763 *base::CommandLine::ForCurrentProcess();
785 std::string process_type = 764 std::string process_type =
786 command_line.GetSwitchValueASCII(switches::kProcessType); 765 command_line.GetSwitchValueASCII(switches::kProcessType);
787 766
788 delegate_->ProcessExiting(process_type); 767 delegate_->ProcessExiting(process_type);
789 } 768 }
790 769
791 #if defined(OS_WIN) 770 #if defined(OS_WIN)
792 #ifdef _CRTDBG_MAP_ALLOC 771 #ifdef _CRTDBG_MAP_ALLOC
793 _CrtDumpMemoryLeaks(); 772 _CrtDumpMemoryLeaks();
794 #endif // _CRTDBG_MAP_ALLOC 773 #endif // _CRTDBG_MAP_ALLOC
795 #endif // OS_WIN 774 #endif // OS_WIN
796 775
797 #if defined(OS_MACOSX) && !defined(OS_IOS) 776 #if defined(OS_MACOSX)
798 autorelease_pool_.reset(NULL); 777 autorelease_pool_.reset(NULL);
799 #endif 778 #endif
800 779
801 exit_manager_.reset(NULL); 780 exit_manager_.reset(NULL);
802 781
803 delegate_ = NULL; 782 delegate_ = NULL;
804 is_shutdown_ = true; 783 is_shutdown_ = true;
805 } 784 }
806 785
807 private: 786 private:
(...skipping 23 matching lines...) Expand all
831 810
832 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 811 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
833 }; 812 };
834 813
835 // static 814 // static
836 ContentMainRunner* ContentMainRunner::Create() { 815 ContentMainRunner* ContentMainRunner::Create() {
837 return new ContentMainRunnerImpl(); 816 return new ContentMainRunnerImpl();
838 } 817 }
839 818
840 } // namespace content 819 } // 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