| 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" |
| 46 #include "content/common/url_schemes.h" | 47 #include "content/common/url_schemes.h" |
| 47 #include "content/public/app/content_main.h" | 48 #include "content/public/app/content_main.h" |
| 48 #include "content/public/app/content_main_delegate.h" | 49 #include "content/public/app/content_main_delegate.h" |
| 49 #include "content/public/common/content_client.h" | 50 #include "content/public/common/content_client.h" |
| 50 #include "content/public/common/content_constants.h" | 51 #include "content/public/common/content_constants.h" |
| 51 #include "content/public/common/content_descriptor_keys.h" | 52 #include "content/public/common/content_descriptor_keys.h" |
| 52 #include "content/public/common/content_paths.h" | 53 #include "content/public/common/content_paths.h" |
| 53 #include "content/public/common/content_switches.h" | 54 #include "content/public/common/content_switches.h" |
| 54 #include "content/public/common/main_function_params.h" | 55 #include "content/public/common/main_function_params.h" |
| 55 #include "content/public/common/sandbox_init.h" | 56 #include "content/public/common/sandbox_init.h" |
| 56 #include "ipc/ipc_descriptors.h" | 57 #include "ipc/ipc_descriptors.h" |
| 57 #include "media/base/media.h" | 58 #include "media/base/media.h" |
| 58 #include "ppapi/features/features.h" | 59 #include "ppapi/features/features.h" |
| 60 #include "services/service_manager/public/cpp/shared_file_util.h" |
| 59 #include "ui/base/ui_base_paths.h" | 61 #include "ui/base/ui_base_paths.h" |
| 60 #include "ui/base/ui_base_switches.h" | 62 #include "ui/base/ui_base_switches.h" |
| 61 | 63 |
| 62 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ | 64 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ |
| 63 !defined(CHROME_MULTIPLE_DLL_BROWSER) | 65 !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 64 #include "gin/v8_initializer.h" | 66 #include "gin/v8_initializer.h" |
| 65 #endif | 67 #endif |
| 66 | 68 |
| 67 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
| 68 #include <malloc.h> | 70 #include <malloc.h> |
| 69 #include <cstring> | 71 #include <cstring> |
| 70 | 72 |
| 71 #include "base/trace_event/trace_event_etw_export_win.h" | 73 #include "base/trace_event/trace_event_etw_export_win.h" |
| 74 #include "base/win/process_startup_helper.h" |
| 72 #include "sandbox/win/src/sandbox_types.h" | 75 #include "sandbox/win/src/sandbox_types.h" |
| 76 #include "ui/base/win/atl_module.h" |
| 73 #include "ui/display/win/dpi.h" | 77 #include "ui/display/win/dpi.h" |
| 74 #elif defined(OS_MACOSX) | 78 #elif defined(OS_MACOSX) |
| 79 #include "base/allocator/allocator_shim.h" |
| 75 #include "base/mac/scoped_nsautorelease_pool.h" | 80 #include "base/mac/scoped_nsautorelease_pool.h" |
| 76 #include "base/power_monitor/power_monitor_device_source.h" | 81 #include "base/power_monitor/power_monitor_device_source.h" |
| 82 #include "content/app/mac/mac_init.h" |
| 77 #include "content/browser/mach_broker_mac.h" | 83 #include "content/browser/mach_broker_mac.h" |
| 78 #include "content/common/sandbox_init_mac.h" | 84 #include "content/common/sandbox_init_mac.h" |
| 79 #endif // OS_WIN | 85 #endif // OS_WIN |
| 80 | 86 |
| 81 #if defined(OS_POSIX) | 87 #if defined(OS_POSIX) |
| 82 #include <signal.h> | 88 #include <signal.h> |
| 83 | 89 |
| 84 #include "base/file_descriptor_store.h" | 90 #include "base/file_descriptor_store.h" |
| 85 #include "base/posix/global_descriptors.h" | 91 #include "base/posix/global_descriptors.h" |
| 86 #include "content/public/common/content_descriptors.h" | 92 #include "content/public/common/content_descriptors.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 231 |
| 226 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 232 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 227 base::LazyInstance<ContentGpuClient>::DestructorAtExit | 233 base::LazyInstance<ContentGpuClient>::DestructorAtExit |
| 228 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; | 234 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; |
| 229 base::LazyInstance<ContentRendererClient>::DestructorAtExit | 235 base::LazyInstance<ContentRendererClient>::DestructorAtExit |
| 230 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 236 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
| 231 base::LazyInstance<ContentUtilityClient>::DestructorAtExit | 237 base::LazyInstance<ContentUtilityClient>::DestructorAtExit |
| 232 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 238 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
| 233 #endif // !CHROME_MULTIPLE_DLL_BROWSER | 239 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
| 234 | 240 |
| 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 |
| 235 void CommonSubprocessInit() { | 288 void CommonSubprocessInit() { |
| 236 #if defined(OS_WIN) | 289 #if defined(OS_WIN) |
| 237 // HACK: Let Windows know that we have started. This is needed to suppress | 290 // HACK: Let Windows know that we have started. This is needed to suppress |
| 238 // the IDC_APPSTARTING cursor from being displayed for a prolonged period | 291 // the IDC_APPSTARTING cursor from being displayed for a prolonged period |
| 239 // while a subprocess is starting. | 292 // while a subprocess is starting. |
| 240 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); | 293 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); |
| 241 MSG msg; | 294 MSG msg; |
| 242 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); | 295 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); |
| 243 #endif | 296 #endif |
| 244 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 297 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 Shutdown(); | 524 Shutdown(); |
| 472 } | 525 } |
| 473 | 526 |
| 474 int Initialize(const ContentMainParams& params) override { | 527 int Initialize(const ContentMainParams& params) override { |
| 475 ui_task_ = params.ui_task; | 528 ui_task_ = params.ui_task; |
| 476 | 529 |
| 477 #if defined(USE_AURA) | 530 #if defined(USE_AURA) |
| 478 env_mode_ = params.env_mode; | 531 env_mode_ = params.env_mode; |
| 479 #endif | 532 #endif |
| 480 | 533 |
| 534 #if defined(OS_MACOSX) && BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 535 base::allocator::InitializeAllocatorShim(); |
| 536 #endif |
| 537 base::EnableTerminationOnOutOfMemory(); |
| 481 #if defined(OS_WIN) | 538 #if defined(OS_WIN) |
| 539 base::win::RegisterInvalidParamHandler(); |
| 540 ui::win::CreateATLModuleIfNeeded(); |
| 541 |
| 482 sandbox_info_ = *params.sandbox_info; | 542 sandbox_info_ = *params.sandbox_info; |
| 483 #else // !OS_WIN | 543 #else // !OS_WIN |
| 484 | 544 |
| 485 #if defined(OS_MACOSX) | |
| 486 autorelease_pool_ = params.autorelease_pool; | |
| 487 #endif // defined(OS_MACOSX) | |
| 488 | |
| 489 #if defined(OS_ANDROID) | 545 #if defined(OS_ANDROID) |
| 490 // See note at the initialization of ExitManager, below; basically, | 546 // See note at the initialization of ExitManager, below; basically, |
| 491 // only Android builds have the ctor/dtor handlers set up to use | 547 // only Android builds have the ctor/dtor handlers set up to use |
| 492 // TRACE_EVENT right away. | 548 // TRACE_EVENT right away. |
| 493 TRACE_EVENT0("startup,benchmark,rail", "ContentMainRunnerImpl::Initialize"); | 549 TRACE_EVENT0("startup,benchmark,rail", "ContentMainRunnerImpl::Initialize"); |
| 494 #endif // OS_ANDROID | 550 #endif // OS_ANDROID |
| 495 | 551 |
| 496 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 552 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
| 497 ALLOW_UNUSED_LOCAL(g_fds); | 553 ALLOW_UNUSED_LOCAL(g_fds); |
| 498 | 554 |
| 499 // On Android, the ipc_fd is passed through the Java service. | 555 // On Android, |
| 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. |
| 500 #if !defined(OS_ANDROID) | 561 #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(); |
| 501 g_fds->Set(kMojoIPCChannel, | 567 g_fds->Set(kMojoIPCChannel, |
| 502 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 568 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor); |
| 503 | 569 |
| 504 g_fds->Set( | 570 g_fds->Set( |
| 505 kFieldTrialDescriptor, | 571 kFieldTrialDescriptor, |
| 506 kFieldTrialDescriptor + base::GlobalDescriptors::kBaseDescriptor); | 572 kFieldTrialDescriptor + base::GlobalDescriptors::kBaseDescriptor); |
| 507 #endif // !OS_ANDROID | 573 #endif // !OS_ANDROID |
| 508 | 574 |
| 509 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 575 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 510 g_fds->Set(kCrashDumpSignal, | 576 g_fds->Set(kCrashDumpSignal, |
| 511 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 577 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); |
| 512 #endif // OS_LINUX || OS_OPENBSD | 578 #endif // OS_LINUX || OS_OPENBSD |
| 513 | 579 |
| 580 |
| 514 #endif // !OS_WIN | 581 #endif // !OS_WIN |
| 515 | 582 |
| 516 is_initialized_ = true; | 583 is_initialized_ = true; |
| 517 delegate_ = params.delegate; | 584 delegate_ = params.delegate; |
| 518 | 585 |
| 519 // The exit manager is in charge of calling the dtors of singleton objects. | 586 // The exit manager is in charge of calling the dtors of singleton objects. |
| 520 // On Android, AtExitManager is set up when library is loaded. | 587 // On Android, AtExitManager is set up when library is loaded. |
| 521 // A consequence of this is that you can't use the ctor/dtor-based | 588 // A consequence of this is that you can't use the ctor/dtor-based |
| 522 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. | 589 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. |
| 523 #if !defined(OS_ANDROID) | 590 #if !defined(OS_ANDROID) |
| 524 if (!ui_task_) { | 591 if (!ui_task_) { |
| 525 // When running browser tests, don't create a second AtExitManager as that | 592 // When running browser tests, don't create a second AtExitManager as that |
| 526 // interfers with shutdown when objects created before ContentMain is | 593 // interfers with shutdown when objects created before ContentMain is |
| 527 // called are destructed when it returns. | 594 // called are destructed when it returns. |
| 528 exit_manager_.reset(new base::AtExitManager); | 595 exit_manager_.reset(new base::AtExitManager); |
| 529 } | 596 } |
| 530 #endif // !OS_ANDROID | 597 #endif // !OS_ANDROID |
| 531 | 598 |
| 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. |
| 532 #if !defined(OS_ANDROID) | 610 #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. |
| 533 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) | 632 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) |
| 534 tracked_objects::ScopedTracker::Enable(); | 633 tracked_objects::ScopedTracker::Enable(); |
| 634 |
| 635 SetProcessTitleFromCommandLine(argv); |
| 535 #endif // !OS_ANDROID | 636 #endif // !OS_ANDROID |
| 536 | 637 |
| 537 int exit_code = 0; | 638 int exit_code = 0; |
| 538 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) | 639 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) |
| 539 return exit_code; | 640 return exit_code; |
| 540 | 641 |
| 541 completed_basic_startup_ = true; | 642 completed_basic_startup_ = true; |
| 542 | 643 |
| 543 const base::CommandLine& command_line = | 644 const base::CommandLine& command_line = |
| 544 *base::CommandLine::ForCurrentProcess(); | 645 *base::CommandLine::ForCurrentProcess(); |
| 545 std::string process_type = | 646 std::string process_type = |
| 546 command_line.GetSwitchValueASCII(switches::kProcessType); | 647 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 547 | 648 |
| 649 // Initialize mojo here so that services can be registered. |
| 650 InitializeMojo(); |
| 651 |
| 548 #if defined(OS_WIN) | 652 #if defined(OS_WIN) |
| 549 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) { | 653 if (command_line.HasSwitch(switches::kDeviceScaleFactor)) { |
| 550 std::string scale_factor_string = command_line.GetSwitchValueASCII( | 654 std::string scale_factor_string = command_line.GetSwitchValueASCII( |
| 551 switches::kDeviceScaleFactor); | 655 switches::kDeviceScaleFactor); |
| 552 double scale_factor = 0; | 656 double scale_factor = 0; |
| 553 if (base::StringToDouble(scale_factor_string, &scale_factor)) | 657 if (base::StringToDouble(scale_factor_string, &scale_factor)) |
| 554 display::win::SetDefaultDeviceScaleFactor(scale_factor); | 658 display::win::SetDefaultDeviceScaleFactor(scale_factor); |
| 555 } | 659 } |
| 556 #endif | 660 #endif |
| 557 | 661 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 if (process_type.empty() || | 702 if (process_type.empty() || |
| 599 (delegate_ && | 703 (delegate_ && |
| 600 delegate_->ProcessRegistersWithSystemProcess(process_type))) { | 704 delegate_->ProcessRegistersWithSystemProcess(process_type))) { |
| 601 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 705 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
| 602 } | 706 } |
| 603 | 707 |
| 604 if (!process_type.empty() && | 708 if (!process_type.empty() && |
| 605 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { | 709 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { |
| 606 MachBroker::ChildSendTaskPortToParent(); | 710 MachBroker::ChildSendTaskPortToParent(); |
| 607 } | 711 } |
| 712 #elif defined(OS_WIN) |
| 713 base::win::SetupCRT(command_line); |
| 608 #endif | 714 #endif |
| 609 | 715 |
| 610 // If we are on a platform where the default allocator is overridden (shim | 716 // If we are on a platform where the default allocator is overridden (shim |
| 611 // layer on windows, tcmalloc on Linux Desktop) smoke-tests that the | 717 // layer on windows, tcmalloc on Linux Desktop) smoke-tests that the |
| 612 // overriding logic is working correctly. If not causes a hard crash, as its | 718 // overriding logic is working correctly. If not causes a hard crash, as its |
| 613 // unexpected absence has security implications. | 719 // unexpected absence has security implications. |
| 614 CHECK(base::allocator::IsAllocatorInitialized()); | 720 CHECK(base::allocator::IsAllocatorInitialized()); |
| 615 | 721 |
| 616 #if defined(OS_POSIX) | 722 #if defined(OS_POSIX) |
| 617 if (!process_type.empty()) { | 723 if (!process_type.empty()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 if (!process_type.empty() && process_type != switches::kZygoteProcess) | 819 if (!process_type.empty() && process_type != switches::kZygoteProcess) |
| 714 InitializeFieldTrialAndFeatureList(&field_trial_list); | 820 InitializeFieldTrialAndFeatureList(&field_trial_list); |
| 715 | 821 |
| 716 base::HistogramBase::EnableActivityReportHistogram(process_type); | 822 base::HistogramBase::EnableActivityReportHistogram(process_type); |
| 717 | 823 |
| 718 MainFunctionParams main_params(command_line); | 824 MainFunctionParams main_params(command_line); |
| 719 main_params.ui_task = ui_task_; | 825 main_params.ui_task = ui_task_; |
| 720 #if defined(OS_WIN) | 826 #if defined(OS_WIN) |
| 721 main_params.sandbox_info = &sandbox_info_; | 827 main_params.sandbox_info = &sandbox_info_; |
| 722 #elif defined(OS_MACOSX) | 828 #elif defined(OS_MACOSX) |
| 723 main_params.autorelease_pool = autorelease_pool_; | 829 main_params.autorelease_pool = autorelease_pool_.get(); |
| 724 #endif | 830 #endif |
| 725 #if defined(USE_AURA) | 831 #if defined(USE_AURA) |
| 726 main_params.env_mode = env_mode_; | 832 main_params.env_mode = env_mode_; |
| 727 #endif | 833 #endif |
| 728 | 834 |
| 729 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | 835 return RunNamedProcessTypeMain(process_type, main_params, delegate_); |
| 730 } | 836 } |
| 731 | 837 |
| 732 void Shutdown() override { | 838 void Shutdown() override { |
| 733 DCHECK(is_initialized_); | 839 DCHECK(is_initialized_); |
| 734 DCHECK(!is_shutdown_); | 840 DCHECK(!is_shutdown_); |
| 735 | 841 |
| 736 if (completed_basic_startup_ && delegate_) { | 842 if (completed_basic_startup_ && delegate_) { |
| 737 const base::CommandLine& command_line = | 843 const base::CommandLine& command_line = |
| 738 *base::CommandLine::ForCurrentProcess(); | 844 *base::CommandLine::ForCurrentProcess(); |
| 739 std::string process_type = | 845 std::string process_type = |
| 740 command_line.GetSwitchValueASCII(switches::kProcessType); | 846 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 741 | 847 |
| 742 delegate_->ProcessExiting(process_type); | 848 delegate_->ProcessExiting(process_type); |
| 743 } | 849 } |
| 744 | 850 |
| 745 #if defined(OS_WIN) | 851 #if defined(OS_WIN) |
| 746 #ifdef _CRTDBG_MAP_ALLOC | 852 #ifdef _CRTDBG_MAP_ALLOC |
| 747 _CrtDumpMemoryLeaks(); | 853 _CrtDumpMemoryLeaks(); |
| 748 #endif // _CRTDBG_MAP_ALLOC | 854 #endif // _CRTDBG_MAP_ALLOC |
| 749 #endif // OS_WIN | 855 #endif // OS_WIN |
| 750 | 856 |
| 857 #if defined(OS_MACOSX) |
| 858 autorelease_pool_.reset(NULL); |
| 859 #endif |
| 860 |
| 751 exit_manager_.reset(NULL); | 861 exit_manager_.reset(NULL); |
| 752 | 862 |
| 753 delegate_ = NULL; | 863 delegate_ = NULL; |
| 754 is_shutdown_ = true; | 864 is_shutdown_ = true; |
| 755 } | 865 } |
| 756 | 866 |
| 757 private: | 867 private: |
| 758 // True if the runner has been initialized. | 868 // True if the runner has been initialized. |
| 759 bool is_initialized_; | 869 bool is_initialized_; |
| 760 | 870 |
| 761 // True if the runner has been shut down. | 871 // True if the runner has been shut down. |
| 762 bool is_shutdown_; | 872 bool is_shutdown_; |
| 763 | 873 |
| 764 // True if basic startup was completed. | 874 // True if basic startup was completed. |
| 765 bool completed_basic_startup_; | 875 bool completed_basic_startup_; |
| 766 | 876 |
| 767 // Used if the embedder doesn't set one. | 877 // Used if the embedder doesn't set one. |
| 768 ContentClient empty_content_client_; | 878 ContentClient empty_content_client_; |
| 769 | 879 |
| 770 // The delegate will outlive this object. | 880 // The delegate will outlive this object. |
| 771 ContentMainDelegate* delegate_; | 881 ContentMainDelegate* delegate_; |
| 772 | 882 |
| 773 std::unique_ptr<base::AtExitManager> exit_manager_; | 883 std::unique_ptr<base::AtExitManager> exit_manager_; |
| 774 #if defined(OS_WIN) | 884 #if defined(OS_WIN) |
| 775 sandbox::SandboxInterfaceInfo sandbox_info_; | 885 sandbox::SandboxInterfaceInfo sandbox_info_; |
| 776 #elif defined(OS_MACOSX) | 886 #elif defined(OS_MACOSX) |
| 777 base::mac::ScopedNSAutoreleasePool* autorelease_pool_ = nullptr; | 887 std::unique_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; |
| 778 #endif | 888 #endif |
| 779 | 889 |
| 780 base::Closure* ui_task_; | 890 base::Closure* ui_task_; |
| 781 | 891 |
| 782 #if defined(USE_AURA) | 892 #if defined(USE_AURA) |
| 783 aura::Env::Mode env_mode_ = aura::Env::Mode::LOCAL; | 893 aura::Env::Mode env_mode_ = aura::Env::Mode::LOCAL; |
| 784 #endif | 894 #endif |
| 785 | 895 |
| 786 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 896 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 787 }; | 897 }; |
| 788 | 898 |
| 789 // static | 899 // static |
| 790 ContentMainRunner* ContentMainRunner::Create() { | 900 ContentMainRunner* ContentMainRunner::Create() { |
| 791 return new ContentMainRunnerImpl(); | 901 return new ContentMainRunnerImpl(); |
| 792 } | 902 } |
| 793 | 903 |
| 794 } // namespace content | 904 } // namespace content |
| OLD | NEW |