Skip to content

Commit

Permalink
Add ChromeBrowserParts for non main parts.
Browse files Browse the repository at this point in the history
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.

BUG=103821
TEST=Make sure all tests and autotests run

Review URL: http://codereview.chromium.org/8539038

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110327 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
stevenjb@google.com committed Nov 16, 2011
1 parent e29014c commit a2b6aab
Show file tree
Hide file tree
Showing 33 changed files with 351 additions and 356 deletions.
74 changes: 42 additions & 32 deletions chrome/browser/chrome_browser_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1166,23 +1160,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() {
Expand Down Expand Up @@ -1505,6 +1514,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)
Expand Down Expand Up @@ -1570,6 +1583,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)
Expand Down Expand Up @@ -1618,6 +1636,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
Expand Down Expand Up @@ -1843,25 +1866,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;

// Set the notification UI manager after any desktop initialization in
// PreMainMessageLoopRun() is complete, and before starting the browser.
DesktopNotificationServiceFactory::GetForProfile(profile_)->SetUIManager(
g_browser_process->notification_ui_manager());

// 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)
Expand Down Expand Up @@ -1931,18 +1935,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.

Expand Down Expand Up @@ -2064,8 +2063,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);
Expand Down
35 changes: 22 additions & 13 deletions chrome/browser/chrome_browser_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,6 +18,7 @@

class BrowserInit;
class BrowserProcessImpl;
class ChromeBrowserMainExtraParts;
class FieldTrialSynchronizer;
class HistogramSynchronizer;
class MetricsService;
Expand All @@ -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;
Expand All @@ -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()| ---------------------------------------

Expand Down Expand Up @@ -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);
Expand All @@ -115,7 +122,6 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
// Methods for Main Message Loop -------------------------------------------

int PreMainMessageLoopRunImpl();
void StartBrowserOrUITask();

// Members initialized on construction ---------------------------------------

Expand All @@ -137,6 +143,9 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
// SetupMetricsAndFieldTrials is called.
scoped_ptr<base::FieldTrialList> field_trial_list_;

// Vector of additional ChromeBrowserMainExtraParts.
ScopedVector<ChromeBrowserMainExtraParts> chrome_extra_parts_;

// Members initialized after / released before main_message_loop_ ------------

scoped_ptr<BrowserInit> browser_init_;
Expand Down
38 changes: 38 additions & 0 deletions chrome/browser/chrome_browser_main_extra_parts.cc
Original file line number Diff line number Diff line change
@@ -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() {
}
44 changes: 44 additions & 0 deletions chrome/browser/chrome_browser_main_extra_parts.h
Original file line number Diff line number Diff line change
@@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand All @@ -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() {
}
Loading

0 comments on commit a2b6aab

Please sign in to comment.