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

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

Issue 10915227: 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" 51 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
52 #endif 52 #endif
53 53
54 #if defined(OS_WIN) 54 #if defined(OS_WIN)
55 #include <cstring> 55 #include <cstring>
56 #include <atlbase.h> 56 #include <atlbase.h>
57 #include <atlapp.h> 57 #include <atlapp.h>
58 #include <malloc.h> 58 #include <malloc.h>
59 #elif defined(OS_MACOSX) 59 #elif defined(OS_MACOSX)
60 #include "base/mac/scoped_nsautorelease_pool.h" 60 #include "base/mac/scoped_nsautorelease_pool.h"
61 #if !defined(OS_IOS)
61 #include "base/mach_ipc_mac.h" 62 #include "base/mach_ipc_mac.h"
62 #include "base/system_monitor/system_monitor.h" 63 #include "base/system_monitor/system_monitor.h"
63 #include "content/browser/mach_broker_mac.h" 64 #include "content/browser/mach_broker_mac.h"
64 #include "content/common/sandbox_init_mac.h" 65 #include "content/common/sandbox_init_mac.h"
66 #endif // !OS_IOS
65 #endif // OS_WIN 67 #endif // OS_WIN
66 68
67 #if defined(OS_POSIX) 69 #if defined(OS_POSIX)
68 #include <signal.h> 70 #include <signal.h>
69 71
70 #include "base/global_descriptors_posix.h" 72 #include "base/global_descriptors_posix.h"
71 #include "content/public/common/content_descriptors.h" 73 #include "content/public/common/content_descriptors.h"
72 74
73 #if !defined(OS_MACOSX) 75 #if !defined(OS_MACOSX)
74 #include "content/public/common/zygote_fork_delegate_linux.h" 76 #include "content/public/common/zygote_fork_delegate_linux.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; 158 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER;
157 base::LazyInstance<ContentRendererClient> 159 base::LazyInstance<ContentRendererClient>
158 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; 160 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
159 base::LazyInstance<ContentUtilityClient> 161 base::LazyInstance<ContentUtilityClient>
160 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; 162 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER;
161 163
162 #if defined(OS_WIN) 164 #if defined(OS_WIN)
163 165
164 static CAppModule _Module; 166 static CAppModule _Module;
165 167
166 #elif defined(OS_MACOSX) 168 #elif defined(OS_MACOSX) && !defined(OS_IOS)
167 169
168 // Completes the Mach IPC handshake by sending this process' task port to the 170 // Completes the Mach IPC handshake by sending this process' task port to the
169 // parent process. The parent is listening on the Mach port given by 171 // parent process. The parent is listening on the Mach port given by
170 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory 172 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory
171 // stats to display in the task manager. 173 // stats to display in the task manager.
172 void SendTaskPortToParentProcess() { 174 void SendTaskPortToParentProcess() {
173 const mach_msg_timeout_t kTimeoutMs = 100; 175 const mach_msg_timeout_t kTimeoutMs = 100;
174 const int32_t kMessageId = 0; 176 const int32_t kMessageId = 0;
175 std::string mach_port_name = MachBroker::GetMachPortName(); 177 std::string mach_port_name = MachBroker::GetMachPortName();
176 178
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // when presenting them to the user), reset the locale for numeric 235 // when presenting them to the user), reset the locale for numeric
234 // formatting. 236 // formatting.
235 // Note that this is not correct for plugin processes -- they can 237 // Note that this is not correct for plugin processes -- they can
236 // surface UI -- but it's likely they get this wrong too so why not. 238 // surface UI -- but it's likely they get this wrong too so why not.
237 setlocale(LC_NUMERIC, "C"); 239 setlocale(LC_NUMERIC, "C");
238 #endif 240 #endif
239 } 241 }
240 242
241 static base::ProcessId GetBrowserPid(const CommandLine& command_line) { 243 static base::ProcessId GetBrowserPid(const CommandLine& command_line) {
242 base::ProcessId browser_pid = base::GetCurrentProcId(); 244 base::ProcessId browser_pid = base::GetCurrentProcId();
245 #if !defined(OS_IOS)
243 if (command_line.HasSwitch(switches::kProcessChannelID)) { 246 if (command_line.HasSwitch(switches::kProcessChannelID)) {
244 #if defined(OS_WIN) || defined(OS_MACOSX) 247 #if defined(OS_WIN) || defined(OS_MACOSX)
245 std::string channel_name = 248 std::string channel_name =
246 command_line.GetSwitchValueASCII(switches::kProcessChannelID); 249 command_line.GetSwitchValueASCII(switches::kProcessChannelID);
247 250
248 int browser_pid_int; 251 int browser_pid_int;
249 base::StringToInt(channel_name, &browser_pid_int); 252 base::StringToInt(channel_name, &browser_pid_int);
250 browser_pid = static_cast<base::ProcessId>(browser_pid_int); 253 browser_pid = static_cast<base::ProcessId>(browser_pid_int);
251 DCHECK_NE(browser_pid_int, 0); 254 DCHECK_NE(browser_pid_int, 0);
252 #elif defined(OS_ANDROID) 255 #elif defined(OS_ANDROID)
253 // On Android, the browser process isn't the parent. A bunch 256 // On Android, the browser process isn't the parent. A bunch
254 // of work will be required before callers of this routine will 257 // of work will be required before callers of this routine will
255 // get what they want. 258 // get what they want.
256 // 259 //
257 // Note: On Linux, base::GetParentProcessId() is defined in 260 // Note: On Linux, base::GetParentProcessId() is defined in
258 // process_util_linux.cc. Note that *_linux.cc is excluded from 261 // process_util_linux.cc. Note that *_linux.cc is excluded from
259 // Android builds but a special exception is made in base.gypi 262 // Android builds but a special exception is made in base.gypi
260 // for a few files including process_util_linux.cc. 263 // for a few files including process_util_linux.cc.
261 LOG(ERROR) << "GetBrowserPid() not implemented for Android()."; 264 LOG(ERROR) << "GetBrowserPid() not implemented for Android().";
262 #elif defined(OS_POSIX) 265 #elif defined(OS_POSIX)
263 // On linux, we're in a process forked from the zygote here; so we need the 266 // On linux, we're in a process forked from the zygote here; so we need the
264 // parent's parent process' id. 267 // parent's parent process' id.
265 browser_pid = 268 browser_pid =
266 base::GetParentProcessId( 269 base::GetParentProcessId(
267 base::GetParentProcessId(base::GetCurrentProcId())); 270 base::GetParentProcessId(base::GetCurrentProcId()));
268 #endif 271 #endif
269 } 272 }
273 #endif // !OS_IOS
270 return browser_pid; 274 return browser_pid;
271 } 275 }
272 276
273 static void InitializeStatsTable(const CommandLine& command_line) { 277 static void InitializeStatsTable(const CommandLine& command_line) {
274 // Initialize the Stats Counters table. With this initialized, 278 // Initialize the Stats Counters table. With this initialized,
275 // the StatsViewer can be utilized to read counters outside of 279 // the StatsViewer can be utilized to read counters outside of
276 // Chrome. These lines can be commented out to effectively turn 280 // Chrome. These lines can be commented out to effectively turn
277 // counters 'off'. The table is created and exists for the life 281 // counters 'off'. The table is created and exists for the life
278 // of the process. It is not cleaned up. 282 // of the process. It is not cleaned up.
279 if (command_line.HasSwitch(switches::kEnableStatsTable)) { 283 if (command_line.HasSwitch(switches::kEnableStatsTable)) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 392 }
389 393
390 if (delegate) 394 if (delegate)
391 return delegate->RunProcess(process_type, main_params); 395 return delegate->RunProcess(process_type, main_params);
392 396
393 NOTREACHED() << "Unknown zygote process type: " << process_type; 397 NOTREACHED() << "Unknown zygote process type: " << process_type;
394 return 1; 398 return 1;
395 } 399 }
396 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 400 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
397 401
402 #if !defined(OS_IOS)
398 // Run the FooMain() for a given process type. 403 // Run the FooMain() for a given process type.
399 // If |process_type| is empty, runs BrowserMain(). 404 // If |process_type| is empty, runs BrowserMain().
400 // Returns the exit code for this process. 405 // Returns the exit code for this process.
401 int RunNamedProcessTypeMain( 406 int RunNamedProcessTypeMain(
402 const std::string& process_type, 407 const std::string& process_type,
403 const MainFunctionParams& main_function_params, 408 const MainFunctionParams& main_function_params,
404 ContentMainDelegate* delegate) { 409 ContentMainDelegate* delegate) {
405 static const MainFunction kMainFunctions[] = { 410 static const MainFunction kMainFunctions[] = {
406 { "", BrowserMain }, 411 { "", BrowserMain },
407 { switches::kRendererProcess, RendererMain }, 412 { switches::kRendererProcess, RendererMain },
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 return RunZygote(main_function_params, delegate); 445 return RunZygote(main_function_params, delegate);
441 #endif 446 #endif
442 447
443 // If it's a process we don't know about, the embedder should know. 448 // If it's a process we don't know about, the embedder should know.
444 if (delegate) 449 if (delegate)
445 return delegate->RunProcess(process_type, main_function_params); 450 return delegate->RunProcess(process_type, main_function_params);
446 451
447 NOTREACHED() << "Unknown process type: " << process_type; 452 NOTREACHED() << "Unknown process type: " << process_type;
448 return 1; 453 return 1;
449 } 454 }
455 #endif // !OS_IOS
450 456
451 class ContentMainRunnerImpl : public ContentMainRunner { 457 class ContentMainRunnerImpl : public ContentMainRunner {
452 public: 458 public:
453 ContentMainRunnerImpl() 459 ContentMainRunnerImpl()
454 : is_initialized_(false), 460 : is_initialized_(false),
455 is_shutdown_(false), 461 is_shutdown_(false),
456 completed_basic_startup_(false), 462 completed_basic_startup_(false),
457 delegate_(NULL) { 463 delegate_(NULL) {
458 #if defined(OS_WIN) 464 #if defined(OS_WIN)
459 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); 465 memset(&sandbox_info_, 0, sizeof(sandbox_info_));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); 524 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
519 } 525 }
520 #endif 526 #endif
521 527
522 // On Android, 528 // On Android,
523 // - setlocale() is not supported. 529 // - setlocale() is not supported.
524 // - We do not override the signal handlers so that we can get 530 // - We do not override the signal handlers so that we can get
525 // stack trace when crashing. 531 // stack trace when crashing.
526 // - The ipc_fd is passed through the Java service. 532 // - The ipc_fd is passed through the Java service.
527 // Thus, these are all disabled. 533 // Thus, these are all disabled.
528 #if !defined(OS_ANDROID) 534 #if !defined(OS_ANDROID) && !defined(OS_IOS)
529 // Set C library locale to make sure CommandLine can parse argument values 535 // Set C library locale to make sure CommandLine can parse argument values
530 // in correct encoding. 536 // in correct encoding.
531 setlocale(LC_ALL, ""); 537 setlocale(LC_ALL, "");
532 538
533 SetupSignalHandlers(); 539 SetupSignalHandlers();
534 540
535 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); 541 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
536 g_fds->Set(kPrimaryIPCChannel, 542 g_fds->Set(kPrimaryIPCChannel,
537 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 543 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
538 #endif 544 #endif // !OS_ANDROID && !OS_IOS
539 545
540 #if defined(OS_LINUX) || defined(OS_OPENBSD) 546 #if defined(OS_LINUX) || defined(OS_OPENBSD)
541 g_fds->Set(kCrashDumpSignal, 547 g_fds->Set(kCrashDumpSignal,
542 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); 548 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
543 #endif 549 #endif
544 550
545 #endif // !OS_WIN 551 #endif // !OS_WIN
546 552
547 is_initialized_ = true; 553 is_initialized_ = true;
548 delegate_ = delegate; 554 delegate_ = delegate;
549 555
550 base::EnableTerminationOnHeapCorruption(); 556 base::EnableTerminationOnHeapCorruption();
551 base::EnableTerminationOnOutOfMemory(); 557 base::EnableTerminationOnOutOfMemory();
552 558
559 // The exit manager is in charge of calling the dtors of singleton objects.
553 // On Android, AtExitManager is set up when library is loaded. 560 // On Android, AtExitManager is set up when library is loaded.
554 #if !defined(OS_ANDROID) 561 // On iOS, it's set up in main(), which can't call directly through to here.
555 // The exit manager is in charge of calling the dtors of singleton objects. 562 #if !defined(OS_ANDROID) && !defined(OS_IOS)
556 exit_manager_.reset(new base::AtExitManager); 563 exit_manager_.reset(new base::AtExitManager);
557 #endif 564 #endif // !OS_ANDROID && !OS_IOS
558 565
559 #if defined(OS_MACOSX) 566 #if defined(OS_MACOSX)
560 // We need this pool for all the objects created before we get to the 567 // We need this pool for all the objects created before we get to the
561 // event loop, but we don't want to leave them hanging around until the 568 // event loop, but we don't want to leave them hanging around until the
562 // app quits. Each "main" needs to flush this pool right before it goes into 569 // app quits. Each "main" needs to flush this pool right before it goes into
563 // its main event loop to get rid of the cruft. 570 // its main event loop to get rid of the cruft.
564 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 571 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
565 #endif 572 #endif
566 573
567 // On Android, the command line is initialized when library is loaded. 574 // On Android, the command line is initialized when library is loaded.
(...skipping 21 matching lines...) Expand all
589 base::RouteStdioToConsole(); 596 base::RouteStdioToConsole();
590 #endif 597 #endif
591 598
592 // Enable startup tracing asap to avoid early TRACE_EVENT calls being 599 // Enable startup tracing asap to avoid early TRACE_EVENT calls being
593 // ignored. 600 // ignored.
594 if (command_line.HasSwitch(switches::kTraceStartup)) { 601 if (command_line.HasSwitch(switches::kTraceStartup)) {
595 base::debug::TraceLog::GetInstance()->SetEnabled( 602 base::debug::TraceLog::GetInstance()->SetEnabled(
596 command_line.GetSwitchValueASCII(switches::kTraceStartup)); 603 command_line.GetSwitchValueASCII(switches::kTraceStartup));
597 } 604 }
598 605
599 #if defined(OS_MACOSX) 606 #if defined(OS_MACOSX) && !defined(OS_IOS)
600 // We need to allocate the IO Ports before the Sandbox is initialized or 607 // We need to allocate the IO Ports before the Sandbox is initialized or
601 // the first instance of SystemMonitor is created. 608 // the first instance of SystemMonitor is created.
602 // It's important not to allocate the ports for processes which don't 609 // It's important not to allocate the ports for processes which don't
603 // register with the system monitor - see crbug.com/88867. 610 // register with the system monitor - see crbug.com/88867.
604 if (process_type.empty() || 611 if (process_type.empty() ||
605 process_type == switches::kPluginProcess || 612 process_type == switches::kPluginProcess ||
606 process_type == switches::kRendererProcess || 613 process_type == switches::kRendererProcess ||
607 process_type == switches::kUtilityProcess || 614 process_type == switches::kUtilityProcess ||
608 process_type == switches::kWorkerProcess || 615 process_type == switches::kWorkerProcess ||
609 (delegate && 616 (delegate &&
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 if (command_line.HasSwitch(switches::kUserAgent)) { 671 if (command_line.HasSwitch(switches::kUserAgent)) {
665 webkit_glue::SetUserAgent( 672 webkit_glue::SetUserAgent(
666 command_line.GetSwitchValueASCII(switches::kUserAgent), true); 673 command_line.GetSwitchValueASCII(switches::kUserAgent), true);
667 } 674 }
668 675
669 if (!process_type.empty()) 676 if (!process_type.empty())
670 CommonSubprocessInit(process_type); 677 CommonSubprocessInit(process_type);
671 678
672 #if defined(OS_WIN) 679 #if defined(OS_WIN)
673 CHECK(InitializeSandbox(sandbox_info)); 680 CHECK(InitializeSandbox(sandbox_info));
674 #elif defined(OS_MACOSX) 681 #elif defined(OS_MACOSX) && !defined(OS_IOS)
675 if (process_type == switches::kRendererProcess || 682 if (process_type == switches::kRendererProcess ||
676 process_type == switches::kPpapiPluginProcess || 683 process_type == switches::kPpapiPluginProcess ||
677 (delegate && delegate->DelaySandboxInitialization(process_type))) { 684 (delegate && delegate->DelaySandboxInitialization(process_type))) {
678 // On OS X the renderer sandbox needs to be initialized later in the 685 // On OS X the renderer sandbox needs to be initialized later in the
679 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). 686 // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
680 } else { 687 } else {
681 CHECK(InitializeSandbox()); 688 CHECK(InitializeSandbox());
682 } 689 }
683 #endif 690 #endif
684 691
685 if (delegate) 692 if (delegate)
686 delegate->SandboxInitialized(process_type); 693 delegate->SandboxInitialized(process_type);
687 694
688 #if defined(OS_POSIX) 695 #if defined(OS_POSIX) && !defined(OS_IOS)
689 SetProcessTitleFromCommandLine(argv); 696 SetProcessTitleFromCommandLine(argv);
690 #endif 697 #endif
691 698
692 // Return -1 to indicate no early termination. 699 // Return -1 to indicate no early termination.
693 return -1; 700 return -1;
694 } 701 }
695 702
696 virtual int Run() OVERRIDE { 703 virtual int Run() OVERRIDE {
697 DCHECK(is_initialized_); 704 DCHECK(is_initialized_);
698 DCHECK(!is_shutdown_); 705 DCHECK(!is_shutdown_);
699 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 706 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
700 std::string process_type = 707 std::string process_type =
701 command_line.GetSwitchValueASCII(switches::kProcessType); 708 command_line.GetSwitchValueASCII(switches::kProcessType);
702 709
703 MainFunctionParams main_params(command_line); 710 MainFunctionParams main_params(command_line);
704 #if defined(OS_WIN) 711 #if defined(OS_WIN)
705 main_params.sandbox_info = &sandbox_info_; 712 main_params.sandbox_info = &sandbox_info_;
706 #elif defined(OS_MACOSX) 713 #elif defined(OS_MACOSX)
707 main_params.autorelease_pool = autorelease_pool_.get(); 714 main_params.autorelease_pool = autorelease_pool_.get();
708 #endif 715 #endif
709 716
717 #if !defined(OS_IOS)
710 return RunNamedProcessTypeMain(process_type, main_params, delegate_); 718 return RunNamedProcessTypeMain(process_type, main_params, delegate_);
719 #else
720 return 1;
721 #endif
711 } 722 }
712 723
713 virtual void Shutdown() OVERRIDE { 724 virtual void Shutdown() OVERRIDE {
714 DCHECK(is_initialized_); 725 DCHECK(is_initialized_);
715 DCHECK(!is_shutdown_); 726 DCHECK(!is_shutdown_);
716 727
717 if (completed_basic_startup_ && delegate_) { 728 if (completed_basic_startup_ && delegate_) {
718 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 729 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
719 std::string process_type = 730 std::string process_type =
720 command_line.GetSwitchValueASCII(switches::kProcessType); 731 command_line.GetSwitchValueASCII(switches::kProcessType);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 776
766 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 777 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
767 }; 778 };
768 779
769 // static 780 // static
770 ContentMainRunner* ContentMainRunner::Create() { 781 ContentMainRunner* ContentMainRunner::Create() {
771 return new ContentMainRunnerImpl(); 782 return new ContentMainRunnerImpl();
772 } 783 }
773 784
774 } // namespace content 785 } // 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