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

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

Powered by Google App Engine
This is Rietveld 408576698