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/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | 50 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
51 #endif | 51 #endif |
52 | 52 |
53 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
54 #include <cstring> | 54 #include <cstring> |
55 #include <atlbase.h> | 55 #include <atlbase.h> |
56 #include <atlapp.h> | 56 #include <atlapp.h> |
57 #include <malloc.h> | 57 #include <malloc.h> |
58 #elif defined(OS_MACOSX) | 58 #elif defined(OS_MACOSX) |
59 #include "base/mac/scoped_nsautorelease_pool.h" | 59 #include "base/mac/scoped_nsautorelease_pool.h" |
60 #if !defined(OS_IOS) | |
60 #include "base/mach_ipc_mac.h" | 61 #include "base/mach_ipc_mac.h" |
61 #include "base/system_monitor/system_monitor.h" | 62 #include "base/system_monitor/system_monitor.h" |
62 #include "content/browser/mach_broker_mac.h" | 63 #include "content/browser/mach_broker_mac.h" |
63 #include "content/common/sandbox_init_mac.h" | 64 #include "content/common/sandbox_init_mac.h" |
65 #endif // !OS_IOS | |
64 #endif // OS_WIN | 66 #endif // OS_WIN |
65 | 67 |
66 #if defined(OS_POSIX) | 68 #if defined(OS_POSIX) |
67 #include <signal.h> | 69 #include <signal.h> |
68 | 70 |
69 #include "base/global_descriptors_posix.h" | 71 #include "base/global_descriptors_posix.h" |
70 #include "content/public/common/content_descriptors.h" | 72 #include "content/public/common/content_descriptors.h" |
71 | 73 |
72 #if !defined(OS_MACOSX) | 74 #if !defined(OS_MACOSX) |
73 #include "content/public/common/zygote_fork_delegate_linux.h" | 75 #include "content/public/common/zygote_fork_delegate_linux.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
103 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; | 105 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; |
104 base::LazyInstance<ContentRendererClient> | 106 base::LazyInstance<ContentRendererClient> |
105 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 107 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
106 base::LazyInstance<ContentUtilityClient> | 108 base::LazyInstance<ContentUtilityClient> |
107 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 109 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
108 | 110 |
109 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
110 | 112 |
111 static CAppModule _Module; | 113 static CAppModule _Module; |
112 | 114 |
113 #elif defined(OS_MACOSX) | 115 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
114 | 116 |
115 // Completes the Mach IPC handshake by sending this process' task port to the | 117 // Completes the Mach IPC handshake by sending this process' task port to the |
116 // parent process. The parent is listening on the Mach port given by | 118 // parent process. The parent is listening on the Mach port given by |
117 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory | 119 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory |
118 // stats to display in the task manager. | 120 // stats to display in the task manager. |
119 void SendTaskPortToParentProcess() { | 121 void SendTaskPortToParentProcess() { |
120 const mach_msg_timeout_t kTimeoutMs = 100; | 122 const mach_msg_timeout_t kTimeoutMs = 100; |
121 const int32_t kMessageId = 0; | 123 const int32_t kMessageId = 0; |
122 std::string mach_port_name = MachBroker::GetMachPortName(); | 124 std::string mach_port_name = MachBroker::GetMachPortName(); |
123 | 125 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 // when presenting them to the user), reset the locale for numeric | 182 // when presenting them to the user), reset the locale for numeric |
181 // formatting. | 183 // formatting. |
182 // Note that this is not correct for plugin processes -- they can | 184 // Note that this is not correct for plugin processes -- they can |
183 // surface UI -- but it's likely they get this wrong too so why not. | 185 // surface UI -- but it's likely they get this wrong too so why not. |
184 setlocale(LC_NUMERIC, "C"); | 186 setlocale(LC_NUMERIC, "C"); |
185 #endif | 187 #endif |
186 } | 188 } |
187 | 189 |
188 static base::ProcessId GetBrowserPid(const CommandLine& command_line) { | 190 static base::ProcessId GetBrowserPid(const CommandLine& command_line) { |
189 base::ProcessId browser_pid = base::GetCurrentProcId(); | 191 base::ProcessId browser_pid = base::GetCurrentProcId(); |
192 #if !defined(OS_IOS) | |
190 if (command_line.HasSwitch(switches::kProcessChannelID)) { | 193 if (command_line.HasSwitch(switches::kProcessChannelID)) { |
191 #if defined(OS_WIN) || defined(OS_MACOSX) | 194 #if defined(OS_WIN) || defined(OS_MACOSX) |
192 std::string channel_name = | 195 std::string channel_name = |
193 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 196 command_line.GetSwitchValueASCII(switches::kProcessChannelID); |
194 | 197 |
195 int browser_pid_int; | 198 int browser_pid_int; |
196 base::StringToInt(channel_name, &browser_pid_int); | 199 base::StringToInt(channel_name, &browser_pid_int); |
197 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | 200 browser_pid = static_cast<base::ProcessId>(browser_pid_int); |
198 DCHECK_NE(browser_pid_int, 0); | 201 DCHECK_NE(browser_pid_int, 0); |
199 #elif defined(OS_ANDROID) | 202 #elif defined(OS_ANDROID) |
200 // On Android, the browser process isn't the parent. A bunch | 203 // On Android, the browser process isn't the parent. A bunch |
201 // of work will be required before callers of this routine will | 204 // of work will be required before callers of this routine will |
202 // get what they want. | 205 // get what they want. |
203 // | 206 // |
204 // Note: On Linux, base::GetParentProcessId() is defined in | 207 // Note: On Linux, base::GetParentProcessId() is defined in |
205 // process_util_linux.cc. Note that *_linux.cc is excluded from | 208 // process_util_linux.cc. Note that *_linux.cc is excluded from |
206 // Android builds but a special exception is made in base.gypi | 209 // Android builds but a special exception is made in base.gypi |
207 // for a few files including process_util_linux.cc. | 210 // for a few files including process_util_linux.cc. |
208 LOG(ERROR) << "GetBrowserPid() not implemented for Android()."; | 211 LOG(ERROR) << "GetBrowserPid() not implemented for Android()."; |
209 #elif defined(OS_POSIX) | 212 #elif defined(OS_POSIX) |
210 // On linux, we're in a process forked from the zygote here; so we need the | 213 // On linux, we're in a process forked from the zygote here; so we need the |
211 // parent's parent process' id. | 214 // parent's parent process' id. |
212 browser_pid = | 215 browser_pid = |
213 base::GetParentProcessId( | 216 base::GetParentProcessId( |
214 base::GetParentProcessId(base::GetCurrentProcId())); | 217 base::GetParentProcessId(base::GetCurrentProcId())); |
215 #endif | 218 #endif |
216 } | 219 } |
220 #endif // !OS_IOS | |
217 return browser_pid; | 221 return browser_pid; |
218 } | 222 } |
219 | 223 |
220 static void InitializeStatsTable(const CommandLine& command_line) { | 224 static void InitializeStatsTable(const CommandLine& command_line) { |
221 // Initialize the Stats Counters table. With this initialized, | 225 // Initialize the Stats Counters table. With this initialized, |
222 // the StatsViewer can be utilized to read counters outside of | 226 // the StatsViewer can be utilized to read counters outside of |
223 // Chrome. These lines can be commented out to effectively turn | 227 // Chrome. These lines can be commented out to effectively turn |
224 // counters 'off'. The table is created and exists for the life | 228 // counters 'off'. The table is created and exists for the life |
225 // of the process. It is not cleaned up. | 229 // of the process. It is not cleaned up. |
226 if (command_line.HasSwitch(switches::kEnableStatsTable)) { | 230 if (command_line.HasSwitch(switches::kEnableStatsTable)) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 return delegate->RunProcess(process_type, main_params); | 342 return delegate->RunProcess(process_type, main_params); |
339 | 343 |
340 NOTREACHED() << "Unknown zygote process type: " << process_type; | 344 NOTREACHED() << "Unknown zygote process type: " << process_type; |
341 return 1; | 345 return 1; |
342 } | 346 } |
343 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 347 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
344 | 348 |
345 // Run the FooMain() for a given process type. | 349 // Run the FooMain() for a given process type. |
346 // If |process_type| is empty, runs BrowserMain(). | 350 // If |process_type| is empty, runs BrowserMain(). |
347 // Returns the exit code for this process. | 351 // Returns the exit code for this process. |
348 int RunNamedProcessTypeMain( | 352 int RunNamedProcessTypeMain( |
jam
2012/09/04 19:38:49
nit: i would just put this whole method behind an
leng
2012/09/05 11:57:10
Done.
| |
349 const std::string& process_type, | 353 const std::string& process_type, |
350 const MainFunctionParams& main_function_params, | 354 const MainFunctionParams& main_function_params, |
351 ContentMainDelegate* delegate) { | 355 ContentMainDelegate* delegate) { |
356 #if defined(OS_IOS) | |
357 // None of the *Main processes exist on iOS. | |
358 NOTREACHED(); | |
359 #else | |
352 static const MainFunction kMainFunctions[] = { | 360 static const MainFunction kMainFunctions[] = { |
353 { "", BrowserMain }, | 361 { "", BrowserMain }, |
354 { switches::kRendererProcess, RendererMain }, | 362 { switches::kRendererProcess, RendererMain }, |
355 { switches::kPluginProcess, PluginMain }, | 363 { switches::kPluginProcess, PluginMain }, |
356 { switches::kWorkerProcess, WorkerMain }, | 364 { switches::kWorkerProcess, WorkerMain }, |
357 { switches::kPpapiPluginProcess, PpapiPluginMain }, | 365 { switches::kPpapiPluginProcess, PpapiPluginMain }, |
358 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, | 366 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, |
359 { switches::kUtilityProcess, UtilityMain }, | 367 { switches::kUtilityProcess, UtilityMain }, |
360 { switches::kGpuProcess, GpuMain }, | 368 { switches::kGpuProcess, GpuMain }, |
361 }; | 369 }; |
(...skipping 23 matching lines...) Expand all Loading... | |
385 // for why we don't use ZygoteMain directly. | 393 // for why we don't use ZygoteMain directly. |
386 if (process_type == switches::kZygoteProcess) | 394 if (process_type == switches::kZygoteProcess) |
387 return RunZygote(main_function_params, delegate); | 395 return RunZygote(main_function_params, delegate); |
388 #endif | 396 #endif |
389 | 397 |
390 // 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. |
391 if (delegate) | 399 if (delegate) |
392 return delegate->RunProcess(process_type, main_function_params); | 400 return delegate->RunProcess(process_type, main_function_params); |
393 | 401 |
394 NOTREACHED() << "Unknown process type: " << process_type; | 402 NOTREACHED() << "Unknown process type: " << process_type; |
403 #endif // !OS_IOS | |
395 return 1; | 404 return 1; |
396 } | 405 } |
397 | 406 |
398 class ContentMainRunnerImpl : public ContentMainRunner { | 407 class ContentMainRunnerImpl : public ContentMainRunner { |
399 public: | 408 public: |
400 ContentMainRunnerImpl() | 409 ContentMainRunnerImpl() |
401 : is_initialized_(false), | 410 : is_initialized_(false), |
402 is_shutdown_(false), | 411 is_shutdown_(false), |
403 completed_basic_startup_(false), | 412 completed_basic_startup_(false), |
404 delegate_(NULL) { | 413 delegate_(NULL) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 477 |
469 // On Android, | 478 // On Android, |
470 // - setlocale() is not supported. | 479 // - setlocale() is not supported. |
471 // - We do not override the signal handlers so that we can get | 480 // - We do not override the signal handlers so that we can get |
472 // stack trace when crashing. | 481 // stack trace when crashing. |
473 // - The ipc_fd is passed through the Java service. | 482 // - The ipc_fd is passed through the Java service. |
474 // Thus, these are all disabled. | 483 // Thus, these are all disabled. |
475 #if !defined(OS_ANDROID) | 484 #if !defined(OS_ANDROID) |
476 // Set C library locale to make sure CommandLine can parse argument values | 485 // Set C library locale to make sure CommandLine can parse argument values |
477 // in correct encoding. | 486 // in correct encoding. |
478 setlocale(LC_ALL, ""); | 487 setlocale(LC_ALL, ""); |
jam
2012/09/04 19:38:49
do you really need this on ios? if not, then just
leng
2012/09/05 11:57:10
All our tests passed without it.
Done.
| |
479 | 488 |
489 #if !defined(OS_IOS) | |
480 SetupSignalHandlers(); | 490 SetupSignalHandlers(); |
481 | 491 |
482 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 492 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
483 g_fds->Set(kPrimaryIPCChannel, | 493 g_fds->Set(kPrimaryIPCChannel, |
484 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 494 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
485 #endif | 495 #endif // !OS_IOS |
496 #endif // !OS_ANDROID | |
486 | 497 |
487 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 498 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
488 g_fds->Set(kCrashDumpSignal, | 499 g_fds->Set(kCrashDumpSignal, |
489 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 500 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); |
490 #endif | 501 #endif |
491 | 502 |
492 #endif // !OS_WIN | 503 #endif // !OS_WIN |
493 | 504 |
494 is_initialized_ = true; | 505 is_initialized_ = true; |
495 delegate_ = delegate; | 506 delegate_ = delegate; |
496 | 507 |
497 base::EnableTerminationOnHeapCorruption(); | 508 base::EnableTerminationOnHeapCorruption(); |
498 base::EnableTerminationOnOutOfMemory(); | 509 base::EnableTerminationOnOutOfMemory(); |
499 | 510 |
500 // On Android, AtExitManager is set up when library is loaded. | 511 // On Android, AtExitManager is set up when library is loaded. |
501 #if !defined(OS_ANDROID) | 512 // On iOS, it's set up in main(), which can't call directly through to here. |
513 #if !defined(OS_ANDROID) && !defined(OS_IOS) | |
jam
2012/09/04 19:38:49
i would then combined this with the ifdef at 484 (
leng
2012/09/05 11:57:10
Done.
| |
502 // The exit manager is in charge of calling the dtors of singleton objects. | 514 // The exit manager is in charge of calling the dtors of singleton objects. |
503 exit_manager_.reset(new base::AtExitManager); | 515 exit_manager_.reset(new base::AtExitManager); |
504 #endif | 516 #endif |
505 | 517 |
506 #if defined(OS_MACOSX) | 518 #if defined(OS_MACOSX) |
507 // We need this pool for all the objects created before we get to the | 519 // We need this pool for all the objects created before we get to the |
508 // event loop, but we don't want to leave them hanging around until the | 520 // event loop, but we don't want to leave them hanging around until the |
509 // app quits. Each "main" needs to flush this pool right before it goes into | 521 // app quits. Each "main" needs to flush this pool right before it goes into |
510 // its main event loop to get rid of the cruft. | 522 // its main event loop to get rid of the cruft. |
511 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 523 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
(...skipping 24 matching lines...) Expand all Loading... | |
536 base::RouteStdioToConsole(); | 548 base::RouteStdioToConsole(); |
537 #endif | 549 #endif |
538 | 550 |
539 // Enable startup tracing asap to avoid early TRACE_EVENT calls being | 551 // Enable startup tracing asap to avoid early TRACE_EVENT calls being |
540 // ignored. | 552 // ignored. |
541 if (command_line.HasSwitch(switches::kTraceStartup)) { | 553 if (command_line.HasSwitch(switches::kTraceStartup)) { |
542 base::debug::TraceLog::GetInstance()->SetEnabled( | 554 base::debug::TraceLog::GetInstance()->SetEnabled( |
543 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | 555 command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
544 } | 556 } |
545 | 557 |
546 #if defined(OS_MACOSX) | 558 #if defined(OS_MACOSX) && !defined(OS_IOS) |
547 // We need to allocate the IO Ports before the Sandbox is initialized or | 559 // We need to allocate the IO Ports before the Sandbox is initialized or |
548 // the first instance of SystemMonitor is created. | 560 // the first instance of SystemMonitor is created. |
549 // It's important not to allocate the ports for processes which don't | 561 // It's important not to allocate the ports for processes which don't |
550 // register with the system monitor - see crbug.com/88867. | 562 // register with the system monitor - see crbug.com/88867. |
551 if (process_type.empty() || | 563 if (process_type.empty() || |
552 process_type == switches::kPluginProcess || | 564 process_type == switches::kPluginProcess || |
553 process_type == switches::kRendererProcess || | 565 process_type == switches::kRendererProcess || |
554 process_type == switches::kUtilityProcess || | 566 process_type == switches::kUtilityProcess || |
555 process_type == switches::kWorkerProcess || | 567 process_type == switches::kWorkerProcess || |
556 (delegate && | 568 (delegate && |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 if (command_line.HasSwitch(switches::kUserAgent)) { | 620 if (command_line.HasSwitch(switches::kUserAgent)) { |
609 webkit_glue::SetUserAgent( | 621 webkit_glue::SetUserAgent( |
610 command_line.GetSwitchValueASCII(switches::kUserAgent), true); | 622 command_line.GetSwitchValueASCII(switches::kUserAgent), true); |
611 } | 623 } |
612 | 624 |
613 if (!process_type.empty()) | 625 if (!process_type.empty()) |
614 CommonSubprocessInit(process_type); | 626 CommonSubprocessInit(process_type); |
615 | 627 |
616 #if defined(OS_WIN) | 628 #if defined(OS_WIN) |
617 CHECK(InitializeSandbox(sandbox_info)); | 629 CHECK(InitializeSandbox(sandbox_info)); |
618 #elif defined(OS_MACOSX) | 630 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
619 if (process_type == switches::kRendererProcess || | 631 if (process_type == switches::kRendererProcess || |
620 process_type == switches::kPpapiPluginProcess || | 632 process_type == switches::kPpapiPluginProcess || |
621 (delegate && delegate->DelaySandboxInitialization(process_type))) { | 633 (delegate && delegate->DelaySandboxInitialization(process_type))) { |
622 // On OS X the renderer sandbox needs to be initialized later in the | 634 // On OS X the renderer sandbox needs to be initialized later in the |
623 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). | 635 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). |
624 } else { | 636 } else { |
625 CHECK(InitializeSandbox()); | 637 CHECK(InitializeSandbox()); |
626 } | 638 } |
627 #endif | 639 #endif |
628 | 640 |
629 if (delegate) | 641 if (delegate) |
630 delegate->SandboxInitialized(process_type); | 642 delegate->SandboxInitialized(process_type); |
631 | 643 |
632 #if defined(OS_POSIX) | 644 #if defined(OS_POSIX) && !defined(OS_IOS) |
633 SetProcessTitleFromCommandLine(argv); | 645 SetProcessTitleFromCommandLine(argv); |
634 #endif | 646 #endif |
635 | 647 |
636 // Return -1 to indicate no early termination. | 648 // Return -1 to indicate no early termination. |
637 return -1; | 649 return -1; |
638 } | 650 } |
639 | 651 |
640 virtual int Run() OVERRIDE { | 652 virtual int Run() OVERRIDE { |
641 DCHECK(is_initialized_); | 653 DCHECK(is_initialized_); |
642 DCHECK(!is_shutdown_); | 654 DCHECK(!is_shutdown_); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 | 721 |
710 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 722 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
711 }; | 723 }; |
712 | 724 |
713 // static | 725 // static |
714 ContentMainRunner* ContentMainRunner::Create() { | 726 ContentMainRunner* ContentMainRunner::Create() { |
715 return new ContentMainRunnerImpl(); | 727 return new ContentMainRunnerImpl(); |
716 } | 728 } |
717 | 729 |
718 } // namespace content | 730 } // namespace content |
OLD | NEW |