| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/chromeos/login/background_view.h" | 23 #include "chrome/browser/chromeos/login/background_view.h" |
| 24 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 24 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
| 25 #include "chrome/browser/chromeos/login/helper.h" | 25 #include "chrome/browser/chromeos/login/helper.h" |
| 26 #include "chrome/browser/chromeos/login/login_utils.h" | 26 #include "chrome/browser/chromeos/login/login_utils.h" |
| 27 #include "chrome/browser/chromeos/login/message_bubble.h" | 27 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 28 #include "chrome/browser/chromeos/login/wizard_controller.h" | 28 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 29 #include "chrome/browser/chromeos/status/status_area_view.h" | 29 #include "chrome/browser/chromeos/status/status_area_view.h" |
| 30 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 30 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
| 31 #include "chrome/browser/chromeos/view_ids.h" | 31 #include "chrome/browser/chromeos/view_ids.h" |
| 32 #include "chrome/browser/chromeos/wm_ipc.h" | 32 #include "chrome/browser/chromeos/wm_ipc.h" |
| 33 #include "chrome/browser/profile_manager.h" |
| 33 #include "chrome/browser/views/window.h" | 34 #include "chrome/browser/views/window.h" |
| 34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/net/gaia/google_service_auth_error.h" | 36 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 36 #include "gfx/native_widget_types.h" | 37 #include "gfx/native_widget_types.h" |
| 37 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
| 38 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 39 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
| 40 #include "views/screen.h" | 41 #include "views/screen.h" |
| 41 #include "views/widget/widget_gtk.h" | 42 #include "views/widget/widget_gtk.h" |
| 42 #include "views/window/window.h" | 43 #include "views/window/window.h" |
| 43 | 44 |
| 44 namespace chromeos { | 45 namespace chromeos { |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 // Max number of users we'll show. The true max is the min of this and the | 49 // Max number of users we'll show. The true max is the min of this and the |
| 49 // number of windows that fit on the screen. | 50 // number of windows that fit on the screen. |
| 50 const size_t kMaxUsers = 5; | 51 const size_t kMaxUsers = 5; |
| 51 | 52 |
| 52 // Used to indicate no user has been selected. | 53 // Used to indicate no user has been selected. |
| 53 const size_t kNotSelected = -1; | 54 const size_t kNotSelected = -1; |
| 54 | 55 |
| 55 // Offset of cursor in first position from edit left side. It's used to position | 56 // Offset of cursor in first position from edit left side. It's used to position |
| 56 // info bubble arrow to cursor. | 57 // info bubble arrow to cursor. |
| 57 const int kCursorOffset = 5; | 58 const int kCursorOffset = 5; |
| 58 | 59 |
| 60 // Url for setting up sync authentication. |
| 61 const char kSettingsSyncLoginUrl[] = "chrome://settings/personal"; |
| 62 |
| 59 // Used to handle the asynchronous response of deleting a cryptohome directory. | 63 // Used to handle the asynchronous response of deleting a cryptohome directory. |
| 60 class RemoveAttempt : public CryptohomeLibrary::Delegate { | 64 class RemoveAttempt : public CryptohomeLibrary::Delegate { |
| 61 public: | 65 public: |
| 62 explicit RemoveAttempt(const std::string& user_email) | 66 explicit RemoveAttempt(const std::string& user_email) |
| 63 : user_email_(user_email) { | 67 : user_email_(user_email) { |
| 64 if (CrosLibrary::Get()->EnsureLoaded()) { | 68 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 65 CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncRemove( | 69 CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncRemove( |
| 66 user_email_, this); | 70 user_email_, this); |
| 67 } | 71 } |
| 68 } | 72 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // TODO(xiyuan): Wait for the cached settings update before using them. | 112 // TODO(xiyuan): Wait for the cached settings update before using them. |
| 109 ExistingUserController::ExistingUserController( | 113 ExistingUserController::ExistingUserController( |
| 110 const std::vector<UserManager::User>& users, | 114 const std::vector<UserManager::User>& users, |
| 111 const gfx::Rect& background_bounds) | 115 const gfx::Rect& background_bounds) |
| 112 : background_bounds_(background_bounds), | 116 : background_bounds_(background_bounds), |
| 113 background_window_(NULL), | 117 background_window_(NULL), |
| 114 background_view_(NULL), | 118 background_view_(NULL), |
| 115 selected_view_index_(kNotSelected), | 119 selected_view_index_(kNotSelected), |
| 116 num_login_attempts_(0), | 120 num_login_attempts_(0), |
| 117 bubble_(NULL), | 121 bubble_(NULL), |
| 118 user_settings_(new UserCrosSettingsProvider()) { | 122 user_settings_(new UserCrosSettingsProvider()), |
| 123 two_factor_error_(false) { |
| 119 if (delete_scheduled_instance_) | 124 if (delete_scheduled_instance_) |
| 120 delete_scheduled_instance_->Delete(); | 125 delete_scheduled_instance_->Delete(); |
| 121 | 126 |
| 122 // Caclulate the max number of users from available screen size. | 127 // Caclulate the max number of users from available screen size. |
| 123 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { | 128 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { |
| 124 size_t max_users = kMaxUsers; | 129 size_t max_users = kMaxUsers; |
| 125 int screen_width = background_bounds.width(); | 130 int screen_width = background_bounds.width(); |
| 126 if (screen_width > 0) { | 131 if (screen_width > 0) { |
| 127 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, | 132 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, |
| 128 static_cast<size_t>((screen_width - login::kUserImageSize) | 133 static_cast<size_t>((screen_width - login::kUserImageSize) |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 376 |
| 372 void ExistingUserController::SelectUser(int index) { | 377 void ExistingUserController::SelectUser(int index) { |
| 373 if (index >= 0 && index < static_cast<int>(controllers_.size()) && | 378 if (index >= 0 && index < static_cast<int>(controllers_.size()) && |
| 374 index != static_cast<int>(selected_view_index_)) { | 379 index != static_cast<int>(selected_view_index_)) { |
| 375 WmIpc::Message message(WM_IPC_MESSAGE_WM_SELECT_LOGIN_USER); | 380 WmIpc::Message message(WM_IPC_MESSAGE_WM_SELECT_LOGIN_USER); |
| 376 message.set_param(0, index); | 381 message.set_param(0, index); |
| 377 WmIpc::instance()->SendMessage(message); | 382 WmIpc::instance()->SendMessage(message); |
| 378 } | 383 } |
| 379 } | 384 } |
| 380 | 385 |
| 386 void ExistingUserController::SetLoginFailure(const LoginFailure& failure) { |
| 387 if ((failure.reason() == LoginFailure::NETWORK_AUTH_FAILED && |
| 388 failure.error().state() == GoogleServiceAuthError::TWO_FACTOR)) { |
| 389 two_factor_error_ = true; |
| 390 } |
| 391 } |
| 392 |
| 381 void ExistingUserController::OnLoginFailure(const LoginFailure& failure) { | 393 void ExistingUserController::OnLoginFailure(const LoginFailure& failure) { |
| 382 std::string error = failure.GetErrorString(); | 394 std::string error = failure.GetErrorString(); |
| 383 | 395 |
| 384 // Check networking after trying to login in case user is | 396 // Check networking after trying to login in case user is |
| 385 // cached locally or the local admin account. | 397 // cached locally or the local admin account. |
| 386 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); | 398 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); |
| 387 if (!network || !CrosLibrary::Get()->EnsureLoaded()) { | 399 if (!network || !CrosLibrary::Get()->EnsureLoaded()) { |
| 388 ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY, error); | 400 ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY, error); |
| 389 } else if (!network->Connected()) { | 401 } else if (!network->Connected()) { |
| 390 ShowError(IDS_LOGIN_ERROR_OFFLINE_FAILED_NETWORK_NOT_CONNECTED, error); | 402 ShowError(IDS_LOGIN_ERROR_OFFLINE_FAILED_NETWORK_NOT_CONNECTED, error); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 const GaiaAuthConsumer::ClientLoginResult& credentials, | 491 const GaiaAuthConsumer::ClientLoginResult& credentials, |
| 480 bool pending_requests) { | 492 bool pending_requests) { |
| 481 // LoginPerformer instance will delete itself once online auth result is OK. | 493 // LoginPerformer instance will delete itself once online auth result is OK. |
| 482 // In case of failure it'll bring up ScreenLock and ask for | 494 // In case of failure it'll bring up ScreenLock and ask for |
| 483 // correct password/display error message. | 495 // correct password/display error message. |
| 484 // Even in case when following online,offline protocol and returning | 496 // Even in case when following online,offline protocol and returning |
| 485 // requests_pending = false, let LoginPerformer delete itself. | 497 // requests_pending = false, let LoginPerformer delete itself. |
| 486 login_performer_->set_delegate(NULL); | 498 login_performer_->set_delegate(NULL); |
| 487 LoginPerformer* performer = login_performer_.release(); | 499 LoginPerformer* performer = login_performer_.release(); |
| 488 performer = NULL; | 500 performer = NULL; |
| 501 bool known_user = UserManager::Get()->IsKnownUser(username); |
| 502 if (two_factor_error_ && !known_user && !start_url_.is_valid()) { |
| 503 // If we have a two factor error and and this is a new user and we are not |
| 504 // already directing the user to a start url (e.g. a help page), |
| 505 // direct them to the personal settings page. |
| 506 // TODO(stevenjb): direct the user to a lightweight sync login page. |
| 507 start_url_ = GURL(kSettingsSyncLoginUrl); |
| 508 } |
| 489 AppendStartUrlToCmdline(); | 509 AppendStartUrlToCmdline(); |
| 490 if (selected_view_index_ + 1 == controllers_.size() && | 510 if (selected_view_index_ + 1 == controllers_.size() && !known_user) { |
| 491 !UserManager::Get()->IsKnownUser(username)) { | |
| 492 // For new user login don't launch browser until we pass image screen. | 511 // For new user login don't launch browser until we pass image screen. |
| 493 LoginUtils::Get()->EnableBrowserLaunch(false); | 512 LoginUtils::Get()->EnableBrowserLaunch(false); |
| 494 LoginUtils::Get()->CompleteLogin(username, password, credentials); | 513 LoginUtils::Get()->CompleteLogin(username, password, credentials); |
| 495 ActivateWizard(WizardController::IsDeviceRegistered() ? | 514 ActivateWizard(WizardController::IsDeviceRegistered() ? |
| 496 WizardController::kUserImageScreenName : | 515 WizardController::kUserImageScreenName : |
| 497 WizardController::kRegistrationScreenName); | 516 WizardController::kRegistrationScreenName); |
| 498 } else { | 517 } else { |
| 499 // Hide the login windows now. | 518 // Hide the login windows now. |
| 500 WmIpc::Message message(WM_IPC_MESSAGE_WM_HIDE_LOGIN); | 519 WmIpc::Message message(WM_IPC_MESSAGE_WM_HIDE_LOGIN); |
| 501 WmIpc::instance()->SendMessage(message); | 520 WmIpc::instance()->SendMessage(message); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 void ExistingUserController::RecoverEncryptedData( | 589 void ExistingUserController::RecoverEncryptedData( |
| 571 const std::string& old_password) { | 590 const std::string& old_password) { |
| 572 login_performer_->RecoverEncryptedData(old_password); | 591 login_performer_->RecoverEncryptedData(old_password); |
| 573 } | 592 } |
| 574 | 593 |
| 575 void ExistingUserController::ResyncEncryptedData() { | 594 void ExistingUserController::ResyncEncryptedData() { |
| 576 login_performer_->ResyncEncryptedData(); | 595 login_performer_->ResyncEncryptedData(); |
| 577 } | 596 } |
| 578 | 597 |
| 579 } // namespace chromeos | 598 } // namespace chromeos |
| OLD | NEW |