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

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

Issue 10907062: Minimal number of if-def changes to support OS_IOS in content_main_runner.cc (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 8 years, 3 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 | no next file » | 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 <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
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
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
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 339 }
336 340
337 if (delegate) 341 if (delegate)
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
349 #if !defined(OS_IOS)
345 // Run the FooMain() for a given process type. 350 // Run the FooMain() for a given process type.
346 // If |process_type| is empty, runs BrowserMain(). 351 // If |process_type| is empty, runs BrowserMain().
347 // Returns the exit code for this process. 352 // Returns the exit code for this process.
348 int RunNamedProcessTypeMain( 353 int RunNamedProcessTypeMain(
349 const std::string& process_type, 354 const std::string& process_type,
350 const MainFunctionParams& main_function_params, 355 const MainFunctionParams& main_function_params,
351 ContentMainDelegate* delegate) { 356 ContentMainDelegate* delegate) {
352 static const MainFunction kMainFunctions[] = { 357 static const MainFunction kMainFunctions[] = {
353 { "", BrowserMain }, 358 { "", BrowserMain },
354 { switches::kRendererProcess, RendererMain }, 359 { switches::kRendererProcess, RendererMain },
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 return RunZygote(main_function_params, delegate); 392 return RunZygote(main_function_params, delegate);
388 #endif 393 #endif
389 394
390 // If it's a process we don't know about, the embedder should know. 395 // If it's a process we don't know about, the embedder should know.
391 if (delegate) 396 if (delegate)
392 return delegate->RunProcess(process_type, main_function_params); 397 return delegate->RunProcess(process_type, main_function_params);
393 398
394 NOTREACHED() << "Unknown process type: " << process_type; 399 NOTREACHED() << "Unknown process type: " << process_type;
395 return 1; 400 return 1;
396 } 401 }
402 #endif // !OS_IOS
397 403
398 class ContentMainRunnerImpl : public ContentMainRunner { 404 class ContentMainRunnerImpl : public ContentMainRunner {
399 public: 405 public:
400 ContentMainRunnerImpl() 406 ContentMainRunnerImpl()
401 : is_initialized_(false), 407 : is_initialized_(false),
402 is_shutdown_(false), 408 is_shutdown_(false),
403 completed_basic_startup_(false), 409 completed_basic_startup_(false),
404 delegate_(NULL) { 410 delegate_(NULL) {
405 #if defined(OS_WIN) 411 #if defined(OS_WIN)
406 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); 412 memset(&sandbox_info_, 0, sizeof(sandbox_info_));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); 471 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
466 } 472 }
467 #endif 473 #endif
468 474
469 // On Android, 475 // On Android,
470 // - setlocale() is not supported. 476 // - setlocale() is not supported.
471 // - We do not override the signal handlers so that we can get 477 // - We do not override the signal handlers so that we can get
472 // stack trace when crashing. 478 // stack trace when crashing.
473 // - The ipc_fd is passed through the Java service. 479 // - The ipc_fd is passed through the Java service.
474 // Thus, these are all disabled. 480 // Thus, these are all disabled.
475 #if !defined(OS_ANDROID) 481 #if !defined(OS_ANDROID) && !defined(OS_IOS)
476 // Set C library locale to make sure CommandLine can parse argument values 482 // Set C library locale to make sure CommandLine can parse argument values
477 // in correct encoding. 483 // in correct encoding.
478 setlocale(LC_ALL, ""); 484 setlocale(LC_ALL, "");
479 485
480 SetupSignalHandlers(); 486 SetupSignalHandlers();
481 487
482 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); 488 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
483 g_fds->Set(kPrimaryIPCChannel, 489 g_fds->Set(kPrimaryIPCChannel,
484 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 490 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
485 #endif 491
492 // The exit manager is in charge of calling the dtors of singleton objects.
493 // On Android, AtExitManager is set up when library is loaded.
494 // On iOS, it's set up in main(), which can't call directly through to here.
495 exit_manager_.reset(new base::AtExitManager);
496
497 #endif // !OS_ANDROID && !OS_IOS
486 498
487 #if defined(OS_LINUX) || defined(OS_OPENBSD) 499 #if defined(OS_LINUX) || defined(OS_OPENBSD)
488 g_fds->Set(kCrashDumpSignal, 500 g_fds->Set(kCrashDumpSignal,
489 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); 501 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
490 #endif 502 #endif
491 503
492 #endif // !OS_WIN 504 #endif // !OS_WIN
493 505
494 is_initialized_ = true; 506 is_initialized_ = true;
495 delegate_ = delegate; 507 delegate_ = delegate;
496 508
497 base::EnableTerminationOnHeapCorruption(); 509 base::EnableTerminationOnHeapCorruption();
498 base::EnableTerminationOnOutOfMemory(); 510 base::EnableTerminationOnOutOfMemory();
499 511
500 // On Android, AtExitManager is set up when library is loaded.
501 #if !defined(OS_ANDROID)
502 // The exit manager is in charge of calling the dtors of singleton objects.
503 exit_manager_.reset(new base::AtExitManager);
504 #endif
505
506 #if defined(OS_MACOSX) 512 #if defined(OS_MACOSX)
507 // We need this pool for all the objects created before we get to the 513 // 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 514 // 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 515 // 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. 516 // its main event loop to get rid of the cruft.
511 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 517 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
512 #endif 518 #endif
513 519
514 // On Android, the command line is initialized when library is loaded. 520 // On Android, the command line is initialized when library is loaded.
515 #if !defined(OS_ANDROID) 521 #if !defined(OS_ANDROID)
(...skipping 20 matching lines...) Expand all
536 base::RouteStdioToConsole(); 542 base::RouteStdioToConsole();
537 #endif 543 #endif
538 544
539 // Enable startup tracing asap to avoid early TRACE_EVENT calls being 545 // Enable startup tracing asap to avoid early TRACE_EVENT calls being
540 // ignored. 546 // ignored.
541 if (command_line.HasSwitch(switches::kTraceStartup)) { 547 if (command_line.HasSwitch(switches::kTraceStartup)) {
542 base::debug::TraceLog::GetInstance()->SetEnabled( 548 base::debug::TraceLog::GetInstance()->SetEnabled(
543 command_line.GetSwitchValueASCII(switches::kTraceStartup)); 549 command_line.GetSwitchValueASCII(switches::kTraceStartup));
544 } 550 }
545 551
546 #if defined(OS_MACOSX) 552 #if defined(OS_MACOSX) && !defined(OS_IOS)
547 // We need to allocate the IO Ports before the Sandbox is initialized or 553 // We need to allocate the IO Ports before the Sandbox is initialized or
548 // the first instance of SystemMonitor is created. 554 // the first instance of SystemMonitor is created.
549 // It's important not to allocate the ports for processes which don't 555 // It's important not to allocate the ports for processes which don't
550 // register with the system monitor - see crbug.com/88867. 556 // register with the system monitor - see crbug.com/88867.
551 if (process_type.empty() || 557 if (process_type.empty() ||
552 process_type == switches::kPluginProcess || 558 process_type == switches::kPluginProcess ||
553 process_type == switches::kRendererProcess || 559 process_type == switches::kRendererProcess ||
554 process_type == switches::kUtilityProcess || 560 process_type == switches::kUtilityProcess ||
555 process_type == switches::kWorkerProcess || 561 process_type == switches::kWorkerProcess ||
556 (delegate && 562 (delegate &&
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 if (command_line.HasSwitch(switches::kUserAgent)) { 614 if (command_line.HasSwitch(switches::kUserAgent)) {
609 webkit_glue::SetUserAgent( 615 webkit_glue::SetUserAgent(
610 command_line.GetSwitchValueASCII(switches::kUserAgent), true); 616 command_line.GetSwitchValueASCII(switches::kUserAgent), true);
611 } 617 }
612 618
613 if (!process_type.empty()) 619 if (!process_type.empty())
614 CommonSubprocessInit(process_type); 620 CommonSubprocessInit(process_type);
615 621
616 #if defined(OS_WIN) 622 #if defined(OS_WIN)
617 CHECK(InitializeSandbox(sandbox_info)); 623 CHECK(InitializeSandbox(sandbox_info));
618 #elif defined(OS_MACOSX) 624 #elif defined(OS_MACOSX) && !defined(OS_IOS)
619 if (process_type == switches::kRendererProcess || 625 if (process_type == switches::kRendererProcess ||
620 process_type == switches::kPpapiPluginProcess || 626 process_type == switches::kPpapiPluginProcess ||
621 (delegate && delegate->DelaySandboxInitialization(process_type))) { 627 (delegate && delegate->DelaySandboxInitialization(process_type))) {
622 // On OS X the renderer sandbox needs to be initialized later in the 628 // On OS X the renderer sandbox needs to be initialized later in the
623 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). 629 // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
624 } else { 630 } else {
625 CHECK(InitializeSandbox()); 631 CHECK(InitializeSandbox());
626 } 632 }
627 #endif 633 #endif
628 634
629 if (delegate) 635 if (delegate)
630 delegate->SandboxInitialized(process_type); 636 delegate->SandboxInitialized(process_type);
631 637
632 #if defined(OS_POSIX) 638 #if defined(OS_POSIX) && !defined(OS_IOS)
633 SetProcessTitleFromCommandLine(argv); 639 SetProcessTitleFromCommandLine(argv);
634 #endif 640 #endif
635 641
636 // Return -1 to indicate no early termination. 642 // Return -1 to indicate no early termination.
637 return -1; 643 return -1;
638 } 644 }
639 645
640 virtual int Run() OVERRIDE { 646 virtual int Run() OVERRIDE {
641 DCHECK(is_initialized_); 647 DCHECK(is_initialized_);
642 DCHECK(!is_shutdown_); 648 DCHECK(!is_shutdown_);
643 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 649 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
644 std::string process_type = 650 std::string process_type =
645 command_line.GetSwitchValueASCII(switches::kProcessType); 651 command_line.GetSwitchValueASCII(switches::kProcessType);
646 652
647 MainFunctionParams main_params(command_line); 653 MainFunctionParams main_params(command_line);
648 #if defined(OS_WIN) 654 #if defined(OS_WIN)
649 main_params.sandbox_info = &sandbox_info_; 655 main_params.sandbox_info = &sandbox_info_;
650 #elif defined(OS_MACOSX) 656 #elif defined(OS_MACOSX)
651 main_params.autorelease_pool = autorelease_pool_.get(); 657 main_params.autorelease_pool = autorelease_pool_.get();
652 #endif 658 #endif
653 659
660 #if !defined(OS_IOS)
654 return RunNamedProcessTypeMain(process_type, main_params, delegate_); 661 return RunNamedProcessTypeMain(process_type, main_params, delegate_);
662 #else
663 return 1;
664 #endif
655 } 665 }
656 666
657 virtual void Shutdown() OVERRIDE { 667 virtual void Shutdown() OVERRIDE {
658 DCHECK(is_initialized_); 668 DCHECK(is_initialized_);
659 DCHECK(!is_shutdown_); 669 DCHECK(!is_shutdown_);
660 670
661 if (completed_basic_startup_ && delegate_) { 671 if (completed_basic_startup_ && delegate_) {
662 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 672 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
663 std::string process_type = 673 std::string process_type =
664 command_line.GetSwitchValueASCII(switches::kProcessType); 674 command_line.GetSwitchValueASCII(switches::kProcessType);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 719
710 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 720 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
711 }; 721 };
712 722
713 // static 723 // static
714 ContentMainRunner* ContentMainRunner::Create() { 724 ContentMainRunner* ContentMainRunner::Create() {
715 return new ContentMainRunnerImpl(); 725 return new ContentMainRunnerImpl();
716 } 726 }
717 727
718 } // namespace content 728 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698