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

Unified Diff: chrome/browser/chromeos/chrome_browser_main_chromeos.cc

Issue 8670001: Move chromeos specific code to ChromeBrowserMainPartsChromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/chrome_browser_main_chromeos.cc
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
index e7ce5b8a6ae878c2c9a8d5c8e61b975d7b20699c..9b41b73783ee85dba4c92092b1264a7062a313ce 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
@@ -9,27 +9,51 @@
#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/brightness_observer.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/screen_lock_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/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/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/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 "chrome/browser/chromeos/boot_times_loader.h"
+#include "chrome/browser/chromeos/external_metrics.h"
+#include "ui/base/l10n/l10n_util.h"
#if defined(TOOLKIT_USES_GTK)
#include <gtk/gtk.h>
@@ -82,6 +106,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,
+ 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
+ // set the user name for sync.
+ chromeos::LoginUtils::Get()->RestoreAuthenticationSession(
+ chromeos::UserManager::Get()->logged_in_user().email(), profile);
+ }
+ }
+}
+
+// ChromeBrowserMainPartsChromeos ----------------------------------------------
+
ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos(
const content::MainFunctionParams& parameters)
: ChromeBrowserMainPartsLinux(parameters) {
@@ -106,8 +235,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();
@@ -115,10 +245,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) {
@@ -131,11 +262,124 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopStart() {
new chromeos::CrosNetworkChangeNotifierFactory());
chromeos::accessibility::SystemEventObserver::Initialize();
+
+ ChromeBrowserMainPartsLinux::PreMainMessageLoopStart();
}
-void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() {
+void ChromeBrowserMainPartsChromeos::PostBrowserProcessInit() {
+ // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
+ // -- immediately after CreateChildThreads().
+
+ // 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 */);
+ }
+
+ // In Aura builds this will initialize aura_shell::Shell.
+ ChromeBrowserMainPartsLinux::PostBrowserProcessInit();
+}
+
+void ChromeBrowserMainPartsChromeos::PostProfileInitialized() {
satorux1 2011/11/23 23:51:53 This looks like an useful hook. Maybe we can move
stevenjb 2011/11/24 01:35:39 Definitely sounds like a good idea. I will make a
+ // -- 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::PostProfileInitialized();
+}
+
+void ChromeBrowserMainPartsChromeos::PreBrowserStart() {
+ // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
+ // -- just before MetricsService::LogNeedForCleanShutdown().
+
+ // 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();
@@ -149,10 +393,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());
@@ -194,11 +439,25 @@ 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();
+
+ // 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();
// Shutdown the upgrade detector for Chrome OS. The upgrade detector
// stops monitoring changes from the update engine.
@@ -221,4 +480,6 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()
->RemoveObserver(brightness_observer_.get());
}
+
+ ChromeBrowserMainPartsLinux::PostMainMessageLoopRun();
}

Powered by Google App Engine
This is Rietveld 408576698