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

Side by Side Diff: chrome/browser/chromeos/login/session/user_session_manager.cc

Issue 745613002: [cros] Cleanup: remove LoginUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get rid of FakeChromeUserManager usage in ExistingUserController* tests Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/login/session/user_session_manager.h" 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/app_mode/app_mode_utils.h" 23 #include "chrome/browser/app_mode/app_mode_utils.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browser_process_platform_part_chromeos.h" 25 #include "chrome/browser/browser_process_platform_part_chromeos.h"
26 #include "chrome/browser/browser_shutdown.h" 26 #include "chrome/browser/browser_shutdown.h"
27 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 28 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
29 #include "chrome/browser/chromeos/base/locale_util.h" 29 #include "chrome/browser/chromeos/base/locale_util.h"
30 #include "chrome/browser/chromeos/boot_times_recorder.h" 30 #include "chrome/browser/chromeos/boot_times_recorder.h"
31 #include "chrome/browser/chromeos/first_run/first_run.h" 31 #include "chrome/browser/chromeos/first_run/first_run.h"
32 #include "chrome/browser/chromeos/input_method/input_method_util.h" 32 #include "chrome/browser/chromeos/input_method/input_method_util.h"
33 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
33 #include "chrome/browser/chromeos/login/chrome_restart_request.h" 34 #include "chrome/browser/chromeos/login/chrome_restart_request.h"
34 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" 35 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
35 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" 36 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
37 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
36 #include "chrome/browser/chromeos/login/profile_auth_data.h" 38 #include "chrome/browser/chromeos/login/profile_auth_data.h"
37 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" 39 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
38 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h" 40 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h"
39 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" 41 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
40 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" 42 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
41 #include "chrome/browser/chromeos/login/startup_utils.h" 43 #include "chrome/browser/chromeos/login/startup_utils.h"
42 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" 44 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h"
43 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 45 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
44 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 46 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
45 #include "chrome/browser/chromeos/login/user_flow.h" 47 #include "chrome/browser/chromeos/login/user_flow.h"
(...skipping 22 matching lines...) Expand all
68 #include "chrome/common/chrome_switches.h" 70 #include "chrome/common/chrome_switches.h"
69 #include "chrome/common/logging_chrome.h" 71 #include "chrome/common/logging_chrome.h"
70 #include "chrome/common/pref_names.h" 72 #include "chrome/common/pref_names.h"
71 #include "chrome/common/url_constants.h" 73 #include "chrome/common/url_constants.h"
72 #include "chromeos/cert_loader.h" 74 #include "chromeos/cert_loader.h"
73 #include "chromeos/chromeos_switches.h" 75 #include "chromeos/chromeos_switches.h"
74 #include "chromeos/cryptohome/cryptohome_util.h" 76 #include "chromeos/cryptohome/cryptohome_util.h"
75 #include "chromeos/dbus/cryptohome_client.h" 77 #include "chromeos/dbus/cryptohome_client.h"
76 #include "chromeos/dbus/dbus_thread_manager.h" 78 #include "chromeos/dbus/dbus_thread_manager.h"
77 #include "chromeos/dbus/session_manager_client.h" 79 #include "chromeos/dbus/session_manager_client.h"
80 #include "chromeos/login/auth/stub_authenticator.h"
78 #include "chromeos/login/user_names.h" 81 #include "chromeos/login/user_names.h"
79 #include "chromeos/network/portal_detector/network_portal_detector.h" 82 #include "chromeos/network/portal_detector/network_portal_detector.h"
80 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h" 83 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h"
81 #include "chromeos/settings/cros_settings_names.h" 84 #include "chromeos/settings/cros_settings_names.h"
82 #include "components/component_updater/component_updater_service.h" 85 #include "components/component_updater/component_updater_service.h"
83 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 86 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
84 #include "components/session_manager/core/session_manager.h" 87 #include "components/session_manager/core/session_manager.h"
85 #include "components/signin/core/browser/account_tracker_service.h" 88 #include "components/signin/core/browser/account_tracker_service.h"
86 #include "components/signin/core/browser/signin_manager_base.h" 89 #include "components/signin/core/browser/signin_manager_base.h"
87 #include "components/user_manager/user.h" 90 #include "components/user_manager/user.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 309 }
307 } 310 }
308 311
309 // static 312 // static
310 void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) { 313 void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) {
311 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); 314 registry->RegisterStringPref(prefs::kRLZBrand, std::string());
312 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); 315 registry->RegisterBooleanPref(prefs::kRLZDisabled, false);
313 } 316 }
314 317
315 UserSessionManager::UserSessionManager() 318 UserSessionManager::UserSessionManager()
316 : delegate_(NULL), 319 : delegate_(nullptr),
320 authenticator_(nullptr),
317 has_auth_cookies_(false), 321 has_auth_cookies_(false),
318 user_sessions_restored_(false), 322 user_sessions_restored_(false),
319 user_sessions_restore_in_progress_(false), 323 user_sessions_restore_in_progress_(false),
320 exit_after_session_restore_(false), 324 exit_after_session_restore_(false),
321 session_restore_strategy_( 325 session_restore_strategy_(
322 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN), 326 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN),
323 running_easy_unlock_key_ops_(false) { 327 running_easy_unlock_key_ops_(false),
328 should_launch_browser_(true) {
324 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 329 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
325 user_manager::UserManager::Get()->AddSessionStateObserver(this); 330 user_manager::UserManager::Get()->AddSessionStateObserver(this);
326 } 331 }
327 332
328 UserSessionManager::~UserSessionManager() { 333 UserSessionManager::~UserSessionManager() {
329 // UserManager is destroyed before singletons, so we need to check if it 334 // UserManager is destroyed before singletons, so we need to check if it
330 // still exists. 335 // still exists.
331 // TODO(nkostylev): fix order of destruction of UserManager 336 // TODO(nkostylev): fix order of destruction of UserManager
332 // / UserSessionManager objects. 337 // / UserSessionManager objects.
333 if (user_manager::UserManager::IsInitialized()) 338 if (user_manager::UserManager::IsInitialized())
(...skipping 24 matching lines...) Expand all
358 const base::CommandLine user_flags(base::CommandLine::NO_PROGRAM); 363 const base::CommandLine user_flags(base::CommandLine::NO_PROGRAM);
359 if (!about_flags::AreSwitchesIdenticalToCurrentCommandLine( 364 if (!about_flags::AreSwitchesIdenticalToCurrentCommandLine(
360 user_flags, *base::CommandLine::ForCurrentProcess(), NULL)) { 365 user_flags, *base::CommandLine::ForCurrentProcess(), NULL)) {
361 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( 366 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
362 chromeos::login::kGuestUserName, base::CommandLine::StringVector()); 367 chromeos::login::kGuestUserName, base::CommandLine::StringVector());
363 } 368 }
364 369
365 RestartChrome(cmd_line_str); 370 RestartChrome(cmd_line_str);
366 } 371 }
367 372
373 scoped_refptr<Authenticator> UserSessionManager::CreateAuthenticator(
374 AuthStatusConsumer* consumer) {
375 // Screen locker needs new Authenticator instance each time.
376 if (ScreenLocker::default_screen_locker()) {
377 if (authenticator_.get())
378 authenticator_->SetConsumer(NULL);
379 authenticator_ = NULL;
380 }
381
382 if (authenticator_.get() == NULL) {
383 if (injected_user_context_) {
384 authenticator_ =
385 new StubAuthenticator(consumer, *injected_user_context_.get());
386 } else {
387 authenticator_ = new ChromeCryptohomeAuthenticator(consumer);
388 }
389 } else {
390 // TODO(nkostylev): Fix this hack by improving Authenticator dependencies.
391 authenticator_->SetConsumer(consumer);
392 }
393 return authenticator_;
394 }
395
368 void UserSessionManager::StartSession( 396 void UserSessionManager::StartSession(
369 const UserContext& user_context, 397 const UserContext& user_context,
370 StartSessionType start_session_type, 398 StartSessionType start_session_type,
371 scoped_refptr<Authenticator> authenticator,
372 bool has_auth_cookies, 399 bool has_auth_cookies,
373 bool has_active_session, 400 bool has_active_session,
374 UserSessionManagerDelegate* delegate) { 401 UserSessionManagerDelegate* delegate) {
375 authenticator_ = authenticator;
376 delegate_ = delegate; 402 delegate_ = delegate;
377 start_session_type_ = start_session_type; 403 start_session_type_ = start_session_type;
378 404
379 VLOG(1) << "Starting session for " << user_context.GetUserID(); 405 VLOG(1) << "Starting session for " << user_context.GetUserID();
380 406
381 PreStartSession(); 407 PreStartSession();
382 CreateUserSession(user_context, has_auth_cookies); 408 CreateUserSession(user_context, has_auth_cookies);
383 409
384 if (!has_active_session) 410 if (!has_active_session)
385 StartCrosSession(); 411 StartCrosSession();
386 412
387 // TODO(nkostylev): Notify UserLoggedIn() after profile is actually 413 // TODO(nkostylev): Notify UserLoggedIn() after profile is actually
388 // ready to be used (http://crbug.com/361528). 414 // ready to be used (http://crbug.com/361528).
389 NotifyUserLoggedIn(); 415 NotifyUserLoggedIn();
390 PrepareProfile(); 416 PrepareProfile();
391 } 417 }
392 418
419 void UserSessionManager::DelegateDeleted(UserSessionManagerDelegate* delegate) {
420 if (delegate_ == delegate)
421 delegate_ = nullptr;
422 }
423
393 void UserSessionManager::PerformPostUserLoggedInActions() { 424 void UserSessionManager::PerformPostUserLoggedInActions() {
394 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 425 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
395 if (user_manager->GetLoggedInUsers().size() == 1) { 426 if (user_manager->GetLoggedInUsers().size() == 1) {
396 if (NetworkPortalDetector::IsInitialized()) { 427 if (NetworkPortalDetector::IsInitialized()) {
397 NetworkPortalDetector::Get()->SetStrategy( 428 NetworkPortalDetector::Get()->SetStrategy(
398 PortalDetectorStrategy::STRATEGY_ID_SESSION); 429 PortalDetectorStrategy::STRATEGY_ID_SESSION);
399 } 430 }
400 } 431 }
401 } 432 }
402 433
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 } 1013 }
983 1014
984 UpdateEasyUnlockKeys(user_context_); 1015 UpdateEasyUnlockKeys(user_context_);
985 user_context_.ClearSecrets(); 1016 user_context_.ClearSecrets();
986 1017
987 // Now that profile is ready, proceed to either alternative login flows or 1018 // Now that profile is ready, proceed to either alternative login flows or
988 // launch browser. 1019 // launch browser.
989 bool browser_launched = InitializeUserSession(profile); 1020 bool browser_launched = InitializeUserSession(profile);
990 1021
991 // TODO(nkostylev): This pointer should probably never be NULL, but it looks 1022 // TODO(nkostylev): This pointer should probably never be NULL, but it looks
992 // like LoginUtilsImpl::OnProfileCreated() may be getting called before 1023 // like OnProfileCreated() may be getting called before
993 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is 1024 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is
994 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace 1025 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace
995 // this 'if' statement with a CHECK(delegate_) once the underlying issue is 1026 // this 'if' statement with a CHECK(delegate_) once the underlying issue is
996 // resolved. 1027 // resolved.
997 if (delegate_) 1028 if (delegate_)
998 delegate_->OnProfilePrepared(profile, browser_launched); 1029 delegate_->OnProfilePrepared(profile, browser_launched);
999 } 1030 }
1000 1031
1001 void UserSessionManager::ActivateWizard(const std::string& screen_name) { 1032 void UserSessionManager::ActivateWizard(const std::string& screen_name) {
1002 LoginDisplayHost* host = LoginDisplayHostImpl::default_host(); 1033 LoginDisplayHost* host = LoginDisplayHostImpl::default_host();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 // Mark the device as registered., i.e. the second part of OOBE as 1098 // Mark the device as registered., i.e. the second part of OOBE as
1068 // completed. 1099 // completed.
1069 if (!StartupUtils::IsDeviceRegistered()) 1100 if (!StartupUtils::IsDeviceRegistered())
1070 StartupUtils::MarkDeviceRegistered(base::Closure()); 1101 StartupUtils::MarkDeviceRegistered(base::Closure());
1071 1102
1072 ActivateWizard(WizardController::kTermsOfServiceScreenName); 1103 ActivateWizard(WizardController::kTermsOfServiceScreenName);
1073 return false; 1104 return false;
1074 } 1105 }
1075 } 1106 }
1076 1107
1077 LoginUtils::Get()->DoBrowserLaunch(profile, 1108 DoBrowserLaunch(profile, LoginDisplayHostImpl::default_host());
1078 LoginDisplayHostImpl::default_host());
1079 return true; 1109 return true;
1080 } 1110 }
1081 1111
1082 void UserSessionManager::InitSessionRestoreStrategy() { 1112 void UserSessionManager::InitSessionRestoreStrategy() {
1083 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 1113 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1084 bool in_app_mode = chrome::IsRunningInForcedAppMode(); 1114 bool in_app_mode = chrome::IsRunningInForcedAppMode();
1085 1115
1086 // Are we in kiosk app mode? 1116 // Are we in kiosk app mode?
1087 if (in_app_mode) { 1117 if (in_app_mode) {
1088 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) { 1118 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 if (!user_already_logged_in) { 1311 if (!user_already_logged_in) {
1282 UserContext user_context(user_id); 1312 UserContext user_context(user_id);
1283 user_context.SetUserIDHash(user_id_hash); 1313 user_context.SetUserIDHash(user_id_hash);
1284 user_context.SetIsUsingOAuth(false); 1314 user_context.SetIsUsingOAuth(false);
1285 1315
1286 // Will call OnProfilePrepared() once profile has been loaded. 1316 // Will call OnProfilePrepared() once profile has been loaded.
1287 // Only handling secondary users here since primary user profile 1317 // Only handling secondary users here since primary user profile
1288 // (and session) has been loaded on Chrome startup. 1318 // (and session) has been loaded on Chrome startup.
1289 StartSession(user_context, 1319 StartSession(user_context,
1290 SECONDARY_USER_SESSION_AFTER_CRASH, 1320 SECONDARY_USER_SESSION_AFTER_CRASH,
1291 NULL, // authenticator
1292 false, // has_auth_cookies 1321 false, // has_auth_cookies
1293 true, // has_active_session, this is restart after crash 1322 true, // has_active_session, this is restart after crash
1294 this); 1323 this);
1295 } else { 1324 } else {
1296 RestorePendingUserSessions(); 1325 RestorePendingUserSessions();
1297 } 1326 }
1298 } 1327 }
1299 1328
1300 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { 1329 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() {
1301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 1330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 if (login_host) { 1473 if (login_host) {
1445 login_host->SetStatusAreaVisible(true); 1474 login_host->SetStatusAreaVisible(true);
1446 login_host->BeforeSessionStart(); 1475 login_host->BeforeSessionStart();
1447 } 1476 }
1448 1477
1449 BootTimesRecorder::Get()->AddLoginTimeMarker("BrowserLaunched", false); 1478 BootTimesRecorder::Get()->AddLoginTimeMarker("BrowserLaunched", false);
1450 1479
1451 VLOG(1) << "Launching browser..."; 1480 VLOG(1) << "Launching browser...";
1452 TRACE_EVENT0("login", "LaunchBrowser"); 1481 TRACE_EVENT0("login", "LaunchBrowser");
1453 1482
1454 StartupBrowserCreator browser_creator; 1483 if (should_launch_browser_) {
1455 int return_code; 1484 StartupBrowserCreator browser_creator;
1456 chrome::startup::IsFirstRun first_run = 1485 int return_code;
1457 ::first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN 1486 chrome::startup::IsFirstRun first_run =
1458 : chrome::startup::IS_NOT_FIRST_RUN; 1487 ::first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
1488 : chrome::startup::IS_NOT_FIRST_RUN;
1459 1489
1460 browser_creator.LaunchBrowser( 1490 browser_creator.LaunchBrowser(
1461 *base::CommandLine::ForCurrentProcess(), profile, base::FilePath(), 1491 *base::CommandLine::ForCurrentProcess(), profile, base::FilePath(),
1462 chrome::startup::IS_PROCESS_STARTUP, first_run, &return_code); 1492 chrome::startup::IS_PROCESS_STARTUP, first_run, &return_code);
1463 1493
1464 // Triggers app launcher start page service to load start page web contents. 1494 // Triggers app launcher start page service to load start page web contents.
1465 app_list::StartPageService::Get(profile); 1495 app_list::StartPageService::Get(profile);
1496 } else {
1497 LOG(WARNING) << "Browser hasn't been launched, should_launch_browser_"
1498 << " is false. This is normal in some tests.";
1499 }
1466 1500
1467 // Mark login host for deletion after browser starts. This 1501 // Mark login host for deletion after browser starts. This
1468 // guarantees that the message loop will be referenced by the 1502 // guarantees that the message loop will be referenced by the
1469 // browser before it is dereferenced by the login host. 1503 // browser before it is dereferenced by the login host.
1470 if (login_host) 1504 if (login_host)
1471 login_host->Finalize(); 1505 login_host->Finalize();
1472 user_manager::UserManager::Get()->SessionStarted(); 1506 user_manager::UserManager::Get()->SessionStarted();
1473 chromeos::BootTimesRecorder::Get()->LoginDone( 1507 chromeos::BootTimesRecorder::Get()->LoginDone(
1474 user_manager::UserManager::Get()->IsCurrentUserNew()); 1508 user_manager::UserManager::Get()->IsCurrentUserNew());
1475 } 1509 }
(...skipping 20 matching lines...) Expand all
1496 const base::Closure& callback, 1530 const base::Closure& callback,
1497 InputEventsBlocker* /* input_events_blocker */, 1531 InputEventsBlocker* /* input_events_blocker */,
1498 const locale_util::LanguageSwitchResult& /* result */) { 1532 const locale_util::LanguageSwitchResult& /* result */) {
1499 callback.Run(); 1533 callback.Run();
1500 } 1534 }
1501 1535
1502 void UserSessionManager::RemoveProfileForTesting(Profile* profile) { 1536 void UserSessionManager::RemoveProfileForTesting(Profile* profile) {
1503 default_ime_states_.erase(profile); 1537 default_ime_states_.erase(profile);
1504 } 1538 }
1505 1539
1540 void UserSessionManager::InjectStubUserContext(
1541 const UserContext& user_context) {
1542 injected_user_context_.reset(new UserContext(user_context));
1543 authenticator_ = NULL;
1544 }
1545
1506 } // namespace chromeos 1546 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698