| OLD | NEW |
| 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/screens/user_selection_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/user_selection_screen.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_process_platform_part.h" | 12 #include "chrome/browser/browser_process_platform_part.h" |
| 13 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 13 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 14 #include "chrome/browser/chromeos/login/reauth_stats.h" | 14 #include "chrome/browser/chromeos/login/reauth_stats.h" |
| 15 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 15 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 16 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" | 16 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" |
| 17 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 17 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 18 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/signin/easy_unlock_service.h" | 21 #include "chrome/browser/signin/easy_unlock_service.h" |
| 22 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" | 22 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| 23 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 23 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 24 #include "components/proximity_auth/screenlock_bridge.h" | 24 #include "components/proximity_auth/screenlock_bridge.h" |
| 25 #include "components/signin/core/account_id/account_id.h" | 25 #include "components/user_manager/user_id.h" |
| 26 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
| 27 #include "components/user_manager/user_type.h" | 27 #include "components/user_manager/user_type.h" |
| 28 #include "ui/base/user_activity/user_activity_detector.h" | 28 #include "ui/base/user_activity/user_activity_detector.h" |
| 29 | 29 |
| 30 namespace chromeos { | 30 namespace chromeos { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // User dictionary keys. | 34 // User dictionary keys. |
| 35 const char kKeyUsername[] = "username"; | 35 const char kKeyUsername[] = "username"; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 // static | 137 // static |
| 138 void UserSelectionScreen::FillUserDictionary( | 138 void UserSelectionScreen::FillUserDictionary( |
| 139 user_manager::User* user, | 139 user_manager::User* user, |
| 140 bool is_owner, | 140 bool is_owner, |
| 141 bool is_signin_to_add, | 141 bool is_signin_to_add, |
| 142 AuthType auth_type, | 142 AuthType auth_type, |
| 143 const std::vector<std::string>* public_session_recommended_locales, | 143 const std::vector<std::string>* public_session_recommended_locales, |
| 144 base::DictionaryValue* user_dict) { | 144 base::DictionaryValue* user_dict) { |
| 145 const user_manager::UserID user_id = user->email(); |
| 145 const bool is_public_session = | 146 const bool is_public_session = |
| 146 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 147 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; |
| 147 const bool is_legacy_supervised_user = | 148 const bool is_legacy_supervised_user = |
| 148 user->GetType() == user_manager::USER_TYPE_SUPERVISED; | 149 user->GetType() == user_manager::USER_TYPE_SUPERVISED; |
| 149 const bool is_child_user = user->GetType() == user_manager::USER_TYPE_CHILD; | 150 const bool is_child_user = user->GetType() == user_manager::USER_TYPE_CHILD; |
| 150 | 151 |
| 151 user_dict->SetString(kKeyUsername, user->GetAccountId().GetUserEmail()); | 152 user_dict->SetString(kKeyUsername, user_id); |
| 152 user_dict->SetString(kKeyEmailAddress, user->display_email()); | 153 user_dict->SetString(kKeyEmailAddress, user->display_email()); |
| 153 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); | 154 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); |
| 154 user_dict->SetBoolean(kKeyPublicAccount, is_public_session); | 155 user_dict->SetBoolean(kKeyPublicAccount, is_public_session); |
| 155 user_dict->SetBoolean(kKeyLegacySupervisedUser, is_legacy_supervised_user); | 156 user_dict->SetBoolean(kKeyLegacySupervisedUser, is_legacy_supervised_user); |
| 156 user_dict->SetBoolean(kKeyChildUser, is_child_user); | 157 user_dict->SetBoolean(kKeyChildUser, is_child_user); |
| 157 user_dict->SetBoolean(kKeyDesktopUser, false); | 158 user_dict->SetBoolean(kKeyDesktopUser, false); |
| 158 user_dict->SetInteger(kKeyInitialAuthType, auth_type); | 159 user_dict->SetInteger(kKeyInitialAuthType, auth_type); |
| 159 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); | 160 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); |
| 160 user_dict->SetBoolean(kKeyIsOwner, is_owner); | 161 user_dict->SetBoolean(kKeyIsOwner, is_owner); |
| 161 | 162 |
| 162 FillMultiProfileUserPrefs(user, user_dict, is_signin_to_add); | 163 FillMultiProfileUserPrefs(user, user_dict, is_signin_to_add); |
| 163 FillKnownUserPrefs(user, user_dict); | 164 FillKnownUserPrefs(user, user_dict); |
| 164 | 165 |
| 165 if (is_public_session) { | 166 if (is_public_session) { |
| 166 AddPublicSessionDetailsToUserDictionaryEntry( | 167 AddPublicSessionDetailsToUserDictionaryEntry( |
| 167 user_dict, public_session_recommended_locales); | 168 user_dict, public_session_recommended_locales); |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 | 171 |
| 171 // static | 172 // static |
| 172 void UserSelectionScreen::FillKnownUserPrefs(user_manager::User* user, | 173 void UserSelectionScreen::FillKnownUserPrefs(user_manager::User* user, |
| 173 base::DictionaryValue* user_dict) { | 174 base::DictionaryValue* user_dict) { |
| 174 std::string gaia_id; | 175 std::string gaia_id; |
| 175 if (user_manager::UserManager::Get()->FindGaiaID(user->GetAccountId(), | 176 if (user_manager::UserManager::Get()->FindGaiaID(user->email(), &gaia_id)) { |
| 176 &gaia_id)) { | |
| 177 user_dict->SetString(kKeyGaiaID, gaia_id); | 177 user_dict->SetString(kKeyGaiaID, gaia_id); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 // static | 181 // static |
| 182 void UserSelectionScreen::FillMultiProfileUserPrefs( | 182 void UserSelectionScreen::FillMultiProfileUserPrefs( |
| 183 user_manager::User* user, | 183 user_manager::User* user, |
| 184 base::DictionaryValue* user_dict, | 184 base::DictionaryValue* user_dict, |
| 185 bool is_signin_to_add) { | 185 bool is_signin_to_add) { |
| 186 const std::string& user_id = user->email(); | 186 const std::string& user_id = user->email(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN) { | 232 token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN) { |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 | 235 |
| 236 if (is_public_session) | 236 if (is_public_session) |
| 237 return false; | 237 return false; |
| 238 | 238 |
| 239 // At this point the reason for invalid token should be already set. If not, | 239 // At this point the reason for invalid token should be already set. If not, |
| 240 // this might be a leftover from an old version. | 240 // this might be a leftover from an old version. |
| 241 if (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) | 241 if (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) |
| 242 RecordReauthReason(user->GetAccountId(), ReauthReason::OTHER); | 242 RecordReauthReason(user->email(), ReauthReason::OTHER); |
| 243 | 243 |
| 244 return user->force_online_signin() || | 244 return user->force_online_signin() || |
| 245 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) || | 245 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) || |
| 246 (token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); | 246 (token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { | 249 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { |
| 250 handler_ = handler; | 250 handler_ = handler; |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 users_list.Append(user_dict); | 397 users_list.Append(user_dict); |
| 398 } | 398 } |
| 399 | 399 |
| 400 handler_->LoadUsers(users_list, show_guest_); | 400 handler_->LoadUsers(users_list, show_guest_); |
| 401 } | 401 } |
| 402 | 402 |
| 403 void UserSelectionScreen::HandleGetUsers() { | 403 void UserSelectionScreen::HandleGetUsers() { |
| 404 SendUserList(); | 404 SendUserList(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void UserSelectionScreen::CheckUserStatus(const std::string& user_email) { | 407 void UserSelectionScreen::CheckUserStatus(const std::string& user_id) { |
| 408 // No checks on lock screen. | 408 // No checks on lock screen. |
| 409 if (ScreenLocker::default_screen_locker()) | 409 if (ScreenLocker::default_screen_locker()) |
| 410 return; | 410 return; |
| 411 | 411 |
| 412 if (!token_handle_util_.get()) { | 412 if (!token_handle_util_.get()) { |
| 413 token_handle_util_.reset( | 413 token_handle_util_.reset( |
| 414 new TokenHandleUtil(user_manager::UserManager::Get())); | 414 new TokenHandleUtil(user_manager::UserManager::Get())); |
| 415 } | 415 } |
| 416 | 416 |
| 417 const AccountId account_id = AccountId::FromUserEmail(user_email); | 417 if (token_handle_util_->HasToken(user_id)) { |
| 418 if (token_handle_util_->HasToken(account_id)) { | |
| 419 token_handle_util_->CheckToken( | 418 token_handle_util_->CheckToken( |
| 420 account_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, | 419 user_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, |
| 421 weak_factory_.GetWeakPtr())); | 420 weak_factory_.GetWeakPtr())); |
| 422 } | 421 } |
| 423 } | 422 } |
| 424 | 423 |
| 425 void UserSelectionScreen::OnUserStatusChecked( | 424 void UserSelectionScreen::OnUserStatusChecked( |
| 426 const AccountId& account_id, | 425 const user_manager::UserID& user_id, |
| 427 TokenHandleUtil::TokenHandleStatus status) { | 426 TokenHandleUtil::TokenHandleStatus status) { |
| 428 if (status == TokenHandleUtil::INVALID) { | 427 if (status == TokenHandleUtil::INVALID) { |
| 429 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE); | 428 RecordReauthReason(user_id, ReauthReason::INVALID_TOKEN_HANDLE); |
| 430 token_handle_util_->MarkHandleInvalid(account_id); | 429 token_handle_util_->MarkHandleInvalid(user_id); |
| 431 SetAuthType(account_id.GetUserEmail(), ONLINE_SIGN_IN, base::string16()); | 430 SetAuthType(user_id, ONLINE_SIGN_IN, base::string16()); |
| 432 } | 431 } |
| 433 } | 432 } |
| 434 | 433 |
| 435 // EasyUnlock stuff | 434 // EasyUnlock stuff |
| 436 | 435 |
| 437 void UserSelectionScreen::SetAuthType(const std::string& user_id, | 436 void UserSelectionScreen::SetAuthType(const std::string& user_id, |
| 438 AuthType auth_type, | 437 AuthType auth_type, |
| 439 const base::string16& initial_value) { | 438 const base::string16& initial_value) { |
| 440 if (GetAuthType(user_id) == FORCE_OFFLINE_PASSWORD) | 439 if (GetAuthType(user_id) == FORCE_OFFLINE_PASSWORD) |
| 441 return; | 440 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 void UserSelectionScreen::Unlock(const std::string& user_email) { | 491 void UserSelectionScreen::Unlock(const std::string& user_email) { |
| 493 DCHECK_EQ(GetScreenType(), LOCK_SCREEN); | 492 DCHECK_EQ(GetScreenType(), LOCK_SCREEN); |
| 494 ScreenLocker::Hide(); | 493 ScreenLocker::Hide(); |
| 495 } | 494 } |
| 496 | 495 |
| 497 void UserSelectionScreen::AttemptEasySignin(const std::string& user_id, | 496 void UserSelectionScreen::AttemptEasySignin(const std::string& user_id, |
| 498 const std::string& secret, | 497 const std::string& secret, |
| 499 const std::string& key_label) { | 498 const std::string& key_label) { |
| 500 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN); | 499 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN); |
| 501 | 500 |
| 502 UserContext user_context(AccountId::FromUserEmail(user_id)); | 501 UserContext user_context(user_id); |
| 503 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK); | 502 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK); |
| 504 user_context.SetKey(Key(secret)); | 503 user_context.SetKey(Key(secret)); |
| 505 user_context.GetKey()->SetLabel(key_label); | 504 user_context.GetKey()->SetLabel(key_label); |
| 506 | 505 |
| 507 login_display_delegate_->Login(user_context, SigninSpecifics()); | 506 login_display_delegate_->Login(user_context, SigninSpecifics()); |
| 508 } | 507 } |
| 509 | 508 |
| 510 void UserSelectionScreen::HardLockPod(const std::string& user_id) { | 509 void UserSelectionScreen::HardLockPod(const std::string& user_id) { |
| 511 view_->SetAuthType(user_id, OFFLINE_PASSWORD, base::string16()); | 510 view_->SetAuthType(user_id, OFFLINE_PASSWORD, base::string16()); |
| 512 EasyUnlockService* service = GetEasyUnlockServiceForUser(user_id); | 511 EasyUnlockService* service = GetEasyUnlockServiceForUser(user_id); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // The user profile should exist if and only if this is the lock screen. | 549 // The user profile should exist if and only if this is the lock screen. |
| 551 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); | 550 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); |
| 552 | 551 |
| 553 if (!profile) | 552 if (!profile) |
| 554 profile = profile_helper->GetSigninProfile(); | 553 profile = profile_helper->GetSigninProfile(); |
| 555 | 554 |
| 556 return EasyUnlockService::Get(profile); | 555 return EasyUnlockService::Get(profile); |
| 557 } | 556 } |
| 558 | 557 |
| 559 } // namespace chromeos | 558 } // namespace chromeos |
| OLD | NEW |