| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "base/process/process.h" | 36 #include "base/process/process.h" |
| 37 #include "base/process/process_handle.h" | 37 #include "base/process/process_handle.h" |
| 38 #include "base/profiler/scoped_tracker.h" | 38 #include "base/profiler/scoped_tracker.h" |
| 39 #include "base/strings/string_number_conversions.h" | 39 #include "base/strings/string_number_conversions.h" |
| 40 #include "base/strings/string_util.h" | 40 #include "base/strings/string_util.h" |
| 41 #include "base/strings/stringprintf.h" | 41 #include "base/strings/stringprintf.h" |
| 42 #include "base/trace_event/trace_event.h" | 42 #include "base/trace_event/trace_event.h" |
| 43 #include "build/build_config.h" | 43 #include "build/build_config.h" |
| 44 #include "components/tracing/common/trace_startup.h" | 44 #include "components/tracing/common/trace_startup.h" |
| 45 #include "content/app/mojo/mojo_init.h" | 45 #include "content/app/mojo/mojo_init.h" |
| 46 #include "content/common/set_process_title.h" | |
| 47 #include "content/common/url_schemes.h" | 46 #include "content/common/url_schemes.h" |
| 48 #include "content/public/app/content_main.h" | 47 #include "content/public/app/content_main.h" |
| 49 #include "content/public/app/content_main_delegate.h" | 48 #include "content/public/app/content_main_delegate.h" |
| 50 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
| 51 #include "content/public/common/content_constants.h" | 50 #include "content/public/common/content_constants.h" |
| 52 #include "content/public/common/content_descriptor_keys.h" | 51 #include "content/public/common/content_descriptor_keys.h" |
| 53 #include "content/public/common/content_paths.h" | 52 #include "content/public/common/content_paths.h" |
| 54 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
| 55 #include "content/public/common/main_function_params.h" | 54 #include "content/public/common/main_function_params.h" |
| 56 #include "content/public/common/sandbox_init.h" | 55 #include "content/public/common/sandbox_init.h" |
| 57 #include "ipc/ipc_descriptors.h" | 56 #include "ipc/ipc_descriptors.h" |
| 58 #include "media/base/media.h" | 57 #include "media/base/media.h" |
| 59 #include "ppapi/features/features.h" | 58 #include "ppapi/features/features.h" |
| 60 #include "services/service_manager/public/cpp/shared_file_util.h" | |
| 61 #include "ui/base/ui_base_paths.h" | 59 #include "ui/base/ui_base_paths.h" |
| 62 #include "ui/base/ui_base_switches.h" | 60 #include "ui/base/ui_base_switches.h" |
| 63 | 61 |
| 64 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ | 62 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ |
| 65 !defined(CHROME_MULTIPLE_DLL_BROWSER) | 63 !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 66 #include "gin/v8_initializer.h" | 64 #include "gin/v8_initializer.h" |
| 67 #endif | 65 #endif |
| 68 | 66 |
| 69 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
| 70 #include <malloc.h> | 68 #include <malloc.h> |
| 71 #include <cstring> | 69 #include <cstring> |
| 72 | 70 |
| 73 #include "base/trace_event/trace_event_etw_export_win.h" | 71 #include "base/trace_event/trace_event_etw_export_win.h" |
| 74 #include "base/win/process_startup_helper.h" | |
| 75 #include "sandbox/win/src/sandbox_types.h" | 72 #include "sandbox/win/src/sandbox_types.h" |
| 76 #include "ui/base/win/atl_module.h" | |
| 77 #include "ui/display/win/dpi.h" | 73 #include "ui/display/win/dpi.h" |
| 78 #elif defined(OS_MACOSX) | 74 #elif defined(OS_MACOSX) |
| 79 #include "base/allocator/allocator_shim.h" | |
| 80 #include "base/mac/scoped_nsautorelease_pool.h" | 75 #include "base/mac/scoped_nsautorelease_pool.h" |
| 81 #include "base/power_monitor/power_monitor_device_source.h" | 76 #include "base/power_monitor/power_monitor_device_source.h" |
| 82 #include "content/app/mac/mac_init.h" | |
| 83 #include "content/browser/mach_broker_mac.h" | 77 #include "content/browser/mach_broker_mac.h" |
| 84 #include "content/common/sandbox_init_mac.h" | 78 #include "content/common/sandbox_init_mac.h" |
| 85 #endif // OS_WIN | 79 #endif // OS_WIN |
| 86 | 80 |
| 87 #if defined(OS_POSIX) | 81 #if defined(OS_POSIX) |
| 88 #include <signal.h> | 82 #include <signal.h> |
| 89 | 83 |
| 90 #include "base/file_descriptor_store.h" | 84 #include "base/file_descriptor_store.h" |
| 91 #include "base/posix/global_descriptors.h" | 85 #include "base/posix/global_descriptors.h" |
| 92 #include "content/public/common/content_descriptors.h" | 86 #include "content/public/common/content_descriptors.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 225 |
| 232 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 226 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 233 base::LazyInstance<ContentGpuClient>::DestructorAtExit | 227 base::LazyInstance<ContentGpuClient>::DestructorAtExit |
| 234 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; | 228 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; |
| 235 base::LazyInstance<ContentRendererClient>::DestructorAtExit | 229 base::LazyInstance<ContentRendererClient>::DestructorAtExit |
| 236 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 230 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
| 237 base::LazyInstance<ContentUtilityClient>::DestructorAtExit | 231 base::LazyInstance<ContentUtilityClient>::DestructorAtExit |
| 238 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 232 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
| 239 #endif // !CHROME_MULTIPLE_DLL_BROWSER | 233 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
| 240 | 234 |
| 241 #if defined(OS_POSIX) | |
| 242 | |
| 243 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. | |
| 244 void SetupSignalHandlers() { | |
| 245 // Sanitise our signal handling state. Signals that were ignored by our | |
| 246 // parent will also be ignored by us. We also inherit our parent's sigmask. | |
| 247 sigset_t empty_signal_set; | |
| 248 CHECK_EQ(0, sigemptyset(&empty_signal_set)); | |
| 249 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); | |
| 250 | |
| 251 struct sigaction sigact; | |
| 252 memset(&sigact, 0, sizeof(sigact)); | |
| 253 sigact.sa_handler = SIG_DFL; | |
| 254 static const int signals_to_reset[] = | |
| 255 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, | |
| 256 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. | |
| 257 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { | |
| 258 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL)); | |
| 259 } | |
| 260 | |
| 261 // Always ignore SIGPIPE. We check the return value of write(). | |
| 262 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN)); | |
| 263 } | |
| 264 | |
| 265 void PopulateFDsFromCommandLine() { | |
| 266 const std::string& shared_file_param = | |
| 267 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 268 switches::kSharedFiles); | |
| 269 if (shared_file_param.empty()) | |
| 270 return; | |
| 271 | |
| 272 base::Optional<std::map<int, std::string>> shared_file_descriptors = | |
| 273 service_manager::ParseSharedFileSwitchValue(shared_file_param); | |
| 274 if (!shared_file_descriptors) | |
| 275 return; | |
| 276 | |
| 277 for (const auto& descriptor : *shared_file_descriptors) { | |
| 278 base::MemoryMappedFile::Region region; | |
| 279 const std::string& key = descriptor.second; | |
| 280 base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->TakeFD( | |
| 281 descriptor.first, ®ion); | |
| 282 base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region); | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 #endif // OS_POSIX | |
| 287 | |
| 288 void CommonSubprocessInit() { | 235 void CommonSubprocessInit() { |
| 289 #if defined(OS_WIN) | 236 #if defined(OS_WIN) |
| 290 // HACK: Let Windows know that we have started. This is needed to suppress | 237 // HACK: Let Windows know that we have started. This is needed to suppress |
| 291 // the IDC_APPSTARTING cursor from being displayed for a prolonged period | 238 // the IDC_APPSTARTING cursor from being displayed for a prolonged period |
| 292 // while a subprocess is starting. | 239 // while a subprocess is starting. |
| 293 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); | 240 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); |
| 294 MSG msg; | 241 MSG msg; |
| 295 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); | 242 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); |
| 296 #endif | 243 #endif |
| 297 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 244 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 Shutdown(); | 471 Shutdown(); |
| 525 } | 472 } |
| 526 | 473 |
| 527 int Initialize(const ContentMainParams& params) override { | 474 int Initialize(const ContentMainParams& params) override { |
| 528 ui_task_ = params.ui_task; | 475 ui_task_ = params.ui_task; |
| 529 | 476 |
| 530 #if defined(USE_AURA) | 477 #if defined(USE_AURA) |
| 531 env_mode_ = params.env_mode; | 478 env_mode_ = params.env_mode; |
| 532 #endif | 479 #endif |
| 533 | 480 |
| 534 #if defined(OS_MACOSX) && BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | |
| 535 base::allocator::InitializeAllocatorShim(); | |
| 536 #endif | |
| 537 base::EnableTerminationOnOutOfMemory(); | |
| 538 #if defined(OS_WIN) | 481 #if defined(OS_WIN) |
| 539 base::win::RegisterInvalidParamHandler(); | |
| 540 ui::win::CreateATLModuleIfNeeded(); | |
| 541 | |
| 542 sandbox_info_ = *params.sandbox_info; | 482 sandbox_info_ = *params.sandbox_info; |
| 543 #else // !OS_WIN | 483 #else // !OS_WIN |
| 544 | 484 |
| 485 #if defined(OS_MACOSX) |
| 486 autorelease_pool_ = params.autorelease_pool; |
| 487 #endif // defined(OS_MACOSX) |
| 488 |
| 545 #if defined(OS_ANDROID) | 489 #if defined(OS_ANDROID) |
| 546 // See note at the initialization of ExitManager, below; basically, | 490 // See note at the initialization of ExitManager, below; basically, |
| 547 // only Android builds have the ctor/dtor handlers set up to use | 491 // only Android builds have the ctor/dtor handlers set up to use |
| 548 // TRACE_EVENT right away. | 492 // TRACE_EVENT right away. |
| 549 TRACE_EVENT0("startup,benchmark,rail", "ContentMainRunnerImpl::Initialize"); | 493 TRACE_EVENT0("startup,benchmark,rail", "ContentMainRunnerImpl::Initialize"); |
| 550 #endif // OS_ANDROID | 494 #endif // OS_ANDROID |
| 551 | 495 |
| 552 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 496 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
| 553 ALLOW_UNUSED_LOCAL(g_fds); | 497 ALLOW_UNUSED_LOCAL(g_fds); |
| 554 | 498 |
| 555 // On Android, | 499 // On Android, the ipc_fd is passed through the Java service. |
| 556 // - setlocale() is not supported. | |
| 557 // - We do not override the signal handlers so that we can get | |
| 558 // stack trace when crashing. | |
| 559 // - The ipc_fd is passed through the Java service. | |
| 560 // Thus, these are all disabled. | |
| 561 #if !defined(OS_ANDROID) | 500 #if !defined(OS_ANDROID) |
| 562 // Set C library locale to make sure CommandLine can parse argument values | |
| 563 // in correct encoding. | |
| 564 setlocale(LC_ALL, ""); | |
| 565 | |
| 566 SetupSignalHandlers(); | |
| 567 g_fds->Set(kMojoIPCChannel, | 501 g_fds->Set(kMojoIPCChannel, |
| 568 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 502 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 569 | 503 |
| 570 g_fds->Set( | 504 g_fds->Set( |
| 571 kFieldTrialDescriptor, | 505 kFieldTrialDescriptor, |
| 572 kFieldTrialDescriptor + base::GlobalDescriptors::kBaseDescriptor); | 506 kFieldTrialDescriptor + base::GlobalDescriptors::kBaseDescriptor); |
| 573 #endif // !OS_ANDROID | 507 #endif // !OS_ANDROID |
| 574 | 508 |
| 575 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 509 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 576 g_fds->Set(kCrashDumpSignal, | 510 g_fds->Set(kCrashDumpSignal, |
| 577 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 511 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); |
| 578 #endif // OS_LINUX || OS_OPENBSD | 512 #endif // OS_LINUX || OS_OPENBSD |
| 579 | 513 |
| 580 | |
| 581 #endif // !OS_WIN | 514 #endif // !OS_WIN |
| 582 | 515 |
| 583 is_initialized_ = true; | 516 is_initialized_ = true; |
| 584 delegate_ = params.delegate; | 517 delegate_ = params.delegate; |
| 585 | 518 |
| 586 // The exit manager is in charge of calling the dtors of singleton objects. | 519 // The exit manager is in charge of calling the dtors of singleton objects. |
| 587 // On Android, AtExitManager is set up when library is loaded. | 520 // On Android, AtExitManager is set up when library is loaded. |
| 588 // A consequence of this is that you can't use the ctor/dtor-based | 521 // A consequence of this is that you can't use the ctor/dtor-based |
| 589 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. | 522 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. |
| 590 #if !defined(OS_ANDROID) | 523 #if !defined(OS_ANDROID) |
| 591 if (!ui_task_) { | 524 if (!ui_task_) { |
| 592 // When running browser tests, don't create a second AtExitManager as that | 525 // When running browser tests, don't create a second AtExitManager as that |
| 593 // interfers with shutdown when objects created before ContentMain is | 526 // interfers with shutdown when objects created before ContentMain is |
| 594 // called are destructed when it returns. | 527 // called are destructed when it returns. |
| 595 exit_manager_.reset(new base::AtExitManager); | 528 exit_manager_.reset(new base::AtExitManager); |
| 596 } | 529 } |
| 597 #endif // !OS_ANDROID | 530 #endif // !OS_ANDROID |
| 598 | 531 |
| 599 #if defined(OS_MACOSX) | |
| 600 // We need this pool for all the objects created before we get to the | |
| 601 // event loop, but we don't want to leave them hanging around until the | |
| 602 // app quits. Each "main" needs to flush this pool right before it goes into | |
| 603 // its main event loop to get rid of the cruft. | |
| 604 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | |
| 605 InitializeMac(); | |
| 606 #endif | |
| 607 | |
| 608 // On Android, the command line is initialized and the FDs set when the | |
| 609 // library is loaded and we have already started our TRACE_EVENT0. | |
| 610 #if !defined(OS_ANDROID) | 532 #if !defined(OS_ANDROID) |
| 611 // argc/argv are ignored on Windows and Android; see command_line.h for | |
| 612 // details. | |
| 613 int argc = 0; | |
| 614 const char** argv = NULL; | |
| 615 | |
| 616 #if !defined(OS_WIN) | |
| 617 argc = params.argc; | |
| 618 argv = params.argv; | |
| 619 #endif | |
| 620 | |
| 621 base::CommandLine::Init(argc, argv); | |
| 622 | |
| 623 #if defined(OS_POSIX) | |
| 624 PopulateFDsFromCommandLine(); | |
| 625 #endif | |
| 626 | |
| 627 base::EnableTerminationOnHeapCorruption(); | |
| 628 | |
| 629 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. | |
| 630 // Enable profiler recording right after command line is initialized so that | |
| 631 // browser startup can be instrumented. | |
| 632 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) | 533 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) |
| 633 tracked_objects::ScopedTracker::Enable(); | 534 tracked_objects::ScopedTracker::Enable(); |
| 634 | |
| 635 SetProcessTitleFromCommandLine(argv); | |
| 636 #endif // !OS_ANDROID | 535 #endif // !OS_ANDROID |
| 637 | 536 |
| 638 int exit_code = 0; | 537 int exit_code = 0; |
| 639 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) | 538 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) |
| 640 return exit_code; | 539 return exit_code; |
| 641 | 540 |
| 642 completed_basic_startup_ = true; | 541 completed_basic_startup_ = true; |
| 643 | 542 |
| 644 const base::CommandLine& command_line = | 543 const base::CommandLine& command_line = |
| 645 *base::CommandLine::ForCurrentProcess(); | 544 *base::CommandLine::ForCurrentProcess(); |
| 646 std::string process_type = | 545 std::string process_type = |
| 647 command_line.GetSwitchValueASCII(switches::kProcessType); | 546 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 648 | 547 |
| 649 // Initialize mojo here so that services can be registered. | |
| 650 InitializeMojo(); | |
| 651 | |
| 652 #if defined(OS_WIN) | 548 #if defined(OS_WIN) |
| 653 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) { | 549 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) { |
| 654 std::string scale_factor_string = command_line.GetSwitchValueASCII( | 550 std::string scale_factor_string = command_line.GetSwitchValueASCII( |
| 655 switches::kDeviceScaleFactor); | 551 switches::kDeviceScaleFactor); |
| 656 double scale_factor = 0; | 552 double scale_factor = 0; |
| 657 if (base::StringToDouble(scale_factor_string, &scale_factor)) | 553 if (base::StringToDouble(scale_factor_string, &scale_factor)) |
| 658 display::win::SetDefaultDeviceScaleFactor(scale_factor); | 554 display::win::SetDefaultDeviceScaleFactor(scale_factor); |
| 659 } | 555 } |
| 660 #endif | 556 #endif |
| 661 | 557 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 if (process_type.empty() || | 598 if (process_type.empty() || |
| 703 (delegate_ && | 599 (delegate_ && |
| 704 delegate_->ProcessRegistersWithSystemProcess(process_type))) { | 600 delegate_->ProcessRegistersWithSystemProcess(process_type))) { |
| 705 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 601 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
| 706 } | 602 } |
| 707 | 603 |
| 708 if (!process_type.empty() && | 604 if (!process_type.empty() && |
| 709 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { | 605 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { |
| 710 MachBroker::ChildSendTaskPortToParent(); | 606 MachBroker::ChildSendTaskPortToParent(); |
| 711 } | 607 } |
| 712 #elif defined(OS_WIN) | |
| 713 base::win::SetupCRT(command_line); | |
| 714 #endif | 608 #endif |
| 715 | 609 |
| 716 // If we are on a platform where the default allocator is overridden (shim | 610 // If we are on a platform where the default allocator is overridden (shim |
| 717 // layer on windows, tcmalloc on Linux Desktop) smoke-tests that the | 611 // layer on windows, tcmalloc on Linux Desktop) smoke-tests that the |
| 718 // overriding logic is working correctly. If not causes a hard crash, as its | 612 // overriding logic is working correctly. If not causes a hard crash, as its |
| 719 // unexpected absence has security implications. | 613 // unexpected absence has security implications. |
| 720 CHECK(base::allocator::IsAllocatorInitialized()); | 614 CHECK(base::allocator::IsAllocatorInitialized()); |
| 721 | 615 |
| 722 #if defined(OS_POSIX) | 616 #if defined(OS_POSIX) |
| 723 if (!process_type.empty()) { | 617 if (!process_type.empty()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 if (!process_type.empty() && process_type != switches::kZygoteProcess) | 713 if (!process_type.empty() && process_type != switches::kZygoteProcess) |
| 820 InitializeFieldTrialAndFeatureList(&field_trial_list); | 714 InitializeFieldTrialAndFeatureList(&field_trial_list); |
| 821 | 715 |
| 822 base::HistogramBase::EnableActivityReportHistogram(process_type); | 716 base::HistogramBase::EnableActivityReportHistogram(process_type); |
| 823 | 717 |
| 824 MainFunctionParams main_params(command_line); | 718 MainFunctionParams main_params(command_line); |
| 825 main_params.ui_task = ui_task_; | 719 main_params.ui_task = ui_task_; |
| 826 #if defined(OS_WIN) | 720 #if defined(OS_WIN) |
| 827 main_params.sandbox_info = &sandbox_info_; | 721 main_params.sandbox_info = &sandbox_info_; |
| 828 #elif defined(OS_MACOSX) | 722 #elif defined(OS_MACOSX) |
| 829 main_params.autorelease_pool = autorelease_pool_.get(); | 723 main_params.autorelease_pool = autorelease_pool_; |
| 830 #endif | 724 #endif |
| 831 #if defined(USE_AURA) | 725 #if defined(USE_AURA) |
| 832 main_params.env_mode = env_mode_; | 726 main_params.env_mode = env_mode_; |
| 833 #endif | 727 #endif |
| 834 | 728 |
| 835 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | 729 return RunNamedProcessTypeMain(process_type, main_params, delegate_); |
| 836 } | 730 } |
| 837 | 731 |
| 838 void Shutdown() override { | 732 void Shutdown() override { |
| 839 DCHECK(is_initialized_); | 733 DCHECK(is_initialized_); |
| 840 DCHECK(!is_shutdown_); | 734 DCHECK(!is_shutdown_); |
| 841 | 735 |
| 842 if (completed_basic_startup_ && delegate_) { | 736 if (completed_basic_startup_ && delegate_) { |
| 843 const base::CommandLine& command_line = | 737 const base::CommandLine& command_line = |
| 844 *base::CommandLine::ForCurrentProcess(); | 738 *base::CommandLine::ForCurrentProcess(); |
| 845 std::string process_type = | 739 std::string process_type = |
| 846 command_line.GetSwitchValueASCII(switches::kProcessType); | 740 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 847 | 741 |
| 848 delegate_->ProcessExiting(process_type); | 742 delegate_->ProcessExiting(process_type); |
| 849 } | 743 } |
| 850 | 744 |
| 851 #if defined(OS_WIN) | 745 #if defined(OS_WIN) |
| 852 #ifdef _CRTDBG_MAP_ALLOC | 746 #ifdef _CRTDBG_MAP_ALLOC |
| 853 _CrtDumpMemoryLeaks(); | 747 _CrtDumpMemoryLeaks(); |
| 854 #endif // _CRTDBG_MAP_ALLOC | 748 #endif // _CRTDBG_MAP_ALLOC |
| 855 #endif // OS_WIN | 749 #endif // OS_WIN |
| 856 | 750 |
| 857 #if defined(OS_MACOSX) | |
| 858 autorelease_pool_.reset(NULL); | |
| 859 #endif | |
| 860 | |
| 861 exit_manager_.reset(NULL); | 751 exit_manager_.reset(NULL); |
| 862 | 752 |
| 863 delegate_ = NULL; | 753 delegate_ = NULL; |
| 864 is_shutdown_ = true; | 754 is_shutdown_ = true; |
| 865 } | 755 } |
| 866 | 756 |
| 867 private: | 757 private: |
| 868 // True if the runner has been initialized. | 758 // True if the runner has been initialized. |
| 869 bool is_initialized_; | 759 bool is_initialized_; |
| 870 | 760 |
| 871 // True if the runner has been shut down. | 761 // True if the runner has been shut down. |
| 872 bool is_shutdown_; | 762 bool is_shutdown_; |
| 873 | 763 |
| 874 // True if basic startup was completed. | 764 // True if basic startup was completed. |
| 875 bool completed_basic_startup_; | 765 bool completed_basic_startup_; |
| 876 | 766 |
| 877 // Used if the embedder doesn't set one. | 767 // Used if the embedder doesn't set one. |
| 878 ContentClient empty_content_client_; | 768 ContentClient empty_content_client_; |
| 879 | 769 |
| 880 // The delegate will outlive this object. | 770 // The delegate will outlive this object. |
| 881 ContentMainDelegate* delegate_; | 771 ContentMainDelegate* delegate_; |
| 882 | 772 |
| 883 std::unique_ptr<base::AtExitManager> exit_manager_; | 773 std::unique_ptr<base::AtExitManager> exit_manager_; |
| 884 #if defined(OS_WIN) | 774 #if defined(OS_WIN) |
| 885 sandbox::SandboxInterfaceInfo sandbox_info_; | 775 sandbox::SandboxInterfaceInfo sandbox_info_; |
| 886 #elif defined(OS_MACOSX) | 776 #elif defined(OS_MACOSX) |
| 887 std::unique_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; | 777 base::mac::ScopedNSAutoreleasePool* autorelease_pool_ = nullptr; |
| 888 #endif | 778 #endif |
| 889 | 779 |
| 890 base::Closure* ui_task_; | 780 base::Closure* ui_task_; |
| 891 | 781 |
| 892 #if defined(USE_AURA) | 782 #if defined(USE_AURA) |
| 893 aura::Env::Mode env_mode_ = aura::Env::Mode::LOCAL; | 783 aura::Env::Mode env_mode_ = aura::Env::Mode::LOCAL; |
| 894 #endif | 784 #endif |
| 895 | 785 |
| 896 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 786 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 897 }; | 787 }; |
| 898 | 788 |
| 899 // static | 789 // static |
| 900 ContentMainRunner* ContentMainRunner::Create() { | 790 ContentMainRunner* ContentMainRunner::Create() { |
| 901 return new ContentMainRunnerImpl(); | 791 return new ContentMainRunnerImpl(); |
| 902 } | 792 } |
| 903 | 793 |
| 904 } // namespace content | 794 } // namespace content |
| OLD | NEW |