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

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

Issue 190853004: Convert ContentMain to take a struct instead of parameters that vary depending on the platform. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/app/content_main.cc ('k') | content/public/app/content_main.h » ('j') | 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 12 matching lines...) Expand all
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
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
536 #if defined(OS_WIN) 537 virtual int Initialize(const ContentMainParams& params) OVERRIDE {
537 virtual int Initialize(HINSTANCE instance, 538 #if defined(OS_WIN)
538 sandbox::SandboxInterfaceInfo* sandbox_info, 539 RegisterInvalidParamHandler();
539 ContentMainDelegate* delegate) OVERRIDE { 540 _Module.Init(NULL, static_cast<HINSTANCE>(params.instance));
540 // argc/argv are ignored on Windows; see command_line.h for details.
541 int argc = 0;
542 char** argv = NULL;
543 541
544 RegisterInvalidParamHandler(); 542 sandbox_info_ = *params.sandbox_info;
545 _Module.Init(NULL, static_cast<HINSTANCE>(instance));
546
547 sandbox_info_ = *sandbox_info;
548 #else // !OS_WIN 543 #else // !OS_WIN
549 virtual int Initialize(int argc,
550 const char** argv,
551 ContentMainDelegate* delegate) OVERRIDE {
552 544
553 #if defined(OS_ANDROID) 545 #if defined(OS_ANDROID)
554 // See note at the initialization of ExitManager, below; basically, 546 // See note at the initialization of ExitManager, below; basically,
555 // 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
556 // TRACE_EVENT right away. 548 // TRACE_EVENT right away.
557 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize"); 549 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize");
558 #endif // OS_ANDROID 550 #endif // OS_ANDROID
559 551
560 // NOTE(willchan): One might ask why these TCMalloc-related calls are done 552 // 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 553 // here rather than in process_util_linux.cc with the definition of
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 #endif // !OS_ANDROID && !OS_IOS 603 #endif // !OS_ANDROID && !OS_IOS
612 604
613 #if defined(OS_LINUX) || defined(OS_OPENBSD) 605 #if defined(OS_LINUX) || defined(OS_OPENBSD)
614 g_fds->Set(kCrashDumpSignal, 606 g_fds->Set(kCrashDumpSignal,
615 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); 607 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
616 #endif 608 #endif
617 609
618 #endif // !OS_WIN 610 #endif // !OS_WIN
619 611
620 is_initialized_ = true; 612 is_initialized_ = true;
621 delegate_ = delegate; 613 delegate_ = params.delegate;
622 614
623 base::EnableTerminationOnHeapCorruption(); 615 base::EnableTerminationOnHeapCorruption();
624 base::EnableTerminationOnOutOfMemory(); 616 base::EnableTerminationOnOutOfMemory();
625 617
626 // The exit manager is in charge of calling the dtors of singleton objects. 618 // The exit manager is in charge of calling the dtors of singleton objects.
627 // On Android, AtExitManager is set up when library is loaded. 619 // 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. 620 // 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 621 // 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. 622 // TRACE_EVENT methods on Linux or iOS builds till after we set this up.
631 #if !defined(OS_ANDROID) && !defined(OS_IOS) 623 #if !defined(OS_ANDROID) && !defined(OS_IOS)
632 exit_manager_.reset(new base::AtExitManager); 624 exit_manager_.reset(new base::AtExitManager);
633 #endif // !OS_ANDROID && !OS_IOS 625 #endif // !OS_ANDROID && !OS_IOS
634 626
635 #if defined(OS_MACOSX) 627 #if defined(OS_MACOSX)
636 // We need this pool for all the objects created before we get to the 628 // 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 629 // 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 630 // 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. 631 // its main event loop to get rid of the cruft.
640 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 632 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
641 #endif 633 #endif
642 634
643 // On Android, the command line is initialized when library is loaded and 635 // On Android, the command line is initialized when library is loaded and
644 // we have already started our TRACE_EVENT0. 636 // we have already started our TRACE_EVENT0.
645 #if !defined(OS_ANDROID) 637 #if !defined(OS_ANDROID)
638 // argc/argv are ignored on Windows and Android; see command_line.h for
639 // details.
640 int argc = 0;
641 const char** argv = NULL;
642
643 #if !defined(OS_WIN)
644 argc = params.argc;
645 argv = params.argv;
646 #endif
647
646 CommandLine::Init(argc, argv); 648 CommandLine::Init(argc, argv);
649
650 #if !defined(OS_IOS)
651 SetProcessTitleFromCommandLine(argv);
652 #endif
647 #endif // !OS_ANDROID 653 #endif // !OS_ANDROID
648 654
649 int exit_code; 655 int exit_code;
650 if (delegate && delegate->BasicStartupComplete(&exit_code)) 656 if (delegate_ && delegate_->BasicStartupComplete(&exit_code))
651 return exit_code; 657 return exit_code;
652 658
653 completed_basic_startup_ = true; 659 completed_basic_startup_ = true;
654 660
655 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 661 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
656 std::string process_type = 662 std::string process_type =
657 command_line.GetSwitchValueASCII(switches::kProcessType); 663 command_line.GetSwitchValueASCII(switches::kProcessType);
658 664
659 if (!GetContentClient()) 665 if (!GetContentClient())
660 SetContentClient(&empty_content_client_); 666 SetContentClient(&empty_content_client_);
(...skipping 21 matching lines...) Expand all
682 // management setup to be completed. 688 // management setup to be completed.
683 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize"); 689 TRACE_EVENT0("startup", "ContentMainRunnerImpl::Initialize");
684 #endif // !OS_ANDROID 690 #endif // !OS_ANDROID
685 691
686 #if defined(OS_MACOSX) && !defined(OS_IOS) 692 #if defined(OS_MACOSX) && !defined(OS_IOS)
687 // We need to allocate the IO Ports before the Sandbox is initialized or 693 // We need to allocate the IO Ports before the Sandbox is initialized or
688 // the first instance of PowerMonitor is created. 694 // the first instance of PowerMonitor is created.
689 // It's important not to allocate the ports for processes which don't 695 // It's important not to allocate the ports for processes which don't
690 // register with the power monitor - see crbug.com/88867. 696 // register with the power monitor - see crbug.com/88867.
691 if (process_type.empty() || 697 if (process_type.empty() ||
692 (delegate && 698 (delegate_ &&
693 delegate->ProcessRegistersWithSystemProcess(process_type))) { 699 delegate_->ProcessRegistersWithSystemProcess(process_type))) {
694 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); 700 base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
695 } 701 }
696 702
697 if (!process_type.empty() && 703 if (!process_type.empty() &&
698 (!delegate || delegate->ShouldSendMachPort(process_type))) { 704 (!delegate_ || delegate_->ShouldSendMachPort(process_type))) {
699 MachBroker::ChildSendTaskPortToParent(); 705 MachBroker::ChildSendTaskPortToParent();
700 } 706 }
701 #elif defined(OS_WIN) 707 #elif defined(OS_WIN)
702 if (command_line.HasSwitch(switches::kEnableHighResolutionTime)) 708 if (command_line.HasSwitch(switches::kEnableHighResolutionTime))
703 base::TimeTicks::SetNowIsHighResNowIfSupported(); 709 base::TimeTicks::SetNowIsHighResNowIfSupported();
704 710
705 // This must be done early enough since some helper functions like 711 // This must be done early enough since some helper functions like
706 // IsTouchEnabled, needed to load resources, may call into the theme dll. 712 // IsTouchEnabled, needed to load resources, may call into the theme dll.
707 EnableThemeSupportOnAllWindowStations(); 713 EnableThemeSupportOnAllWindowStations();
708 SetupCRT(command_line); 714 SetupCRT(command_line);
(...skipping 22 matching lines...) Expand all
731 #endif 737 #endif
732 738
733 ui::RegisterPathProvider(); 739 ui::RegisterPathProvider();
734 RegisterPathProvider(); 740 RegisterPathProvider();
735 RegisterContentSchemes(true); 741 RegisterContentSchemes(true);
736 742
737 CHECK(base::i18n::InitializeICU()); 743 CHECK(base::i18n::InitializeICU());
738 744
739 InitializeStatsTable(command_line); 745 InitializeStatsTable(command_line);
740 746
741 if (delegate) 747 if (delegate_)
742 delegate->PreSandboxStartup(); 748 delegate_->PreSandboxStartup();
743 749
744 // Set any custom user agent passed on the command line now so the string 750 // 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 751 // doesn't change between calls to webkit_glue::GetUserAgent(), otherwise it
746 // defaults to the user agent set during SetContentClient(). 752 // defaults to the user agent set during SetContentClient().
747 if (command_line.HasSwitch(switches::kUserAgent)) { 753 if (command_line.HasSwitch(switches::kUserAgent)) {
748 webkit_glue::SetUserAgent( 754 webkit_glue::SetUserAgent(
749 command_line.GetSwitchValueASCII(switches::kUserAgent)); 755 command_line.GetSwitchValueASCII(switches::kUserAgent));
750 } 756 }
751 757
752 if (!process_type.empty()) 758 if (!process_type.empty())
753 CommonSubprocessInit(process_type); 759 CommonSubprocessInit(process_type);
754 760
755 #if defined(OS_WIN) 761 #if defined(OS_WIN)
756 CHECK(InitializeSandbox(sandbox_info)); 762 CHECK(InitializeSandbox(params.sandbox_info));
757 #elif defined(OS_MACOSX) && !defined(OS_IOS) 763 #elif defined(OS_MACOSX) && !defined(OS_IOS)
758 if (process_type == switches::kRendererProcess || 764 if (process_type == switches::kRendererProcess ||
759 process_type == switches::kPpapiPluginProcess || 765 process_type == switches::kPpapiPluginProcess ||
760 (delegate && delegate->DelaySandboxInitialization(process_type))) { 766 (delegate_ && delegate_->DelaySandboxInitialization(process_type))) {
761 // On OS X the renderer sandbox needs to be initialized later in the 767 // On OS X the renderer sandbox needs to be initialized later in the
762 // startup sequence in RendererMainPlatformDelegate::EnableSandbox(). 768 // startup sequence in RendererMainPlatformDelegate::EnableSandbox().
763 } else { 769 } else {
764 CHECK(InitializeSandbox()); 770 CHECK(InitializeSandbox());
765 } 771 }
766 #endif 772 #endif
767 773
768 if (delegate) 774 if (delegate_)
769 delegate->SandboxInitialized(process_type); 775 delegate_->SandboxInitialized(process_type);
770
771 #if defined(OS_POSIX) && !defined(OS_IOS)
772 SetProcessTitleFromCommandLine(argv);
773 #endif
774 776
775 // Return -1 to indicate no early termination. 777 // Return -1 to indicate no early termination.
776 return -1; 778 return -1;
777 } 779 }
778 780
779 virtual int Run() OVERRIDE { 781 virtual int Run() OVERRIDE {
780 DCHECK(is_initialized_); 782 DCHECK(is_initialized_);
781 DCHECK(!is_shutdown_); 783 DCHECK(!is_shutdown_);
782 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 784 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
783 std::string process_type = 785 std::string process_type =
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 854
853 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 855 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
854 }; 856 };
855 857
856 // static 858 // static
857 ContentMainRunner* ContentMainRunner::Create() { 859 ContentMainRunner* ContentMainRunner::Create() {
858 return new ContentMainRunnerImpl(); 860 return new ContentMainRunnerImpl();
859 } 861 }
860 862
861 } // namespace content 863 } // namespace content
OLDNEW
« no previous file with comments | « content/app/content_main.cc ('k') | content/public/app/content_main.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698