diff options
author | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-21 19:13:31 +0000 |
---|---|---|
committer | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-21 19:13:31 +0000 |
commit | 50462bf085b6504b0fe0d947664348870b0f26c7 (patch) | |
tree | 94474e4a310b97410ef4a449edd7d31d8d629abc | |
parent | 3a08f3fcd05e5f4b703b043ee1a7ff48cc4c86f4 (diff) | |
download | chromium_src-50462bf085b6504b0fe0d947664348870b0f26c7.zip chromium_src-50462bf085b6504b0fe0d947664348870b0f26c7.tar.gz chromium_src-50462bf085b6504b0fe0d947664348870b0f26c7.tar.bz2 |
Add ChromeBrowserMainExtraParts for non main parts. (take 3)
This was originally submitted as http://codereview.chromium.org/8539038/ which was reverted because of a failing test on win.
This reverts the code back to a single instance of BrowserMainParts, with auxillary parts (Gtk, Views, Aura, Touch) implemented from a new base class, ChromeBrowserParts, which has a Chrome specific interface, allowing initialization to be better subdivided.
This should fix the notifications auto tests.
This CL also addresses the test failure on win (and a test failure on linux_chromeos triggered by the windows fix).
BUG=103821
TEST=Make sure all tests and autotests run
TBR=jam@chromium.org
Review URL: http://codereview.chromium.org/8480032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110972 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 379 insertions, 371 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 8ba3c3ef..f8a5d8b 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -32,6 +32,7 @@ #include "chrome/browser/background/background_mode_manager.h" #include "chrome/browser/browser_process_impl.h" #include "chrome/browser/browser_shutdown.h" +#include "chrome/browser/chrome_browser_main_extra_parts.h" #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/default_apps_trial.h" #include "chrome/browser/extensions/extension_protocols.h" @@ -558,13 +559,6 @@ void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line, } } -#else - -void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line, - Profile* profile) { - // Dummy empty function for non-ChromeOS builds to avoid extra ifdefs below. -} - #endif // defined(OS_CHROMEOS) #if defined(OS_MACOSX) @@ -685,6 +679,9 @@ ChromeBrowserMainParts::ChromeBrowserMainParts( } ChromeBrowserMainParts::~ChromeBrowserMainParts() { + for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) + delete chrome_extra_parts_[i]; + chrome_extra_parts_.clear(); } // This will be called after the command-line has been mutated by about:flags @@ -1166,23 +1163,38 @@ DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { } #endif +// content::BrowserMainParts implementation ------------------------------------ + void ChromeBrowserMainParts::PreEarlyInitialization() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PreEarlyInitialization(); } void ChromeBrowserMainParts::PostEarlyInitialization() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostEarlyInitialization(); } void ChromeBrowserMainParts::ToolkitInitialized() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->ToolkitInitialized(); } void ChromeBrowserMainParts::PreMainMessageLoopStart() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PreMainMessageLoopStart(); } void ChromeBrowserMainParts::PostMainMessageLoopStart() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostMainMessageLoopStart(); } void ChromeBrowserMainParts::PreMainMessageLoopRun() { result_code_ = PreMainMessageLoopRunImpl(); + + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PreMainMessageLoopRun(); } int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { @@ -1496,6 +1508,10 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { SetBrowserX11ErrorHandlers(); #endif + // Desktop construction occurs here, (required before profile creation). + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostBrowserProcessInit(); + // Profile creation ---------------------------------------------------------- #if defined(OS_CHROMEOS) @@ -1561,6 +1577,11 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( profile_->GetTokenService()); } + + // Tests should be able to tune login manager before showing it. + // Thus only show login manager in normal (non-testing) mode. + if (!parameters().ui_task) + OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); #endif #if !defined(OS_MACOSX) @@ -1609,6 +1630,11 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { } #endif + // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized(). + // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts). + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostProfileInitialized(); + // Show the First Run UI if this is the first time Chrome has been run on // this computer, or we're being compelled to do so by a command line flag. // Note that this be done _after_ the PrefService is initialized and all @@ -1834,20 +1860,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { NaClProcessHost::EarlyStartup(); #endif - run_message_loop_ = true; - return content::RESULT_CODE_NORMAL_EXIT; -} - -// Called from MainMessageLoopRun(). -void ChromeBrowserMainParts::StartBrowserOrUITask() { - // Still initializing, so need to allow IO. - base::ThreadRestrictions::ScopedAllowIO allow_io; - - // Tests should be able to tune login manager before showing it. - // Thus only show login manager in normal (non-testing) mode. - if (!parameters().ui_task) - OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); - if (parameters().ui_task) { // We are in test mode. Run one task and enter the main message loop. #if defined(OS_MACOSX) @@ -1917,18 +1929,13 @@ void ChromeBrowserMainParts::StartBrowserOrUITask() { } } browser_init_.reset(); + return result_code_; } bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { // Set the result code set in PreMainMessageLoopRun or set above. *result_code = result_code_; - // TODO(stevenjb): Move this to another phase, and/or clean up - // PreMainMessageLoopRun() so that this can happen after desktop - // initilaization and before running the main loop. - if (run_message_loop_) - StartBrowserOrUITask(); - if (!run_message_loop_) return true; // Don't run the default message loop. @@ -2050,8 +2057,19 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() { // to bypass this code. Perhaps we need a *final* hook that is called on all // paths from content/browser/browser_main. CHECK(MetricsService::UmaMetricsProperlyShutdown()); + + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostMainMessageLoopRun(); } +// Public members: + +void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { + chrome_extra_parts_.push_back(parts); +} + +// Misc ------------------------------------------------------------------------ + // This code is specific to the Windows-only PreReadExperiment field-trial. void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { DCHECK(name != NULL); diff --git a/chrome/browser/chrome_browser_main.h b/chrome/browser/chrome_browser_main.h index 867b14c..806af87 100644 --- a/chrome/browser/chrome_browser_main.h +++ b/chrome/browser/chrome_browser_main.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" #include "base/metrics/field_trial.h" #include "base/tracked_objects.h" #include "chrome/browser/first_run/first_run.h" @@ -17,6 +18,7 @@ class BrowserInit; class BrowserProcessImpl; +class ChromeBrowserMainExtraParts; class FieldTrialSynchronizer; class HistogramSynchronizer; class MetricsService; @@ -43,23 +45,14 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { public: virtual ~ChromeBrowserMainParts(); - // Constructs metrics service and does related initialization, including - // creation of field trials. Call only after labs have been converted to - // switches. - MetricsService* SetupMetricsAndFieldTrials(PrefService* local_state); - - const content::MainFunctionParams& parameters() const { - return parameters_; - } - const CommandLine& parsed_command_line() const { - return parsed_command_line_; - } + // Add additional ChromeBrowserMainExtraParts. + virtual void AddParts(ChromeBrowserMainExtraParts* parts); protected: explicit ChromeBrowserMainParts( const content::MainFunctionParams& parameters); - // content::BrowserParts overrides + // content::BrowserMainParts overrides. virtual void PreEarlyInitialization() OVERRIDE; virtual void PostEarlyInitialization() OVERRIDE; virtual void ToolkitInitialized() OVERRIDE; @@ -72,6 +65,15 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { // Displays a warning message that we can't find any locale data files. virtual void ShowMissingLocaleMessageBox() = 0; + const content::MainFunctionParams& parameters() const { + return parameters_; + } + const CommandLine& parsed_command_line() const { + return parsed_command_line_; + } + + Profile* profile() { return profile_; } + private: // Methods for |EarlyInitialization()| --------------------------------------- @@ -104,6 +106,11 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- + // Constructs metrics service and does related initialization, including + // creation of field trials. Call only after labs have been converted to + // switches. + MetricsService* SetupMetricsAndFieldTrials(PrefService* local_state); + static MetricsService* InitializeMetrics( const CommandLine& parsed_command_line, const PrefService* local_state); @@ -115,7 +122,6 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { // Methods for Main Message Loop ------------------------------------------- int PreMainMessageLoopRunImpl(); - void StartBrowserOrUITask(); // Members initialized on construction --------------------------------------- @@ -137,6 +143,10 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { // SetupMetricsAndFieldTrials is called. scoped_ptr<base::FieldTrialList> field_trial_list_; + // Vector of additional ChromeBrowserMainExtraParts. + // Parts are deleted in the inverse order they are added. + std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_; + // Members initialized after / released before main_message_loop_ ------------ scoped_ptr<BrowserInit> browser_init_; diff --git a/chrome/browser/chrome_browser_main_extra_parts.cc b/chrome/browser/chrome_browser_main_extra_parts.cc new file mode 100644 index 0000000..3188931 --- /dev/null +++ b/chrome/browser/chrome_browser_main_extra_parts.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chrome_browser_main_extra_parts.h" + +ChromeBrowserMainExtraParts::ChromeBrowserMainExtraParts() { +} + +ChromeBrowserMainExtraParts::~ChromeBrowserMainExtraParts() { +} + +void ChromeBrowserMainExtraParts::PreEarlyInitialization() { +} + +void ChromeBrowserMainExtraParts::PostEarlyInitialization() { +} + +void ChromeBrowserMainExtraParts::PreMainMessageLoopStart() { +} + +void ChromeBrowserMainExtraParts::PostMainMessageLoopStart() { +} + +void ChromeBrowserMainExtraParts::ToolkitInitialized() { +} + +void ChromeBrowserMainExtraParts::PostBrowserProcessInit() { +} + +void ChromeBrowserMainExtraParts::PostProfileInitialized() { +} + +void ChromeBrowserMainExtraParts::PreMainMessageLoopRun() { +} + +void ChromeBrowserMainExtraParts::PostMainMessageLoopRun() { +} diff --git a/chrome/browser/chrome_browser_main_extra_parts.h b/chrome/browser/chrome_browser_main_extra_parts.h new file mode 100644 index 0000000..a839d44 --- /dev/null +++ b/chrome/browser/chrome_browser_main_extra_parts.h @@ -0,0 +1,44 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_H_ +#define CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +// Interface class for Parts owned by ChromeBrowserMainParts. +// The default implementation for all methods is empty. + +// Most of these map to content::BrowserMainParts methods. This interface is +// separate to allow stages to be further subdivided for Chrome specific +// initialization stages (e.g. browser process init, profile init). + +class ChromeBrowserMainExtraParts { + public: + ChromeBrowserMainExtraParts(); + virtual ~ChromeBrowserMainExtraParts(); + + // EarlyInitialization methods. + virtual void PreEarlyInitialization(); + virtual void PostEarlyInitialization(); + + // PreMainMessageLoopStart methods. + virtual void PreMainMessageLoopStart(); + virtual void PostMainMessageLoopStart(); + + // ToolkitInitialized methods. + virtual void ToolkitInitialized(); + + // MainMessageLoopRun methods. + virtual void PostBrowserProcessInit(); + virtual void PostProfileInitialized(); + virtual void PreMainMessageLoopRun(); + virtual void PostMainMessageLoopRun(); + + private: + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraParts); +}; + +#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_H_ diff --git a/chrome/browser/chrome_browser_parts_aura.cc b/chrome/browser/chrome_browser_main_extra_parts_aura.cc index a2907e1..ea5214f 100644 --- a/chrome/browser/chrome_browser_parts_aura.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_aura.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chrome_browser_parts_aura.h" +#include "chrome/browser/chrome_browser_main_extra_parts_aura.h" #include "chrome/browser/ui/views/aura/chrome_shell_delegate.h" #include "ui/aura/desktop.h" #include "ui/aura_shell/shell.h" @@ -11,26 +11,11 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #endif -ChromeBrowserPartsAura::ChromeBrowserPartsAura() - : content::BrowserMainParts() { +ChromeBrowserMainExtraPartsAura::ChromeBrowserMainExtraPartsAura() + : ChromeBrowserMainExtraParts() { } -void ChromeBrowserPartsAura::PreEarlyInitialization() { -} - -void ChromeBrowserPartsAura::PostEarlyInitialization() { -} - -void ChromeBrowserPartsAura::ToolkitInitialized() { -} - -void ChromeBrowserPartsAura::PreMainMessageLoopStart() { -} - -void ChromeBrowserPartsAura::PostMainMessageLoopStart() { -} - -void ChromeBrowserPartsAura::PreMainMessageLoopRun() { +void ChromeBrowserMainExtraPartsAura::PostBrowserProcessInit() { #if defined(OS_CHROMEOS) if (chromeos::system::runtime_environment::IsRunningOnChromeOS()) aura::Desktop::set_use_fullscreen_host_window(true); @@ -39,10 +24,3 @@ void ChromeBrowserPartsAura::PreMainMessageLoopRun() { // Shell takes ownership of ChromeShellDelegate. aura_shell::Shell::CreateInstance(new ChromeShellDelegate); } - -bool ChromeBrowserPartsAura::MainMessageLoopRun(int* result_code) { - return false; -} - -void ChromeBrowserPartsAura::PostMainMessageLoopRun() { -} diff --git a/chrome/browser/chrome_browser_main_extra_parts_aura.h b/chrome/browser/chrome_browser_main_extra_parts_aura.h new file mode 100644 index 0000000..2af4a18 --- /dev/null +++ b/chrome/browser/chrome_browser_main_extra_parts_aura.h @@ -0,0 +1,22 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_AURA_H_ +#define CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_AURA_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/chrome_browser_main_extra_parts.h" + +class ChromeBrowserMainExtraPartsAura : public ChromeBrowserMainExtraParts { + public: + ChromeBrowserMainExtraPartsAura(); + + virtual void PostBrowserProcessInit() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAura); +}; + +#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_AURA_H_ diff --git a/chrome/browser/chrome_browser_parts_gtk.cc b/chrome/browser/chrome_browser_main_extra_parts_gtk.cc index 3d1a5aa..406d3ec 100644 --- a/chrome/browser/chrome_browser_parts_gtk.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_gtk.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chrome_browser_parts_gtk.h" +#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h" #include <gtk/gtk.h> @@ -14,37 +14,16 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/gtk_util.h" -ChromeBrowserPartsGtk::ChromeBrowserPartsGtk() - : content::BrowserMainParts() { +ChromeBrowserMainExtraPartsGtk::ChromeBrowserMainExtraPartsGtk() + : ChromeBrowserMainExtraParts() { } -void ChromeBrowserPartsGtk::PreEarlyInitialization() { +void ChromeBrowserMainExtraPartsGtk::PreEarlyInitialization() { DetectRunningAsRoot(); } -void ChromeBrowserPartsGtk::PostEarlyInitialization() { -} - -void ChromeBrowserPartsGtk::ToolkitInitialized() { -} - -void ChromeBrowserPartsGtk::PreMainMessageLoopStart() { -} - -void ChromeBrowserPartsGtk::PostMainMessageLoopStart() { -} - -void ChromeBrowserPartsGtk::PreMainMessageLoopRun() { -} - -bool ChromeBrowserPartsGtk::MainMessageLoopRun(int* result_code) { - return false; -} - -void ChromeBrowserPartsGtk::PostMainMessageLoopRun() { -} -void ChromeBrowserPartsGtk::DetectRunningAsRoot() { +void ChromeBrowserMainExtraPartsGtk::DetectRunningAsRoot() { if (geteuid() == 0) { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kUserDataDir)) @@ -86,7 +65,7 @@ void ChromeBrowserPartsGtk::DetectRunningAsRoot() { } // static -void ChromeBrowserPartsGtk::ShowMessageBox(const char* message) { +void ChromeBrowserMainExtraPartsGtk::ShowMessageBox(const char* message) { GtkWidget* dialog = gtk_message_dialog_new( NULL, static_cast<GtkDialogFlags>(0), diff --git a/chrome/browser/chrome_browser_main_extra_parts_gtk.h b/chrome/browser/chrome_browser_main_extra_parts_gtk.h new file mode 100644 index 0000000..34b596f --- /dev/null +++ b/chrome/browser/chrome_browser_main_extra_parts_gtk.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Contains functions used by BrowserMain() that are gtk-specific. + +#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_GTK_H_ +#define CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_GTK_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "chrome/browser/chrome_browser_main_extra_parts.h" + +class ChromeBrowserMainExtraPartsGtk : public ChromeBrowserMainExtraParts { + public: + ChromeBrowserMainExtraPartsGtk(); + + virtual void PreEarlyInitialization() OVERRIDE; + + static void ShowMessageBox(const char* message); + + private: + void DetectRunningAsRoot(); +}; + +#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_GTK_H_ diff --git a/chrome/browser/chrome_browser_parts_touch.cc b/chrome/browser/chrome_browser_main_extra_parts_touch.cc index 506cf1d..bfaa919 100644 --- a/chrome/browser/chrome_browser_parts_touch.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_touch.cc @@ -2,19 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chrome_browser_parts_touch.h" +#include "chrome/browser/chrome_browser_main_extra_parts_touch.h" #include "chrome/browser/ui/touch/sensors/screen_orientation_listener.h" -ChromeBrowserPartsTouch::ChromeBrowserPartsTouch() - : content::BrowserMainParts() { +ChromeBrowserMainExtraPartsTouch::ChromeBrowserMainExtraPartsTouch() + : ChromeBrowserMainExtraParts() { } -void ChromeBrowserPartsTouch::PreMainMessageLoopRun() { +void ChromeBrowserMainExtraPartsTouch::PreMainMessageLoopRun() { // Make sure the singleton ScreenOrientationListener object is created. ScreenOrientationListener::GetInstance(); } - -bool ChromeBrowserPartsTouch::MainMessageLoopRun(int* result_code) { - return false; -} diff --git a/chrome/browser/chrome_browser_main_extra_parts_touch.h b/chrome/browser/chrome_browser_main_extra_parts_touch.h new file mode 100644 index 0000000..603a750 --- /dev/null +++ b/chrome/browser/chrome_browser_main_extra_parts_touch.h @@ -0,0 +1,22 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_TOUCH_H_ +#define CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_TOUCH_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/chrome_browser_main_extra_parts.h" + +class ChromeBrowserMainExtraPartsTouch : public ChromeBrowserMainExtraParts { + public: + ChromeBrowserMainExtraPartsTouch(); + + virtual void PreMainMessageLoopRun() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsTouch); +}; + +#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_TOUCH_H_ diff --git a/chrome/browser/chrome_browser_parts_views.cc b/chrome/browser/chrome_browser_main_extra_parts_views.cc index 328eb7c..af505df 100644 --- a/chrome/browser/chrome_browser_parts_views.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_views.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chrome_browser_parts_views.h" +#include "chrome/browser/chrome_browser_main_extra_parts_views.h" #include <string> @@ -11,11 +11,11 @@ #include "chrome/common/chrome_switches.h" #include "views/widget/widget.h" -ChromeBrowserPartsViews::ChromeBrowserPartsViews() - : content::BrowserMainParts() { +ChromeBrowserMainExtraPartsViews::ChromeBrowserMainExtraPartsViews() + : ChromeBrowserMainExtraParts() { } -void ChromeBrowserPartsViews::ToolkitInitialized() { +void ChromeBrowserMainExtraPartsViews::ToolkitInitialized() { // The delegate needs to be set before any UI is created so that windows // display the correct icon. if (!views::ViewsDelegate::views_delegate) @@ -25,10 +25,3 @@ void ChromeBrowserPartsViews::ToolkitInitialized() { if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugViewsPaint)) views::Widget::SetDebugPaintEnabled(true); } - -void ChromeBrowserPartsViews::PreMainMessageLoopRun() { -} - -bool ChromeBrowserPartsViews::MainMessageLoopRun(int* result_code) { - return false; -} diff --git a/chrome/browser/chrome_browser_main_extra_parts_views.h b/chrome/browser/chrome_browser_main_extra_parts_views.h new file mode 100644 index 0000000..6ac14c7 --- /dev/null +++ b/chrome/browser/chrome_browser_main_extra_parts_views.h @@ -0,0 +1,21 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Contains functions used by BrowserMain() that are views-specific. + +#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_VIEWS_H_ +#define CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_VIEWS_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "chrome/browser/chrome_browser_main_extra_parts.h" + +class ChromeBrowserMainExtraPartsViews : public ChromeBrowserMainExtraParts { + public: + ChromeBrowserMainExtraPartsViews(); + + virtual void ToolkitInitialized() OVERRIDE; +}; + +#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_EXTRA_PARTS_VIEWS_H_ diff --git a/chrome/browser/chrome_browser_main_linux.cc b/chrome/browser/chrome_browser_main_linux.cc index 9abc2ca..4900de6 100644 --- a/chrome/browser/chrome_browser_main_linux.cc +++ b/chrome/browser/chrome_browser_main_linux.cc @@ -5,7 +5,7 @@ #include "chrome/browser/chrome_browser_main_linux.h" #if defined(TOOLKIT_USES_GTK) -#include "chrome/browser/chrome_browser_parts_gtk.h" +#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h" #endif ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( @@ -18,7 +18,7 @@ void ChromeBrowserMainPartsLinux::ShowMissingLocaleMessageBox() { // This should never happen on Aura. NOTREACHED() << chrome_browser::kMissingLocaleDataMessage; #elif defined(TOOLKIT_USES_GTK) - ChromeBrowserPartsGtk::ShowMessageBox( + ChromeBrowserMainExtraPartsGtk::ShowMessageBox( chrome_browser::kMissingLocaleDataMessage); #else #error "Need MessageBox implementation for linux without Aura or Gtk" diff --git a/chrome/browser/chrome_browser_main_unittest.cc b/chrome/browser/chrome_browser_main_unittest.cc index 4a2f265..f5c549b 100644 --- a/chrome/browser/chrome_browser_main_unittest.cc +++ b/chrome/browser/chrome_browser_main_unittest.cc @@ -30,12 +30,9 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { scoped_ptr<content::MainFunctionParams> params( new content::MainFunctionParams(command_line_)); - ScopedVector<content::BrowserMainParts> bwv; - content::GetContentClient()->browser()->CreateBrowserMainParts( - *params, &(bwv.get())); - ChromeBrowserMainParts* cbw = NULL; - if (bwv.size() >= 1) - cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); + scoped_ptr<content::BrowserMainParts> bw( + content::GetContentClient()->browser()->CreateBrowserMainParts(*params)); + ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get()); EXPECT_TRUE(cbw); if (cbw) { cbw->WarmConnectionFieldTrial(); @@ -46,12 +43,9 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) { scoped_ptr<content::MainFunctionParams> params( new content::MainFunctionParams(command_line_)); - ScopedVector<content::BrowserMainParts> bwv; - content::GetContentClient()->browser()->CreateBrowserMainParts( - *params, &(bwv.get())); - ChromeBrowserMainParts* cbw = NULL; - if (bwv.size() >= 1) - cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); + scoped_ptr<content::BrowserMainParts> bw( + content::GetContentClient()->browser()->CreateBrowserMainParts(*params)); + ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get()); EXPECT_TRUE(cbw); if (cbw) { const int kNumRuns = 1000; @@ -71,17 +65,15 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) { new content::MainFunctionParams(command_line_)); // This test ends up launching a new process, and that doesn't initialize the // ContentClient interfaces. - ScopedVector<content::BrowserMainParts> bwv; + scoped_ptr<content::BrowserMainParts> bw; if (content::GetContentClient()) { - content::GetContentClient()->browser()->CreateBrowserMainParts( - *params, &(bwv.get())); + bw.reset(content::GetContentClient()->browser()->CreateBrowserMainParts( + *params)); } else { chrome::ChromeContentBrowserClient ccbc; - ccbc.CreateBrowserMainParts(*params, &(bwv.get())); + bw.reset(ccbc.CreateBrowserMainParts(*params)); } - ChromeBrowserMainParts* cbw = NULL; - if (bwv.size() >= 1) - cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); + ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get()); EXPECT_TRUE(cbw); if (cbw) { #if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) diff --git a/chrome/browser/chrome_browser_parts_aura.h b/chrome/browser/chrome_browser_parts_aura.h deleted file mode 100644 index dbc9d76..0000000 --- a/chrome/browser/chrome_browser_parts_aura.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROME_BROWSER_PARTS_AURA_H_ -#define CHROME_BROWSER_CHROME_BROWSER_PARTS_AURA_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "content/public/browser/browser_main_parts.h" - -class ChromeBrowserPartsAura : public content::BrowserMainParts { - public: - ChromeBrowserPartsAura(); - - virtual void PreEarlyInitialization() OVERRIDE; - virtual void PostEarlyInitialization() OVERRIDE; - virtual void ToolkitInitialized() OVERRIDE; - virtual void PreMainMessageLoopStart() OVERRIDE; - virtual void PostMainMessageLoopStart() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(ChromeBrowserPartsAura); -}; - -#endif // CHROME_BROWSER_CHROME_BROWSER_PARTS_AURA_H_ diff --git a/chrome/browser/chrome_browser_parts_gtk.h b/chrome/browser/chrome_browser_parts_gtk.h deleted file mode 100644 index e824f3c..0000000 --- a/chrome/browser/chrome_browser_parts_gtk.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Contains functions used by BrowserMain() that are gtk-specific. - -#ifndef CHROME_BROWSER_CHROME_BROWSER_PARTS_GTK_H_ -#define CHROME_BROWSER_CHROME_BROWSER_PARTS_GTK_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "content/public/browser/browser_main_parts.h" - -class ChromeBrowserPartsGtk : public content::BrowserMainParts { - public: - ChromeBrowserPartsGtk(); - - virtual void PreEarlyInitialization() OVERRIDE; - virtual void PostEarlyInitialization() OVERRIDE; - virtual void ToolkitInitialized() OVERRIDE; - virtual void PreMainMessageLoopStart() OVERRIDE; - virtual void PostMainMessageLoopStart() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE; - - static void ShowMessageBox(const char* message); - - private: - void DetectRunningAsRoot(); -}; - -#endif // CHROME_BROWSER_CHROME_BROWSER_PARTS_GTK_H_ diff --git a/chrome/browser/chrome_browser_parts_touch.h b/chrome/browser/chrome_browser_parts_touch.h deleted file mode 100644 index 0cd9502..0000000 --- a/chrome/browser/chrome_browser_parts_touch.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROME_BROWSER_PARTS_TOUCH_H_ -#define CHROME_BROWSER_CHROME_BROWSER_PARTS_TOUCH_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "content/public/browser/browser_main_parts.h" - -class ChromeBrowserPartsTouch : public content::BrowserMainParts { - public: - ChromeBrowserPartsTouch(); - - virtual void PreEarlyInitialization() OVERRIDE {} - virtual void PostEarlyInitialization() OVERRIDE {} - virtual void PreMainMessageLoopStart() OVERRIDE {} - virtual void ToolkitInitialized() OVERRIDE {} - virtual void PostMainMessageLoopStart() OVERRIDE {} - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE {} - - private: - DISALLOW_COPY_AND_ASSIGN(ChromeBrowserPartsTouch); -}; - -#endif // CHROME_BROWSER_CHROME_BROWSER_PARTS_TOUCH_H_ diff --git a/chrome/browser/chrome_browser_parts_views.h b/chrome/browser/chrome_browser_parts_views.h deleted file mode 100644 index e3805dc..0000000 --- a/chrome/browser/chrome_browser_parts_views.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Contains functions used by BrowserMain() that are views-specific. - -#ifndef CHROME_BROWSER_CHROME_BROWSER_PARTS_VIEWS_H_ -#define CHROME_BROWSER_CHROME_BROWSER_PARTS_VIEWS_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "content/public/browser/browser_main_parts.h" - -class ChromeBrowserPartsViews : public content::BrowserMainParts { - public: - ChromeBrowserPartsViews(); - - virtual void PreEarlyInitialization() OVERRIDE {} - virtual void PostEarlyInitialization() OVERRIDE {} - virtual void PreMainMessageLoopStart() OVERRIDE {} - virtual void ToolkitInitialized() OVERRIDE; - virtual void PostMainMessageLoopStart() OVERRIDE {} - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE {} -}; - -#endif // CHROME_BROWSER_CHROME_BROWSER_PARTS_VIEWS_H_ diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 018acf5..62fe5b0 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -93,15 +93,19 @@ #endif #if defined(TOOLKIT_USES_GTK) -#include "chrome/browser/chrome_browser_parts_gtk.h" +#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h" #endif #if defined(TOOLKIT_VIEWS) -#include "chrome/browser/chrome_browser_parts_views.h" +#include "chrome/browser/chrome_browser_main_extra_parts_views.h" #endif #if defined(USE_AURA) -#include "chrome/browser/chrome_browser_parts_aura.h" +#include "chrome/browser/chrome_browser_main_extra_parts_aura.h" +#endif + +#if defined(TOUCH_UI) +#include "chrome/browser/chrome_browser_main_extra_parts_touch.h" #endif #if defined(OS_LINUX) || defined(OS_OPENBSD) @@ -109,10 +113,6 @@ #include "chrome/browser/crash_handler_host_linux.h" #endif -#if defined(TOUCH_UI) -#include "chrome/browser/chrome_browser_parts_touch.h" -#endif - #if defined(TOOLKIT_VIEWS) #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" #elif defined(TOOLKIT_USES_GTK) @@ -216,43 +216,44 @@ RenderProcessHostPrivilege GetProcessPrivilege( namespace chrome { -void ChromeContentBrowserClient::CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<content::BrowserMainParts*>* parts_list) { +content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( + const content::MainFunctionParams& parameters) { + ChromeBrowserMainParts* main_parts; // Construct the Main browser parts based on the OS type. #if defined(OS_WIN) - parts_list->push_back(new ChromeBrowserMainPartsWin(parameters)); + main_parts = new ChromeBrowserMainPartsWin(parameters); #elif defined(OS_MACOSX) - parts_list->push_back(new ChromeBrowserMainPartsMac(parameters)); + main_parts = new ChromeBrowserMainPartsMac(parameters); #elif defined(OS_CHROMEOS) - parts_list->push_back(new ChromeBrowserMainPartsChromeos(parameters)); + main_parts = new ChromeBrowserMainPartsChromeos(parameters); #elif defined(OS_LINUX) || defined(OS_OPENBSD) - parts_list->push_back(new ChromeBrowserMainPartsLinux(parameters)); + main_parts = new ChromeBrowserMainPartsLinux(parameters); #elif defined(OS_POSIX) - parts_list->push_back(new ChromeBrowserMainPartsPosix(parameters)); + main_parts = new ChromeBrowserMainPartsPosix(parameters); #else NOTREACHED(); - parts_list->push_back(new ChromeBrowserMainParts(parameters)); + main_parts = new ChromeBrowserMainParts(parameters); #endif // Construct additional browser parts. Stages are called in the order in // which they are added. #if defined(TOOLKIT_USES_GTK) - parts_list->push_back(new ChromeBrowserPartsGtk()); + main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); #endif #if defined(TOOLKIT_VIEWS) - parts_list->push_back(new ChromeBrowserPartsViews()); + main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); #endif #if defined(USE_AURA) - parts_list->push_back(new ChromeBrowserPartsAura()); + main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); #endif #if defined(TOUCH_UI) - parts_list->push_back(new ChromeBrowserPartsTouch()); + main_parts->AddParts(new ChromeBrowserMainExtraPartsTouch()); #endif + return main_parts; } RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget( diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index c91e658..e174d4d 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -15,9 +15,8 @@ namespace chrome { class ChromeContentBrowserClient : public content::ContentBrowserClient { public: - virtual void CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<content::BrowserMainParts*>* parts_list) OVERRIDE; + virtual content::BrowserMainParts* CreateBrowserMainParts( + const content::MainFunctionParams& parameters) OVERRIDE; virtual RenderWidgetHostView* CreateViewForWidget( RenderWidgetHost* widget) OVERRIDE; virtual TabContentsView* CreateTabContentsView( diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 8c39e33..5b737ac 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -87,32 +87,10 @@ ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos( } ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() { - // Shutdown the upgrade detector for Chrome OS. The upgrade detector - // stops monitoring changes from the update engine. - if (UpgradeDetectorChromeos::GetInstance()) - UpgradeDetectorChromeos::GetInstance()->Shutdown(); - - // Shutdown the network change notifier for Chrome OS. The network - // change notifier stops monitoring changes from the power manager and - // the network manager. - if (chromeos::CrosNetworkChangeNotifierFactory::GetInstance()) - chromeos::CrosNetworkChangeNotifierFactory::GetInstance()->Shutdown(); - chromeos::disks::DiskMountManager::Shutdown(); chromeos::BluetoothManager::Shutdown(); - // We should remove observers attached to D-Bus clients before - // DBusThreadManager is shut down. - if (session_manager_observer_.get()) { - chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> - RemoveObserver(session_manager_observer_.get()); - } - if (brightness_observer_.get()) { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient() - ->RemoveObserver(brightness_observer_.get()); - } - chromeos::DBusThreadManager::Shutdown(); if (!parameters().ui_task && chromeos::CrosLibrary::Get()) @@ -169,7 +147,7 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { } void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { - ChromeBrowserMainPartsPosix::PostMainMessageLoopStart(); + ChromeBrowserMainPartsLinux::PostMainMessageLoopStart(); MessageLoopForUI* message_loop = MessageLoopForUI::current(); message_loop->AddObserver(g_message_loop_observer.Pointer()); @@ -212,3 +190,30 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { #endif } } + +// Shut down services before the browser process, etc are destroyed. +void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { + ChromeBrowserMainPartsLinux::PostMainMessageLoopRun(); + + // Shutdown the upgrade detector for Chrome OS. The upgrade detector + // stops monitoring changes from the update engine. + if (UpgradeDetectorChromeos::GetInstance()) + UpgradeDetectorChromeos::GetInstance()->Shutdown(); + + // Shutdown the network change notifier for Chrome OS. The network + // change notifier stops monitoring changes from the power manager and + // the network manager. + if (chromeos::CrosNetworkChangeNotifierFactory::GetInstance()) + chromeos::CrosNetworkChangeNotifierFactory::GetInstance()->Shutdown(); + + // We should remove observers attached to D-Bus clients before + // DBusThreadManager is shut down. + if (session_manager_observer_.get()) { + chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> + RemoveObserver(session_manager_observer_.get()); + } + if (brightness_observer_.get()) { + chromeos::DBusThreadManager::Get()->GetPowerManagerClient() + ->RemoveObserver(brightness_observer_.get()); + } +} diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index ddd17be..449d9fa 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -23,10 +23,12 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { const content::MainFunctionParams& parameters); virtual ~ChromeBrowserMainPartsChromeos(); + // content::BrowserMainParts overrides. virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; virtual void PostMainMessageLoopStart() OVERRIDE; + virtual void PreMainMessageLoopRun() OVERRIDE; + virtual void PostMainMessageLoopRun() OVERRIDE; private: scoped_ptr<chromeos::BrightnessObserver> brightness_observer_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9e8ebdb..06c7a9f 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -355,14 +355,16 @@ 'browser/chrome_browser_main_win.h', 'browser/chrome_browser_main_x11.cc', 'browser/chrome_browser_main_x11.h', - 'browser/chrome_browser_parts_aura.cc', - 'browser/chrome_browser_parts_aura.h', - 'browser/chrome_browser_parts_gtk.cc', - 'browser/chrome_browser_parts_gtk.h', - 'browser/chrome_browser_parts_touch.cc', - 'browser/chrome_browser_parts_touch.h', - 'browser/chrome_browser_parts_views.cc', - 'browser/chrome_browser_parts_views.h', + 'browser/chrome_browser_main_extra_parts.cc', + 'browser/chrome_browser_main_extra_parts.h', + 'browser/chrome_browser_main_extra_parts_aura.cc', + 'browser/chrome_browser_main_extra_parts_aura.h', + 'browser/chrome_browser_main_extra_parts_gtk.cc', + 'browser/chrome_browser_main_extra_parts_gtk.h', + 'browser/chrome_browser_main_extra_parts_touch.cc', + 'browser/chrome_browser_main_extra_parts_touch.h', + 'browser/chrome_browser_main_extra_parts_views.cc', + 'browser/chrome_browser_main_extra_parts_views.h', 'browser/chrome_content_browser_client.cc', 'browser/chrome_content_browser_client.h', 'browser/chrome_plugin_message_filter.cc', diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc index 2059d2a..dd93e58 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -158,26 +158,21 @@ BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) } BrowserMainLoop::~BrowserMainLoop() { - // Destroy added parts in reverse order. - for (int i = static_cast<int>(parts_list_.size())-1; i >= 0; --i) - delete parts_list_[i]; - parts_list_.clear(); - #if defined(OS_WIN) OleUninitialize(); #endif } void BrowserMainLoop::Init() { - GetContentClient()->browser()->CreateBrowserMainParts( - parameters_, &parts_list_); + parts_.reset( + GetContentClient()->browser()->CreateBrowserMainParts(parameters_)); } // BrowserMainLoop stages ================================================== void BrowserMainLoop::EarlyInitialization() { - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->PreEarlyInitialization(); + if (parts_.get()) + parts_->PreEarlyInitialization(); #if defined(OS_WIN) net::EnsureWinsockInit(); @@ -223,13 +218,13 @@ void BrowserMainLoop::EarlyInitialization() { if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) net::set_tcp_fastopen_enabled(true); - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->PostEarlyInitialization(); + if (parts_.get()) + parts_->PostEarlyInitialization(); } void BrowserMainLoop::MainMessageLoopStart() { - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->PreMainMessageLoopStart(); + if (parts_.get()) + parts_->PreMainMessageLoopStart(); #if defined(OS_WIN) // If we're running tests (ui_task is non-null), then the ResourceBundle @@ -260,31 +255,24 @@ void BrowserMainLoop::MainMessageLoopStart() { system_message_window_.reset(new SystemMessageWindowWin); #endif - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->PostMainMessageLoopStart(); + if (parts_.get()) + parts_->PostMainMessageLoopStart(); } void BrowserMainLoop::RunMainMessageLoopParts( bool* completed_main_message_loop) { - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->PreMainMessageLoopRun(); + if (parts_.get()) + parts_->PreMainMessageLoopRun(); TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); // If the UI thread blocks, the whole UI is unresponsive. // Do not allow disk IO from the UI thread. base::ThreadRestrictions::SetIOAllowed(false); - // Iterate through each of the parts. If any of them ran the main - // message loop then they should return |true|. Otherwise - // BrowserMainLoop::MainMessageLoopRun loop will be run. bool ran_main_loop = false; - for (size_t i = 0; i < parts_list_.size(); ++i) { - int result_code = result_code_; - if (parts_list_[i]->MainMessageLoopRun(&result_code)) { - ran_main_loop = true; - result_code_ = result_code; - } - } + if (parts_.get()) + ran_main_loop = parts_->MainMessageLoopRun(&result_code_); + if (!ran_main_loop) MainMessageLoopRun(); @@ -293,8 +281,8 @@ void BrowserMainLoop::RunMainMessageLoopParts( if (completed_main_message_loop) *completed_main_message_loop = true; - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->PostMainMessageLoopRun(); + if (parts_.get()) + parts_->PostMainMessageLoopRun(); } void BrowserMainLoop::InitializeMainThread() { @@ -343,8 +331,8 @@ void BrowserMainLoop::InitializeToolkit() { LOG_GETLASTERROR(FATAL); #endif - for (size_t i = 0; i < parts_list_.size(); ++i) - parts_list_[i]->ToolkitInitialized(); + if (parts_.get()) + parts_->ToolkitInitialized(); } void BrowserMainLoop::MainMessageLoopRun() { diff --git a/content/browser/browser_main_loop.h b/content/browser/browser_main_loop.h index 0abe7e1..d02d578 100644 --- a/content/browser/browser_main_loop.h +++ b/content/browser/browser_main_loop.h @@ -6,8 +6,6 @@ #define CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ #pragma once -#include <vector> - #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" @@ -55,11 +53,6 @@ class BrowserMainLoop { const CommandLine& parsed_command_line_; int result_code_; - // Vector of BrowserMainParts set by CreateBrowserMainParts ------------------ - // The BrowserParts fucntions for each part are called in the order added. - // They are released (destroyed) in the reverse order. - std::vector<BrowserMainParts*> parts_list_; - // Members initialized in |MainMessageLoopStart()| --------------------------- scoped_ptr<MessageLoop> main_message_loop_; scoped_ptr<base::SystemMonitor> system_monitor_; @@ -68,6 +61,13 @@ class BrowserMainLoop { #if defined(OS_WIN) scoped_ptr<SystemMessageWindowWin> system_message_window_; #endif + + // Destroy parts_ before main_message_loop_ (required) and before other + // classes constructed in content (but after main_thread_). + scoped_ptr<BrowserMainParts> parts_; + + // Members initialized in |InitializeMainThread()| --------------------------- + // This must get destroyed before other threads that are created in parts_. scoped_ptr<BrowserThreadImpl> main_thread_; DISALLOW_COPY_AND_ASSIGN(BrowserMainLoop); diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index b2c2dd6..5b1c08b 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -23,9 +23,9 @@ MockContentBrowserClient::MockContentBrowserClient() { MockContentBrowserClient::~MockContentBrowserClient() { } -void MockContentBrowserClient::CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<BrowserMainParts*>* parts_list) { +BrowserMainParts* MockContentBrowserClient::CreateBrowserMainParts( + const content::MainFunctionParams& parameters) { + return NULL; } RenderWidgetHostView* MockContentBrowserClient::CreateViewForWidget( diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index 56a7be2..2b61f71 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -21,9 +21,8 @@ class MockContentBrowserClient : public ContentBrowserClient { MockContentBrowserClient(); virtual ~MockContentBrowserClient(); - virtual void CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<BrowserMainParts*>* parts_list) OVERRIDE; + virtual BrowserMainParts* CreateBrowserMainParts( + const content::MainFunctionParams& parameters) OVERRIDE; virtual RenderWidgetHostView* CreateViewForWidget( RenderWidgetHost* widget) OVERRIDE; virtual TabContentsView* CreateTabContentsView( diff --git a/content/public/browser/browser_main_parts.h b/content/public/browser/browser_main_parts.h index 0bbaa83..860541c 100644 --- a/content/public/browser/browser_main_parts.h +++ b/content/public/browser/browser_main_parts.h @@ -15,9 +15,8 @@ namespace content { // Each stage is represented by a single BrowserMainParts method, called from // the corresponding method in |BrowserMainLoop| (e.g., EarlyInitialization()) // which does the following: -// - calls a method (e.g., "PreEarlyInitialization()") for each member of -// |parts_|. Parts will implement platform or tookit specific code for that -// stage. +// - calls a method (e.g., "PreEarlyInitialization()") which implements +// platform / tookit specific code for that stage. // - calls various methods for things common to all platforms (for that stage). // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific // code to be called after the common code. @@ -49,9 +48,6 @@ namespace content { // existing chunk which makes it longer than one or two lines, please move // the code out into a separate method.) // -// There can be any number of "Parts". These should be constructed in -// ContentBrowserClient::CreateBrowserMainParts. Each stage will be called -// for each part in the order it was added. Destruction is in the inverse order. class CONTENT_EXPORT BrowserMainParts { public: BrowserMainParts() {} @@ -63,17 +59,16 @@ class CONTENT_EXPORT BrowserMainParts { virtual void PreMainMessageLoopStart() = 0; + virtual void PostMainMessageLoopStart() = 0; + // Allows an embedder to do any extra toolkit initialization. virtual void ToolkitInitialized() = 0; - virtual void PostMainMessageLoopStart() = 0; - virtual void PreMainMessageLoopRun() = 0; // Returns true if the message loop was run, false otherwise. + // If this returns false, the default implementation will be run. // May set |result_code|, which will be returned by |BrowserMain()|. - // If no BrowserMainParts implementations return true, the default - // implementation will be run. virtual bool MainMessageLoopRun(int* result_code) = 0; virtual void PostMainMessageLoopRun() = 0; diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 2a2a9f7..7d5438e 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -85,9 +85,8 @@ class ContentBrowserClient { // Allows the embedder to set any number of custom BrowserMainParts // implementations for the browser startup code. See comments in // browser_main_parts.h. - virtual void CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<BrowserMainParts*>* parts_list) = 0; + virtual BrowserMainParts* CreateBrowserMainParts( + const content::MainFunctionParams& parameters) = 0; // Platform-specific creator. Use this to construct new RenderWidgetHostViews // rather than using RenderWidgetHostViewWin & friends. diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index ec25de5..394af26 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -28,10 +28,9 @@ ShellContentBrowserClient::ShellContentBrowserClient() ShellContentBrowserClient::~ShellContentBrowserClient() { } -void ShellContentBrowserClient::CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<BrowserMainParts*>* parts_list) { - parts_list->push_back(new ShellBrowserMainParts(parameters)); +BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( + const content::MainFunctionParams& parameters) { + return new ShellBrowserMainParts(parameters); } RenderWidgetHostView* ShellContentBrowserClient::CreateViewForWidget( diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 1231ae0..4d0ac37 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -33,9 +33,8 @@ class ShellContentBrowserClient : public ContentBrowserClient shell_browser_main_parts_ = parts; } - virtual void CreateBrowserMainParts( - const content::MainFunctionParams& parameters, - std::vector<BrowserMainParts*>* parts_list) OVERRIDE; + virtual BrowserMainParts* CreateBrowserMainParts( + const content::MainFunctionParams& parameters) OVERRIDE; virtual RenderWidgetHostView* CreateViewForWidget( RenderWidgetHost* widget) OVERRIDE; virtual TabContentsView* CreateTabContentsView( |