Commit f967b723 authored by jam@chromium.org's avatar jam@chromium.org

Start moving code from BrowserMain to content, so that it can be reused by all...

Start moving code from BrowserMain to content, so that it can be reused by all embedders of content. I've based the refactoring on the existing BrowserMainParts. This is the first step; I didn't want to do it all at the same time because it would be too big. Remaining tasks:-rename the browser_main files in chrome to chrome_browser_main-move the OS specific implementations of BrowserMainParts that are needed for content-finish splitting the remaining BrowserMain function (now that's in TemporaryContinue())BUG=90445
Review URL: http://codereview.chromium.org/7779040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99884 0039d316-1c4b-4281-b951-d872f2087c98
parent 557d842f
...@@ -6,13 +6,12 @@ ...@@ -6,13 +6,12 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/metrics/stats_counters.h" #include "base/metrics/stats_counters.h"
#include "base/metrics/stats_table.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/browser/diagnostics/diagnostics_main.h" #include "chrome/browser/diagnostics/diagnostics_main.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
...@@ -33,7 +32,6 @@ ...@@ -33,7 +32,6 @@
#include "content/common/content_client.h" #include "content/common/content_client.h"
#include "content/common/content_counters.h" #include "content/common/content_counters.h"
#include "content/common/content_paths.h" #include "content/common/content_paths.h"
#include "ipc/ipc_switches.h"
#include "media/base/media.h" #include "media/base/media.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
...@@ -92,6 +90,8 @@ ...@@ -92,6 +90,8 @@
#endif #endif
#if !defined(NACL_WIN64) // We don't build the this code on win nacl64. #if !defined(NACL_WIN64) // We don't build the this code on win nacl64.
base::LazyInstance<chrome::ChromeContentBrowserClient>
g_chrome_content_browser_client(base::LINKER_INITIALIZED);
base::LazyInstance<chrome::ChromeContentRendererClient> base::LazyInstance<chrome::ChromeContentRendererClient>
g_chrome_content_renderer_client(base::LINKER_INITIALIZED); g_chrome_content_renderer_client(base::LINKER_INITIALIZED);
base::LazyInstance<chrome::ChromeContentUtilityClient> base::LazyInstance<chrome::ChromeContentUtilityClient>
...@@ -101,7 +101,6 @@ base::LazyInstance<chrome::ChromeContentUtilityClient> ...@@ -101,7 +101,6 @@ base::LazyInstance<chrome::ChromeContentUtilityClient>
base::LazyInstance<chrome::ChromeContentPluginClient> base::LazyInstance<chrome::ChromeContentPluginClient>
g_chrome_content_plugin_client(base::LINKER_INITIALIZED); g_chrome_content_plugin_client(base::LINKER_INITIALIZED);
extern int BrowserMain(const MainFunctionParams&);
extern int RendererMain(const MainFunctionParams&); extern int RendererMain(const MainFunctionParams&);
extern int NaClMain(const MainFunctionParams&); extern int NaClMain(const MainFunctionParams&);
extern int ProfileImportMain(const MainFunctionParams&); extern int ProfileImportMain(const MainFunctionParams&);
...@@ -279,7 +278,12 @@ void InitializeChromeContentRendererClient() { ...@@ -279,7 +278,12 @@ void InitializeChromeContentRendererClient() {
} }
void InitializeChromeContentClient(const std::string& process_type) { void InitializeChromeContentClient(const std::string& process_type) {
if (process_type == switches::kPluginProcess) { if (process_type.empty()) {
#if !defined(NACL_WIN64) // We don't build the this code on win nacl64.
content::GetContentClient()->set_browser(
&g_chrome_content_browser_client.Get());
#endif
} else if (process_type == switches::kPluginProcess) {
content::GetContentClient()->set_plugin( content::GetContentClient()->set_plugin(
&g_chrome_content_plugin_client.Get()); &g_chrome_content_plugin_client.Get());
} else if (process_type == switches::kRendererProcess || } else if (process_type == switches::kRendererProcess ||
...@@ -339,27 +343,6 @@ void SetMacProcessName(const std::string& process_type) { ...@@ -339,27 +343,6 @@ void SetMacProcessName(const std::string& process_type) {
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
void InitializeStatsTable(base::ProcessId browser_pid,
const CommandLine& command_line) {
// Initialize the Stats Counters table. With this initialized,
// the StatsViewer can be utilized to read counters outside of
// Chrome. These lines can be commented out to effectively turn
// counters 'off'. The table is created and exists for the life
// of the process. It is not cleaned up.
if (command_line.HasSwitch(switches::kEnableStatsTable) ||
command_line.HasSwitch(switches::kEnableBenchmarking)) {
// NOTIMPLEMENTED: we probably need to shut this down correctly to avoid
// leaking shared memory regions on posix platforms.
std::string statsfile =
base::StringPrintf("%s-%u",
chrome::kStatsFilename,
static_cast<unsigned int>(browser_pid));
base::StatsTable *stats_table = new base::StatsTable(statsfile,
chrome::kStatsMaxThreads, chrome::kStatsMaxCounters);
base::StatsTable::set_current(stats_table);
}
}
#if defined(OS_POSIX) #if defined(OS_POSIX)
// Check for --version and --product-version; return true if we encountered // Check for --version and --product-version; return true if we encountered
// one of these switches and should exit now. // one of these switches and should exit now.
...@@ -570,27 +553,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate { ...@@ -570,27 +553,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
if (!user_data_dir.empty()) if (!user_data_dir.empty())
CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir)); CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir));
base::ProcessId browser_pid = base::GetCurrentProcId();
if (!process_type.empty() &&
#if defined(OS_MACOSX)
process_type != switches::kRelauncherProcess &&
#endif
process_type != switches::kServiceProcess) {
#if defined(OS_WIN) || defined(OS_MACOSX)
std::string channel_name =
command_line.GetSwitchValueASCII(switches::kProcessChannelID);
int browser_pid_int;
base::StringToInt(channel_name, &browser_pid_int);
browser_pid = static_cast<base::ProcessId>(browser_pid_int);
DCHECK_NE(browser_pid_int, 0);
#elif defined(OS_POSIX)
// On linux, we're in the zygote here; so we need the parent process' id.
browser_pid = base::GetParentProcessId(base::GetCurrentProcId());
#endif
}
InitializeStatsTable(browser_pid, command_line);
startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
(content::Counters::chrome_main())); (content::Counters::chrome_main()));
...@@ -694,7 +656,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate { ...@@ -694,7 +656,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
const std::string& process_type, const std::string& process_type,
const MainFunctionParams& main_function_params) OVERRIDE { const MainFunctionParams& main_function_params) OVERRIDE {
static const MainFunction kMainFunctions[] = { static const MainFunction kMainFunctions[] = {
{ "", BrowserMain },
// An extension process is just a renderer process. We use a different // An extension process is just a renderer process. We use a different
// command line argument to differentiate crash reports. // command line argument to differentiate crash reports.
{ switches::kExtensionProcess, RendererMain }, { switches::kExtensionProcess, RendererMain },
...@@ -775,13 +736,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate { ...@@ -775,13 +736,6 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
std::string process_type = std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType); command_line.GetSwitchValueASCII(switches::kProcessType);
// The StatsTable must be initialized in each process; we already
// initialized for the browser process, now we need to initialize
// within the new processes as well.
pid_t browser_pid = base::GetParentProcessId(
base::GetParentProcessId(base::GetCurrentProcId()));
InitializeStatsTable(browser_pid, command_line);
#if defined(USE_LINUX_BREAKPAD) #if defined(USE_LINUX_BREAKPAD)
// Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets
// this up for the browser process in a different manner. // this up for the browser process in a different manner.
......
This diff is collapsed.
...@@ -8,27 +8,15 @@ ...@@ -8,27 +8,15 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/tracked_objects.h" #include "base/tracked_objects.h"
#include "content/browser/browser_main.h"
class BrowserThread;
class CommandLine;
class HistogramSynchronizer;
class FieldTrialSynchronizer; class FieldTrialSynchronizer;
class HighResolutionTimerManager; class HistogramSynchronizer;
struct MainFunctionParams;
class MessageLoop;
class MetricsService; class MetricsService;
class PrefService; class PrefService;
class ShutdownWatcherHelper;
namespace base {
class SystemMonitor;
}
namespace net {
class NetworkChangeNotifier;
}
namespace chrome_browser { namespace chrome_browser {
// For use by ShowMissingLocaleMessageBox. // For use by ShowMissingLocaleMessageBox.
...@@ -36,59 +24,9 @@ extern const char kMissingLocaleDataTitle[]; ...@@ -36,59 +24,9 @@ extern const char kMissingLocaleDataTitle[];
extern const char kMissingLocaleDataMessage[]; extern const char kMissingLocaleDataMessage[];
} }
// BrowserMainParts: class ChromeBrowserMainParts : public content::BrowserMainParts {
// This class contains different "stages" to be executed in |BrowserMain()|,
// mostly initialization. This is made into a class rather than just functions
// so each stage can create and maintain state. Each part is represented by a
// single method (e.g., "EarlyInitialization()"), which does the following:
// - calls a method (e.g., "PreEarlyInitialization()") which individual
// platforms can override to provide platform-specific code which is to be
// executed before the common code;
// - calls various methods for things common to all platforms (for that given
// stage); and
// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
// code to be called after the common code.
// As indicated above, platforms should override the default "Pre...()" and
// "Post...()" methods when necessary; they need not call the superclass's
// implementation (which is empty).
//
// Parts:
// - EarlyInitialization: things which should be done as soon as possible on
// program start (such as setting up signal handlers) and things to be done
// at some generic time before the start of the main message loop.
// - MainMessageLoopStart: things beginning with the start of the main message
// loop and ending with initialization of the main thread; platform-specific
// things which should be done immediately before the start of the main
// message loop should go in |PreMainMessageLoopStart()|.
// - (more to come)
//
// How to add stuff (to existing parts):
// - Figure out when your new code should be executed. What must happen
// before/after your code is executed? Are there performance reasons for
// running your code at a particular time? Document these things!
// - Split out any platform-specific bits. Please avoid #ifdefs it at all
// possible. You have two choices for platform-specific code: (1) Execute it
// from one of the platform-specific |Pre/Post...()| methods; do this if the
// code is unique to a platform type. Or (2) execute it from one of the
// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
// implementations of your code (in a virtual method); do this if you need to
// provide different implementations across most/all platforms.
// - Unless your new code is just one or two lines, put it into a separate
// method with a well-defined purpose. (Likewise, if you're adding to an
// existing chunk which makes it longer than one or two lines, please move
// the code out into a separate method.)
class BrowserMainParts {
public: public:
// This static method is to be implemented by each platform and should virtual ~ChromeBrowserMainParts();
// instantiate the appropriate subclass.
static BrowserMainParts* CreateBrowserMainParts(
const MainFunctionParams& parameters);
virtual ~BrowserMainParts();
// Parts to be called by |BrowserMain()|.
void EarlyInitialization();
void MainMessageLoopStart();
// Constructs HistogramSynchronizer which gets released early (before // Constructs HistogramSynchronizer which gets released early (before
// main_message_loop_). // main_message_loop_).
...@@ -102,25 +40,12 @@ class BrowserMainParts { ...@@ -102,25 +40,12 @@ class BrowserMainParts {
PrefService* local_state); PrefService* local_state);
protected: protected:
explicit BrowserMainParts(const MainFunctionParams& parameters); explicit ChromeBrowserMainParts(const MainFunctionParams& parameters);
// Accessors for data members (below) ---------------------------------------- virtual void PostMainMessageLoopStart() OVERRIDE;
const MainFunctionParams& parameters() const { virtual void ToolkitInitialized() OVERRIDE;
return parameters_;
} virtual int TemporaryContinue() OVERRIDE;
const CommandLine& parsed_command_line() const {
return parsed_command_line_;
}
MessageLoop& main_message_loop() const {
return *main_message_loop_;
}
// Methods to be overridden to provide platform-specific code; these
// correspond to the "parts" above.
virtual void PreEarlyInitialization() {}
virtual void PostEarlyInitialization() {}
virtual void PreMainMessageLoopStart() {}
virtual void PostMainMessageLoopStart() {}
private: private:
// Methods for |EarlyInitialization()| --------------------------------------- // Methods for |EarlyInitialization()| ---------------------------------------
...@@ -147,13 +72,6 @@ class BrowserMainParts { ...@@ -147,13 +72,6 @@ class BrowserMainParts {
// A/B test for using a different host prefix in Google search suggest. // A/B test for using a different host prefix in Google search suggest.
void SuggestPrefixFieldTrial(); void SuggestPrefixFieldTrial();
// Used to initialize NSPR where appropriate.
virtual void InitializeSSL() = 0;
// Methods for |MainMessageLoopStart()| --------------------------------------
void InitializeMainThread();
// Methods for |SetupMetricsAndFieldTrials()| -------------------------------- // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
static MetricsService* InitializeMetrics( static MetricsService* InitializeMetrics(
...@@ -166,8 +84,10 @@ class BrowserMainParts { ...@@ -166,8 +84,10 @@ class BrowserMainParts {
// Members initialized on construction --------------------------------------- // Members initialized on construction ---------------------------------------
const MainFunctionParams& parameters_; // Create ShutdownWatcherHelper object for watching jank during shutdown.
const CommandLine& parsed_command_line_; // Please keep |shutdown_watcher| as the first object constructed, and hence
// it is destroyed last.
scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
#if defined(TRACK_ALL_TASK_OBJECTS) #if defined(TRACK_ALL_TASK_OBJECTS)
// Creating this object starts tracking the creation and deletion of Task // Creating this object starts tracking the creation and deletion of Task
...@@ -180,13 +100,6 @@ class BrowserMainParts { ...@@ -180,13 +100,6 @@ class BrowserMainParts {
// SetupMetricsAndFieldTrials is called. // SetupMetricsAndFieldTrials is called.
scoped_ptr<base::FieldTrialList> field_trial_list_; scoped_ptr<base::FieldTrialList> field_trial_list_;
// Members initialized in |MainMessageLoopStart()| ---------------------------
scoped_ptr<MessageLoop> main_message_loop_;
scoped_ptr<base::SystemMonitor> system_monitor_;
scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
scoped_ptr<BrowserThread> main_thread_;
// Members initialized after / released before main_message_loop_ ------------ // Members initialized after / released before main_message_loop_ ------------
// Initialized in SetupHistogramSynchronizer. // Initialized in SetupHistogramSynchronizer.
...@@ -198,14 +111,9 @@ class BrowserMainParts { ...@@ -198,14 +111,9 @@ class BrowserMainParts {
FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket); FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket);
FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random); FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random);
FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid); FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
}; };
// Perform platform-specific work that needs to be done after the main event
// loop has ended.
void DidEndMainMessageLoop();
// Records the conditions that can prevent Breakpad from generating and // Records the conditions that can prevent Breakpad from generating and
// sending crash reports. The presence of a Breakpad handler (after // sending crash reports. The presence of a Breakpad handler (after
// attempting to initialize crash reporting) and the presence of a debugger // attempting to initialize crash reporting) and the presence of a debugger
......
...@@ -81,6 +81,10 @@ int BrowserX11IOErrorHandler(Display* d) { ...@@ -81,6 +81,10 @@ int BrowserX11IOErrorHandler(Display* d) {
} // namespace } // namespace
BrowserMainPartsGtk::BrowserMainPartsGtk(const MainFunctionParams& parameters)
: BrowserMainPartsPosix(parameters) {
}
void BrowserMainPartsGtk::PreEarlyInitialization() { void BrowserMainPartsGtk::PreEarlyInitialization() {
DetectRunningAsRoot(); DetectRunningAsRoot();
...@@ -163,9 +167,13 @@ void BrowserMainPartsGtk::SetupSandbox() { ...@@ -163,9 +167,13 @@ void BrowserMainPartsGtk::SetupSandbox() {
zhost->Init(sandbox_cmd); zhost->Init(sandbox_cmd);
} }
namespace content {
void DidEndMainMessageLoop() { void DidEndMainMessageLoop() {
} }
}
void RecordBreakpadStatusUMA(MetricsService* metrics) { void RecordBreakpadStatusUMA(MetricsService* metrics) {
#if defined(USE_LINUX_BREAKPAD) #if defined(USE_LINUX_BREAKPAD)
metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
...@@ -221,11 +229,3 @@ void SetBrowserX11ErrorHandlers() { ...@@ -221,11 +229,3 @@ void SetBrowserX11ErrorHandlers() {
// goes away. // goes away.
ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler);
} }
#if !defined(OS_CHROMEOS)
// static
BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
const MainFunctionParams& parameters) {
return new BrowserMainPartsGtk(parameters);
}
#endif
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
class BrowserMainPartsGtk : public BrowserMainPartsPosix { class BrowserMainPartsGtk : public BrowserMainPartsPosix {
public: public:
explicit BrowserMainPartsGtk(const MainFunctionParams& parameters) explicit BrowserMainPartsGtk(const MainFunctionParams& parameters);
: BrowserMainPartsPosix(parameters) {}
virtual void PreEarlyInitialization() OVERRIDE; virtual void PreEarlyInitialization() OVERRIDE;
......
// 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_BROWSER_MAIN_MAC_H_
#define CHROME_BROWSER_BROWSER_MAIN_MAC_H_
#pragma once
#include "chrome/browser/browser_main_posix.h"
class BrowserMainPartsMac : public BrowserMainPartsPosix {
public:
explicit BrowserMainPartsMac(const MainFunctionParams& parameters);
virtual void PreEarlyInitialization() OVERRIDE;
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void InitializeSSL() OVERRIDE;
};
#endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/browser_main_posix.h" #include "chrome/browser/browser_main_mac.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
...@@ -27,11 +27,15 @@ ...@@ -27,11 +27,15 @@
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
namespace content {
void DidEndMainMessageLoop() { void DidEndMainMessageLoop() {
AppController* appController = [NSApp delegate]; AppController* appController = [NSApp delegate];
[appController didEndMainMessageLoop]; [appController didEndMainMessageLoop];
} }
}
void RecordBreakpadStatusUMA(MetricsService* metrics) { void RecordBreakpadStatusUMA(MetricsService* metrics) {
metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged());
...@@ -68,90 +72,80 @@ void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { ...@@ -68,90 +72,80 @@ void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
// BrowserMainPartsMac --------------------------------------------------------- // BrowserMainPartsMac ---------------------------------------------------------
class BrowserMainPartsMac : public BrowserMainPartsPosix { BrowserMainPartsMac::BrowserMainPartsMac(const MainFunctionParams& parameters)
public: : BrowserMainPartsPosix(parameters) {
explicit BrowserMainPartsMac(const MainFunctionParams& parameters) }
: BrowserMainPartsPosix(parameters) {}
protected: void BrowserMainPartsMac::PreEarlyInitialization() {
virtual void PreEarlyInitialization() { BrowserMainPartsPosix::PreEarlyInitialization();
BrowserMainPartsPosix::PreEarlyInitialization();
if (base::mac::WasLaunchedAsHiddenLoginItem()) { if (base::mac::WasLaunchedAsHiddenLoginItem()) {
CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
singleton_command_line->AppendSwitch(switches::kNoStartupWindow); singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
}
} }
}
virtual void PreMainMessageLoopStart() { void BrowserMainPartsMac::PreMainMessageLoopStart() {
BrowserMainPartsPosix::PreMainMessageLoopStart(); BrowserMainPartsPosix::PreMainMessageLoopStart();
// Tell Cooca to finish its initalization, which we want to do manually // Tell Cooca to finish its initialization, which we want to do manually
// instead of calling NSApplicationMain(). The primary reason is that NSAM() // instead of calling NSApplicationMain(). The primary reason is that NSAM()
// never returns, which would leave all the objects currently on the stack // never returns, which would leave all the objects currently on the stack
// in scoped_ptrs hanging and never cleaned up. We then load the main nib // in scoped_ptrs hanging and never cleaned up. We then load the main nib
// directly. The main event loop is run from common code using the // directly. The main event loop is run from common code using the
// MessageLoop API, which works out ok for us because it's a wrapper around // MessageLoop API, which works out ok for us because it's a wrapper around
// CFRunLoop. // CFRunLoop.
// Initialize NSApplication using the custom subclass. // Initialize NSApplication using the custom subclass.
[BrowserCrApplication sharedApplication]; [BrowserCrApplication sharedApplication];
// If ui_task is not NULL, the app is actually a browser_test, so startup is // If ui_task is not NULL, the app is actually a browser_test, so startup is
// handled outside of BrowserMain (which is what called this). // handled outside of BrowserMain (which is what called this).
if (!parameters().ui_task) { if (!parameters().ui_task) {
// The browser process only wants to support the language Cocoa will use, // The browser process only wants to support the language Cocoa will use,
// so force the app locale to be overriden with that value. // so force the app locale to be overriden with that value.
l10n_util::OverrideLocaleWithCocoaLocale(); l10n_util::OverrideLocaleWithCocoaLocale();
// Before we load the nib, we need to start up the resource bundle so we // Before we load the nib, we need to start up the resource bundle so we
// have the strings avaiable for localization. // have the strings avaiable for localization.
// TODO(markusheintz): Read preference pref::kApplicationLocale in order // TODO(markusheintz): Read preference pref::kApplicationLocale in order
// to enforce the application locale. // to enforce the application locale.
const std::string loaded_locale = const std::string loaded_locale =
ResourceBundle::InitSharedInstance(std::string()); ResourceBundle::InitSharedInstance(std::string());
CHECK(!loaded_locale.empty()) << "Default locale could not be found"; CHECK(!loaded_locale.empty()) << "Default locale could not be found";
FilePath resources_pack_path; FilePath resources_pack_path;
PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
}
// Now load the nib (from the right bundle).
scoped_nsobject<NSNib>
nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
bundle:base::mac::MainAppBundle()]);
// TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you
// change this, you'll probably need to change the Valgrind suppression.
[nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
// Make sure the app controller has been created.
DCHECK([NSApp delegate]);
// This is a no-op if the KeystoneRegistration framework is not present.
// The framework is only distributed with branded Google Chrome builds.
[[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
// Prevent Cocoa from turning command-line arguments into
// |-application:openFiles:|, since we already handle them directly.
[[NSUserDefaults standardUserDefaults]
setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
} }
private: // Now load the nib (from the right bundle).
virtual void InitializeSSL() { scoped_nsobject<NSNib>
// Use NSS for SSL by default. nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
// The default client socket factory uses NSS for SSL by default on Mac. bundle:base::mac::MainAppBundle()]);
if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you
net::ClientSocketFactory::UseSystemSSL(); // change this, you'll probably need to change the Valgrind suppression.
} else { [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
// We want to be sure to init NSPR on the main thread. // Make sure the app controller has been created.
crypto::EnsureNSPRInit(); DCHECK([NSApp delegate]);
}
} // This is a no-op if the KeystoneRegistration framework is not present.
}; // The framework is only distributed with branded Google Chrome builds.
[[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
// Prevent Cocoa from turning command-line arguments into
// |-application:openFiles:|, since we already handle them directly.
[[NSUserDefaults standardUserDefaults]
setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
}
// static void BrowserMainPartsMac::InitializeSSL() {
BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( // Use NSS for SSL by default.
const MainFunctionParams& parameters) { // The default client socket factory uses NSS for SSL by default on Mac.
return new BrowserMainPartsMac(parameters); if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) {
net::ClientSocketFactory::UseSystemSSL();
} else {
// We want to be sure to init NSPR on the main thread.
crypto::EnsureNSPRInit();
}
} }
...@@ -186,6 +186,11 @@ void SetFileDescriptorLimit(unsigned int max_descriptors) { ...@@ -186,6 +186,11 @@ void SetFileDescriptorLimit(unsigned int max_descriptors) {
// BrowserMainPartsPosix ------------------------------------------------------- // BrowserMainPartsPosix -------------------------------------------------------
BrowserMainPartsPosix::BrowserMainPartsPosix(
const MainFunctionParams& parameters)
: ChromeBrowserMainParts(parameters) {
}
void BrowserMainPartsPosix::PreEarlyInitialization() { void BrowserMainPartsPosix::PreEarlyInitialization() {
// We need to accept SIGCHLD, even though our handler is a no-op because // We need to accept SIGCHLD, even though our handler is a no-op because
// otherwise we cannot wait on children. (According to POSIX 2001.) // otherwise we cannot wait on children. (According to POSIX 2001.)
......
...@@ -7,14 +7,12 @@ ...@@ -7,14 +7,12 @@
#include "chrome/browser/browser_main.h" #include "chrome/browser/browser_main.h"
class BrowserMainPartsPosix : public BrowserMainParts { class BrowserMainPartsPosix : public ChromeBrowserMainParts {
public: public:
explicit BrowserMainPartsPosix(const MainFunctionParams& parameters) explicit BrowserMainPartsPosix(const MainFunctionParams& parameters);
: BrowserMainParts(parameters) {}
protected: virtual void PreEarlyInitialization() OVERRIDE;
virtual void PreEarlyInitialization(); virtual void PostMainMessageLoopStart() OVERRIDE;
virtual void PostMainMessageLoopStart();
private: private:
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
......
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_pref_service.h" #include "chrome/test/base/testing_pref_service.h"
#include "content/browser/content_browser_client.h"
#include "content/common/main_function_params.h" #include "content/common/main_function_params.h"
#include "content/common/sandbox_init_wrapper.h" #include "content/common/sandbox_init_wrapper.h"
#include "net/socket/client_socket_pool_base.h" #include "net/socket/client_socket_pool_base.h"
...@@ -32,10 +35,12 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { ...@@ -32,10 +35,12 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) {
scoped_ptr<MainFunctionParams> params( scoped_ptr<MainFunctionParams> params(
new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL));
scoped_ptr<BrowserMainParts> bw(BrowserMainParts::CreateBrowserMainParts( scoped_ptr<content::BrowserMainParts> bw(
*params)); content::GetContentClient()->browser()->CreateBrowserMainParts(
*params));
bw->WarmConnectionFieldTrial(); ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get());
cbw->WarmConnectionFieldTrial();
EXPECT_EQ(0, net::GetSocketReusePolicy()); EXPECT_EQ(0, net::GetSocketReusePolicy());
} }
...@@ -43,12 +48,14 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { ...@@ -43,12 +48,14 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) {
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) { TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) {
scoped_ptr<MainFunctionParams> params( scoped_ptr<MainFunctionParams> params(
new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL));
scoped_ptr<BrowserMainParts> bw(BrowserMainParts::CreateBrowserMainParts( scoped_ptr<content::BrowserMainParts> bw(
*params)); content::GetContentClient()->browser()->CreateBrowserMainParts(
*params));
ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get());
const int kNumRuns = 1000; const int kNumRuns = 1000;
for (int i = 0; i < kNumRuns; i++) { for (int i = 0; i < kNumRuns; i++) {
bw->WarmConnectionFieldTrial(); cbw->WarmConnectionFieldTrial();
int val = net::GetSocketReusePolicy(); int val = net::GetSocketReusePolicy();
EXPECT_LE(val, 2); EXPECT_LE(val, 2);
EXPECT_GE(val, 0); EXPECT_GE(val, 0);
...@@ -60,9 +67,17 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) { ...@@ -60,9 +67,17 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) {
scoped_ptr<MainFunctionParams> params( scoped_ptr<MainFunctionParams> params(
new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL));
scoped_ptr<BrowserMainParts> bw(BrowserMainParts::CreateBrowserMainParts( // This test ends up launching a new process, and that doesn't initialize the
*params)); // ContentClient interfaces.
scoped_ptr<content::BrowserMainParts> bw;
EXPECT_DEBUG_DEATH(bw->WarmConnectionFieldTrial(), if (content::GetContentClient()) {
bw.reset(content::GetContentClient()->browser()->CreateBrowserMainParts(
*params));
} else {
chrome::ChromeContentBrowserClient ccbc;
bw.reset(ccbc.CreateBrowserMainParts(*params));
}
ChromeBrowserMainParts* cbw = static_cast<ChromeBrowserMainParts*>(bw.get());
EXPECT_DEBUG_DEATH(cbw->WarmConnectionFieldTrial(),
"Not a valid socket reuse policy group"); "Not a valid socket reuse policy group");
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/browser_main.h"
#include "chrome/browser/browser_main_win.h" #include "chrome/browser/browser_main_win.h"
#include <windows.h> #include <windows.h>
...@@ -62,10 +61,14 @@ void InitializeWindowProcExceptions() { ...@@ -62,10 +61,14 @@ void InitializeWindowProcExceptions() {
} }
} // namespace } // namespace
namespace content {
void DidEndMainMessageLoop() { void DidEndMainMessageLoop() {
OleUninitialize(); OleUninitialize();
} }
}
void RecordBreakpadStatusUMA(MetricsService* metrics) { void RecordBreakpadStatusUMA(MetricsService* metrics) {
DWORD len = ::GetEnvironmentVariableW( DWORD len = ::GetEnvironmentVariableW(
ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0); ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0);
...@@ -280,47 +283,37 @@ bool CheckMachineLevelInstall() { ...@@ -280,47 +283,37 @@ bool CheckMachineLevelInstall() {
// BrowserMainPartsWin --------------------------------------------------------- // BrowserMainPartsWin ---------------------------------------------------------
class BrowserMainPartsWin : public BrowserMainParts { BrowserMainPartsWin::BrowserMainPartsWin(const MainFunctionParams& parameters)
public: : ChromeBrowserMainParts(parameters) {
explicit BrowserMainPartsWin(const MainFunctionParams& parameters) }
: BrowserMainParts(parameters) {}
protected: void BrowserMainPartsWin::PreEarlyInitialization() {
virtual void PreEarlyInitialization() { // Initialize Winsock.
// Initialize Winsock. net::EnsureWinsockInit();
net::EnsureWinsockInit(); }
}
virtual void PreMainMessageLoopStart() { void BrowserMainPartsWin::PreMainMessageLoopStart() {
OleInitialize(NULL); OleInitialize(NULL);
// If we're running tests (ui_task is non-null), then the ResourceBundle // If we're running tests (ui_task is non-null), then the ResourceBundle
// has already been initialized. // has already been initialized.
if (!parameters().ui_task) { if (!parameters().ui_task) {
// Override the configured locale with the user's preferred UI language. // Override the configured locale with the user's preferred UI language.
l10n_util::OverrideLocaleWithUILanguageList(); l10n_util::OverrideLocaleWithUILanguageList();
// Make sure that we know how to handle exceptions from the message loop. // Make sure that we know how to handle exceptions from the message loop.
InitializeWindowProcExceptions(); InitializeWindowProcExceptions();
}
} }
}
private: void BrowserMainPartsWin::InitializeSSL() {
virtual void InitializeSSL() { // Use NSS for SSL by default.
// Use NSS for SSL by default. // The default client socket factory uses NSS for SSL by default on
// The default client socket factory uses NSS for SSL by default on // Windows.
// Windows. if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) {
if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { net::ClientSocketFactory::UseSystemSSL();
net::ClientSocketFactory::UseSystemSSL(); } else {
} else { // We want to be sure to init NSPR on the main thread.
// We want to be sure to init NSPR on the main thread. crypto::EnsureNSPRInit();
crypto::EnsureNSPRInit();
}
} }
};
// static
BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
const MainFunctionParams& parameters) {
return new BrowserMainPartsWin(parameters);
} }
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#define CHROME_BROWSER_BROWSER_MAIN_WIN_H_ #define CHROME_BROWSER_BROWSER_MAIN_WIN_H_
#pragma once #pragma once
#include "chrome/browser/browser_main.h"
class CommandLine; class CommandLine;
// Handle uninstallation when given the appropriate the command-line switch. // Handle uninstallation when given the appropriate the command-line switch.
...@@ -37,4 +39,13 @@ int HandleIconsCommands(const CommandLine& parsed_command_line); ...@@ -37,4 +39,13 @@ int HandleIconsCommands(const CommandLine& parsed_command_line);
// user level Chrome. // user level Chrome.
bool CheckMachineLevelInstall(); bool CheckMachineLevelInstall();
class BrowserMainPartsWin : public ChromeBrowserMainParts {
public:
explicit BrowserMainPartsWin(const MainFunctionParams& parameters);
virtual void PreEarlyInitialization() OVERRIDE;
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void InitializeSSL() OVERRIDE;
};
#endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_ #endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_
...@@ -311,7 +311,7 @@ unsigned int BrowserProcessImpl::ReleaseModule() { ...@@ -311,7 +311,7 @@ unsigned int BrowserProcessImpl::ReleaseModule() {
FROM_HERE, FROM_HERE,
NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true)); NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop)); FROM_HERE, NewRunnableFunction(content::DidEndMainMessageLoop));
MessageLoop::current()->Quit(); MessageLoop::current()->Quit();
} }
return module_ref_count_; return module_ref_count_;
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include "base/linux_util.h" #include "base/linux_util.h"
#include "chrome/browser/browser_main_gtk.h"
#include "chrome/browser/crash_handler_host_linux.h" #include "chrome/browser/crash_handler_host_linux.h"
#endif #endif
...@@ -84,6 +85,13 @@ ...@@ -84,6 +85,13 @@
#include "chrome/browser/tab_contents/tab_contents_view_gtk.h" #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
#include "chrome/browser/tab_contents/tab_contents_view_mac.h" #include "chrome/browser/tab_contents/tab_contents_view_mac.h"
#include "chrome/browser/browser_main_mac.h"
#endif
#if defined(OS_WIN)
#include "chrome/browser/browser_main_win.h"
#elif defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/browser_main_chromeos.h"
#endif #endif
#if defined(USE_NSS) #if defined(USE_NSS)
...@@ -113,6 +121,21 @@ static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { ...@@ -113,6 +121,21 @@ static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
namespace chrome { namespace chrome {
content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
const MainFunctionParams& parameters) {
#if defined(OS_WIN)
return new BrowserMainPartsWin(parameters);
#elif defined(OS_MACOSX)
return new BrowserMainPartsMac(parameters);
#elif defined(OS_CHROMEOS)
return new BrowserMainPartsChromeos(parameters);
#elif defined(OS_LINUX)
return new BrowserMainPartsGtk(parameters);
#else
return NULL;
#endif
}
TabContentsView* ChromeContentBrowserClient::CreateTabContentsView( TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
TabContents* tab_contents) { TabContents* tab_contents) {
#if defined(TOUCH_UI) #if defined(TOUCH_UI)
......
...@@ -15,6 +15,8 @@ namespace chrome { ...@@ -15,6 +15,8 @@ namespace chrome {
class ChromeContentBrowserClient : public content::ContentBrowserClient { class ChromeContentBrowserClient : public content::ContentBrowserClient {
public: public:
virtual content::BrowserMainParts* CreateBrowserMainParts(
const MainFunctionParams& parameters) OVERRIDE;
virtual TabContentsView* CreateTabContentsView( virtual TabContentsView* CreateTabContentsView(
TabContents* tab_contents) OVERRIDE; TabContents* tab_contents) OVERRIDE;
virtual void RenderViewHostCreated(RenderViewHost* render_view_host) OVERRIDE; virtual void RenderViewHostCreated(RenderViewHost* render_view_host) OVERRIDE;
......
...@@ -4,8 +4,15 @@ ...@@ -4,8 +4,15 @@
#include "chrome/browser/chromeos/browser_main_chromeos.h" #include "chrome/browser/chromeos/browser_main_chromeos.h"
#include "base/command_line.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h"
#include "chrome/common/chrome_switches.h"
#include "content/common/main_function_params.h"
#include "net/base/network_change_notifier.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
...@@ -41,14 +48,36 @@ class MessageLoopObserver : public MessageLoopForUI::Observer { ...@@ -41,14 +48,36 @@ class MessageLoopObserver : public MessageLoopForUI::Observer {
static base::LazyInstance<MessageLoopObserver> g_message_loop_observer( static base::LazyInstance<MessageLoopObserver> g_message_loop_observer(
base::LINKER_INITIALIZED); base::LINKER_INITIALIZED);
BrowserMainPartsChromeos::BrowserMainPartsChromeos(
const MainFunctionParams& parameters)
: BrowserMainPartsGtk(parameters) {
}
BrowserMainPartsChromeos::~BrowserMainPartsChromeos() {
if (!parameters().ui_task && chromeos::CrosLibrary::Get())
chromeos::CrosLibrary::Shutdown();
// To be precise, logout (browser shutdown) is not yet done, but the
// remaining work is negligible, hence we say LogoutDone here.
chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone",
false);
chromeos::BootTimesLoader::Get()->WriteLogoutTimes();
}
void BrowserMainPartsChromeos::PreMainMessageLoopStart() {
// Initialize CrosLibrary only for the browser, unless running tests
// (which do their own CrosLibrary setup).
if (!parameters().ui_task) {
bool use_stub = parameters().command_line_.HasSwitch(switches::kStubCros);
chromeos::CrosLibrary::Initialize(use_stub);
}
// Replace the default NetworkChangeNotifierFactory with ChromeOS specific
// implementation.
net::NetworkChangeNotifier::SetFactory(
new chromeos::CrosNetworkChangeNotifierFactory());
}
void BrowserMainPartsChromeos::PostMainMessageLoopStart() { void BrowserMainPartsChromeos::PostMainMessageLoopStart() {
BrowserMainPartsPosix::PostMainMessageLoopStart(); BrowserMainPartsPosix::PostMainMessageLoopStart();
MessageLoopForUI* message_loop = MessageLoopForUI::current(); MessageLoopForUI* message_loop = MessageLoopForUI::current();
message_loop->AddObserver(g_message_loop_observer.Pointer()); message_loop->AddObserver(g_message_loop_observer.Pointer());
} }
// static
BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
const MainFunctionParams& parameters) {
return new BrowserMainPartsChromeos(parameters);
}
...@@ -9,11 +9,14 @@ ...@@ -9,11 +9,14 @@
class BrowserMainPartsChromeos : public BrowserMainPartsGtk { class BrowserMainPartsChromeos : public BrowserMainPartsGtk {
public: public:
explicit BrowserMainPartsChromeos(const MainFunctionParams& parameters) explicit BrowserMainPartsChromeos(const MainFunctionParams& parameters);
: BrowserMainPartsGtk(parameters) {}
protected: ~BrowserMainPartsChromeos();
virtual void PostMainMessageLoopStart();
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void PostMainMessageLoopStart() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsChromeos); DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsChromeos);
}; };
......
...@@ -81,6 +81,8 @@ NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { ...@@ -81,6 +81,8 @@ NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() {
online_notification_task_->Cancel(); online_notification_task_->Cancel();
online_notification_task_ = NULL; online_notification_task_ = NULL;
} }
if (!chromeos::CrosLibrary::Get())
return;
chromeos::NetworkLibrary* lib = chromeos::NetworkLibrary* lib =
chromeos::CrosLibrary::Get()->GetNetworkLibrary(); chromeos::CrosLibrary::Get()->GetNetworkLibrary();
lib->RemoveNetworkManagerObserver(this); lib->RemoveNetworkManagerObserver(this);
......
...@@ -496,35 +496,6 @@ void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) { ...@@ -496,35 +496,6 @@ void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) {
p->SetPoint(p->x() + position.x(), p->y() + position.y()); p->SetPoint(p->x() + position.x(), p->y() + position.y());
} }
void InitRCStyles() {
static const char kRCText[] =
// Make our dialogs styled like the GNOME HIG.
//
// TODO(evanm): content-area-spacing was introduced in a later
// version of GTK, so we need to set that manually on all dialogs.
// Perhaps it would make sense to have a shared FixupDialog() function.
"style \"gnome-dialog\" {\n"
" xthickness = 12\n"
" GtkDialog::action-area-border = 0\n"
" GtkDialog::button-spacing = 6\n"
" GtkDialog::content-area-spacing = 18\n"
" GtkDialog::content-area-border = 12\n"
"}\n"
// Note we set it at the "application" priority, so users can override.
"widget \"GtkDialog\" style : application \"gnome-dialog\"\n"
// Make our about dialog special, so the image is flush with the edge.
"style \"about-dialog\" {\n"
" GtkDialog::action-area-border = 12\n"
" GtkDialog::button-spacing = 6\n"
" GtkDialog::content-area-spacing = 18\n"
" GtkDialog::content-area-border = 0\n"
"}\n"
"widget \"about-dialog\" style : application \"about-dialog\"\n";
gtk_rc_parse_string(kRCText);
}
GtkWidget* CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, GtkWidget* CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget,
bool pack_at_end, int padding) { bool pack_at_end, int padding) {
GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0); GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0);
......
...@@ -127,9 +127,6 @@ gfx::Size GetWidgetSize(GtkWidget* widget); ...@@ -127,9 +127,6 @@ gfx::Size GetWidgetSize(GtkWidget* widget);
// relative to the widget's top-left origin. // relative to the widget's top-left origin.
void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p); void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p);
// Initialize some GTK settings so that our dialogs are consistent.
void InitRCStyles();
// Stick the widget in the given hbox without expanding vertically. The widget // Stick the widget in the given hbox without expanding vertically. The widget
// is packed at the start of the hbox. This is useful for widgets that would // is packed at the start of the hbox. This is useful for widgets that would
// otherwise expand to fill the vertical space of the hbox // otherwise expand to fill the vertical space of the hbox
......
...@@ -291,6 +291,7 @@ ...@@ -291,6 +291,7 @@
'browser/browser_main_gtk.cc', 'browser/browser_main_gtk.cc',
'browser/browser_main_gtk.h', 'browser/browser_main_gtk.h',
'browser/browser_main_mac.mm', 'browser/browser_main_mac.mm',
'browser/browser_main_mac.h',
'browser/browser_main_posix.cc', 'browser/browser_main_posix.cc',
'browser/browser_main_posix.h', 'browser/browser_main_posix.h',
'browser/browser_main_win.cc', 'browser/browser_main_win.cc',
......
...@@ -719,6 +719,7 @@ ...@@ -719,6 +719,7 @@
'../content/common/child_process.cc', '../content/common/child_process.cc',
'../content/common/child_thread.cc', '../content/common/child_thread.cc',
'../content/common/content_client.cc', '../content/common/content_client.cc',
'../content/common/content_constants.cc',
'../content/common/content_counters.cc', '../content/common/content_counters.cc',
'../content/common/content_message_generator.cc', '../content/common/content_message_generator.cc',
'../content/common/content_paths.cc', '../content/common/content_paths.cc',
......
...@@ -104,10 +104,8 @@ const char* const kHelperFlavorSuffixes[] = { ...@@ -104,10 +104,8 @@ const char* const kHelperFlavorSuffixes[] = {
const wchar_t kNaClAppName[] = L"nacl64"; const wchar_t kNaClAppName[] = L"nacl64";
#if defined(GOOGLE_CHROME_BUILD) #if defined(GOOGLE_CHROME_BUILD)
const wchar_t kBrowserAppName[] = L"Chrome"; const wchar_t kBrowserAppName[] = L"Chrome";
const char kStatsFilename[] = "ChromeStats2";
#else #else
const wchar_t kBrowserAppName[] = L"Chromium"; const wchar_t kBrowserAppName[] = L"Chromium";
const char kStatsFilename[] = "ChromiumStats2";
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -158,9 +156,6 @@ const FilePath::CharType kJumpListIconDirname[] = FPL("JumpListIcons"); ...@@ -158,9 +156,6 @@ const FilePath::CharType kJumpListIconDirname[] = FPL("JumpListIcons");
const FilePath::CharType kWebAppDirname[] = FPL("Web Applications"); const FilePath::CharType kWebAppDirname[] = FPL("Web Applications");
const FilePath::CharType kServiceStateFileName[] = FPL("Service State"); const FilePath::CharType kServiceStateFileName[] = FPL("Service State");
const int kStatsMaxThreads = 32;
const int kStatsMaxCounters = 3000;
// We don't enable record mode in the released product because users could // We don't enable record mode in the released product because users could
// potentially be tricked into running a product in record mode without // potentially be tricked into running a product in record mode without
// knowing it. Enable in debug builds. Playback mode is allowed always, // knowing it. Enable in debug builds. Playback mode is allowed always,
......
...@@ -46,7 +46,6 @@ extern const wchar_t kCrashReportLog[]; ...@@ -46,7 +46,6 @@ extern const wchar_t kCrashReportLog[];
extern const wchar_t kTestingInterfaceDLL[]; extern const wchar_t kTestingInterfaceDLL[];
extern const char kInitialProfile[]; extern const char kInitialProfile[];
extern const char kMultiProfileDirPrefix[]; extern const char kMultiProfileDirPrefix[];
extern const char kStatsFilename[];
extern const wchar_t kBrowserResourcesDll[]; extern const wchar_t kBrowserResourcesDll[];
extern const wchar_t kNaClAppName[]; extern const wchar_t kNaClAppName[];
extern const FilePath::CharType kExtensionFileExtension[]; extern const FilePath::CharType kExtensionFileExtension[];
...@@ -84,9 +83,6 @@ extern const FilePath::CharType kJumpListIconDirname[]; ...@@ -84,9 +83,6 @@ extern const FilePath::CharType kJumpListIconDirname[];
extern const FilePath::CharType kWebAppDirname[]; extern const FilePath::CharType kWebAppDirname[];
extern const FilePath::CharType kServiceStateFileName[]; extern const FilePath::CharType kServiceStateFileName[];
extern const int kStatsMaxThreads;
extern const int kStatsMaxCounters;
extern const bool kRecordModeEnabled; extern const bool kRecordModeEnabled;
// Most sequence numbers are used by a renderer when responding to a browser // Most sequence numbers are used by a renderer when responding to a browser
......
...@@ -101,12 +101,6 @@ const char kAutomationReinitializeOnChannelError[] = ...@@ -101,12 +101,6 @@ const char kAutomationReinitializeOnChannelError[] =
const char kBlockReadingThirdPartyCookies[] = const char kBlockReadingThirdPartyCookies[] =
"block-reading-third-party-cookies"; "block-reading-third-party-cookies";
// Causes the browser process to throw an assertion on startup.
const char kBrowserAssertTest[] = "assert-test";
// Causes the browser process to crash on startup.
const char kBrowserCrashTest[] = "crash-test";
// How often (in seconds) to check for updates. Should only be used for // How often (in seconds) to check for updates. Should only be used for
// testing purposes. // testing purposes.
const char kCheckForUpdateIntervalSec[] = "check-for-update-interval"; const char kCheckForUpdateIntervalSec[] = "check-for-update-interval";
...@@ -303,9 +297,6 @@ const char kDisableSanitizedClientSidePhishingDetection[] = ...@@ -303,9 +297,6 @@ const char kDisableSanitizedClientSidePhishingDetection[] =
// Disable site-specific tailoring to compatibility issues in WebKit. // Disable site-specific tailoring to compatibility issues in WebKit.
const char kDisableSiteSpecificQuirks[] = "disable-site-specific-quirks"; const char kDisableSiteSpecificQuirks[] = "disable-site-specific-quirks";
// Disable False Start in SSL and TLS connections.
const char kDisableSSLFalseStart[] = "disable-ssl-false-start";
// Disable SSL v3 (usually for testing purposes). // Disable SSL v3 (usually for testing purposes).
const char kDisableSSL3[] = "disable-ssl3"; const char kDisableSSL3[] = "disable-ssl3";
...@@ -441,11 +432,6 @@ const char kEnableConnectBackupJobs[] = "enable-connect-backup-jobs"; ...@@ -441,11 +432,6 @@ const char kEnableConnectBackupJobs[] = "enable-connect-backup-jobs";
// Enables web developers to create apps for Chrome without using crx packages. // Enables web developers to create apps for Chrome without using crx packages.
const char kEnableCrxlessWebApps[] = "enable-crxless-web-apps"; const char kEnableCrxlessWebApps[] = "enable-crxless-web-apps";
// Enable DNS side checking of certificates. Still experimental, should only
// be used by developers at the current time.
const char kEnableDNSCertProvenanceChecking[] =
"enable-dns-cert-provenance-checking";
// Enables extension APIs that are in development. // Enables extension APIs that are in development.
const char kEnableExperimentalExtensionApis[] = const char kEnableExperimentalExtensionApis[] =
"enable-experimental-extension-apis"; "enable-experimental-extension-apis";
...@@ -502,9 +488,6 @@ const char kEnableNaCl[] = "enable-nacl"; ...@@ -502,9 +488,6 @@ const char kEnableNaCl[] = "enable-nacl";
// Enables debugging via RSP over a socket. // Enables debugging via RSP over a socket.
const char kEnableNaClDebug[] = "enable-nacl-debug"; const char kEnableNaClDebug[] = "enable-nacl-debug";
// Enables TLS origin bound certificate extension.
const char kEnableOriginBoundCerts[] = "enable-origin-bound-certs";
// Enable content settings based on host *and* plug-in. // Enable content settings based on host *and* plug-in.
const char kEnableResourceContentSettings[] = const char kEnableResourceContentSettings[] =
"enable-resource-content-settings"; "enable-resource-content-settings";
...@@ -524,10 +507,6 @@ const char kEnableShortcutsProvider[] = "enable-shortcuts-provider"; ...@@ -524,10 +507,6 @@ const char kEnableShortcutsProvider[] = "enable-shortcuts-provider";
// On platforms that support it, enable smooth scroll animation. // On platforms that support it, enable smooth scroll animation.
const char kEnableSmoothScrolling[] = "enable-smooth-scrolling"; const char kEnableSmoothScrolling[] = "enable-smooth-scrolling";
// Enables TLS cached info extension.
const char kEnableSSLCachedInfo[] = "enable-ssl-cached-info";
// Enable OAuth sign-in for sync. // Enable OAuth sign-in for sync.
const char kEnableSyncOAuth[] = "enable-sync-oauth"; const char kEnableSyncOAuth[] = "enable-sync-oauth";
...@@ -547,10 +526,6 @@ const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu"; ...@@ -547,10 +526,6 @@ const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu";
// Enable the "synced bookmarks" folder. // Enable the "synced bookmarks" folder.
const char kEnableSyncedBookmarksFolder[] = "enable-synced-bookmarks-folder"; const char kEnableSyncedBookmarksFolder[] = "enable-synced-bookmarks-folder";
// Enable use of experimental TCP sockets API for sending data in the
// SYN packet.
const char kEnableTcpFastOpen[] = "enable-tcp-fastopen";
// Enables the option to show tabs as a vertical stack down the side of the // Enables the option to show tabs as a vertical stack down the side of the
// browser window. // browser window.
const char kEnableVerticalTabs[] = "enable-vertical-tabs"; const char kEnableVerticalTabs[] = "enable-vertical-tabs";
......
...@@ -45,8 +45,6 @@ extern const char kAuthServerWhitelist[]; ...@@ -45,8 +45,6 @@ extern const char kAuthServerWhitelist[];
extern const char kAutomationClientChannelID[]; extern const char kAutomationClientChannelID[];
extern const char kAutomationReinitializeOnChannelError[]; extern const char kAutomationReinitializeOnChannelError[];
extern const char kBlockReadingThirdPartyCookies[]; extern const char kBlockReadingThirdPartyCookies[];
extern const char kBrowserAssertTest[];
extern const char kBrowserCrashTest[];
extern const char kCheckForUpdateIntervalSec[]; extern const char kCheckForUpdateIntervalSec[];
extern const char kChromeVersion[]; extern const char kChromeVersion[];
extern const char kCipherSuiteBlacklist[]; extern const char kCipherSuiteBlacklist[];
...@@ -92,7 +90,6 @@ extern const char kDisableRestoreBackgroundContents[]; ...@@ -92,7 +90,6 @@ extern const char kDisableRestoreBackgroundContents[];
extern const char kDisableSanitizedClientSidePhishingDetection[]; extern const char kDisableSanitizedClientSidePhishingDetection[];
extern const char kDisableSiteSpecificQuirks[]; extern const char kDisableSiteSpecificQuirks[];
extern const char kDisableSSL3[]; extern const char kDisableSSL3[];
extern const char kDisableSSLFalseStart[];
extern const char kDisableSync[]; extern const char kDisableSync[];
extern const char kDisableSyncApps[]; extern const char kDisableSyncApps[];
extern const char kDisableSyncAutofill[]; extern const char kDisableSyncAutofill[];
...@@ -129,7 +126,6 @@ extern const char kEnableCloudPrint[]; ...@@ -129,7 +126,6 @@ extern const char kEnableCloudPrint[];
extern const char kEnableCompositeToTexture[]; extern const char kEnableCompositeToTexture[];
extern const char kEnableConnectBackupJobs[]; extern const char kEnableConnectBackupJobs[];
extern const char kEnableCrxlessWebApps[]; extern const char kEnableCrxlessWebApps[];
extern const char kEnableDNSCertProvenanceChecking[];
extern const char kEnableExperimentalExtensionApis[]; extern const char kEnableExperimentalExtensionApis[];
extern const char kEnableExtensionTimelineApi[]; extern const char kEnableExtensionTimelineApi[];
extern const char kEnableFastback[]; extern const char kEnableFastback[];
...@@ -144,21 +140,18 @@ extern const char kEnableMacCookies[]; ...@@ -144,21 +140,18 @@ extern const char kEnableMacCookies[];
extern const char kEnableMemoryInfo[]; extern const char kEnableMemoryInfo[];
extern const char kEnableNaCl[]; extern const char kEnableNaCl[];
extern const char kEnableNaClDebug[]; extern const char kEnableNaClDebug[];
extern const char kEnableOriginBoundCerts[];
extern const char kEnablePanels[]; extern const char kEnablePanels[];
extern const char kEnablePreconnect[]; extern const char kEnablePreconnect[];
extern const char kEnableResourceContentSettings[]; extern const char kEnableResourceContentSettings[];
extern const char kEnableSearchProviderApiV2[]; extern const char kEnableSearchProviderApiV2[];
extern const char kEnableShortcutsProvider[]; extern const char kEnableShortcutsProvider[];
extern const char kEnableSmoothScrolling[]; extern const char kEnableSmoothScrolling[];
extern const char kEnableSSLCachedInfo[];
extern const char kEnableSyncOAuth[]; extern const char kEnableSyncOAuth[];
extern const char kEnableSyncSearchEngines[]; extern const char kEnableSyncSearchEngines[];
extern const char kEnableSyncSessions[]; extern const char kEnableSyncSessions[];
extern const char kEnableSyncSessionsForOtherClients[]; extern const char kEnableSyncSessionsForOtherClients[];
extern const char kEnableSyncedBookmarksFolder[]; extern const char kEnableSyncedBookmarksFolder[];
extern const char kEnableTabGroupsContextMenu[]; extern const char kEnableTabGroupsContextMenu[];
extern const char kEnableTcpFastOpen[];
extern const char kEnableTopSites[]; extern const char kEnableTopSites[];
extern const char kEnableVerticalTabs[]; extern const char kEnableVerticalTabs[];
extern const char kEnableWatchdog[]; extern const char kEnableWatchdog[];
......
...@@ -12,15 +12,19 @@ ...@@ -12,15 +12,19 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/metrics/stats_table.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/string_number_conversions.h"
#include "content/app/content_main_delegate.h" #include "content/app/content_main_delegate.h"
#include "content/common/content_constants.h"
#include "content/common/content_paths.h" #include "content/common/content_paths.h"
#include "content/common/content_switches.h" #include "content/common/content_switches.h"
#include "content/common/main_function_params.h" #include "content/common/main_function_params.h"
#include "content/common/sandbox_init_wrapper.h" #include "content/common/sandbox_init_wrapper.h"
#include "content/common/set_process_title.h" #include "content/common/set_process_title.h"
#include "crypto/nss_util.h" #include "crypto/nss_util.h"
#include "ipc/ipc_switches.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_paths.h"
...@@ -53,6 +57,7 @@ int tc_set_new_mode(int mode); ...@@ -53,6 +57,7 @@ int tc_set_new_mode(int mode);
} }
#endif #endif
extern int BrowserMain(const MainFunctionParams&);
extern int RendererMain(const MainFunctionParams&); extern int RendererMain(const MainFunctionParams&);
extern int GpuMain(const MainFunctionParams&); extern int GpuMain(const MainFunctionParams&);
extern int PluginMain(const MainFunctionParams&); extern int PluginMain(const MainFunctionParams&);
...@@ -184,6 +189,27 @@ void CommonSubprocessInit(const std::string& process_type) { ...@@ -184,6 +189,27 @@ void CommonSubprocessInit(const std::string& process_type) {
#endif #endif
} }
void InitializeStatsTable(base::ProcessId browser_pid,
const CommandLine& command_line) {
// Initialize the Stats Counters table. With this initialized,
// the StatsViewer can be utilized to read counters outside of
// Chrome. These lines can be commented out to effectively turn
// counters 'off'. The table is created and exists for the life
// of the process. It is not cleaned up.
if (command_line.HasSwitch(switches::kEnableStatsTable) ||
command_line.HasSwitch(switches::kEnableBenchmarking)) {
// NOTIMPLEMENTED: we probably need to shut this down correctly to avoid
// leaking shared memory regions on posix platforms.
std::string statsfile =
base::StringPrintf("%s-%u",
content::kStatsFilename,
static_cast<unsigned int>(browser_pid));
base::StatsTable* stats_table = new base::StatsTable(statsfile,
content::kStatsMaxThreads, content::kStatsMaxCounters);
base::StatsTable::set_current(stats_table);
}
}
// We dispatch to a process-type-specific FooMain() based on a command-line // We dispatch to a process-type-specific FooMain() based on a command-line
// flag. This struct is used to build a table of (flag, main function) pairs. // flag. This struct is used to build a table of (flag, main function) pairs.
struct MainFunction { struct MainFunction {
...@@ -217,6 +243,13 @@ int RunZygote(const MainFunctionParams& main_function_params, ...@@ -217,6 +243,13 @@ int RunZygote(const MainFunctionParams& main_function_params,
// line so update it here with the new version. // line so update it here with the new version.
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); const CommandLine& command_line = *CommandLine::ForCurrentProcess();
// The StatsTable must be initialized in each process; we already
// initialized for the browser process, now we need to initialize
// within the new processes as well.
pid_t browser_pid = base::GetParentProcessId(
base::GetParentProcessId(base::GetCurrentProcId()));
InitializeStatsTable(browser_pid, command_line);
MainFunctionParams main_params(command_line, MainFunctionParams main_params(command_line,
main_function_params.sandbox_info_, main_function_params.sandbox_info_,
main_function_params.autorelease_pool_); main_function_params.autorelease_pool_);
...@@ -244,6 +277,7 @@ int RunNamedProcessTypeMain(const std::string& process_type, ...@@ -244,6 +277,7 @@ int RunNamedProcessTypeMain(const std::string& process_type,
const MainFunctionParams& main_function_params, const MainFunctionParams& main_function_params,
content::ContentMainDelegate* delegate) { content::ContentMainDelegate* delegate) {
static const MainFunction kMainFunctions[] = { static const MainFunction kMainFunctions[] = {
{ "", BrowserMain },
{ switches::kRendererProcess, RendererMain }, { switches::kRendererProcess, RendererMain },
{ switches::kPluginProcess, PluginMain }, { switches::kPluginProcess, PluginMain },
{ switches::kWorkerProcess, WorkerMain }, { switches::kWorkerProcess, WorkerMain },
...@@ -389,6 +423,24 @@ int ContentMain(int argc, ...@@ -389,6 +423,24 @@ int ContentMain(int argc,
CHECK(icu_util::Initialize()); CHECK(icu_util::Initialize());
base::ProcessId browser_pid = base::GetCurrentProcId();
if (command_line.HasSwitch(switches::kProcessChannelID)) {
#if defined(OS_WIN) || defined(OS_MACOSX)
std::string channel_name =
command_line.GetSwitchValueASCII(switches::kProcessChannelID);
int browser_pid_int;
base::StringToInt(channel_name, &browser_pid_int);
browser_pid = static_cast<base::ProcessId>(browser_pid_int);
DCHECK_NE(browser_pid_int, 0);
#elif defined(OS_POSIX)
// On linux, we're in the zygote here; so we need the parent process' id.
browser_pid = base::GetParentProcessId(base::GetCurrentProcId());
#endif
}
InitializeStatsTable(browser_pid, command_line);
if (delegate) delegate->PreSandboxStartup(); if (delegate) delegate->PreSandboxStartup();
if (!process_type.empty()) if (!process_type.empty())
......
This diff is collapsed.
// 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 CONTENT_BROWSER_BROWSER_MAIN_H_
#define CONTENT_BROWSER_BROWSER_MAIN_H_
#pragma once
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
class BrowserThread;
class CommandLine;
class HighResolutionTimerManager;
class MessageLoop;
struct MainFunctionParams;
namespace base {
class SystemMonitor;
}
namespace net {
class NetworkChangeNotifier;
}
namespace content {
// BrowserMainParts:
// This class contains different "stages" to be executed in |BrowserMain()|,
// mostly initialization. This is made into a class rather than just functions
// so each stage can create and maintain state. Each part is represented by a
// single method (e.g., "EarlyInitialization()"), which does the following:
// - calls a method (e.g., "PreEarlyInitialization()") which individual
// platforms can override to provide platform-specific code which is to be
// executed before the common code;
// - calls various methods for things common to all platforms (for that given
// stage); and
// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
// code to be called after the common code.
// As indicated above, platforms should override the default "Pre...()" and
// "Post...()" methods when necessary; they need not call the superclass's
// implementation (which is empty).
//
// Parts:
// - EarlyInitialization: things which should be done as soon as possible on
// program start (such as setting up signal handlers) and things to be done
// at some generic time before the start of the main message loop.
// - MainMessageLoopStart: things beginning with the start of the main message
// loop and ending with initialization of the main thread; platform-specific
// things which should be done immediately before the start of the main
// message loop should go in |PreMainMessageLoopStart()|.
// - (more to come)
//
// How to add stuff (to existing parts):
// - Figure out when your new code should be executed. What must happen
// before/after your code is executed? Are there performance reasons for
// running your code at a particular time? Document these things!
// - Split out any platform-specific bits. Please avoid #ifdefs it at all
// possible. You have two choices for platform-specific code: (1) Execute it
// from one of the platform-specific |Pre/Post...()| methods; do this if the
// code is unique to a platform type. Or (2) execute it from one of the
// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
// implementations of your code (in a virtual method); do this if you need to
// provide different implementations across most/all platforms.
// - Unless your new code is just one or two lines, put it into a separate
// method with a well-defined purpose. (Likewise, if you're adding to an
// existing chunk which makes it longer than one or two lines, please move
// the code out into a separate method.)
class BrowserMainParts {
public:
explicit BrowserMainParts(const MainFunctionParams& parameters);
virtual ~BrowserMainParts();
// Parts to be called by |BrowserMain()|.
void EarlyInitialization();
void MainMessageLoopStart();
void InitializeToolkit();
// Temporary function since not all the code from chrome is moved over yet.
virtual int TemporaryContinue();
protected:
// Methods to be overridden to provide platform-specific code; these
// correspond to the "parts" above.
virtual void PreEarlyInitialization();
virtual void PostEarlyInitialization();
virtual void PreMainMessageLoopStart();
virtual void PostMainMessageLoopStart();
// Used to initialize NSPR where appropriate.
virtual void InitializeSSL();
// Allows an embedder to do any extra toolkit initialization.
virtual void ToolkitInitialized();
// Accessors for data members (below) ----------------------------------------
const MainFunctionParams& parameters() const {
return parameters_;
}
const CommandLine& parsed_command_line() const {
return parsed_command_line_;
}
MessageLoop& main_message_loop() const {
return *main_message_loop_;
}
private:
void InitializeMainThread();
// Members initialized on construction ---------------------------------------
const MainFunctionParams& parameters_;
const CommandLine& parsed_command_line_;
// Members initialized in |MainMessageLoopStart()| ---------------------------
scoped_ptr<MessageLoop> main_message_loop_;
scoped_ptr<base::SystemMonitor> system_monitor_;
scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
scoped_ptr<BrowserThread> main_thread_;
DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
};
// Perform platform-specific work that needs to be done after the main event
// loop has ended. The embedder must be sure to call this.
// TODO(jam): change this so that content calls it so that we don't depend on
// the embedder.
void DidEndMainMessageLoop();
} // namespace content
#endif // CONTENT_BROWSER_BROWSER_MAIN_H_
...@@ -32,8 +32,13 @@ class TabContents; ...@@ -32,8 +32,13 @@ class TabContents;
class TabContentsView; class TabContentsView;
class WorkerProcessHost; class WorkerProcessHost;
struct DesktopNotificationHostMsg_Show_Params; struct DesktopNotificationHostMsg_Show_Params;
struct MainFunctionParams;
struct WebPreferences; struct WebPreferences;
namespace content {
class BrowserMainParts;
}
namespace crypto { namespace crypto {
class CryptoModuleBlockingPasswordDelegate; class CryptoModuleBlockingPasswordDelegate;
} }
...@@ -59,6 +64,7 @@ class Clipboard; ...@@ -59,6 +64,7 @@ class Clipboard;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class BrowserMainParts;
class ResourceContext; class ResourceContext;
class WebUIFactory; class WebUIFactory;
...@@ -74,6 +80,12 @@ class ContentBrowserClient { ...@@ -74,6 +80,12 @@ class ContentBrowserClient {
public: public:
virtual ~ContentBrowserClient() {} virtual ~ContentBrowserClient() {}
// Allows the embedder to return a customed BrowserMainParts implementation
// for the browser staratup code. Can return NULL, in which case the default
// is used.
virtual BrowserMainParts* CreateBrowserMainParts(
const MainFunctionParams& parameters) = 0;
virtual TabContentsView* CreateTabContentsView(TabContents* tab_contents) = 0; virtual TabContentsView* CreateTabContentsView(TabContents* tab_contents) = 0;
// Notifies that a new RenderHostView has been created. // Notifies that a new RenderHostView has been created.
......
...@@ -19,6 +19,11 @@ namespace content { ...@@ -19,6 +19,11 @@ namespace content {
MockContentBrowserClient::~MockContentBrowserClient() { MockContentBrowserClient::~MockContentBrowserClient() {
} }
BrowserMainParts* MockContentBrowserClient::CreateBrowserMainParts(
const MainFunctionParams& parameters) {
return NULL;
}
TabContentsView* MockContentBrowserClient::CreateTabContentsView( TabContentsView* MockContentBrowserClient::CreateTabContentsView(
TabContents* tab_contents) { TabContents* tab_contents) {
return new TestTabContentsView; return new TestTabContentsView;
......
...@@ -18,6 +18,8 @@ class MockContentBrowserClient : public ContentBrowserClient { ...@@ -18,6 +18,8 @@ class MockContentBrowserClient : public ContentBrowserClient {
public: public:
virtual ~MockContentBrowserClient(); virtual ~MockContentBrowserClient();
virtual BrowserMainParts* CreateBrowserMainParts(
const MainFunctionParams& parameters) OVERRIDE;
virtual TabContentsView* CreateTabContentsView( virtual TabContentsView* CreateTabContentsView(
TabContents* tab_contents) OVERRIDE; TabContents* tab_contents) OVERRIDE;
virtual void RenderViewHostCreated( virtual void RenderViewHostCreated(
......
...@@ -16,6 +16,15 @@ const size_t kMaxURLDisplayChars = 32 * 1024; ...@@ -16,6 +16,15 @@ const size_t kMaxURLDisplayChars = 32 * 1024;
const char kDefaultPluginRenderViewId[] = "PluginRenderViewId"; const char kDefaultPluginRenderViewId[] = "PluginRenderViewId";
const char kDefaultPluginRenderProcessId[] = "PluginRenderProcessId"; const char kDefaultPluginRenderProcessId[] = "PluginRenderProcessId";
} // namespace content #if defined(GOOGLE_CHROME_BUILD)
const wchar_t kBrowserAppName[] = L"Chrome";
const char kStatsFilename[] = "ChromeStats2";
#else
const wchar_t kBrowserAppName[] = L"Chromium";
const char kStatsFilename[] = "ChromiumStats2";
#endif
const int kStatsMaxThreads = 32;
const int kStatsMaxCounters = 3000;
#undef FPL } // namespace content
...@@ -35,6 +35,10 @@ extern const size_t kMaxURLDisplayChars; ...@@ -35,6 +35,10 @@ extern const size_t kMaxURLDisplayChars;
extern const char kDefaultPluginRenderViewId[]; extern const char kDefaultPluginRenderViewId[];
extern const char kDefaultPluginRenderProcessId[]; extern const char kDefaultPluginRenderProcessId[];
extern const char kStatsFilename[];
extern const int kStatsMaxThreads;
extern const int kStatsMaxCounters;
} // namespace content } // namespace content
#endif // CONTENT_COMMON_CHROME_CONSTANTS_H_ #endif // CONTENT_COMMON_CHROME_CONSTANTS_H_
...@@ -17,6 +17,12 @@ const char kAllowRunningInsecureContent[] = "allow-running-insecure-content"; ...@@ -17,6 +17,12 @@ const char kAllowRunningInsecureContent[] = "allow-running-insecure-content";
// Allows debugging of sandboxed processes (see zygote_main_linux.cc). // Allows debugging of sandboxed processes (see zygote_main_linux.cc).
const char kAllowSandboxDebugging[] = "allow-sandbox-debugging"; const char kAllowSandboxDebugging[] = "allow-sandbox-debugging";
// Causes the browser process to throw an assertion on startup.
const char kBrowserAssertTest[] = "assert-test";
// Causes the browser process to crash on startup.
const char kBrowserCrashTest[] = "crash-test";
// Path to the exe to run for the renderer and plugin subprocesses. // Path to the exe to run for the renderer and plugin subprocesses.
const char kBrowserSubprocessPath[] = "browser-subprocess-path"; const char kBrowserSubprocessPath[] = "browser-subprocess-path";
...@@ -117,9 +123,6 @@ const char kDisableLocalStorage[] = "disable-local-storage"; ...@@ -117,9 +123,6 @@ const char kDisableLocalStorage[] = "disable-local-storage";
// builds. // builds.
const char kDisableLogging[] = "disable-logging"; const char kDisableLogging[] = "disable-logging";
// Disable smooth scrolling for testing.
const char kDisableSmoothScrolling[] = "disable-smooth-scrolling";
// Prevent plugins from running. // Prevent plugins from running.
const char kDisablePlugins[] = "disable-plugins"; const char kDisablePlugins[] = "disable-plugins";
...@@ -129,6 +132,12 @@ const char kDisablePopupBlocking[] = "disable-popup-blocking"; ...@@ -129,6 +132,12 @@ const char kDisablePopupBlocking[] = "disable-popup-blocking";
// Turns off the accessibility in the renderer. // Turns off the accessibility in the renderer.
const char kDisableRendererAccessibility[] = "disable-renderer-accessibility"; const char kDisableRendererAccessibility[] = "disable-renderer-accessibility";
// Disable False Start in SSL and TLS connections.
const char kDisableSSLFalseStart[] = "disable-ssl-false-start";
// Disable smooth scrolling for testing.
const char kDisableSmoothScrolling[] = "disable-smooth-scrolling";
// Disable the seccomp sandbox (Linux only) // Disable the seccomp sandbox (Linux only)
const char kDisableSeccompSandbox[] = "disable-seccomp-sandbox"; const char kDisableSeccompSandbox[] = "disable-seccomp-sandbox";
...@@ -168,6 +177,11 @@ const char kEnableAccessibilityLogging[] = "enable-accessibility-logging"; ...@@ -168,6 +177,11 @@ const char kEnableAccessibilityLogging[] = "enable-accessibility-logging";
// Enables the benchmarking extensions. // Enables the benchmarking extensions.
const char kEnableBenchmarking[] = "enable-benchmarking"; const char kEnableBenchmarking[] = "enable-benchmarking";
// Enable DNS side checking of certificates. Still experimental, should only
// be used by developers at the current time.
const char kEnableDNSCertProvenanceChecking[] =
"enable-dns-cert-provenance-checking";
// Enables device motion events. // Enables device motion events.
const char kEnableDeviceMotion[] = "enable-device-motion"; const char kEnableDeviceMotion[] = "enable-device-motion";
...@@ -190,9 +204,15 @@ const char kEnableMediaStream[] = "enable-media-stream"; ...@@ -190,9 +204,15 @@ const char kEnableMediaStream[] = "enable-media-stream";
// assumed to be sRGB. // assumed to be sRGB.
const char kEnableMonitorProfile[] = "enable-monitor-profile"; const char kEnableMonitorProfile[] = "enable-monitor-profile";
// Enables TLS origin bound certificate extension.
const char kEnableOriginBoundCerts[] = "enable-origin-bound-certs";
// Enable caching of pre-parsed JS script data. See http://crbug.com/32407. // Enable caching of pre-parsed JS script data. See http://crbug.com/32407.
const char kEnablePreparsedJsCaching[] = "enable-preparsed-js-caching"; const char kEnablePreparsedJsCaching[] = "enable-preparsed-js-caching";
// Enables TLS cached info extension.
const char kEnableSSLCachedInfo[] = "enable-ssl-cached-info";
// Cause the OS X sandbox write to syslog every time an access to a resource // Cause the OS X sandbox write to syslog every time an access to a resource
// is denied by the sandbox. // is denied by the sandbox.
const char kEnableSandboxLogging[] = "enable-sandbox-logging"; const char kEnableSandboxLogging[] = "enable-sandbox-logging";
...@@ -203,6 +223,10 @@ const char kEnableSeccompSandbox[] = "enable-seccomp-sandbox"; ...@@ -203,6 +223,10 @@ const char kEnableSeccompSandbox[] = "enable-seccomp-sandbox";
// Enables StatsTable, logging statistics to a global named shared memory table. // Enables StatsTable, logging statistics to a global named shared memory table.
const char kEnableStatsTable[] = "enable-stats-table"; const char kEnableStatsTable[] = "enable-stats-table";
// Enable use of experimental TCP sockets API for sending data in the
// SYN packet.
const char kEnableTcpFastOpen[] = "enable-tcp-fastopen";
// Enables support for fullscreen video. Current implementation is // Enables support for fullscreen video. Current implementation is
// incomplete and this flag is used for development and testing. // incomplete and this flag is used for development and testing.
const char kEnableVideoFullscreen[] = "enable-video-fullscreen"; const char kEnableVideoFullscreen[] = "enable-video-fullscreen";
......
...@@ -15,6 +15,8 @@ namespace switches { ...@@ -15,6 +15,8 @@ namespace switches {
extern const char kAllowFileAccessFromFiles[]; extern const char kAllowFileAccessFromFiles[];
extern const char kAllowRunningInsecureContent[]; extern const char kAllowRunningInsecureContent[];
extern const char kAllowSandboxDebugging[]; extern const char kAllowSandboxDebugging[];
extern const char kBrowserAssertTest[];
extern const char kBrowserCrashTest[];
extern const char kBrowserSubprocessPath[]; extern const char kBrowserSubprocessPath[];
// TODO(jam): this doesn't belong in content. // TODO(jam): this doesn't belong in content.
extern const char kChromeFrame[]; extern const char kChromeFrame[];
...@@ -50,6 +52,7 @@ extern const char kDisableSmoothScrolling[]; ...@@ -50,6 +52,7 @@ extern const char kDisableSmoothScrolling[];
extern const char kDisablePlugins[]; extern const char kDisablePlugins[];
extern const char kDisablePopupBlocking[]; extern const char kDisablePopupBlocking[];
extern const char kDisableRendererAccessibility[]; extern const char kDisableRendererAccessibility[];
extern const char kDisableSSLFalseStart[];
extern const char kDisableSeccompSandbox[]; extern const char kDisableSeccompSandbox[];
extern const char kDisableSessionStorage[]; extern const char kDisableSessionStorage[];
extern const char kDisableSharedWorkers[]; extern const char kDisableSharedWorkers[];
...@@ -62,16 +65,20 @@ extern const char kEnableAcceleratedDrawing[]; ...@@ -62,16 +65,20 @@ extern const char kEnableAcceleratedDrawing[];
extern const char kEnableAccessibility[]; extern const char kEnableAccessibility[];
extern const char kEnableAccessibilityLogging[]; extern const char kEnableAccessibilityLogging[];
extern const char kEnableBenchmarking[]; extern const char kEnableBenchmarking[];
extern const char kEnableDNSCertProvenanceChecking[];
extern const char kEnableDeviceMotion[]; extern const char kEnableDeviceMotion[];
extern const char kEnableFullScreen[]; extern const char kEnableFullScreen[];
extern const char kEnableGPUPlugin[]; extern const char kEnableGPUPlugin[];
extern const char kEnableLogging[]; extern const char kEnableLogging[];
extern const char kEnableMediaStream[]; extern const char kEnableMediaStream[];
extern const char kEnableMonitorProfile[]; extern const char kEnableMonitorProfile[];
extern const char kEnableOriginBoundCerts[];
extern const char kEnablePreparsedJsCaching[]; extern const char kEnablePreparsedJsCaching[];
extern const char kEnableSSLCachedInfo[];
extern const char kEnableSandboxLogging[]; extern const char kEnableSandboxLogging[];
extern const char kEnableSeccompSandbox[]; extern const char kEnableSeccompSandbox[];
extern const char kEnableStatsTable[]; extern const char kEnableStatsTable[];
extern const char kEnableTcpFastOpen[];
extern const char kEnableVideoFullscreen[]; extern const char kEnableVideoFullscreen[];
extern const char kEnableVideoLogging[]; extern const char kEnableVideoLogging[];
extern const char kEnableWebIntents[]; extern const char kEnableWebIntents[];
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
'browser/browser_child_process_host.cc', 'browser/browser_child_process_host.cc',
'browser/browser_child_process_host.h', 'browser/browser_child_process_host.h',
'browser/browser_context.h', 'browser/browser_context.h',
'browser/browser_main.cc',
'browser/browser_main.h',
'browser/browser_message_filter.cc', 'browser/browser_message_filter.cc',
'browser/browser_message_filter.h', 'browser/browser_message_filter.h',
'browser/browser_thread.cc', 'browser/browser_thread.cc',
......
...@@ -219,4 +219,33 @@ uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { ...@@ -219,4 +219,33 @@ uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
return new_pixels; return new_pixels;
} }
void InitRCStyles() {
static const char kRCText[] =
// Make our dialogs styled like the GNOME HIG.
//
// TODO(evanm): content-area-spacing was introduced in a later
// version of GTK, so we need to set that manually on all dialogs.
// Perhaps it would make sense to have a shared FixupDialog() function.
"style \"gnome-dialog\" {\n"
" xthickness = 12\n"
" GtkDialog::action-area-border = 0\n"
" GtkDialog::button-spacing = 6\n"
" GtkDialog::content-area-spacing = 18\n"
" GtkDialog::content-area-border = 12\n"
"}\n"
// Note we set it at the "application" priority, so users can override.
"widget \"GtkDialog\" style : application \"gnome-dialog\"\n"
// Make our about dialog special, so the image is flush with the edge.
"style \"about-dialog\" {\n"
" GtkDialog::action-area-border = 12\n"
" GtkDialog::button-spacing = 6\n"
" GtkDialog::content-area-spacing = 18\n"
" GtkDialog::content-area-border = 0\n"
"}\n"
"widget \"about-dialog\" style : application \"about-dialog\"\n";
gtk_rc_parse_string(kRCText);
}
} // namespace gfx } // namespace gfx
...@@ -66,6 +66,9 @@ UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label); ...@@ -66,6 +66,9 @@ UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label);
// assumed to be 4 * |width|. // assumed to be 4 * |width|.
uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride);
// Initialize some GTK settings so that our dialogs are consistent.
void InitRCStyles();
} // namespace gfx } // namespace gfx
// It's not legal C++ to have a templatized typedefs, so we wrap it in a // It's not legal C++ to have a templatized typedefs, so we wrap it in a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment