1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
10 #include "ash/ash_switches.h"
11 #include "ash/shell.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/command_line.h"
15 #include "base/file_util.h"
16 #include "base/lazy_instance.h"
17 #include "base/linux_util.h"
18 #include "base/message_loop/message_loop.h"
19 #include "base/path_service.h"
20 #include "base/prefs/pref_service.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h"
23 #include "base/sys_info.h"
24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browser_process_platform_part_chromeos.h"
26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
28 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
29 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
30 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
31 #include "chrome/browser/chromeos/boot_times_loader.h"
32 #include "chrome/browser/chromeos/contacts/contact_manager.h"
33 #include "chrome/browser/chromeos/dbus/cros_dbus_service.h"
34 #include "chrome/browser/chromeos/extensions/default_app_order.h"
35 #include "chrome/browser/chromeos/extensions/extension_system_event_observer.h"
36 #include "chrome/browser/chromeos/external_metrics.h"
37 #include "chrome/browser/chromeos/imageburner/burn_manager.h"
38 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
39 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.h"
40 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h"
41 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
42 #include "chrome/browser/chromeos/login/authenticator.h"
43 #include "chrome/browser/chromeos/login/login_utils.h"
44 #include "chrome/browser/chromeos/login/login_wizard.h"
45 #include "chrome/browser/chromeos/login/screen_locker.h"
46 #include "chrome/browser/chromeos/login/startup_utils.h"
47 #include "chrome/browser/chromeos/login/user_manager.h"
48 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
49 #include "chrome/browser/chromeos/login/wizard_controller.h"
50 #include "chrome/browser/chromeos/memory/oom_priority_manager.h"
51 #include "chrome/browser/chromeos/net/network_portal_detector.h"
52 #include "chrome/browser/chromeos/options/cert_library.h"
53 #include "chrome/browser/chromeos/power/idle_action_warning_observer.h"
54 #include "chrome/browser/chromeos/power/peripheral_battery_observer.h"
55 #include "chrome/browser/chromeos/power/power_button_observer.h"
56 #include "chrome/browser/chromeos/power/power_prefs.h"
57 #include "chrome/browser/chromeos/profiles/profile_helper.h"
58 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
59 #include "chrome/browser/chromeos/settings/device_settings_service.h"
60 #include "chrome/browser/chromeos/settings/owner_key_util.h"
61 #include "chrome/browser/chromeos/status/data_promo_notification.h"
62 #include "chrome/browser/chromeos/system_key_event_listener.h"
63 #include "chrome/browser/chromeos/upgrade_detector_chromeos.h"
64 #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h"
65 #include "chrome/browser/defaults.h"
66 #include "chrome/browser/metrics/metrics_service.h"
67 #include "chrome/browser/net/chrome_network_delegate.h"
68 #include "chrome/browser/policy/browser_policy_connector.h"
69 #include "chrome/browser/profiles/profile.h"
70 #include "chrome/browser/profiles/profile_manager.h"
71 #include "chrome/browser/rlz/rlz.h"
72 #include "chrome/common/chrome_constants.h"
73 #include "chrome/common/chrome_paths.h"
74 #include "chrome/common/chrome_switches.h"
75 #include "chrome/common/chrome_version_info.h"
76 #include "chrome/common/logging_chrome.h"
77 #include "chrome/common/pref_names.h"
78 #include "chromeos/audio/audio_devices_pref_handler.h"
79 #include "chromeos/audio/cras_audio_handler.h"
80 #include "chromeos/chromeos_paths.h"
81 #include "chromeos/chromeos_switches.h"
82 #include "chromeos/cryptohome/async_method_caller.h"
83 #include "chromeos/cryptohome/system_salt_getter.h"
84 #include "chromeos/dbus/dbus_thread_manager.h"
85 #include "chromeos/dbus/power_policy_controller.h"
86 #include "chromeos/dbus/session_manager_client.h"
87 #include "chromeos/disks/disk_mount_manager.h"
88 #include "chromeos/ime/input_method_manager.h"
89 #include "chromeos/ime/xkeyboard.h"
90 #include "chromeos/login/login_state.h"
91 #include "chromeos/network/network_change_notifier_chromeos.h"
92 #include "chromeos/network/network_change_notifier_factory_chromeos.h"
93 #include "chromeos/network/network_handler.h"
94 #include "chromeos/power/power_data_collector.h"
95 #include "chromeos/system/statistics_provider.h"
96 #include "content/public/browser/browser_thread.h"
97 #include "content/public/browser/notification_service.h"
98 #include "content/public/browser/power_save_blocker.h"
99 #include "content/public/common/main_function_params.h"
100 #include "grit/platform_locale_settings.h"
101 #include "media/audio/sounds/sounds_manager.h"
102 #include "net/base/network_change_notifier.h"
103 #include "net/url_request/url_request.h"
104 #include "net/url_request/url_request_context_getter.h"
105 #include "ui/base/touch/touch_device.h"
106 #include "ui/events/event_utils.h"
108 // Exclude X11 dependents for ozone
110 #include "chrome/browser/chromeos/device_uma.h"
117 void ChromeOSVersionCallback(const std::string
& version
) {
118 base::SetLinuxDistro(std::string("CrOS ") + version
);
121 class MessageLoopObserver
: public base::MessageLoopForUI::Observer
{
122 virtual base::EventStatus
WillProcessEvent(
123 const base::NativeEvent
& event
) OVERRIDE
{
124 return base::EVENT_CONTINUE
;
127 virtual void DidProcessEvent(
128 const base::NativeEvent
& event
) OVERRIDE
{
132 static base::LazyInstance
<MessageLoopObserver
> g_message_loop_observer
=
133 LAZY_INSTANCE_INITIALIZER
;
135 // Login -----------------------------------------------------------------------
137 // Class is used to login using passed username and password.
138 // The instance will be deleted upon success or failure.
139 class StubLogin
: public LoginStatusConsumer
,
140 public LoginUtils::Delegate
{
142 StubLogin(std::string username
, std::string password
)
143 : profile_prepared_(false) {
144 authenticator_
= LoginUtils::Get()->CreateAuthenticator(this);
145 authenticator_
.get()->AuthenticateToLogin(
146 ProfileHelper::GetSigninProfile(),
147 UserContext(username
, password
, std::string() /* auth_code */));
150 virtual ~StubLogin() {
151 LoginUtils::Get()->DelegateDeleted(this);
154 virtual void OnLoginFailure(const LoginFailure
& error
) OVERRIDE
{
155 LOG(ERROR
) << "Login Failure: " << error
.GetErrorString();
159 virtual void OnLoginSuccess(const UserContext
& user_context
) OVERRIDE
{
160 if (!profile_prepared_
) {
161 // Will call OnProfilePrepared in the end.
162 LoginUtils::Get()->PrepareProfile(user_context
,
163 std::string(), // display_email
164 false, // has_cookies
165 true, // has_active_session
172 // LoginUtils::Delegate implementation:
173 virtual void OnProfilePrepared(Profile
* profile
) OVERRIDE
{
174 profile_prepared_
= true;
175 LoginUtils::Get()->DoBrowserLaunch(profile
, NULL
);
179 scoped_refptr
<Authenticator
> authenticator_
;
180 bool profile_prepared_
;
183 bool ShouldAutoLaunchKioskApp(const CommandLine
& command_line
) {
184 KioskAppManager
* app_manager
= KioskAppManager::Get();
185 return command_line
.HasSwitch(switches::kLoginManager
) &&
186 !command_line
.HasSwitch(switches::kForceLoginManagerInTests
) &&
187 app_manager
->IsAutoLaunchEnabled() &&
188 KioskAppLaunchError::Get() == KioskAppLaunchError::NONE
;
191 void RunAutoLaunchKioskApp() {
192 ShowLoginWizard(chromeos::WizardController::kAppLaunchSplashScreenName
);
194 // Login screen is skipped but 'login-prompt-visible' signal is still needed.
195 VLOG(1) << "Kiosk app auto launch >> login-prompt-visible";
196 DBusThreadManager::Get()->GetSessionManagerClient()->
197 EmitLoginPromptVisible();
200 void OptionallyRunChromeOSLoginManager(const CommandLine
& parsed_command_line
,
202 if (ShouldAutoLaunchKioskApp(parsed_command_line
)) {
203 RunAutoLaunchKioskApp();
204 } else if (parsed_command_line
.HasSwitch(switches::kLoginManager
)) {
205 const std::string first_screen
=
206 parsed_command_line
.HasSwitch(switches::kLoginScreen
) ?
207 WizardController::kLoginScreenName
: std::string();
208 ShowLoginWizard(first_screen
);
210 if (KioskModeSettings::Get()->IsKioskModeEnabled())
211 InitializeKioskModeScreensaver();
213 // Reset reboot after update flag when login screen is shown.
214 if (!g_browser_process
->browser_policy_connector()->
215 IsEnterpriseManaged()) {
216 PrefService
* local_state
= g_browser_process
->local_state();
217 local_state
->ClearPref(prefs::kRebootAfterUpdate
);
219 } else if (parsed_command_line
.HasSwitch(switches::kLoginUser
) &&
220 parsed_command_line
.HasSwitch(switches::kLoginPassword
)) {
221 BootTimesLoader::Get()->RecordLoginAttempted();
223 parsed_command_line
.GetSwitchValueASCII(switches::kLoginUser
),
224 parsed_command_line
.GetSwitchValueASCII(switches::kLoginPassword
));
226 if (!parsed_command_line
.HasSwitch(::switches::kTestName
)) {
227 // Enable CrasAudioHandler logging when chrome restarts after crashing.
228 if (chromeos::CrasAudioHandler::IsInitialized())
229 chromeos::CrasAudioHandler::Get()->LogErrors();
231 // We did not log in (we crashed or are debugging), so we need to
233 LoginUtils::Get()->RestoreAuthenticationSession(profile
);
242 // Wrapper class for initializing dbus related services and shutting them
243 // down. This gets instantiated in a scoped_ptr so that shutdown methods in the
244 // destructor will get called if and only if this has been instantiated.
247 explicit DBusServices(const content::MainFunctionParams
& parameters
) {
248 if (!base::SysInfo::IsRunningOnChromeOS()) {
249 // Override this path on the desktop, so that the user policy key can be
250 // stored by the stub SessionManagerClient.
251 base::FilePath user_data_dir
;
252 if (PathService::Get(chrome::DIR_USER_DATA
, &user_data_dir
)) {
253 PathService::Override(chromeos::DIR_USER_POLICY_KEYS
,
254 user_data_dir
.AppendASCII("stub_user_policy"));
258 // Initialize DBusThreadManager for the browser. This must be done after
259 // the main message loop is started, as it uses the message loop.
260 DBusThreadManager::Initialize();
261 CrosDBusService::Initialize();
263 // Initialize PowerDataCollector after DBusThreadManager is initialized.
264 PowerDataCollector::Initialize();
266 LoginState::Initialize();
267 SystemSaltGetter::Initialize();
268 CertLoader::Initialize();
270 // This function and SystemKeyEventListener use InputMethodManager.
271 chromeos::input_method::Initialize(
272 content::BrowserThread::GetMessageLoopProxyForThread(
273 content::BrowserThread::UI
),
274 content::BrowserThread::GetMessageLoopProxyForThread(
275 content::BrowserThread::FILE));
276 disks::DiskMountManager::Initialize();
277 cryptohome::AsyncMethodCaller::Initialize();
279 NetworkHandler::Initialize();
280 CertLibrary::Initialize();
282 // Initialize the network change notifier for Chrome OS. The network
283 // change notifier starts to monitor changes from the power manager and
284 // the network manager.
285 NetworkChangeNotifierFactoryChromeos::GetInstance()->Initialize();
287 // Likewise, initialize the upgrade detector for Chrome OS. The upgrade
288 // detector starts to monitor changes from the update engine.
289 UpgradeDetectorChromeos::GetInstance()->Init();
291 if (base::SysInfo::IsRunningOnChromeOS()) {
292 // Disable Num Lock on X start up for http://crosbug.com/29169.
293 input_method::InputMethodManager::Get()->GetXKeyboard()->
294 SetNumLockEnabled(false);
297 // Initialize the device settings service so that we'll take actions per
298 // signals sent from the session manager. This needs to happen before
299 // g_browser_process initializes BrowserPolicyConnector.
300 DeviceSettingsService::Initialize();
301 DeviceSettingsService::Get()->SetSessionManager(
302 DBusThreadManager::Get()->GetSessionManagerClient(),
303 OwnerKeyUtil::Create());
307 CertLibrary::Shutdown();
308 NetworkHandler::Shutdown();
310 cryptohome::AsyncMethodCaller::Shutdown();
311 disks::DiskMountManager::Shutdown();
312 input_method::Shutdown();
314 SystemSaltGetter::Shutdown();
315 LoginState::Shutdown();
317 CrosDBusService::Shutdown();
319 // Shutdown the PowerDataCollector before shutting down DBusThreadManager.
320 PowerDataCollector::Shutdown();
322 // NOTE: This must only be called if Initialize() was called.
323 DBusThreadManager::Shutdown();
328 DISALLOW_COPY_AND_ASSIGN(DBusServices
);
331 } // namespace internal
333 // ChromeBrowserMainPartsChromeos ----------------------------------------------
335 ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos(
336 const content::MainFunctionParams
& parameters
)
337 : ChromeBrowserMainPartsLinux(parameters
) {
340 ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() {
341 if (KioskModeSettings::Get()->IsKioskModeEnabled())
342 ShutdownKioskModeScreensaver();
344 // To be precise, logout (browser shutdown) is not yet done, but the
345 // remaining work is negligible, hence we say LogoutDone here.
346 BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", false);
347 BootTimesLoader::Get()->WriteLogoutTimes();
350 // content::BrowserMainParts and ChromeBrowserMainExtraParts overrides ---------
352 void ChromeBrowserMainPartsChromeos::PreEarlyInitialization() {
353 CommandLine
* singleton_command_line
= CommandLine::ForCurrentProcess();
355 if (parsed_command_line().HasSwitch(switches::kGuestSession
)) {
356 // Disable sync and extensions if we're in "browse without sign-in" mode.
357 singleton_command_line
->AppendSwitch(::switches::kDisableSync
);
358 singleton_command_line
->AppendSwitch(::switches::kDisableExtensions
);
359 browser_defaults::bookmarks_enabled
= false;
362 // If we're not running on real ChromeOS hardware (or under VM), and are not
363 // showing the login manager or attempting a command line login, login with a
365 if (!base::SysInfo::IsRunningOnChromeOS() &&
366 !parsed_command_line().HasSwitch(switches::kLoginManager
) &&
367 !parsed_command_line().HasSwitch(switches::kLoginUser
) &&
368 !parsed_command_line().HasSwitch(switches::kGuestSession
)) {
369 singleton_command_line
->AppendSwitchASCII(
370 switches::kLoginUser
, UserManager::kStubUser
);
371 if (!parsed_command_line().HasSwitch(switches::kLoginProfile
)) {
372 singleton_command_line
->AppendSwitchASCII(switches::kLoginProfile
,
373 chrome::kTestUserProfileDir
);
375 LOG(WARNING
) << "Running as stub user with profile dir: "
376 << singleton_command_line
->GetSwitchValuePath(
377 switches::kLoginProfile
).value();
380 #if defined(GOOGLE_CHROME_BUILD)
381 const char kChromeOSReleaseTrack
[] = "CHROMEOS_RELEASE_TRACK";
383 if (base::SysInfo::GetLsbReleaseValue(kChromeOSReleaseTrack
, &channel
))
384 chrome::VersionInfo::SetChannel(channel
);
387 ChromeBrowserMainPartsLinux::PreEarlyInitialization();
390 void ChromeBrowserMainPartsChromeos::PreMainMessageLoopStart() {
391 // Replace the default NetworkChangeNotifierFactory with ChromeOS specific
392 // implementation. This must be done before BrowserMainLoop calls
393 // net::NetworkChangeNotifier::Create() in MainMessageLoopStart().
394 net::NetworkChangeNotifier::SetFactory(
395 new NetworkChangeNotifierFactoryChromeos());
396 ChromeBrowserMainPartsLinux::PreMainMessageLoopStart();
399 void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() {
400 base::MessageLoopForUI
* message_loop
= base::MessageLoopForUI::current();
401 message_loop
->AddObserver(g_message_loop_observer
.Pointer());
403 dbus_services_
.reset(new internal::DBusServices(parameters()));
405 ChromeBrowserMainPartsLinux::PostMainMessageLoopStart();
408 // Threads are initialized between MainMessageLoopStart and MainMessageLoopRun.
409 // about_flags settings are applied in ChromeBrowserMainParts::PreCreateThreads.
410 void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() {
411 // Set the crypto thread after the IO thread has been created/started.
412 CertLoader::Get()->SetCryptoTaskRunner(
413 content::BrowserThread::GetMessageLoopProxyForThread(
414 content::BrowserThread::IO
));
416 CrasAudioHandler::Initialize(
417 AudioDevicesPrefHandler::Create(g_browser_process
->local_state()));
419 // Start loading machine statistics here. StatisticsProvider::Shutdown()
420 // will ensure that loading is aborted on early exit.
421 bool load_oem_statistics
= !StartupUtils::IsOobeCompleted();
422 system::StatisticsProvider::GetInstance()->StartLoadingMachineStatistics(
423 content::BrowserThread::GetMessageLoopProxyForThread(
424 content::BrowserThread::FILE),
425 load_oem_statistics
);
427 base::FilePath downloads_directory
;
428 CHECK(PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS
, &downloads_directory
));
429 imageburner::BurnManager::Initialize(
430 downloads_directory
, g_browser_process
->system_request_context());
432 // Listen for system key events so that the user will be able to adjust the
433 // volume on the login screen, if Chrome is running on Chrome OS
434 // (i.e. not Linux desktop), and in non-test mode.
435 // Note: SystemKeyEventListener depends on the DBus thread.
436 if (base::SysInfo::IsRunningOnChromeOS() &&
437 !parameters().ui_task
) { // ui_task is non-NULL when running tests.
438 SystemKeyEventListener::Initialize();
441 DeviceOAuth2TokenServiceFactory::Initialize();
443 ChromeBrowserMainPartsLinux::PreMainMessageLoopRun();
446 void ChromeBrowserMainPartsChromeos::PreProfileInit() {
447 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
448 // -- immediately before Profile creation().
450 // Now that the file thread exists we can record our stats.
451 BootTimesLoader::Get()->RecordChromeMainStats();
453 // Trigger prefetching of ownership status.
454 DeviceSettingsService::Get()->Load();
456 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
457 // -- just before CreateProfile().
459 UserManager::Initialize();
461 // Initialize the screen locker now so that it can receive
462 // LOGIN_USER_CHANGED notification from UserManager.
463 if (KioskModeSettings::Get()->IsKioskModeEnabled()) {
464 KioskModeIdleLogout::Initialize();
466 ScreenLocker::InitClass();
469 // This forces the ProfileManager to be created and register for the
470 // notification it needs to track the logged in user.
471 g_browser_process
->profile_manager();
473 // ProfileHelper has to be initialized after UserManager instance is created.
474 g_browser_process
->platform_part()->profile_helper()->Initialize();
476 // TODO(abarth): Should this move to InitializeNetworkOptions()?
477 // Allow access to file:// on ChromeOS for tests.
478 if (parsed_command_line().HasSwitch(::switches::kAllowFileAccess
))
479 ChromeNetworkDelegate::AllowAccessToAllFiles();
481 if (parsed_command_line().HasSwitch(::switches::kEnableContacts
)) {
482 contact_manager_
.reset(new contacts::ContactManager());
483 contact_manager_
->Init();
486 // There are two use cases for kLoginUser:
487 // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin"
488 // 2) if passed alone, to signal that the indicated user has already
489 // logged in and we should behave accordingly.
490 // This handles case 2.
491 bool immediate_login
=
492 parsed_command_line().HasSwitch(switches::kLoginUser
) &&
493 !parsed_command_line().HasSwitch(switches::kLoginPassword
);
494 if (immediate_login
){
495 // Redirects Chrome logging to the user data dir.
496 logging::RedirectChromeLogging(parsed_command_line());
498 // Load the default app order synchronously for restarting case.
499 app_order_loader_
.reset(
500 new default_app_order::ExternalLoader(false /* async */));
503 if (!app_order_loader_
) {
504 app_order_loader_
.reset(
505 new default_app_order::ExternalLoader(true /* async */));
508 media::SoundsManager::Create();
510 // Initialize magnification manager before ash tray is created. And this must
511 // be placed after UserManager::SessionStarted();
512 AccessibilityManager::Initialize();
513 MagnificationManager::Initialize();
515 // Add observers for WallpaperManager. This depends on PowerManagerClient,
516 // TimezoneSettings and CrosSettings.
517 WallpaperManager::Get()->AddObservers();
519 cros_version_loader_
.GetVersion(VersionLoader::VERSION_FULL
,
520 base::Bind(&ChromeOSVersionCallback
),
523 // Make sure that wallpaper boot transition and other delays in OOBE
524 // are disabled for tests and kiosk app launch by default.
525 // Individual tests may enable them if they want.
526 if (parsed_command_line().HasSwitch(::switches::kTestType
) ||
527 ShouldAutoLaunchKioskApp(parsed_command_line())) {
528 WizardController::SetZeroDelays();
531 power_prefs_
.reset(new PowerPrefs(
532 DBusThreadManager::Get()->GetPowerPolicyController()));
534 // In Aura builds this will initialize ash::Shell.
535 ChromeBrowserMainPartsLinux::PreProfileInit();
537 if (immediate_login
) {
538 std::string username
=
539 parsed_command_line().GetSwitchValueASCII(switches::kLoginUser
);
540 UserManager
* user_manager
= UserManager::Get();
541 // In case of multi-profiles --login-profile will contain user_id_hash.
542 std::string username_hash
=
543 parsed_command_line().GetSwitchValueASCII(switches::kLoginProfile
);
544 user_manager
->UserLoggedIn(username
, username_hash
, true);
545 VLOG(1) << "Relaunching browser for user: " << username
546 << " with hash: " << username_hash
;
550 void ChromeBrowserMainPartsChromeos::PostProfileInit() {
551 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
552 // -- just after CreateProfile().
554 // Restarting Chrome inside existing user session. Possible cases:
555 // 1. Chrome is restarted after crash.
556 // 2. Chrome is started in browser_tests skipping the login flow
557 // 3. Chrome is started on dev machine
558 // i.e. not on Chrome OS device w/o login flow.
559 if (parsed_command_line().HasSwitch(switches::kLoginUser
) &&
560 !parsed_command_line().HasSwitch(switches::kLoginPassword
)) {
561 // This is done in LoginUtils::OnProfileCreated during normal login.
562 LoginUtils::Get()->InitRlzDelayed(profile());
564 // Send the PROFILE_PREPARED notification and call SessionStarted()
565 // so that the Launcher and other Profile dependent classes are created.
566 content::NotificationService::current()->Notify(
567 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
568 content::NotificationService::AllSources(),
569 content::Details
<Profile
>(profile()));
570 UserManager::Get()->SessionStarted();
572 // Now is the good time to retrieve other logged in users for this session.
573 // First user has been already marked as logged in and active in
574 // PreProfileInit(). Chrome should tread other user in a session as active
575 // in the background.
576 UserManager::Get()->RestoreActiveSessions();
579 // Initialize the network portal detector for Chrome OS. The network
580 // portal detector starts to listen for notifications from
581 // NetworkStateHandler and initiates captive portal detection for
582 // active networks. Shoule be called before call to
583 // OptionallyRunChromeOSLoginManager, because it depends on
584 // NetworkPortalDetector.
585 NetworkPortalDetector::Initialize();
587 NetworkPortalDetector
* detector
= NetworkPortalDetector::Get();
588 #if defined(GOOGLE_CHROME_BUILD)
589 bool is_official_build
= true;
591 bool is_official_build
= false;
593 // Enable portal detector if EULA was previously accepted or if
594 // this is an unofficial build.
595 if (!is_official_build
|| StartupUtils::IsEulaAccepted())
596 detector
->Enable(true);
599 // Tests should be able to tune login manager before showing it.
600 // Thus only show login manager in normal (non-testing) mode.
601 if (!parameters().ui_task
||
602 parsed_command_line().HasSwitch(switches::kForceLoginManagerInTests
)) {
603 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile());
606 // These observers must be initialized after the profile because
607 // they use the profile to dispatch extension events.
608 extension_system_event_observer_
.reset(new ExtensionSystemEventObserver());
609 if (KioskModeSettings::Get()->IsKioskModeEnabled()) {
610 retail_mode_power_save_blocker_
= content::PowerSaveBlocker::Create(
611 content::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep
,
615 peripheral_battery_observer_
.reset(new PeripheralBatteryObserver());
617 g_browser_process
->platform_part()->InitializeAutomaticRebootManager();
619 // This observer cannot be created earlier because it requires the shell to be
621 idle_action_warning_observer_
.reset(new IdleActionWarningObserver());
623 ChromeBrowserMainPartsLinux::PostProfileInit();
626 void ChromeBrowserMainPartsChromeos::PreBrowserStart() {
627 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
628 // -- just before MetricsService::LogNeedForCleanShutdown().
630 g_browser_process
->metrics_service()->StartExternalMetrics();
632 // Listen for XI_HierarchyChanged events. Note: if this is moved to
633 // PreMainMessageLoopRun() then desktopui_PageCyclerTests fail for unknown
634 // reasons, see http://crosbug.com/24833.
635 XInputHierarchyChangedEventListener::GetInstance();
638 // Start the CrOS input device UMA watcher
639 DeviceUMA::GetInstance();
642 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
643 // -- immediately after ChildProcess::WaitForDebugger().
645 // Start the out-of-memory priority manager here so that we give the most
646 // amount of time for the other services to start up before we start
647 // adjusting the oom priority.
648 g_browser_process
->platform_part()->oom_priority_manager()->Start();
650 if (ui::ShouldDefaultToNaturalScroll()) {
651 CommandLine::ForCurrentProcess()->AppendSwitch(
652 chromeos::switches::kNaturalScrollDefault
);
653 ui::SetNaturalScroll(true);
656 ChromeBrowserMainPartsLinux::PreBrowserStart();
659 void ChromeBrowserMainPartsChromeos::PostBrowserStart() {
660 // These are dependent on the ash::Shell singleton already having been
662 power_button_observer_
.reset(new PowerButtonObserver
);
663 data_promo_notification_
.reset(new DataPromoNotification()),
665 ChromeBrowserMainPartsLinux::PostBrowserStart();
668 // Shut down services before the browser process, etc are destroyed.
669 void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
670 BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", true);
672 g_browser_process
->platform_part()->oom_priority_manager()->Stop();
674 // Stops all in-flight OAuth2 token fetchers before the IO thread stops.
675 DeviceOAuth2TokenServiceFactory::Shutdown();
677 // Shutdown the upgrade detector for Chrome OS. The upgrade detector
678 // stops monitoring changes from the update engine.
679 if (UpgradeDetectorChromeos::GetInstance())
680 UpgradeDetectorChromeos::GetInstance()->Shutdown();
682 // Shutdown the network change notifier for Chrome OS. The network
683 // change notifier stops monitoring changes from the power manager and
684 // the network manager.
685 if (NetworkChangeNotifierFactoryChromeos::GetInstance())
686 NetworkChangeNotifierFactoryChromeos::GetInstance()->Shutdown();
688 // Destroy UI related classes before destroying services that they may
690 data_promo_notification_
.reset();
692 // Tell DeviceSettingsService to stop talking to session_manager. Do not
693 // shutdown DeviceSettingsService yet, it might still be accessed by
694 // BrowserPolicyConnector (owned by g_browser_process).
695 DeviceSettingsService::Get()->UnsetSessionManager();
697 // We should remove observers attached to D-Bus clients before
698 // DBusThreadManager is shut down.
699 extension_system_event_observer_
.reset();
700 retail_mode_power_save_blocker_
.reset();
701 peripheral_battery_observer_
.reset();
702 power_prefs_
.reset();
704 // The XInput2 event listener needs to be shut down earlier than when
705 // Singletons are finally destroyed in AtExitManager.
706 XInputHierarchyChangedEventListener::GetInstance()->Stop();
709 DeviceUMA::GetInstance()->Stop();
712 // SystemKeyEventListener::Shutdown() is always safe to call,
713 // even if Initialize() wasn't called.
714 SystemKeyEventListener::Shutdown();
715 imageburner::BurnManager::Shutdown();
716 CrasAudioHandler::Shutdown();
718 // Detach D-Bus clients before DBusThreadManager is shut down.
719 power_button_observer_
.reset();
720 idle_action_warning_observer_
.reset();
722 // Delete ContactManager while |g_browser_process| is still alive.
723 contact_manager_
.reset();
725 MagnificationManager::Shutdown();
726 AccessibilityManager::Shutdown();
728 media::SoundsManager::Shutdown();
730 system::StatisticsProvider::GetInstance()->Shutdown();
732 // Let the UserManager and WallpaperManager unregister itself as an observer
733 // of the CrosSettings singleton before it is destroyed. This also ensures
734 // that the UserManager has no URLRequest pending (see
735 // http://crbug.com/276659).
736 UserManager::Get()->Shutdown();
737 WallpaperManager::Get()->Shutdown();
739 // Let the AutomaticRebootManager unregister itself as an observer of several
741 g_browser_process
->platform_part()->ShutdownAutomaticRebootManager();
743 // Clean up dependency on CrosSettings and stop pending data fetches.
744 KioskAppManager::Shutdown();
746 // We first call PostMainMessageLoopRun and then destroy UserManager, because
747 // Ash needs to be closed before UserManager is destroyed.
748 ChromeBrowserMainPartsLinux::PostMainMessageLoopRun();
751 // ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() to be
752 // executed after execution of chrome::CloseAsh(), because some
753 // parts of WebUI depends on NetworkPortalDetector.
754 NetworkPortalDetector::Shutdown();
756 UserManager::Destroy();
759 void ChromeBrowserMainPartsChromeos::PostDestroyThreads() {
760 // Destroy DBus services immediately after threads are stopped.
761 dbus_services_
.reset();
763 ChromeBrowserMainPartsLinux::PostDestroyThreads();
765 // Destroy DeviceSettingsService after g_browser_process.
766 DeviceSettingsService::Shutdown();
769 } // namespace chromeos