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

Side by Side Diff: chrome/browser/chromeos/chrome_browser_main_chromeos.cc

Issue 363613004: [cros] Define session_manager component with SessionManager base class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" 5 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 #include "chromeos/disks/disk_mount_manager.h" 95 #include "chromeos/disks/disk_mount_manager.h"
96 #include "chromeos/ime/ime_keyboard.h" 96 #include "chromeos/ime/ime_keyboard.h"
97 #include "chromeos/ime/input_method_manager.h" 97 #include "chromeos/ime/input_method_manager.h"
98 #include "chromeos/login/login_state.h" 98 #include "chromeos/login/login_state.h"
99 #include "chromeos/network/network_change_notifier_chromeos.h" 99 #include "chromeos/network/network_change_notifier_chromeos.h"
100 #include "chromeos/network/network_change_notifier_factory_chromeos.h" 100 #include "chromeos/network/network_change_notifier_factory_chromeos.h"
101 #include "chromeos/network/network_handler.h" 101 #include "chromeos/network/network_handler.h"
102 #include "chromeos/system/statistics_provider.h" 102 #include "chromeos/system/statistics_provider.h"
103 #include "chromeos/tpm_token_loader.h" 103 #include "chromeos/tpm_token_loader.h"
104 #include "components/metrics/metrics_service.h" 104 #include "components/metrics/metrics_service.h"
105 #include "components/session_manager/core/session_manager.h"
105 #include "content/public/browser/browser_thread.h" 106 #include "content/public/browser/browser_thread.h"
106 #include "content/public/browser/notification_service.h" 107 #include "content/public/browser/notification_service.h"
107 #include "content/public/browser/power_save_blocker.h" 108 #include "content/public/browser/power_save_blocker.h"
108 #include "content/public/common/main_function_params.h" 109 #include "content/public/common/main_function_params.h"
109 #include "grit/platform_locale_settings.h" 110 #include "grit/platform_locale_settings.h"
110 #include "media/audio/sounds/sounds_manager.h" 111 #include "media/audio/sounds/sounds_manager.h"
111 #include "net/base/network_change_notifier.h" 112 #include "net/base/network_change_notifier.h"
112 #include "net/url_request/url_request.h" 113 #include "net/url_request/url_request.h"
113 #include "net/url_request/url_request_context_getter.h" 114 #include "net/url_request/url_request_context_getter.h"
114 #include "ui/base/touch/touch_device.h" 115 #include "ui/base/touch/touch_device.h"
115 #include "ui/events/event_utils.h" 116 #include "ui/events/event_utils.h"
116 117
117 // Exclude X11 dependents for ozone 118 // Exclude X11 dependents for ozone
118 #if defined(USE_X11) 119 #if defined(USE_X11)
119 #include "chrome/browser/chromeos/device_uma.h" 120 #include "chrome/browser/chromeos/device_uma.h"
120 #include "chrome/browser/chromeos/events/system_key_event_listener.h" 121 #include "chrome/browser/chromeos/events/system_key_event_listener.h"
121 #include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener .h" 122 #include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener .h"
122 #endif 123 #endif
123 124
124 namespace chromeos { 125 namespace chromeos {
125 126
126 namespace { 127 namespace {
127 128
128 void ChromeOSVersionCallback(const std::string& version) { 129 void ChromeOSVersionCallback(const std::string& version) {
129 base::SetLinuxDistro(std::string("CrOS ") + version); 130 base::SetLinuxDistro(std::string("CrOS ") + version);
130 } 131 }
131 132
132 // Login ----------------------------------------------------------------------- 133 bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) {
133
134 bool ShouldAutoLaunchKioskApp(const CommandLine& command_line) {
135 KioskAppManager* app_manager = KioskAppManager::Get(); 134 KioskAppManager* app_manager = KioskAppManager::Get();
136 return command_line.HasSwitch(switches::kLoginManager) && 135 return command_line.HasSwitch(switches::kLoginManager) &&
137 !command_line.HasSwitch(switches::kForceLoginManagerInTests) && 136 !command_line.HasSwitch(switches::kForceLoginManagerInTests) &&
138 app_manager->IsAutoLaunchEnabled() && 137 app_manager->IsAutoLaunchEnabled() &&
139 KioskAppLaunchError::Get() == KioskAppLaunchError::NONE; 138 KioskAppLaunchError::Get() == KioskAppLaunchError::NONE;
140 } 139 }
141 140
142 void RunAutoLaunchKioskApp() {
143 ShowLoginWizard(chromeos::WizardController::kAppLaunchSplashScreenName);
144
145 // Login screen is skipped but 'login-prompt-visible' signal is still needed.
146 VLOG(1) << "Kiosk app auto launch >> login-prompt-visible";
147 DBusThreadManager::Get()->GetSessionManagerClient()->
148 EmitLoginPromptVisible();
149 }
150
151 void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line,
152 Profile* profile) {
153 std::string login_user = parsed_command_line.
154 GetSwitchValueASCII(chromeos::switches::kLoginUser);
155 if (!base::SysInfo::IsRunningOnChromeOS() &&
156 login_user == UserManager::kStubUser) {
157 return;
158 }
159
160 if (ShouldAutoLaunchKioskApp(parsed_command_line)) {
161 RunAutoLaunchKioskApp();
162 } else if (parsed_command_line.HasSwitch(switches::kLoginManager)) {
163 ShowLoginWizard(std::string());
164
165 if (KioskModeSettings::Get()->IsKioskModeEnabled())
166 InitializeKioskModeScreensaver();
167
168 // Reset reboot after update flag when login screen is shown.
169 policy::BrowserPolicyConnectorChromeOS* connector =
170 g_browser_process->platform_part()->browser_policy_connector_chromeos();
171 if (!connector->IsEnterpriseManaged()) {
172 PrefService* local_state = g_browser_process->local_state();
173 local_state->ClearPref(prefs::kRebootAfterUpdate);
174 }
175 } else {
176 if (!parsed_command_line.HasSwitch(::switches::kTestName)) {
177 // Enable CrasAudioHandler logging when chrome restarts after crashing.
178 if (chromeos::CrasAudioHandler::IsInitialized())
179 chromeos::CrasAudioHandler::Get()->LogErrors();
180
181 // We did not log in (we crashed or are debugging), so we need to
182 // restore Sync.
183 UserSessionManager::GetInstance()->RestoreAuthenticationSession(profile);
184 }
185 }
186 }
187
188 } // namespace 141 } // namespace
189 142
190 namespace internal { 143 namespace internal {
191 144
192 // Wrapper class for initializing dbus related services and shutting them 145 // Wrapper class for initializing dbus related services and shutting them
193 // down. This gets instantiated in a scoped_ptr so that shutdown methods in the 146 // down. This gets instantiated in a scoped_ptr so that shutdown methods in the
194 // destructor will get called if and only if this has been instantiated. 147 // destructor will get called if and only if this has been instantiated.
195 class DBusServices { 148 class DBusServices {
196 public: 149 public:
197 explicit DBusServices(const content::MainFunctionParams& parameters) { 150 explicit DBusServices(const content::MainFunctionParams& parameters) {
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 UserSessionManager::GetInstance()->RespectLocalePreference( 502 UserSessionManager::GetInstance()->RespectLocalePreference(
550 profile, user, callback.Pass()); 503 profile, user, callback.Pass());
551 } 504 }
552 505
553 void ChromeBrowserMainPartsChromeos::PostProfileInit() { 506 void ChromeBrowserMainPartsChromeos::PostProfileInit() {
554 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() 507 // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun()
555 // -- just after CreateProfile(). 508 // -- just after CreateProfile().
556 509
557 BootTimesLoader::Get()->OnChromeProcessStart(); 510 BootTimesLoader::Get()->OnChromeProcessStart();
558 511
559 // Restarting Chrome inside existing user session. Possible cases:
560 // 1. Chrome is restarted after crash.
561 // 2. Chrome is started in browser_tests skipping the login flow.
562 // 3. Chrome is started on dev machine i.e. not on Chrome OS device w/o
563 // login flow. In that case --login-user=[UserManager::kStubUser] is added.
564 // See PreEarlyInitialization().
565 if (parsed_command_line().HasSwitch(switches::kLoginUser)) {
566 std::string login_user = login::CanonicalizeUserID(
567 parsed_command_line().GetSwitchValueASCII(
568 chromeos::switches::kLoginUser));
569 if (!base::SysInfo::IsRunningOnChromeOS() &&
570 login_user == UserManager::kStubUser) {
571 // For dev machines and stub user emulate as if sync has been initialized.
572 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
573 login_user);
574 }
575
576 // This is done in SessionManager::OnProfileCreated during normal login.
577 UserSessionManager::GetInstance()->InitRlz(profile());
578
579 // Send the PROFILE_PREPARED notification and call SessionStarted()
580 // so that the Launcher and other Profile dependent classes are created.
581 content::NotificationService::current()->Notify(
582 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
583 content::NotificationService::AllSources(),
584 content::Details<Profile>(profile()));
585 UserManager::Get()->SessionStarted();
586
587 // Now is the good time to retrieve other logged in users for this session.
588 // First user has been already marked as logged in and active in
589 // PreProfileInit(). Chrome should tread other user in a session as active
590 // in the background.
591 UserManager::Get()->RestoreActiveSessions();
592 }
593
594 // Initialize the network portal detector for Chrome OS. The network 512 // Initialize the network portal detector for Chrome OS. The network
595 // portal detector starts to listen for notifications from 513 // portal detector starts to listen for notifications from
596 // NetworkStateHandler and initiates captive portal detection for 514 // NetworkStateHandler and initiates captive portal detection for
597 // active networks. Shoule be called before call to 515 // active networks. Should be called before call to CreateSessionManager,
598 // OptionallyRunChromeOSLoginManager, because it depends on 516 // because it depends on NetworkPortalDetector.
599 // NetworkPortalDetector.
600 NetworkPortalDetectorImpl::Initialize( 517 NetworkPortalDetectorImpl::Initialize(
601 g_browser_process->system_request_context()); 518 g_browser_process->system_request_context());
602 { 519 {
603 NetworkPortalDetector* detector = NetworkPortalDetector::Get(); 520 NetworkPortalDetector* detector = NetworkPortalDetector::Get();
604 #if defined(GOOGLE_CHROME_BUILD) 521 #if defined(GOOGLE_CHROME_BUILD)
605 bool is_official_build = true; 522 bool is_official_build = true;
606 #else 523 #else
607 bool is_official_build = false; 524 bool is_official_build = false;
608 #endif 525 #endif
609 // Enable portal detector if EULA was previously accepted or if 526 // Enable portal detector if EULA was previously accepted or if
610 // this is an unofficial build. 527 // this is an unofficial build.
611 if (!is_official_build || StartupUtils::IsEulaAccepted()) 528 if (!is_official_build || StartupUtils::IsEulaAccepted())
612 detector->Enable(true); 529 detector->Enable(true);
613 } 530 }
614 531
615 // Tests should be able to tune login manager before showing it. 532 bool is_running_test = parameters().ui_task != NULL;
616 // Thus only show login manager in normal (non-testing) mode. 533 g_browser_process->platform_part()->InitializeSessionManager(
617 if (!parameters().ui_task || 534 parsed_command_line(), profile(), is_running_test);
618 parsed_command_line().HasSwitch(switches::kForceLoginManagerInTests)) { 535 g_browser_process->platform_part()->session_manager()->Start();
619 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile());
620 }
621 536
622 // Guest user profile is never initialized with locale settings, 537 // Guest user profile is never initialized with locale settings,
623 // so we need special handling for Guest session. 538 // so we need special handling for Guest session.
624 if (UserManager::Get()->IsLoggedInAsGuest()) 539 if (UserManager::Get()->IsLoggedInAsGuest())
625 SetGuestLocale(profile()); 540 SetGuestLocale(profile());
626 541
627 // These observers must be initialized after the profile because 542 // These observers must be initialized after the profile because
628 // they use the profile to dispatch extension events. 543 // they use the profile to dispatch extension events.
629 extension_system_event_observer_.reset(new ExtensionSystemEventObserver()); 544 extension_system_event_observer_.reset(new ExtensionSystemEventObserver());
630 if (KioskModeSettings::Get()->IsKioskModeEnabled()) { 545 if (KioskModeSettings::Get()->IsKioskModeEnabled()) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // Stops all in-flight OAuth2 token fetchers before the IO thread stops. 716 // Stops all in-flight OAuth2 token fetchers before the IO thread stops.
802 DeviceOAuth2TokenServiceFactory::Shutdown(); 717 DeviceOAuth2TokenServiceFactory::Shutdown();
803 718
804 // Called after 719 // Called after
805 // ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() to be 720 // ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() to be
806 // executed after execution of chrome::CloseAsh(), because some 721 // executed after execution of chrome::CloseAsh(), because some
807 // parts of WebUI depends on NetworkPortalDetector. 722 // parts of WebUI depends on NetworkPortalDetector.
808 NetworkPortalDetector::Shutdown(); 723 NetworkPortalDetector::Shutdown();
809 724
810 UserManager::Destroy(); 725 UserManager::Destroy();
726
727 g_browser_process->platform_part()->ShutdownSessionManager();
811 } 728 }
812 729
813 void ChromeBrowserMainPartsChromeos::PostDestroyThreads() { 730 void ChromeBrowserMainPartsChromeos::PostDestroyThreads() {
814 // Destroy DBus services immediately after threads are stopped. 731 // Destroy DBus services immediately after threads are stopped.
815 dbus_services_.reset(); 732 dbus_services_.reset();
816 733
817 ChromeBrowserMainPartsLinux::PostDestroyThreads(); 734 ChromeBrowserMainPartsLinux::PostDestroyThreads();
818 735
819 // Destroy DeviceSettingsService after g_browser_process. 736 // Destroy DeviceSettingsService after g_browser_process.
820 DeviceSettingsService::Shutdown(); 737 DeviceSettingsService::Shutdown();
821 } 738 }
822 739
823 } // namespace chromeos 740 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698