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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller.cc

Issue 656283002: [session_manager] Move user session initialization code out of ExistingUserController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/existing_user_controller.h" 5 #include "chrome/browser/chromeos/login/existing_user_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 20 #include "base/values.h"
22 #include "base/version.h" 21 #include "base/version.h"
23 #include "chrome/browser/accessibility/accessibility_events.h" 22 #include "chrome/browser/accessibility/accessibility_events.h"
24 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browser_process_platform_part.h" 24 #include "chrome/browser/browser_process_platform_part.h"
26 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
28 #include "chrome/browser/chromeos/boot_times_loader.h" 26 #include "chrome/browser/chromeos/boot_times_loader.h"
29 #include "chrome/browser/chromeos/customization_document.h" 27 #include "chrome/browser/chromeos/customization_document.h"
30 #include "chrome/browser/chromeos/first_run/first_run.h"
31 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" 28 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
32 #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h" 29 #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h"
33 #include "chrome/browser/chromeos/login/helper.h" 30 #include "chrome/browser/chromeos/login/helper.h"
34 #include "chrome/browser/chromeos/login/login_utils.h" 31 #include "chrome/browser/chromeos/login/login_utils.h"
35 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 32 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
36 #include "chrome/browser/chromeos/login/startup_utils.h" 33 #include "chrome/browser/chromeos/login/startup_utils.h"
37 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 34 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
38 #include "chrome/browser/chromeos/login/user_flow.h" 35 #include "chrome/browser/chromeos/login/user_flow.h"
39 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 36 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
40 #include "chrome/browser/chromeos/login/wizard_controller.h" 37 #include "chrome/browser/chromeos/login/wizard_controller.h"
41 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 38 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
42 #include "chrome/browser/chromeos/policy/device_local_account.h" 39 #include "chrome/browser/chromeos/policy/device_local_account.h"
43 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" 40 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
44 #include "chrome/browser/chromeos/profiles/profile_helper.h" 41 #include "chrome/browser/chromeos/profiles/profile_helper.h"
45 #include "chrome/browser/chromeos/settings/cros_settings.h" 42 #include "chrome/browser/chromeos/settings/cros_settings.h"
46 #include "chrome/browser/prefs/session_startup_pref.h"
47 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" 43 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
48 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/chrome_version_info.h" 45 #include "chrome/common/chrome_version_info.h"
50 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
51 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
52 #include "chrome/grit/generated_resources.h" 48 #include "chrome/grit/generated_resources.h"
53 #include "chromeos/chromeos_switches.h" 49 #include "chromeos/chromeos_switches.h"
54 #include "chromeos/dbus/dbus_thread_manager.h" 50 #include "chromeos/dbus/dbus_thread_manager.h"
55 #include "chromeos/dbus/power_manager_client.h" 51 #include "chromeos/dbus/power_manager_client.h"
56 #include "chromeos/dbus/session_manager_client.h" 52 #include "chromeos/dbus/session_manager_client.h"
(...skipping 25 matching lines...) Expand all
82 #include "ui/views/widget/widget.h" 78 #include "ui/views/widget/widget.h"
83 79
84 namespace chromeos { 80 namespace chromeos {
85 81
86 namespace { 82 namespace {
87 83
88 // URL for account creation. 84 // URL for account creation.
89 const char kCreateAccountURL[] = 85 const char kCreateAccountURL[] =
90 "https://accounts.google.com/NewAccount?service=mail"; 86 "https://accounts.google.com/NewAccount?service=mail";
91 87
92 // ChromeVox tutorial URL (used in place of "getting started" url when
93 // accessibility is enabled).
94 const char kChromeVoxTutorialURLPattern[] =
95 "http://www.chromevox.com/tutorial/index.html?lang=%s";
96
97 // Delay for transferring the auth cache to the system profile. 88 // Delay for transferring the auth cache to the system profile.
98 const long int kAuthCacheTransferDelayMs = 2000; 89 const long int kAuthCacheTransferDelayMs = 2000;
99 90
100 // Delay for restarting the ui if safe-mode login has failed. 91 // Delay for restarting the ui if safe-mode login has failed.
101 const long int kSafeModeRestartUiDelayMs = 30000; 92 const long int kSafeModeRestartUiDelayMs = 30000;
102 93
103 // Makes a call to the policy subsystem to reload the policy when we detect 94 // Makes a call to the policy subsystem to reload the policy when we detect
104 // authentication change. 95 // authentication change.
105 void RefreshPoliciesOnUIThread() { 96 void RefreshPoliciesOnUIThread() {
106 if (g_browser_process->policy_service()) 97 if (g_browser_process->policy_service())
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 310 }
320 DCHECK(login_display_.get()); 311 DCHECK(login_display_.get());
321 } 312 }
322 313
323 //////////////////////////////////////////////////////////////////////////////// 314 ////////////////////////////////////////////////////////////////////////////////
324 // ExistingUserController, LoginDisplay::Delegate implementation: 315 // ExistingUserController, LoginDisplay::Delegate implementation:
325 // 316 //
326 317
327 void ExistingUserController::CancelPasswordChangedFlow() { 318 void ExistingUserController::CancelPasswordChangedFlow() {
328 login_performer_.reset(NULL); 319 login_performer_.reset(NULL);
329 login_display_->SetUIEnabled(true); 320 PerformLoginFinishedActions(true /* start public session timer */);
330 StartPublicSessionAutoLoginTimer();
331 } 321 }
332 322
333 void ExistingUserController::CreateAccount() { 323 void ExistingUserController::CreateAccount() {
334 content::RecordAction(base::UserMetricsAction("Login.CreateAccount")); 324 content::RecordAction(base::UserMetricsAction("Login.CreateAccount"));
335 guest_mode_url_ = google_util::AppendGoogleLocaleParam( 325 guest_mode_url_ = google_util::AppendGoogleLocaleParam(
336 GURL(kCreateAccountURL), g_browser_process->GetApplicationLocale()); 326 GURL(kCreateAccountURL), g_browser_process->GetApplicationLocale());
337 LoginAsGuest(); 327 LoginAsGuest();
338 } 328 }
339 329
340 void ExistingUserController::CompleteLogin(const UserContext& user_context) { 330 void ExistingUserController::CompleteLogin(const UserContext& user_context) {
341 login_display_->set_signin_completed(true); 331 login_display_->set_signin_completed(true);
342 if (!host_) { 332 if (!host_) {
343 // Complete login event was generated already from UI. Ignore notification. 333 // Complete login event was generated already from UI. Ignore notification.
344 return; 334 return;
345 } 335 }
346 336
347 // Stop the auto-login timer when attempting login. 337 PerformPreLoginActions(user_context);
348 StopPublicSessionAutoLoginTimer();
349
350 // Disable UI while loading user profile.
351 login_display_->SetUIEnabled(false);
352 338
353 if (!time_init_.is_null()) { 339 if (!time_init_.is_null()) {
354 base::TimeDelta delta = base::Time::Now() - time_init_; 340 base::TimeDelta delta = base::Time::Now() - time_init_;
355 UMA_HISTOGRAM_MEDIUM_TIMES("Login.PromptToCompleteLoginTime", delta); 341 UMA_HISTOGRAM_MEDIUM_TIMES("Login.PromptToCompleteLoginTime", delta);
356 time_init_ = base::Time(); // Reset to null. 342 time_init_ = base::Time(); // Reset to null.
357 } 343 }
358 344
359 host_->OnCompleteLogin(); 345 host_->OnCompleteLogin();
360 346
361 // Do an ownership check now to avoid auto-enrolling if the device has 347 // Do an ownership check now to avoid auto-enrolling if the device has
(...skipping 18 matching lines...) Expand all
380 do_auto_enrollment_ = false; 366 do_auto_enrollment_ = false;
381 auto_enrollment_username_ = user_context.GetUserID(); 367 auto_enrollment_username_ = user_context.GetUserID();
382 resume_login_callback_ = base::Bind( 368 resume_login_callback_ = base::Bind(
383 &ExistingUserController::PerformLogin, 369 &ExistingUserController::PerformLogin,
384 weak_factory_.GetWeakPtr(), 370 weak_factory_.GetWeakPtr(),
385 user_context, LoginPerformer::AUTH_MODE_EXTENSION); 371 user_context, LoginPerformer::AUTH_MODE_EXTENSION);
386 ShowEnrollmentScreen(true, user_context.GetUserID()); 372 ShowEnrollmentScreen(true, user_context.GetUserID());
387 // Enable UI for the enrollment screen. SetUIEnabled(true) will post a 373 // Enable UI for the enrollment screen. SetUIEnabled(true) will post a
388 // request to show the sign-in screen again when invoked at the sign-in 374 // request to show the sign-in screen again when invoked at the sign-in
389 // screen; invoke SetUIEnabled() after navigating to the enrollment screen. 375 // screen; invoke SetUIEnabled() after navigating to the enrollment screen.
390 login_display_->SetUIEnabled(true); 376 PerformLoginFinishedActions(false /* don't start public session timer */);
391 } else { 377 } else {
392 PerformLogin(user_context, LoginPerformer::AUTH_MODE_EXTENSION); 378 PerformLogin(user_context, LoginPerformer::AUTH_MODE_EXTENSION);
393 } 379 }
394 } 380 }
395 381
396 base::string16 ExistingUserController::GetConnectedNetworkName() { 382 base::string16 ExistingUserController::GetConnectedNetworkName() {
397 return network_state_helper_->GetCurrentNetworkName(); 383 return network_state_helper_->GetCurrentNetworkName();
398 } 384 }
399 385
400 bool ExistingUserController::IsSigninInProgress() const { 386 bool ExistingUserController::IsSigninInProgress() const {
(...skipping 20 matching lines...) Expand all
421 LoginAsRetailModeUser(); 407 LoginAsRetailModeUser();
422 return; 408 return;
423 } else if (user_context.GetUserType() == user_manager::USER_TYPE_KIOSK_APP) { 409 } else if (user_context.GetUserType() == user_manager::USER_TYPE_KIOSK_APP) {
424 LoginAsKioskApp(user_context.GetUserID(), specifics.kiosk_diagnostic_mode); 410 LoginAsKioskApp(user_context.GetUserID(), specifics.kiosk_diagnostic_mode);
425 return; 411 return;
426 } 412 }
427 413
428 if (!user_context.HasCredentials()) 414 if (!user_context.HasCredentials())
429 return; 415 return;
430 416
431 // Stop the auto-login timer when attempting login. 417 PerformPreLoginActions(user_context);
432 StopPublicSessionAutoLoginTimer();
433
434 // Disable clicking on other windows.
435 login_display_->SetUIEnabled(false);
436
437 if (last_login_attempt_username_ != user_context.GetUserID()) {
438 last_login_attempt_username_ = user_context.GetUserID();
439 num_login_attempts_ = 0;
440 // Also reset state variables, which are used to determine password change.
441 offline_failed_ = false;
442 online_succeeded_for_.clear();
443 }
444 num_login_attempts_++;
445 PerformLogin(user_context, LoginPerformer::AUTH_MODE_INTERNAL); 418 PerformLogin(user_context, LoginPerformer::AUTH_MODE_INTERNAL);
446 } 419 }
447 420
448 void ExistingUserController::PerformLogin( 421 void ExistingUserController::PerformLogin(
449 const UserContext& user_context, 422 const UserContext& user_context,
450 LoginPerformer::AuthorizationMode auth_mode) { 423 LoginPerformer::AuthorizationMode auth_mode) {
451 ChromeUserManager::Get()->GetUserFlow(last_login_attempt_username_)->set_host( 424 ChromeUserManager::Get()->GetUserFlow(user_context.GetUserID())->set_host(
452 host_); 425 host_);
453 426
454 BootTimesLoader::Get()->RecordLoginAttempted(); 427 BootTimesLoader::Get()->RecordLoginAttempted();
455 428
456 // Disable UI while loading user profile.
457 login_display_->SetUIEnabled(false);
458
459 // Use the same LoginPerformer for subsequent login as it has state 429 // Use the same LoginPerformer for subsequent login as it has state
460 // such as Authenticator instance. 430 // such as Authenticator instance.
461 if (!login_performer_.get() || num_login_attempts_ <= 1) { 431 if (!login_performer_.get() || num_login_attempts_ <= 1) {
462 // Only one instance of LoginPerformer should exist at a time. 432 // Only one instance of LoginPerformer should exist at a time.
463 login_performer_.reset(NULL); 433 login_performer_.reset(NULL);
464 login_performer_.reset(new ChromeLoginPerformer(this)); 434 login_performer_.reset(new ChromeLoginPerformer(this));
465 } 435 }
466 436
467 is_login_in_progress_ = true;
468 if (gaia::ExtractDomainName(user_context.GetUserID()) == 437 if (gaia::ExtractDomainName(user_context.GetUserID()) ==
469 chromeos::login::kSupervisedUserDomain) { 438 chromeos::login::kSupervisedUserDomain) {
470 login_performer_->LoginAsSupervisedUser(user_context); 439 login_performer_->LoginAsSupervisedUser(user_context);
471 } else { 440 } else {
472 login_performer_->PerformLogin(user_context, auth_mode); 441 login_performer_->PerformLogin(user_context, auth_mode);
473 } 442 }
474 SendAccessibilityAlert( 443 SendAccessibilityAlert(
475 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); 444 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN));
476 } 445 }
477 446
478 void ExistingUserController::LoginAsRetailModeUser() { 447 void ExistingUserController::LoginAsRetailModeUser() {
479 // Stop the auto-login timer when attempting login. 448 PerformPreLoginActions(UserContext(user_manager::USER_TYPE_RETAIL_MODE,
480 StopPublicSessionAutoLoginTimer(); 449 chromeos::login::kRetailModeUserName));
481 450
482 // Disable clicking on other windows.
483 login_display_->SetUIEnabled(false);
484 // TODO(rkc): Add a CHECK to make sure retail mode logins are allowed once 451 // TODO(rkc): Add a CHECK to make sure retail mode logins are allowed once
485 // the enterprise policy wiring is done for retail mode. 452 // the enterprise policy wiring is done for retail mode.
486 453
487 // Only one instance of LoginPerformer should exist at a time. 454 // Only one instance of LoginPerformer should exist at a time.
488 login_performer_.reset(NULL); 455 login_performer_.reset(NULL);
489 login_performer_.reset(new ChromeLoginPerformer(this)); 456 login_performer_.reset(new ChromeLoginPerformer(this));
490 is_login_in_progress_ = true;
491 login_performer_->LoginRetailMode(); 457 login_performer_->LoginRetailMode();
492 SendAccessibilityAlert( 458 SendAccessibilityAlert(
493 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_DEMOUSER)); 459 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_DEMOUSER));
494 } 460 }
495 461
496 void ExistingUserController::LoginAsGuest() { 462 void ExistingUserController::LoginAsGuest() {
497 if (is_login_in_progress_ || 463 if (is_login_in_progress_ ||
498 user_manager::UserManager::Get()->IsUserLoggedIn()) { 464 user_manager::UserManager::Get()->IsUserLoggedIn()) {
499 return; 465 return;
500 } 466 }
501 467
502 // Stop the auto-login timer when attempting login. 468 PerformPreLoginActions(UserContext(user_manager::USER_TYPE_GUEST,
503 StopPublicSessionAutoLoginTimer(); 469 chromeos::login::kGuestUserName));
504
505 // Disable clicking on other windows.
506 login_display_->SetUIEnabled(false);
507 470
508 CrosSettingsProvider::TrustedStatus status = 471 CrosSettingsProvider::TrustedStatus status =
509 cros_settings_->PrepareTrustedValues( 472 cros_settings_->PrepareTrustedValues(
510 base::Bind(&ExistingUserController::LoginAsGuest, 473 base::Bind(&ExistingUserController::LoginAsGuest,
511 weak_factory_.GetWeakPtr())); 474 weak_factory_.GetWeakPtr()));
512 // Must not proceed without signature verification. 475 // Must not proceed without signature verification.
513 if (status == CrosSettingsProvider::PERMANENTLY_UNTRUSTED) { 476 if (status == CrosSettingsProvider::PERMANENTLY_UNTRUSTED) {
514 login_display_->ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, 1, 477 login_display_->ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, 1,
515 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 478 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
516 // Reenable clicking on other windows and status area. 479 PerformLoginFinishedActions(false /* don't start public session timer */);
517 login_display_->SetUIEnabled(true);
518 StartPublicSessionAutoLoginTimer();
519 display_email_.clear(); 480 display_email_.clear();
520 return; 481 return;
521 } else if (status != CrosSettingsProvider::TRUSTED) { 482 } else if (status != CrosSettingsProvider::TRUSTED) {
522 // Value of AllowNewUser setting is still not verified. 483 // Value of AllowNewUser setting is still not verified.
523 // Another attempt will be invoked after verification completion. 484 // Another attempt will be invoked after verification completion.
524 return; 485 return;
525 } 486 }
526 487
527 bool allow_guest; 488 bool allow_guest;
528 cros_settings_->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); 489 cros_settings_->GetBoolean(kAccountsPrefAllowGuest, &allow_guest);
529 if (!allow_guest) { 490 if (!allow_guest) {
530 // Disallowed. The UI should normally not show the guest pod but if for some 491 // Disallowed. The UI should normally not show the guest pod but if for some
531 // reason this has been made available to the user here is the time to tell 492 // reason this has been made available to the user here is the time to tell
532 // this nicely. 493 // this nicely.
533 login_display_->ShowError(IDS_LOGIN_ERROR_WHITELIST, 1, 494 login_display_->ShowError(IDS_LOGIN_ERROR_WHITELIST, 1,
534 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 495 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
535 // Reenable clicking on other windows and status area. 496 PerformLoginFinishedActions(true /* start public session timer */);
536 login_display_->SetUIEnabled(true);
537 StartPublicSessionAutoLoginTimer();
538 display_email_.clear(); 497 display_email_.clear();
539 return; 498 return;
540 } 499 }
541 500
542 // Only one instance of LoginPerformer should exist at a time. 501 // Only one instance of LoginPerformer should exist at a time.
543 login_performer_.reset(NULL); 502 login_performer_.reset(NULL);
544 login_performer_.reset(new ChromeLoginPerformer(this)); 503 login_performer_.reset(new ChromeLoginPerformer(this));
545 is_login_in_progress_ = true;
546 login_performer_->LoginOffTheRecord(); 504 login_performer_->LoginOffTheRecord();
547 SendAccessibilityAlert( 505 SendAccessibilityAlert(
548 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_OFFRECORD)); 506 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_OFFRECORD));
549 } 507 }
550 508
551 void ExistingUserController::MigrateUserData(const std::string& old_password) { 509 void ExistingUserController::MigrateUserData(const std::string& old_password) {
552 // LoginPerformer instance has state of the user so it should exist. 510 // LoginPerformer instance has state of the user so it should exist.
553 if (login_performer_.get()) 511 if (login_performer_.get())
554 login_performer_->RecoverEncryptedData(old_password); 512 login_performer_->RecoverEncryptedData(old_password);
555 } 513 }
556 514
557 void ExistingUserController::LoginAsPublicSession( 515 void ExistingUserController::LoginAsPublicSession(
558 const UserContext& user_context) { 516 const UserContext& user_context) {
559 if (is_login_in_progress_ || 517 if (is_login_in_progress_ ||
560 user_manager::UserManager::Get()->IsUserLoggedIn()) { 518 user_manager::UserManager::Get()->IsUserLoggedIn()) {
561 return; 519 return;
562 } 520 }
563 521
564 // Stop the auto-login timer when attempting login. 522 PerformPreLoginActions(user_context);
565 StopPublicSessionAutoLoginTimer();
566
567 // Disable clicking on other windows.
568 login_display_->SetUIEnabled(false);
569 523
570 CrosSettingsProvider::TrustedStatus status = 524 CrosSettingsProvider::TrustedStatus status =
571 cros_settings_->PrepareTrustedValues( 525 cros_settings_->PrepareTrustedValues(
572 base::Bind(&ExistingUserController::LoginAsPublicSession, 526 base::Bind(&ExistingUserController::LoginAsPublicSession,
573 weak_factory_.GetWeakPtr(), 527 weak_factory_.GetWeakPtr(),
574 user_context)); 528 user_context));
575 // If device policy is permanently unavailable, logging into public accounts 529 // If device policy is permanently unavailable, logging into public accounts
576 // is not possible. 530 // is not possible.
577 if (status == CrosSettingsProvider::PERMANENTLY_UNTRUSTED) { 531 if (status == CrosSettingsProvider::PERMANENTLY_UNTRUSTED) {
578 login_display_->ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, 1, 532 login_display_->ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, 1,
579 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 533 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
580 // Re-enable clicking on other windows. 534 PerformLoginFinishedActions(false /* don't start public session timer */);
581 login_display_->SetUIEnabled(true);
582 return; 535 return;
583 } 536 }
584 537
585 // If device policy is not verified yet, this function will be called again 538 // If device policy is not verified yet, this function will be called again
586 // when verification finishes. 539 // when verification finishes.
587 if (status != CrosSettingsProvider::TRUSTED) 540 if (status != CrosSettingsProvider::TRUSTED)
588 return; 541 return;
589 542
590 // If there is no public account with the given user ID, logging in is not 543 // If there is no public account with the given user ID, logging in is not
591 // possible. 544 // possible.
592 const user_manager::User* user = 545 const user_manager::User* user =
593 user_manager::UserManager::Get()->FindUser(user_context.GetUserID()); 546 user_manager::UserManager::Get()->FindUser(user_context.GetUserID());
594 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) { 547 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) {
595 // Re-enable clicking on other windows. 548 PerformLoginFinishedActions(true /* start public session timer */);
596 login_display_->SetUIEnabled(true);
597 StartPublicSessionAutoLoginTimer();
598 return; 549 return;
599 } 550 }
600 551
601 UserContext new_user_context = user_context; 552 UserContext new_user_context = user_context;
602 std::string locale = user_context.GetPublicSessionLocale(); 553 std::string locale = user_context.GetPublicSessionLocale();
603 if (locale.empty()) { 554 if (locale.empty()) {
604 // When performing auto-login, no locale is chosen by the user. Check 555 // When performing auto-login, no locale is chosen by the user. Check
605 // whether a list of recommended locales was set by policy. If so, use its 556 // whether a list of recommended locales was set by policy. If so, use its
606 // first entry. Otherwise, |locale| will remain blank, indicating that the 557 // first entry. Otherwise, |locale| will remain blank, indicating that the
607 // public session should use the current UI locale. 558 // public session should use the current UI locale.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 void ExistingUserController::ShowTPMError() { 713 void ExistingUserController::ShowTPMError() {
763 login_display_->SetUIEnabled(false); 714 login_display_->SetUIEnabled(false);
764 login_display_->ShowErrorScreen(LoginDisplay::TPM_ERROR); 715 login_display_->ShowErrorScreen(LoginDisplay::TPM_ERROR);
765 } 716 }
766 717
767 //////////////////////////////////////////////////////////////////////////////// 718 ////////////////////////////////////////////////////////////////////////////////
768 // ExistingUserController, LoginPerformer::Delegate implementation: 719 // ExistingUserController, LoginPerformer::Delegate implementation:
769 // 720 //
770 721
771 void ExistingUserController::OnAuthFailure(const AuthFailure& failure) { 722 void ExistingUserController::OnAuthFailure(const AuthFailure& failure) {
772 is_login_in_progress_ = false;
773 offline_failed_ = true; 723 offline_failed_ = true;
774
775 guest_mode_url_ = GURL::EmptyGURL(); 724 guest_mode_url_ = GURL::EmptyGURL();
776 std::string error = failure.GetErrorString(); 725 std::string error = failure.GetErrorString();
777 726
727 PerformLoginFinishedActions(false /* don't start public session timer */);
728
778 if (ChromeUserManager::Get() 729 if (ChromeUserManager::Get()
779 ->GetUserFlow(last_login_attempt_username_) 730 ->GetUserFlow(last_login_attempt_username_)
780 ->HandleLoginFailure(failure)) { 731 ->HandleLoginFailure(failure)) {
781 login_display_->SetUIEnabled(true);
782 return; 732 return;
783 } 733 }
784 734
785 if (failure.reason() == AuthFailure::OWNER_REQUIRED) { 735 if (failure.reason() == AuthFailure::OWNER_REQUIRED) {
786 ShowError(IDS_LOGIN_ERROR_OWNER_REQUIRED, error); 736 ShowError(IDS_LOGIN_ERROR_OWNER_REQUIRED, error);
787 content::BrowserThread::PostDelayedTask( 737 content::BrowserThread::PostDelayedTask(
788 content::BrowserThread::UI, FROM_HERE, 738 content::BrowserThread::UI, FROM_HERE,
789 base::Bind(&SessionManagerClient::StopSession, 739 base::Bind(&SessionManagerClient::StopSession,
790 base::Unretained(DBusThreadManager::Get()-> 740 base::Unretained(DBusThreadManager::Get()->
791 GetSessionManagerClient())), 741 GetSessionManagerClient())),
(...skipping 18 matching lines...) Expand all
810 failure.error().state() == 760 failure.error().state() ==
811 GoogleServiceAuthError::HOSTED_NOT_ALLOWED) { 761 GoogleServiceAuthError::HOSTED_NOT_ALLOWED) {
812 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED, error); 762 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED, error);
813 } else { 763 } else {
814 if (!is_known_user) 764 if (!is_known_user)
815 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error); 765 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error);
816 else 766 else
817 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); 767 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error);
818 } 768 }
819 } 769 }
820 // Reenable clicking on other windows and status area.
821 login_display_->SetUIEnabled(true);
822 login_display_->ClearAndEnablePassword(); 770 login_display_->ClearAndEnablePassword();
823 StartPublicSessionAutoLoginTimer(); 771 StartPublicSessionAutoLoginTimer();
824 } 772 }
825 773
826 // Reset user flow to default, so that special flow will not affect next 774 // Reset user flow to default, so that special flow will not affect next
827 // attempt. 775 // attempt.
828 ChromeUserManager::Get()->ResetUserFlow(last_login_attempt_username_); 776 ChromeUserManager::Get()->ResetUserFlow(last_login_attempt_username_);
829 777
830 if (auth_status_consumer_) 778 if (auth_status_consumer_)
831 auth_status_consumer_->OnAuthFailure(failure); 779 auth_status_consumer_->OnAuthFailure(failure);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 this); 817 this);
870 818
871 // Update user's displayed email. 819 // Update user's displayed email.
872 if (!display_email_.empty()) { 820 if (!display_email_.empty()) {
873 user_manager::UserManager::Get()->SaveUserDisplayEmail( 821 user_manager::UserManager::Get()->SaveUserDisplayEmail(
874 user_context.GetUserID(), display_email_); 822 user_context.GetUserID(), display_email_);
875 display_email_.clear(); 823 display_email_.clear();
876 } 824 }
877 } 825 }
878 826
879 void ExistingUserController::OnProfilePrepared(Profile* profile) { 827 void ExistingUserController::OnProfilePrepared(Profile* profile,
828 bool browser_launched) {
880 // Reenable clicking on other windows and status area. 829 // Reenable clicking on other windows and status area.
881 login_display_->SetUIEnabled(true); 830 login_display_->SetUIEnabled(true);
882 831
883 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 832 if (browser_launched)
884 if (user_manager->IsCurrentUserNew() && 833 host_ = NULL;
885 user_manager->IsLoggedInAsSupervisedUser()) { 834
886 // Supervised users should launch into empty desktop on first run. 835 // Inform |auth_status_consumer_| about successful login.
887 CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kSilentLaunch); 836 // TODO(nkostylev): Pass UserContext back crbug.com/424550
837 if (auth_status_consumer_) {
838 auth_status_consumer_->
839 OnAuthSuccess(UserContext(last_login_attempt_username_));
888 } 840 }
889
890 if (user_manager->IsCurrentUserNew() &&
891 !ChromeUserManager::Get()
892 ->GetCurrentUserFlow()
893 ->ShouldSkipPostLoginScreens() &&
894 !WizardController::default_controller()->skip_post_login_screens()) {
895 // Don't specify start URLs if the administrator has configured the start
896 // URLs via policy.
897 if (!SessionStartupPref::TypeIsManaged(profile->GetPrefs()))
898 InitializeStartUrls();
899
900 // Mark the device as registered., i.e. the second part of OOBE as
901 // completed.
902 if (!StartupUtils::IsDeviceRegistered())
903 StartupUtils::MarkDeviceRegistered(base::Closure());
904
905 if (CommandLine::ForCurrentProcess()->HasSwitch(
906 chromeos::switches::kOobeSkipPostLogin)) {
907 LoginUtils::Get()->DoBrowserLaunch(profile, host_);
908 host_ = NULL;
909 } else {
910 ActivateWizard(WizardController::kTermsOfServiceScreenName);
911 }
912 } else {
913 LoginUtils::Get()->DoBrowserLaunch(profile, host_);
914 host_ = NULL;
915 }
916 // Inform |auth_status_consumer_| about successful login.
917 if (auth_status_consumer_)
918 auth_status_consumer_->OnAuthSuccess(UserContext());
919 } 841 }
920 842
921 void ExistingUserController::OnOffTheRecordAuthSuccess() { 843 void ExistingUserController::OnOffTheRecordAuthSuccess() {
922 is_login_in_progress_ = false; 844 is_login_in_progress_ = false;
923 offline_failed_ = false; 845 offline_failed_ = false;
924 846
925 // Mark the device as registered., i.e. the second part of OOBE as completed. 847 // Mark the device as registered., i.e. the second part of OOBE as completed.
926 if (!StartupUtils::IsDeviceRegistered()) 848 if (!StartupUtils::IsDeviceRegistered())
927 StartupUtils::MarkDeviceRegistered(base::Closure()); 849 StartupUtils::MarkDeviceRegistered(base::Closure());
928 850
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 // doing this. See http://crosbug.com/9115 http://crosbug.com/7792 884 // doing this. See http://crosbug.com/9115 http://crosbug.com/7792
963 login_display_->ShowPasswordChangedDialog(show_invalid_old_password_error); 885 login_display_->ShowPasswordChangedDialog(show_invalid_old_password_error);
964 886
965 if (auth_status_consumer_) 887 if (auth_status_consumer_)
966 auth_status_consumer_->OnPasswordChangeDetected(); 888 auth_status_consumer_->OnPasswordChangeDetected();
967 889
968 display_email_.clear(); 890 display_email_.clear();
969 } 891 }
970 892
971 void ExistingUserController::WhiteListCheckFailed(const std::string& email) { 893 void ExistingUserController::WhiteListCheckFailed(const std::string& email) {
972 is_login_in_progress_ = false; 894 PerformLoginFinishedActions(true /* start public session timer */);
973 offline_failed_ = false; 895 offline_failed_ = false;
974 896
975 ShowError(IDS_LOGIN_ERROR_WHITELIST, email); 897 ShowError(IDS_LOGIN_ERROR_WHITELIST, email);
976 898
977 // Reenable clicking on other windows and status area.
978 login_display_->SetUIEnabled(true);
979 login_display_->ShowSigninUI(email); 899 login_display_->ShowSigninUI(email);
980 900
981 if (auth_status_consumer_) { 901 if (auth_status_consumer_) {
982 auth_status_consumer_->OnAuthFailure( 902 auth_status_consumer_->OnAuthFailure(
983 AuthFailure(AuthFailure::WHITELIST_CHECK_FAILED)); 903 AuthFailure(AuthFailure::WHITELIST_CHECK_FAILED));
984 } 904 }
985 905
986 display_email_.clear(); 906 display_email_.clear();
987
988 StartPublicSessionAutoLoginTimer();
989 } 907 }
990 908
991 void ExistingUserController::PolicyLoadFailed() { 909 void ExistingUserController::PolicyLoadFailed() {
992 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, ""); 910 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST, "");
993 911
994 // Reenable clicking on other windows and status area. 912 PerformLoginFinishedActions(false /* don't start public session timer */);
995 is_login_in_progress_ = false;
996 offline_failed_ = false; 913 offline_failed_ = false;
997 login_display_->SetUIEnabled(true);
998
999 display_email_.clear(); 914 display_email_.clear();
1000
1001 // Policy load failure stops login attempts -- restart the timer.
1002 StartPublicSessionAutoLoginTimer();
1003 } 915 }
1004 916
1005 void ExistingUserController::OnOnlineChecked(const std::string& username, 917 void ExistingUserController::OnOnlineChecked(const std::string& username,
1006 bool success) { 918 bool success) {
1007 if (success && last_login_attempt_username_ == username) { 919 if (success && last_login_attempt_username_ == username) {
1008 online_succeeded_for_ = username; 920 online_succeeded_for_ = username;
1009 // Wait for login attempt to end, if it hasn't yet. 921 // Wait for login attempt to end, if it hasn't yet.
1010 if (offline_failed_ && !is_login_in_progress_) 922 if (offline_failed_ && !is_login_in_progress_)
1011 ShowGaiaPasswordChanged(username); 923 ShowGaiaPasswordChanged(username);
1012 } 924 }
1013 } 925 }
1014 926
1015 //////////////////////////////////////////////////////////////////////////////// 927 ////////////////////////////////////////////////////////////////////////////////
1016 // ExistingUserController, private: 928 // ExistingUserController, private:
1017 929
1018 void ExistingUserController::DeviceSettingsChanged() { 930 void ExistingUserController::DeviceSettingsChanged() {
1019 if (host_ != NULL) { 931 if (host_ != NULL) {
1020 // Signed settings or user list changed. Notify views and update them. 932 // Signed settings or user list changed. Notify views and update them.
1021 UpdateLoginDisplay(user_manager::UserManager::Get()->GetUsers()); 933 UpdateLoginDisplay(user_manager::UserManager::Get()->GetUsers());
1022 ConfigurePublicSessionAutoLogin(); 934 ConfigurePublicSessionAutoLogin();
1023 return; 935 return;
1024 } 936 }
1025 } 937 }
1026 938
1027 void ExistingUserController::ActivateWizard(const std::string& screen_name) {
1028 scoped_ptr<base::DictionaryValue> params;
1029 host_->StartWizard(screen_name, params.Pass());
1030 }
1031
1032 LoginPerformer::AuthorizationMode ExistingUserController::auth_mode() const { 939 LoginPerformer::AuthorizationMode ExistingUserController::auth_mode() const {
1033 if (login_performer_) 940 if (login_performer_)
1034 return login_performer_->auth_mode(); 941 return login_performer_->auth_mode();
1035 942
1036 return auth_mode_; 943 return auth_mode_;
1037 } 944 }
1038 945
1039 bool ExistingUserController::password_changed() const { 946 bool ExistingUserController::password_changed() const {
1040 if (login_performer_) 947 if (login_performer_)
1041 return login_performer_->password_changed(); 948 return login_performer_->password_changed();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 public_session_auto_login_delay_), 1023 public_session_auto_login_delay_),
1117 base::Bind( 1024 base::Bind(
1118 &ExistingUserController::OnPublicSessionAutoLoginTimerFire, 1025 &ExistingUserController::OnPublicSessionAutoLoginTimerFire,
1119 weak_factory_.GetWeakPtr())); 1026 weak_factory_.GetWeakPtr()));
1120 } 1027 }
1121 1028
1122 gfx::NativeWindow ExistingUserController::GetNativeWindow() const { 1029 gfx::NativeWindow ExistingUserController::GetNativeWindow() const {
1123 return host_->GetNativeWindow(); 1030 return host_->GetNativeWindow();
1124 } 1031 }
1125 1032
1126 void ExistingUserController::InitializeStartUrls() const {
1127 std::vector<std::string> start_urls;
1128
1129 const base::ListValue *urls;
1130 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
1131 bool can_show_getstarted_guide =
1132 user_manager->GetActiveUser()->GetType() ==
1133 user_manager::USER_TYPE_REGULAR &&
1134 !user_manager->IsCurrentUserNonCryptohomeDataEphemeral();
1135 if (user_manager->IsLoggedInAsDemoUser()) {
1136 if (CrosSettings::Get()->GetList(kStartUpUrls, &urls)) {
1137 // The retail mode user will get start URLs from a special policy if it is
1138 // set.
1139 for (base::ListValue::const_iterator it = urls->begin();
1140 it != urls->end(); ++it) {
1141 std::string url;
1142 if ((*it)->GetAsString(&url))
1143 start_urls.push_back(url);
1144 }
1145 }
1146 can_show_getstarted_guide = false;
1147 // Skip the default first-run behavior for public accounts.
1148 } else if (!user_manager->IsLoggedInAsPublicAccount()) {
1149 if (AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
1150 const char* url = kChromeVoxTutorialURLPattern;
1151 PrefService* prefs = g_browser_process->local_state();
1152 const std::string current_locale =
1153 base::StringToLowerASCII(prefs->GetString(prefs::kApplicationLocale));
1154 std::string vox_url = base::StringPrintf(url, current_locale.c_str());
1155 start_urls.push_back(vox_url);
1156 can_show_getstarted_guide = false;
1157 }
1158 }
1159
1160 // Only show getting started guide for a new user.
1161 const bool should_show_getstarted_guide = user_manager->IsCurrentUserNew();
1162
1163 if (can_show_getstarted_guide && should_show_getstarted_guide) {
1164 // Don't open default Chrome window if we're going to launch the first-run
1165 // app. Because we dont' want the first-run app to be hidden in the
1166 // background.
1167 CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kSilentLaunch);
1168 first_run::MaybeLaunchDialogAfterSessionStart();
1169 } else {
1170 for (size_t i = 0; i < start_urls.size(); ++i) {
1171 CommandLine::ForCurrentProcess()->AppendArg(start_urls[i]);
1172 }
1173 }
1174 }
1175
1176 void ExistingUserController::ShowError(int error_id, 1033 void ExistingUserController::ShowError(int error_id,
1177 const std::string& details) { 1034 const std::string& details) {
1178 // TODO(dpolukhin): show detailed error info. |details| string contains 1035 // TODO(dpolukhin): show detailed error info. |details| string contains
1179 // low level error info that is not localized and even is not user friendly. 1036 // low level error info that is not localized and even is not user friendly.
1180 // For now just ignore it because error_text contains all required information 1037 // For now just ignore it because error_text contains all required information
1181 // for end users, developers can see details string in Chrome logs. 1038 // for end users, developers can see details string in Chrome logs.
1182 VLOG(1) << details; 1039 VLOG(1) << details;
1183 HelpAppLauncher::HelpTopic help_topic_id; 1040 HelpAppLauncher::HelpTopic help_topic_id;
1184 bool is_offline = !network_state_helper_->IsConnected(); 1041 bool is_offline = !network_state_helper_->IsConnected();
1185 switch (login_performer_->error().state()) { 1042 switch (login_performer_->error().state()) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 new_user_context.SetPublicSessionInputMethod(keyboard_layout); 1106 new_user_context.SetPublicSessionInputMethod(keyboard_layout);
1250 1107
1251 LoginAsPublicSessionInternal(new_user_context); 1108 LoginAsPublicSessionInternal(new_user_context);
1252 } 1109 }
1253 1110
1254 void ExistingUserController::LoginAsPublicSessionInternal( 1111 void ExistingUserController::LoginAsPublicSessionInternal(
1255 const UserContext& user_context) { 1112 const UserContext& user_context) {
1256 // Only one instance of LoginPerformer should exist at a time. 1113 // Only one instance of LoginPerformer should exist at a time.
1257 login_performer_.reset(NULL); 1114 login_performer_.reset(NULL);
1258 login_performer_.reset(new ChromeLoginPerformer(this)); 1115 login_performer_.reset(new ChromeLoginPerformer(this));
1259 is_login_in_progress_ = true;
1260 login_performer_->LoginAsPublicSession(user_context); 1116 login_performer_->LoginAsPublicSession(user_context);
1261 SendAccessibilityAlert( 1117 SendAccessibilityAlert(
1262 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_PUBLIC_ACCOUNT)); 1118 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_PUBLIC_ACCOUNT));
1263 } 1119 }
1264 1120
1121 void ExistingUserController::PerformPreLoginActions(
1122 const UserContext& user_context) {
1123 // Disable clicking on other windows and status tray.
1124 login_display_->SetUIEnabled(false);
1125
1126 if (last_login_attempt_username_ != user_context.GetUserID()) {
1127 last_login_attempt_username_ = user_context.GetUserID();
1128 num_login_attempts_ = 0;
1129
1130 // Also reset state variables, which are used to determine password change.
1131 offline_failed_ = false;
1132 online_succeeded_for_.clear();
1133 }
1134
1135 // Guard in cases when we're called twice but login process is still active.
1136 // This might happen when login process is paused till signed settings status
1137 // is verified which results in Login* method called again as a callback.
1138 if (!is_login_in_progress_)
1139 num_login_attempts_++;
1140
1141 is_login_in_progress_ = true;
1142
1143 // Stop the auto-login timer when attempting login.
1144 StopPublicSessionAutoLoginTimer();
1145 }
1146
1147 void ExistingUserController::PerformLoginFinishedActions(
1148 bool start_public_session_timer) {
1149 is_login_in_progress_ = false;
1150
1151 // Reenable clicking on other windows and status area.
1152 login_display_->SetUIEnabled(true);
1153
1154 if (start_public_session_timer)
1155 StartPublicSessionAutoLoginTimer();
1156 }
1157
1265 } // namespace chromeos 1158 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698