diff options
author | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-19 19:26:36 +0000 |
---|---|---|
committer | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-19 19:26:36 +0000 |
commit | 97ef83f1b09593f78e402f32d6ed3f6d4a9526ac (patch) | |
tree | 2655279c6152743a01c7995670e6d8bdf53ce30b /chrome | |
parent | 6b2e6c8e02c3d37aaf7bebf38833c85b851c1074 (diff) | |
download | chromium_src-97ef83f1b09593f78e402f32d6ed3f6d4a9526ac.zip chromium_src-97ef83f1b09593f78e402f32d6ed3f6d4a9526ac.tar.gz chromium_src-97ef83f1b09593f78e402f32d6ed3f6d4a9526ac.tar.bz2 |
Re-apply 922cff9cd081e3ae327b52d3cc6bd8423307dee0
Original CL: http://codereview.chromium.org/8670001
The CL was reverted @ http://codereview.chromium.org/8774035, with no explanation. Fortunately not too much has changed in the meanwhile. I did make sure to update any moved code that changed.
Change-Id: I5e315b5eca407e944c5f029610638fd03ab27297
BUG=chromium-os:103821
TEST=All tests pass.
TBR=satorux@chromium.org, davemoore@chromium.org
Review URL: http://codereview.chromium.org/8982002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115009 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 288 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.h | 11 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_extra_parts.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_extra_parts.h | 6 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_extra_parts_aura.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_extra_parts_aura.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 280 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.h | 7 |
8 files changed, 346 insertions, 260 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 504b41d..d1b0bf3 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -75,6 +75,7 @@ #include "chrome/browser/shell_integration.h" #include "chrome/browser/translate/translate_manager.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_init.h" #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" #include "chrome/common/child_process_logging.h" @@ -128,25 +129,9 @@ #endif #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/audio_handler.h" -#include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros_settings.h" #include "chrome/browser/chromeos/cros_settings_names.h" -#include "chrome/browser/chromeos/customization_document.h" -#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" -#include "chrome/browser/chromeos/external_metrics.h" -#include "chrome/browser/chromeos/login/authenticator.h" -#include "chrome/browser/chromeos/login/login_utils.h" -#include "chrome/browser/chromeos/login/ownership_service.h" -#include "chrome/browser/chromeos/login/screen_locker.h" -#include "chrome/browser/chromeos/login/user_manager.h" -#include "chrome/browser/chromeos/status/status_area_view_chromeos.h" -#include "chrome/browser/chromeos/system/runtime_environment.h" -#include "chrome/browser/chromeos/system_key_event_listener.h" -#include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" -#include "chrome/browser/oom_priority_manager.h" -#include "chrome/browser/ui/views/browser_dialogs.h" #endif // TODO(port): several win-only methods have been pulled out of this, but @@ -484,107 +469,6 @@ void InitializeGpuDataManager(const CommandLine& parsed_command_line) { GpuDataManager::GetInstance()->SetGpuBlacklist(gpu_blacklist); } -#if defined(OS_CHROMEOS) - -// Class is used to login using passed username and password. -// The instance will be deleted upon success or failure. -class StubLogin : public chromeos::LoginStatusConsumer, - public chromeos::LoginUtils::Delegate { - public: - StubLogin(std::string username, std::string password) - : pending_requests_(false), - profile_prepared_(false) { - authenticator_ = chromeos::LoginUtils::Get()->CreateAuthenticator(this); - authenticator_.get()->AuthenticateToLogin( - g_browser_process->profile_manager()->GetDefaultProfile(), - username, - password, - std::string(), - std::string()); - } - - ~StubLogin() { - chromeos::LoginUtils::Get()->DelegateDeleted(this); - } - - void OnLoginFailure(const chromeos::LoginFailure& error) { - LOG(ERROR) << "Login Failure: " << error.GetErrorString(); - delete this; - } - - void OnLoginSuccess(const std::string& username, - const std::string& password, - const GaiaAuthConsumer::ClientLoginResult& credentials, - bool pending_requests, - bool using_oauth) { - pending_requests_ = pending_requests; - if (!profile_prepared_) { - // Will call OnProfilePrepared in the end. - chromeos::LoginUtils::Get()->PrepareProfile(username, - std::string(), - password, - credentials, - pending_requests, - using_oauth, - false, - this); - } else if (!pending_requests) { - delete this; - } - } - - // LoginUtils::Delegate implementation: - virtual void OnProfilePrepared(Profile* profile) { - profile_prepared_ = true; - chromeos::LoginUtils::DoBrowserLaunch(profile, NULL); - if (!pending_requests_) - delete this; - } - - scoped_refptr<chromeos::Authenticator> authenticator_; - bool pending_requests_; - bool profile_prepared_; -}; - -void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line, - Profile* profile) { - if (parsed_command_line.HasSwitch(switches::kLoginManager)) { - std::string first_screen = - parsed_command_line.GetSwitchValueASCII(switches::kLoginScreen); - std::string size_arg = - parsed_command_line.GetSwitchValueASCII( - switches::kLoginScreenSize); - gfx::Size size(0, 0); - // Allow the size of the login window to be set explicitly. If not set, - // default to the entire screen. This is mostly useful for testing. - if (size_arg.size()) { - std::vector<std::string> dimensions; - base::SplitString(size_arg, ',', &dimensions); - if (dimensions.size() == 2) { - int width, height; - if (base::StringToInt(dimensions[0], &width) && - base::StringToInt(dimensions[1], &height)) - size.SetSize(width, height); - } - } - browser::ShowLoginWizard(first_screen, size); - } else if (parsed_command_line.HasSwitch(switches::kLoginUser) && - parsed_command_line.HasSwitch(switches::kLoginPassword)) { - chromeos::BootTimesLoader::Get()->RecordLoginAttempted(); - new StubLogin( - parsed_command_line.GetSwitchValueASCII(switches::kLoginUser), - parsed_command_line.GetSwitchValueASCII(switches::kLoginPassword)); - } else { - if (!parsed_command_line.HasSwitch(switches::kTestName)) { - // We did not log in (we crashed or are debugging), so we need to - // restore Sync. - chromeos::LoginUtils::Get()->RestoreAuthenticationSession(profile); - } - } -} - -#endif // defined(OS_CHROMEOS) - #if defined(OS_MACOSX) OSStatus KeychainCallback(SecKeychainEvent keychain_event, SecKeychainCallbackInfo *info, void *context) { @@ -1191,12 +1075,6 @@ void ChromeBrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, // ----------------------------------------------------------------------------- // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. -#if defined(OS_CHROMEOS) -// Allows authenticator to be invoked without adding refcounting. The instances -// will delete themselves upon completion. -DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin); -#endif - #if defined(OS_WIN) #define DLLEXPORT __declspec(dllexport) @@ -1479,6 +1357,37 @@ void ChromeBrowserMainParts::PreMainMessageLoopRun() { chrome_extra_parts_[i]->PreMainMessageLoopRun(); } +// PreMainMessageLoopRun calls these extra stages in the following order: +// PreMainMessageLoopRunImpl() +// ... initial setup, including browser_process_ setup. +// PreProfileInit() +// ... additional setup, including CreateProfile() +// PostProfileInit() +// ... additional setup +// PreBrowserStart() +// ... browser_init_->Start (OR parameters().ui_task->Run()) +// PostBrowserStart() + +void ChromeBrowserMainParts::PreProfileInit() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PreProfileInit(); +} + +void ChromeBrowserMainParts::PostProfileInit() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostProfileInit(); +} + +void ChromeBrowserMainParts::PreBrowserStart() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PreBrowserStart(); +} + +void ChromeBrowserMainParts::PostBrowserStart() { + for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) + chrome_extra_parts_[i]->PostBrowserStart(); +} + int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { // Create watchdog thread after creating all other threads because it will // watch the other threads and they must be running. @@ -1494,24 +1403,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { browser_process_->resource_dispatcher_host(); #endif -#if defined(OS_CHROMEOS) - // Now that the file thread exists we can record our stats. - chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); - -#if defined(TOOLKIT_USES_GTK) - // Read locale-specific GTK resource information. - std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); - if (!gtkrc.empty()) - gtk_rc_parse_string(gtkrc.c_str()); -#else - // TODO(saintlou): Need to provide an Aura equivalent. - NOTIMPLEMENTED(); -#endif - - // Trigger prefetching of ownership status. - chromeos::OwnershipService::GetSharedInstance()->Prewarm(); -#endif - // Record last shutdown time into a histogram. browser_shutdown::ReadLastShutdownInfo(); @@ -1597,51 +1488,10 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { #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(); + PreProfileInit(); // Profile creation ---------------------------------------------------------- -#if defined(OS_CHROMEOS) - // Initialize the screen locker now so that it can receive - // LOGIN_USER_CHANGED notification from UserManager. - chromeos::ScreenLocker::InitClass(); - - // This forces the ProfileManager to be created and register for the - // notification it needs to track the logged in user. - g_browser_process->profile_manager(); - - // TODO(abarth): Should this move to InitializeNetworkOptions()? - // Allow access to file:// on ChromeOS for tests. - if (parsed_command_line().HasSwitch(switches::kAllowFileAccess)) - net::URLRequest::AllowFileAccess(); - - // There are two use cases for kLoginUser: - // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin" - // 2) if passed alone, to signal that the indicated user has already - // logged in and we should behave accordingly. - // This handles case 2. - if (parsed_command_line().HasSwitch(switches::kLoginUser) && - !parsed_command_line().HasSwitch(switches::kLoginPassword)) { - std::string username = - parsed_command_line().GetSwitchValueASCII(switches::kLoginUser); - VLOG(1) << "Relaunching browser for user: " << username; - chromeos::UserManager::Get()->UserLoggedIn(username); - - // Redirects Chrome logging to the user data dir. - logging::RedirectChromeLogging(parsed_command_line()); - - // Initialize user policy before creating the profile so the profile - // initialization code sees policy settings. - g_browser_process->browser_policy_connector()->InitializeUserPolicy( - username, false /* wait_for_policy_fetch */); - } else if (parsed_command_line().HasSwitch(switches::kLoginManager)) { - // Initialize status area mode early on. - chromeos::StatusAreaViewChromeos:: - SetScreenMode(chromeos::StatusAreaViewChromeos::LOGIN_MODE_WEBUI); - } -#endif - if (is_first_run_) { // Warn the ProfileManager that an import process will run, possibly // locking the WebDataService directory of the next Profile created. @@ -1660,22 +1510,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { } // Post-profile init --------------------------------------------------------- -#if defined(OS_CHROMEOS) - // Pass the TokenService pointer to the policy connector so user policy can - // grab a token and register with the policy server. - // TODO(mnissler): Remove once OAuth is the only authentication mechanism. - if (parsed_command_line().HasSwitch(switches::kLoginUser) && - !parsed_command_line().HasSwitch(switches::kLoginPassword)) { - 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) // Importing other browser settings is done in a browser-like process // that exits when this task has finished. @@ -1722,10 +1556,9 @@ 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(); + // TODO(stevenjb): Move WIN and MACOSX specific code to apprpriate Parts. + // (requires supporting early exit). + PostProfileInit(); // 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. @@ -1876,24 +1709,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { fragmentation_checker::RecordFragmentationMetricForCurrentModule(); #endif -#if defined(OS_CHROMEOS) - metrics_->StartExternalMetrics(); - - // Initialize the audio handler on ChromeOS. - chromeos::AudioHandler::Initialize(); - - // Listen for system key events so that the user will be able to adjust the - // volume on the login screen, if Chrome is running on Chrome OS - // (i.e. not Linux desktop), and in non-test mode. - if (chromeos::system::runtime_environment::IsRunningOnChromeOS() && - !parameters().ui_task) { // ui_task is non-NULL when running tests. - chromeos::SystemKeyEventListener::Initialize(); - } - - // Listen for XI_HierarchyChanged events. - chromeos::XInputHierarchyChangedEventListener::GetInstance(); -#endif - // The extension service may be available at this point. If the command line // specifies --uninstall-extension, attempt the uninstall extension startup // action. @@ -1918,13 +1733,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { record_search_engine_ = is_first_run_ && !profile_->IsOffTheRecord(); #endif -#if defined(OS_CHROMEOS) - // Wait until here to start the out-of-memory priority manager so that - // we give the most amount of time for the other services to start up - // before we start adjusting the oom priority. - g_browser_process->oom_priority_manager()->Start(); -#endif - // Create the instance of the cloud print proxy service so that it can launch // the service process if needed. This is needed because the service process // might have shutdown because an update was available. @@ -1942,6 +1750,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { NaClProcessHost::EarlyStartup(); #endif + PreBrowserStart(); + // Instantiate the notification UI manager, as this triggers a perf timer // used to measure startup time. TODO(stevenjb): Figure out what is actually // triggering the timer and call that explicitly in the approprate place. @@ -2018,6 +1828,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { } } browser_init_.reset(); + + PostBrowserStart(); + return result_code_; } @@ -2043,10 +1856,6 @@ bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { #elif defined(OS_POSIX) MessageLoopForUI::current()->Run(); #endif -#if defined(OS_CHROMEOS) - chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", - true); -#endif return true; } @@ -2107,10 +1916,6 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() { } #endif -#if defined(OS_CHROMEOS) - g_browser_process->oom_priority_manager()->Stop(); -#endif - // Some tests don't set parameters.ui_task, so they started translate // language fetch that was never completed so we need to cleanup here // otherwise it will be done by the destructor in a wrong thread. @@ -2125,17 +1930,6 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() { g_browser_process->metrics_service()->Stop(); -#if defined(OS_CHROMEOS) - // The XInput2 event listener needs to be shut down earlier than when - // Singletons are finally destroyed in AtExitManager. - chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop(); - - // chromeos::SystemKeyEventListener::Shutdown() is always safe to call, - // even if Initialize() wasn't called. - chromeos::SystemKeyEventListener::Shutdown(); - chromeos::AudioHandler::Shutdown(); -#endif - restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); browser_process_->StartTearDown(); } diff --git a/chrome/browser/chrome_browser_main.h b/chrome/browser/chrome_browser_main.h index 491f5d3..c5a7f4f 100644 --- a/chrome/browser/chrome_browser_main.h +++ b/chrome/browser/chrome_browser_main.h @@ -56,6 +56,9 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { const content::MainFunctionParams& parameters); // content::BrowserMainParts overrides. + // These are called in-order by content::BrowserMainLoop. + // Each stage calls the same stages in any ChromeBrowserMainExtraParts added + // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts. virtual void PreEarlyInitialization() OVERRIDE; virtual void PostEarlyInitialization() OVERRIDE; virtual void ToolkitInitialized() OVERRIDE; @@ -71,6 +74,13 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { virtual void PostStopThread(content::BrowserThread::ID identifier) OVERRIDE; virtual void PostDestroyThreads() OVERRIDE; + // Additional stages for ChromeBrowserMainExtraParts. These stages are called + // in order from PreMainMessageLoopStart(). See implementation for details. + virtual void PreProfileInit(); + virtual void PostProfileInit(); + virtual void PreBrowserStart(); + virtual void PostBrowserStart(); + // Displays a warning message that we can't find any locale data files. virtual void ShowMissingLocaleMessageBox() = 0; @@ -82,6 +92,7 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { } Profile* profile() { return profile_; } + MetricsService* metrics() { return metrics_; } private: // Methods for |EarlyInitialization()| --------------------------------------- diff --git a/chrome/browser/chrome_browser_main_extra_parts.cc b/chrome/browser/chrome_browser_main_extra_parts.cc index 3188931..14362a3 100644 --- a/chrome/browser/chrome_browser_main_extra_parts.cc +++ b/chrome/browser/chrome_browser_main_extra_parts.cc @@ -25,10 +25,16 @@ void ChromeBrowserMainExtraParts::PostMainMessageLoopStart() { void ChromeBrowserMainExtraParts::ToolkitInitialized() { } -void ChromeBrowserMainExtraParts::PostBrowserProcessInit() { +void ChromeBrowserMainExtraParts::PreProfileInit() { } -void ChromeBrowserMainExtraParts::PostProfileInitialized() { +void ChromeBrowserMainExtraParts::PostProfileInit() { +} + +void ChromeBrowserMainExtraParts::PreBrowserStart() { +} + +void ChromeBrowserMainExtraParts::PostBrowserStart() { } void ChromeBrowserMainExtraParts::PreMainMessageLoopRun() { diff --git a/chrome/browser/chrome_browser_main_extra_parts.h b/chrome/browser/chrome_browser_main_extra_parts.h index f0cd457..2bf3f1c 100644 --- a/chrome/browser/chrome_browser_main_extra_parts.h +++ b/chrome/browser/chrome_browser_main_extra_parts.h @@ -32,8 +32,10 @@ class ChromeBrowserMainExtraParts { virtual void PostMainMessageLoopStart(); // MainMessageLoopRun methods. - virtual void PostBrowserProcessInit(); - virtual void PostProfileInitialized(); + virtual void PreProfileInit(); + virtual void PostProfileInit(); + virtual void PreBrowserStart(); + virtual void PostBrowserStart(); virtual void PreMainMessageLoopRun(); virtual void PostMainMessageLoopRun(); diff --git a/chrome/browser/chrome_browser_main_extra_parts_aura.cc b/chrome/browser/chrome_browser_main_extra_parts_aura.cc index dcd96f7..30d3fe2 100644 --- a/chrome/browser/chrome_browser_main_extra_parts_aura.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_aura.cc @@ -27,7 +27,7 @@ ChromeBrowserMainExtraPartsAura::ChromeBrowserMainExtraPartsAura() : ChromeBrowserMainExtraParts() { } -void ChromeBrowserMainExtraPartsAura::PostBrowserProcessInit() { +void ChromeBrowserMainExtraPartsAura::PreProfileInit() { if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestCompositor)) { #if defined(USE_WEBKIT_COMPOSITOR) ui::SetupTestCompositor(); diff --git a/chrome/browser/chrome_browser_main_extra_parts_aura.h b/chrome/browser/chrome_browser_main_extra_parts_aura.h index 5b23dcd..d782882 100644 --- a/chrome/browser/chrome_browser_main_extra_parts_aura.h +++ b/chrome/browser/chrome_browser_main_extra_parts_aura.h @@ -13,7 +13,7 @@ class ChromeBrowserMainExtraPartsAura : public ChromeBrowserMainExtraParts { public: ChromeBrowserMainExtraPartsAura(); - virtual void PostBrowserProcessInit() OVERRIDE; + virtual void PreProfileInit() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; private: diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index b72519a..c366189 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -9,27 +9,52 @@ #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/message_loop.h" +#include "base/string_number_conversions.h" +#include "chrome/browser/browser_process_impl.h" #include "chrome/browser/chromeos/accessibility/system_event_observer.h" +#include "chrome/browser/chromeos/audio_handler.h" +#include "chrome/browser/chromeos/audio_handler.h" #include "chrome/browser/chromeos/bluetooth/bluetooth_manager.h" #include "chrome/browser/chromeos/boot_times_loader.h" +#include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/brightness_observer.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" #include "chrome/browser/chromeos/dbus/power_manager_client.h" #include "chrome/browser/chromeos/dbus/session_manager_client.h" #include "chrome/browser/chromeos/disks/disk_mount_manager.h" +#include "chrome/browser/chromeos/external_metrics.h" #include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/xkeyboard.h" +#include "chrome/browser/chromeos/login/authenticator.h" +#include "chrome/browser/chromeos/login/login_utils.h" +#include "chrome/browser/chromeos/login/ownership_service.h" +#include "chrome/browser/chromeos/login/screen_locker.h" #include "chrome/browser/chromeos/login/session_manager_observer.h" +#include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h" #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h" +#include "chrome/browser/chromeos/status/status_area_view_chromeos.h" #include "chrome/browser/chromeos/system/runtime_environment.h" #include "chrome/browser/chromeos/system/statistics_provider.h" +#include "chrome/browser/chromeos/system_key_event_listener.h" #include "chrome/browser/chromeos/upgrade_detector_chromeos.h" +#include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" #include "chrome/browser/defaults.h" +#include "chrome/browser/metrics/metrics_service.h" +#include "chrome/browser/oom_priority_manager.h" +#include "chrome/browser/policy/browser_policy_connector.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/ui/views/browser_dialogs.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/logging_chrome.h" #include "content/public/common/main_function_params.h" +#include "grit/platform_locale_settings.h" #include "net/base/network_change_notifier.h" +#include "net/url_request/url_request.h" +#include "ui/base/l10n/l10n_util.h" #if defined(TOOLKIT_USES_GTK) #include <gtk/gtk.h> @@ -82,6 +107,111 @@ class MessageLoopObserver : public MessageLoopForUI::Observer { static base::LazyInstance<MessageLoopObserver> g_message_loop_observer = LAZY_INSTANCE_INITIALIZER; +// Login ----------------------------------------------------------------------- + +// Class is used to login using passed username and password. +// The instance will be deleted upon success or failure. +class StubLogin : public chromeos::LoginStatusConsumer, + public chromeos::LoginUtils::Delegate { + public: + StubLogin(std::string username, std::string password) + : pending_requests_(false), + profile_prepared_(false) { + authenticator_ = chromeos::LoginUtils::Get()->CreateAuthenticator(this); + authenticator_.get()->AuthenticateToLogin( + g_browser_process->profile_manager()->GetDefaultProfile(), + username, + password, + std::string(), + std::string()); + } + + ~StubLogin() { + chromeos::LoginUtils::Get()->DelegateDeleted(this); + } + + void OnLoginFailure(const chromeos::LoginFailure& error) { + LOG(ERROR) << "Login Failure: " << error.GetErrorString(); + delete this; + } + + void OnLoginSuccess(const std::string& username, + const std::string& password, + const GaiaAuthConsumer::ClientLoginResult& credentials, + bool pending_requests, + bool using_oauth) { + pending_requests_ = pending_requests; + if (!profile_prepared_) { + // Will call OnProfilePrepared in the end. + chromeos::LoginUtils::Get()->PrepareProfile(username, + std::string(), + password, + credentials, + pending_requests, + using_oauth, + false, + this); + } else if (!pending_requests) { + delete this; + } + } + + // LoginUtils::Delegate implementation: + virtual void OnProfilePrepared(Profile* profile) { + profile_prepared_ = true; + chromeos::LoginUtils::DoBrowserLaunch(profile, NULL); + if (!pending_requests_) + delete this; + } + + scoped_refptr<chromeos::Authenticator> authenticator_; + bool pending_requests_; + bool profile_prepared_; +}; + +// Allows authenticator to be invoked without adding refcounting. The instances +// will delete themselves upon completion. +DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin); + +void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line, + Profile* profile) { + if (parsed_command_line.HasSwitch(switches::kLoginManager)) { + std::string first_screen = + parsed_command_line.GetSwitchValueASCII(switches::kLoginScreen); + std::string size_arg = + parsed_command_line.GetSwitchValueASCII( + switches::kLoginScreenSize); + gfx::Size size(0, 0); + // Allow the size of the login window to be set explicitly. If not set, + // default to the entire screen. This is mostly useful for testing. + if (size_arg.size()) { + std::vector<std::string> dimensions; + base::SplitString(size_arg, ',', &dimensions); + if (dimensions.size() == 2) { + int width, height; + if (base::StringToInt(dimensions[0], &width) && + base::StringToInt(dimensions[1], &height)) + size.SetSize(width, height); + } + } + browser::ShowLoginWizard(first_screen, size); + } else if (parsed_command_line.HasSwitch(switches::kLoginUser) && + parsed_command_line.HasSwitch(switches::kLoginPassword)) { + chromeos::BootTimesLoader::Get()->RecordLoginAttempted(); + new StubLogin( + parsed_command_line.GetSwitchValueASCII(switches::kLoginUser), + parsed_command_line.GetSwitchValueASCII(switches::kLoginPassword)); + } else { + if (!parsed_command_line.HasSwitch(switches::kTestName)) { + // We did not log in (we crashed or are debugging), so we need to + // restore Sync. + chromeos::LoginUtils::Get()->RestoreAuthenticationSession(profile); + } + } +} + +// ChromeBrowserMainPartsChromeos ---------------------------------------------- + ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos( const content::MainFunctionParams& parameters) : ChromeBrowserMainPartsLinux(parameters) { @@ -102,8 +232,9 @@ ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() { chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); } +// content::BrowserMainParts and ChromeBrowserMainExtraParts overrides --------- + void ChromeBrowserMainPartsChromeos::PreEarlyInitialization() { - ChromeBrowserMainPartsLinux::PreEarlyInitialization(); if (parsed_command_line().HasSwitch(switches::kGuestSession)) { // Disable sync and extensions if we're in "browse without sign-in" mode. CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); @@ -111,10 +242,11 @@ void ChromeBrowserMainPartsChromeos::PreEarlyInitialization() { singleton_command_line->AppendSwitch(switches::kDisableExtensions); browser_defaults::bookmarks_enabled = false; } + + ChromeBrowserMainPartsLinux::PreEarlyInitialization(); } void ChromeBrowserMainPartsChromeos::PreMainMessageLoopStart() { - ChromeBrowserMainPartsLinux::PreMainMessageLoopStart(); // Initialize CrosLibrary only for the browser, unless running tests // (which do their own CrosLibrary setup). if (!parameters().ui_task) { @@ -125,11 +257,130 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopStart() { // implementation. net::NetworkChangeNotifier::SetFactory( new chromeos::CrosNetworkChangeNotifierFactory()); + + ChromeBrowserMainPartsLinux::PreMainMessageLoopStart(); +} + +void ChromeBrowserMainPartsChromeos::PreProfileInit() { + // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() + // -- immediately before Profile creation(). + + // Now that the file thread exists we can record our stats. + chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); + +#if defined(TOOLKIT_USES_GTK) + // Read locale-specific GTK resource information. + std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); + if (!gtkrc.empty()) + gtk_rc_parse_string(gtkrc.c_str()); +#else + // TODO(saintlou): Need to provide an Aura equivalent. + NOTIMPLEMENTED(); +#endif + + // Trigger prefetching of ownership status. + chromeos::OwnershipService::GetSharedInstance()->Prewarm(); + + // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() + // -- just before CreateProfile(). + + // Initialize the screen locker now so that it can receive + // LOGIN_USER_CHANGED notification from UserManager. + chromeos::ScreenLocker::InitClass(); + + // This forces the ProfileManager to be created and register for the + // notification it needs to track the logged in user. + g_browser_process->profile_manager(); + + // TODO(abarth): Should this move to InitializeNetworkOptions()? + // Allow access to file:// on ChromeOS for tests. + if (parsed_command_line().HasSwitch(switches::kAllowFileAccess)) + net::URLRequest::AllowFileAccess(); + + // There are two use cases for kLoginUser: + // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin" + // 2) if passed alone, to signal that the indicated user has already + // logged in and we should behave accordingly. + // This handles case 2. + if (parsed_command_line().HasSwitch(switches::kLoginUser) && + !parsed_command_line().HasSwitch(switches::kLoginPassword)) { + std::string username = + parsed_command_line().GetSwitchValueASCII(switches::kLoginUser); + VLOG(1) << "Relaunching browser for user: " << username; + chromeos::UserManager::Get()->UserLoggedIn(username); + + // Redirects Chrome logging to the user data dir. + logging::RedirectChromeLogging(parsed_command_line()); + + // Initialize user policy before creating the profile so the profile + // initialization code sees policy settings. + g_browser_process->browser_policy_connector()->InitializeUserPolicy( + username, false /* wait_for_policy_fetch */); + } else if (parsed_command_line().HasSwitch(switches::kLoginManager)) { + // Initialize status area mode early on. + chromeos::StatusAreaViewChromeos:: + SetScreenMode(chromeos::StatusAreaViewChromeos::LOGIN_MODE_WEBUI); + } + + // In Aura builds this will initialize aura_shell::Shell. + ChromeBrowserMainPartsLinux::PreProfileInit(); } -void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { +void ChromeBrowserMainPartsChromeos::PostProfileInit() { + // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() + // -- just after CreateProfile(). + + // Pass the TokenService pointer to the policy connector so user policy can + // grab a token and register with the policy server. + // TODO(mnissler): Remove once OAuth is the only authentication mechanism. + if (parsed_command_line().HasSwitch(switches::kLoginUser) && + !parsed_command_line().HasSwitch(switches::kLoginPassword)) { + 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()); + + ChromeBrowserMainPartsLinux::PostProfileInit(); +} + +void ChromeBrowserMainPartsChromeos::PreBrowserStart() { + // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() + // -- just before MetricsService::LogNeedForCleanShutdown(). + + metrics()->StartExternalMetrics(); + + // Initialize the audio handler on ChromeOS. + chromeos::AudioHandler::Initialize(); + + // Listen for system key events so that the user will be able to adjust the + // volume on the login screen, if Chrome is running on Chrome OS + // (i.e. not Linux desktop), and in non-test mode. + if (chromeos::system::runtime_environment::IsRunningOnChromeOS() && + !parameters().ui_task) { // ui_task is non-NULL when running tests. + chromeos::SystemKeyEventListener::Initialize(); + } + + // Listen for XI_HierarchyChanged events. + chromeos::XInputHierarchyChangedEventListener::GetInstance(); + + // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() + // -- immediately after ChildProcess::WaitForDebugger(). + + // Start the out-of-memory priority manager here so that we give the most + // amount of time for the other services to start up before we start + // adjusting the oom priority. + g_browser_process->oom_priority_manager()->Start(); + + ChromeBrowserMainPartsLinux::PreBrowserStart(); +} + +void ChromeBrowserMainPartsChromeos::PostBrowserStart() { // FILE thread is created in ChromeBrowserMainParts::PreMainMessageLoopRun(). - ChromeBrowserMainPartsLinux::PreMainMessageLoopRun(); + // Get the statistics provider instance here to start loading statistcs // on the background FILE thread. chromeos::system::StatisticsProvider::GetInstance(); @@ -143,10 +394,11 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { if (parsed_command_line().HasSwitch(switches::kEnableBluetooth)) { chromeos::BluetoothManager::Initialize(); } + + ChromeBrowserMainPartsLinux::PostBrowserStart(); } void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { - ChromeBrowserMainPartsLinux::PostMainMessageLoopStart(); MessageLoopForUI* message_loop = MessageLoopForUI::current(); message_loop->AddObserver(g_message_loop_observer.Pointer()); @@ -196,11 +448,16 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { new chromeos::InitialBrowserWindowObserver); #endif } + + ChromeBrowserMainPartsLinux::PostMainMessageLoopStart(); } // Shut down services before the browser process, etc are destroyed. void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { - ChromeBrowserMainPartsLinux::PostMainMessageLoopRun(); + chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", + true); + + g_browser_process->oom_priority_manager()->Stop(); // Shutdown the upgrade detector for Chrome OS. The upgrade detector // stops monitoring changes from the update engine. @@ -229,4 +486,15 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { // these. chromeos::accessibility::SystemEventObserver::Shutdown(); chromeos::BluetoothManager::Shutdown(); + + // The XInput2 event listener needs to be shut down earlier than when + // Singletons are finally destroyed in AtExitManager. + chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop(); + + // chromeos::SystemKeyEventListener::Shutdown() is always safe to call, + // even if Initialize() wasn't called. + chromeos::SystemKeyEventListener::Shutdown(); + chromeos::AudioHandler::Shutdown(); + + ChromeBrowserMainPartsLinux::PostMainMessageLoopRun(); } diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index 449d9fa..80df066 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -27,9 +27,14 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostMainMessageLoopStart() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; + // ChromeBrowserMainExtraParts overrodes. + virtual void PreProfileInit() OVERRIDE; + virtual void PostProfileInit() OVERRIDE; + virtual void PreBrowserStart() OVERRIDE; + virtual void PostBrowserStart() OVERRIDE; + private: scoped_ptr<chromeos::BrightnessObserver> brightness_observer_; scoped_ptr<chromeos::SessionManagerObserver> session_manager_observer_; |