OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/process/process_handle.h" | 23 #include "base/process/process_handle.h" |
24 #include "base/profiler/alternate_timer.h" | 24 #include "base/profiler/alternate_timer.h" |
25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
28 #include "content/browser/browser_main.h" | 28 #include "content/browser/browser_main.h" |
29 #include "content/browser/gpu/gpu_process_host.h" | 29 #include "content/browser/gpu/gpu_process_host.h" |
30 #include "content/common/set_process_title.h" | 30 #include "content/common/set_process_title.h" |
31 #include "content/common/url_schemes.h" | 31 #include "content/common/url_schemes.h" |
32 #include "content/gpu/in_process_gpu_thread.h" | 32 #include "content/gpu/in_process_gpu_thread.h" |
| 33 #include "content/public/app/content_main.h" |
33 #include "content/public/app/content_main_delegate.h" | 34 #include "content/public/app/content_main_delegate.h" |
34 #include "content/public/app/startup_helper_win.h" | 35 #include "content/public/app/startup_helper_win.h" |
35 #include "content/public/browser/content_browser_client.h" | 36 #include "content/public/browser/content_browser_client.h" |
36 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
37 #include "content/public/browser/utility_process_host.h" | 38 #include "content/public/browser/utility_process_host.h" |
38 #include "content/public/common/content_client.h" | 39 #include "content/public/common/content_client.h" |
39 #include "content/public/common/content_constants.h" | 40 #include "content/public/common/content_constants.h" |
40 #include "content/public/common/content_paths.h" | 41 #include "content/public/common/content_paths.h" |
41 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
42 #include "content/public/common/main_function_params.h" | 43 #include "content/public/common/main_function_params.h" |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 527 |
527 static void GetStatsThunk(char* buffer, int buffer_length) { | 528 static void GetStatsThunk(char* buffer, int buffer_length) { |
528 MallocExtension::instance()->GetStats(buffer, buffer_length); | 529 MallocExtension::instance()->GetStats(buffer, buffer_length); |
529 } | 530 } |
530 | 531 |
531 static void ReleaseFreeMemoryThunk() { | 532 static void ReleaseFreeMemoryThunk() { |
532 MallocExtension::instance()->ReleaseFreeMemory(); | 533 MallocExtension::instance()->ReleaseFreeMemory(); |
533 } | 534 } |
534 #endif | 535 #endif |
535 | 536 |
| 537 virtual int Initialize(ContentMainParams* params) OVERRIDE { |
536 #if defined(OS_WIN) | 538 #if defined(OS_WIN) |
537 virtual int Initialize(HINSTANCE instance, | |
538 sandbox::SandboxInterfaceInfo* sandbox_info, | |
539 ContentMainDelegate* delegate) OVERRIDE { | |
540 // argc/argv are ignored on Windows; see command_line.h for details. | 539 // argc/argv are ignored on Windows; see command_line.h for details. |
541 int argc = 0; | 540 int argc = 0; |
542 char** argv = NULL; | 541 char** argv = NULL; |
543 | 542 |
544 RegisterInvalidParamHandler(); | 543 RegisterInvalidParamHandler(); |
545 _Module.Init(NULL, static_cast<HINSTANCE>(instance)); | 544 _Module.Init(NULL, static_cast<HINSTANCE>(params->instance)); |
546 | 545 |
547 sandbox_info_ = *sandbox_info; | 546 sandbox_info_ = *params->sandbox_info; |
548 #else // !OS_WIN | 547 #else // !OS_WIN |
549 virtual int Initialize(int argc, | 548 virtual int Initialize(int argc, |
550 const char** argv, | 549 const char** argv, |
551 ContentMainDelegate* delegate) OVERRIDE { | 550 ContentMainDelegate* delegate) OVERRIDE { |
| 551 int argc = params->argc; |
| 552 char** argv = params->argv; |
552 | 553 |
553 #if defined(OS_ANDROID) | 554 #if defined(OS_ANDROID) |
554 // See note at the initialization of ExitManager, below; basically, | 555 // See note at the initialization of ExitManager, below; basically, |
555 // only Android builds have the ctor/dtor handlers set up to use | 556 // only Android builds have the ctor/dtor handlers set up to use |
556 // TRACE_EVENT right away. | 557 // TRACE_EVENT right away. |
557 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize"); | 558 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize"); |
558 #endif // OS_ANDROID | 559 #endif // OS_ANDROID |
559 | 560 |
560 // NOTE(willchan): One might ask why these TCMalloc-related calls are done | 561 // NOTE(willchan): One might ask why these TCMalloc-related calls are done |
561 // here rather than in process_util_linux.cc with the definition of | 562 // here rather than in process_util_linux.cc with the definition of |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 #endif // !OS_ANDROID && !OS_IOS | 612 #endif // !OS_ANDROID && !OS_IOS |
612 | 613 |
613 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 614 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
614 g_fds->Set(kCrashDumpSignal, | 615 g_fds->Set(kCrashDumpSignal, |
615 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); | 616 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); |
616 #endif | 617 #endif |
617 | 618 |
618 #endif // !OS_WIN | 619 #endif // !OS_WIN |
619 | 620 |
620 is_initialized_ = true; | 621 is_initialized_ = true; |
621 delegate_ = delegate; | 622 delegate_ = params->delegate; |
622 | 623 |
623 base::EnableTerminationOnHeapCorruption(); | 624 base::EnableTerminationOnHeapCorruption(); |
624 base::EnableTerminationOnOutOfMemory(); | 625 base::EnableTerminationOnOutOfMemory(); |
625 | 626 |
626 // The exit manager is in charge of calling the dtors of singleton objects. | 627 // The exit manager is in charge of calling the dtors of singleton objects. |
627 // On Android, AtExitManager is set up when library is loaded. | 628 // On Android, AtExitManager is set up when library is loaded. |
628 // On iOS, it's set up in main(), which can't call directly through to here. | 629 // On iOS, it's set up in main(), which can't call directly through to here. |
629 // A consequence of this is that you can't use the ctor/dtor-based | 630 // A consequence of this is that you can't use the ctor/dtor-based |
630 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. | 631 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. |
631 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 632 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
632 exit_manager_.reset(new base::AtExitManager); | 633 exit_manager_.reset(new base::AtExitManager); |
633 #endif // !OS_ANDROID && !OS_IOS | 634 #endif // !OS_ANDROID && !OS_IOS |
634 | 635 |
635 #if defined(OS_MACOSX) | 636 #if defined(OS_MACOSX) |
636 // We need this pool for all the objects created before we get to the | 637 // We need this pool for all the objects created before we get to the |
637 // event loop, but we don't want to leave them hanging around until the | 638 // event loop, but we don't want to leave them hanging around until the |
638 // app quits. Each "main" needs to flush this pool right before it goes into | 639 // app quits. Each "main" needs to flush this pool right before it goes into |
639 // its main event loop to get rid of the cruft. | 640 // its main event loop to get rid of the cruft. |
640 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 641 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
641 #endif | 642 #endif |
642 | 643 |
643 // On Android, the command line is initialized when library is loaded and | 644 // On Android, the command line is initialized when library is loaded and |
644 // we have already started our TRACE_EVENT0. | 645 // we have already started our TRACE_EVENT0. |
645 #if !defined(OS_ANDROID) | 646 #if !defined(OS_ANDROID) |
646 CommandLine::Init(argc, argv); | 647 CommandLine::Init(argc, argv); |
647 #endif // !OS_ANDROID | 648 #endif // !OS_ANDROID |
648 | 649 |
649 int exit_code; | 650 int exit_code; |
650 if (delegate && delegate->BasicStartupComplete(&exit_code)) | 651 if (delegate_ && delegate_->BasicStartupComplete(&exit_code)) |
651 return exit_code; | 652 return exit_code; |
652 | 653 |
653 completed_basic_startup_ = true; | 654 completed_basic_startup_ = true; |
654 | 655 |
655 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 656 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
656 std::string process_type = | 657 std::string process_type = |
657 command_line.GetSwitchValueASCII(switches::kProcessType); | 658 command_line.GetSwitchValueASCII(switches::kProcessType); |
658 | 659 |
659 if (!GetContentClient()) | 660 if (!GetContentClient()) |
660 SetContentClient(&empty_content_client_); | 661 SetContentClient(&empty_content_client_); |
(...skipping 21 matching lines...) Expand all Loading... |
682 // management setup to be completed. | 683 // management setup to be completed. |
683 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize"); | 684 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize"); |
684 #endif // !OS_ANDROID | 685 #endif // !OS_ANDROID |
685 | 686 |
686 #if defined(OS_MACOSX) && !defined(OS_IOS) | 687 #if defined(OS_MACOSX) && !defined(OS_IOS) |
687 // We need to allocate the IO Ports before the Sandbox is initialized or | 688 // We need to allocate the IO Ports before the Sandbox is initialized or |
688 // the first instance of PowerMonitor is created. | 689 // the first instance of PowerMonitor is created. |
689 // It's important not to allocate the ports for processes which don't | 690 // It's important not to allocate the ports for processes which don't |
690 // register with the power monitor - see crbug.com/88867. | 691 // register with the power monitor - see crbug.com/88867. |
691 if (process_type.empty() || | 692 if (process_type.empty() || |
692 (delegate && | 693 (delegate_ && |
693 delegate->ProcessRegistersWithSystemProcess(process_type))) { | 694 delegate_->ProcessRegistersWithSystemProcess(process_type))) { |
694 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 695 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
695 } | 696 } |
696 | 697 |
697 if (!process_type.empty() && | 698 if (!process_type.empty() && |
698 (!delegate || delegate->ShouldSendMachPort(process_type))) { | 699 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) { |
699 MachBroker::ChildSendTaskPortToParent(); | 700 MachBroker::ChildSendTaskPortToParent(); |
700 } | 701 } |
701 #elif defined(OS_WIN) | 702 #elif defined(OS_WIN) |
702 if (command_line.HasSwitch(switches::kEnableHighResolutionTime)) | 703 if (command_line.HasSwitch(switches::kEnableHighResolutionTime)) |
703 base::TimeTicks::SetNowIsHighResNowIfSupported(); | 704 base::TimeTicks::SetNowIsHighResNowIfSupported(); |
704 | 705 |
705 // This must be done early enough since some helper functions like | 706 // This must be done early enough since some helper functions like |
706 // IsTouchEnabled, needed to load resources, may call into the theme dll. | 707 // IsTouchEnabled, needed to load resources, may call into the theme dll. |
707 EnableThemeSupportOnAllWindowStations(); | 708 EnableThemeSupportOnAllWindowStations(); |
708 SetupCRT(command_line); | 709 SetupCRT(command_line); |
(...skipping 22 matching lines...) Expand all Loading... |
731 #endif | 732 #endif |
732 | 733 |
733 ui::RegisterPathProvider(); | 734 ui::RegisterPathProvider(); |
734 RegisterPathProvider(); | 735 RegisterPathProvider(); |
735 RegisterContentSchemes(true); | 736 RegisterContentSchemes(true); |
736 | 737 |
737 CHECK(base::i18n::InitializeICU()); | 738 CHECK(base::i18n::InitializeICU()); |
738 | 739 |
739 InitializeStatsTable(command_line); | 740 InitializeStatsTable(command_line); |
740 | 741 |
741 if (delegate) | 742 if (delegate_) |
742 delegate->PreSandboxStartup(); | 743 delegate_->PreSandboxStartup(); |
743 | 744 |
744 // Set any custom user agent passed on the command line now so the string | 745 // Set any custom user agent passed on the command line now so the string |
745 // doesn't change between calls to webkit_glue::GetUserAgent(), otherwise it | 746 // doesn't change between calls to webkit_glue::GetUserAgent(), otherwise it |
746 // defaults to the user agent set during SetContentClient(). | 747 // defaults to the user agent set during SetContentClient(). |
747 if (command_line.HasSwitch(switches::kUserAgent)) { | 748 if (command_line.HasSwitch(switches::kUserAgent)) { |
748 webkit_glue::SetUserAgent( | 749 webkit_glue::SetUserAgent( |
749 command_line.GetSwitchValueASCII(switches::kUserAgent)); | 750 command_line.GetSwitchValueASCII(switches::kUserAgent)); |
750 } | 751 } |
751 | 752 |
752 if (!process_type.empty()) | 753 if (!process_type.empty()) |
753 CommonSubprocessInit(process_type); | 754 CommonSubprocessInit(process_type); |
754 | 755 |
755 #if defined(OS_WIN) | 756 #if defined(OS_WIN) |
756 CHECK(InitializeSandbox(sandbox_info)); | 757 CHECK(InitializeSandbox(params->sandbox_info)); |
757 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 758 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
758 if (process_type == switches::kRendererProcess || | 759 if (process_type == switches::kRendererProcess || |
759 process_type == switches::kPpapiPluginProcess || | 760 process_type == switches::kPpapiPluginProcess || |
760 (delegate && delegate->DelaySandboxInitialization(process_type))) { | 761 (delegate_ && delegate_->DelaySandboxInitialization(process_type))) { |
761 // On OS X the renderer sandbox needs to be initialized later in the | 762 // On OS X the renderer sandbox needs to be initialized later in the |
762 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). | 763 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). |
763 } else { | 764 } else { |
764 CHECK(InitializeSandbox()); | 765 CHECK(InitializeSandbox()); |
765 } | 766 } |
766 #endif | 767 #endif |
767 | 768 |
768 if (delegate) | 769 if (delegate_) |
769 delegate->SandboxInitialized(process_type); | 770 delegate_->SandboxInitialized(process_type); |
770 | 771 |
771 #if defined(OS_POSIX) && !defined(OS_IOS) | 772 #if defined(OS_POSIX) && !defined(OS_IOS) |
772 SetProcessTitleFromCommandLine(argv); | 773 SetProcessTitleFromCommandLine(argv); |
773 #endif | 774 #endif |
774 | 775 |
775 // Return -1 to indicate no early termination. | 776 // Return -1 to indicate no early termination. |
776 return -1; | 777 return -1; |
777 } | 778 } |
778 | 779 |
779 virtual int Run() OVERRIDE { | 780 virtual int Run() OVERRIDE { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 853 |
853 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 854 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
854 }; | 855 }; |
855 | 856 |
856 // static | 857 // static |
857 ContentMainRunner* ContentMainRunner::Create() { | 858 ContentMainRunner* ContentMainRunner::Create() { |
858 return new ContentMainRunnerImpl(); | 859 return new ContentMainRunnerImpl(); |
859 } | 860 } |
860 | 861 |
861 } // namespace content | 862 } // namespace content |
OLD | NEW |