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

Side by Side Diff: chrome/browser/chromeos/login/screens/user_selection_screen.cc

Issue 2937553002: Create Mojo Struct for user information used in login/lock screen. (Closed)
Patch Set: rebase Created 3 years, 6 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/screens/user_selection_screen.h" 5 #include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_process_platform_part.h" 20 #include "chrome/browser/browser_process_platform_part.h"
20 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 21 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
21 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" 22 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h"
22 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" 23 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h"
23 #include "chrome/browser/chromeos/login/reauth_stats.h" 24 #include "chrome/browser/chromeos/login/reauth_stats.h"
24 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 25 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
25 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" 26 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h"
26 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 27 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
27 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" 28 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 29 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
29 #include "chrome/browser/chromeos/profiles/profile_helper.h" 30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
30 #include "chrome/browser/signin/easy_unlock_service.h" 31 #include "chrome/browser/signin/easy_unlock_service.h"
31 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" 32 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
32 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 33 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
33 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
35 #include "chrome/grit/theme_resources.h"
34 #include "chromeos/chromeos_switches.h" 36 #include "chromeos/chromeos_switches.h"
35 #include "chromeos/cryptohome/cryptohome_parameters.h" 37 #include "chromeos/cryptohome/cryptohome_parameters.h"
36 #include "chromeos/dbus/cryptohome_client.h" 38 #include "chromeos/dbus/cryptohome_client.h"
37 #include "chromeos/dbus/dbus_method_call_status.h" 39 #include "chromeos/dbus/dbus_method_call_status.h"
38 #include "chromeos/dbus/dbus_thread_manager.h" 40 #include "chromeos/dbus/dbus_thread_manager.h"
39 #include "components/arc/arc_util.h" 41 #include "components/arc/arc_util.h"
40 #include "components/prefs/pref_service.h" 42 #include "components/prefs/pref_service.h"
41 #include "components/proximity_auth/screenlock_bridge.h" 43 #include "components/proximity_auth/screenlock_bridge.h"
42 #include "components/signin/core/account_id/account_id.h" 44 #include "components/signin/core/account_id/account_id.h"
43 #include "components/user_manager/known_user.h" 45 #include "components/user_manager/known_user.h"
44 #include "components/user_manager/user_manager.h" 46 #include "components/user_manager/user_manager.h"
45 #include "components/user_manager/user_type.h" 47 #include "components/user_manager/user_type.h"
46 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
49 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/base/user_activity/user_activity_detector.h" 50 #include "ui/base/user_activity/user_activity_detector.h"
48 51
49 namespace chromeos { 52 namespace chromeos {
50 53
51 namespace { 54 namespace {
52 55
53 // User dictionary keys. 56 // User dictionary keys.
54 const char kKeyUsername[] = "username"; 57 const char kKeyUsername[] = "username";
55 const char kKeyGaiaID[] = "gaiaId"; 58 const char kKeyGaiaID[] = "gaiaId";
56 const char kKeyDisplayName[] = "displayName"; 59 const char kKeyDisplayName[] = "displayName";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 recommended_locales.size() >= 2); 126 recommended_locales.size() >= 2);
124 127
125 // Set |kKeyInitialKeyboardLayout| to the current keyboard layout. This 128 // Set |kKeyInitialKeyboardLayout| to the current keyboard layout. This
126 // value will be used temporarily only because the UI immediately requests a 129 // value will be used temporarily only because the UI immediately requests a
127 // list of keyboard layouts suitable for the currently selected locale. 130 // list of keyboard layouts suitable for the currently selected locale.
128 user_dict->Set(kKeyInitialKeyboardLayout, GetCurrentKeyboardLayout()); 131 user_dict->Set(kKeyInitialKeyboardLayout, GetCurrentKeyboardLayout());
129 } 132 }
130 133
131 // Returns true if the fingerprint icon should be displayed for the given 134 // Returns true if the fingerprint icon should be displayed for the given
132 // |user|. 135 // |user|.
133 bool AllowFingerprintForUser(user_manager::User* user) { 136 bool AllowFingerprintForUser(const user_manager::User* user) {
134 if (!user->is_logged_in()) 137 if (!user->is_logged_in())
135 return false; 138 return false;
136 139
137 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 140 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
138 quick_unlock::QuickUnlockFactory::GetForUser(user); 141 quick_unlock::QuickUnlockFactory::GetForUser(user);
139 if (!quick_unlock_storage) 142 if (!quick_unlock_storage)
140 return false; 143 return false;
141 144
142 return quick_unlock_storage->IsFingerprintAuthenticationAvailable(); 145 return quick_unlock_storage->IsFingerprintAuthenticationAvailable();
143 } 146 }
144 147
145 // Returns true if dircrypto migration check should be performed. 148 // Returns true if dircrypto migration check should be performed.
146 bool ShouldCheckNeedDircryptoMigration() { 149 bool ShouldCheckNeedDircryptoMigration() {
147 return !base::CommandLine::ForCurrentProcess()->HasSwitch( 150 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
148 switches::kDisableEncryptionMigration) && 151 switches::kDisableEncryptionMigration) &&
149 arc::IsArcAvailable(); 152 arc::IsArcAvailable();
150 } 153 }
151 154
152 // Returns true if the user can run ARC based on the user type. 155 // Returns true if the user can run ARC based on the user type.
153 bool IsUserAllowedForARC(const AccountId& account_id) { 156 bool IsUserAllowedForARC(const AccountId& account_id) {
154 return user_manager::UserManager::IsInitialized() && 157 return user_manager::UserManager::IsInitialized() &&
155 arc::IsArcAllowedForUser( 158 arc::IsArcAllowedForUser(
156 user_manager::UserManager::Get()->FindUser(account_id)); 159 user_manager::UserManager::Get()->FindUser(account_id));
157 } 160 }
158 161
162 AccountId GetOwnerAccountId() {
163 std::string owner_email;
164 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner,
165 &owner_email);
166 const AccountId owner = user_manager::known_user::GetAccountId(
167 owner_email, std::string() /* id */, AccountType::UNKNOWN);
168 return owner;
169 }
170
171 bool IsEnterpriseManaged() {
172 policy::BrowserPolicyConnectorChromeOS* connector =
173 g_browser_process->platform_part()->browser_policy_connector_chromeos();
174 return connector->IsEnterpriseManaged();
175 }
176
177 bool IsSigninToAdd() {
178 return LoginDisplayHost::default_host() &&
179 user_manager::UserManager::Get()->IsUserLoggedIn();
180 }
181
182 bool CanRemoveUser(bool is_single_user, const user_manager::User* user) {
183 // Single user check here is necessary because owner info might not be
184 // available when running into login screen on first boot.
185 // See http://crosbug.com/12723
186 if (is_single_user && !IsEnterpriseManaged())
187 return false;
188 if (!user->GetAccountId().is_valid())
189 return false;
190 if (user->GetAccountId() == GetOwnerAccountId())
191 return false;
192 if (user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT ||
193 user->is_logged_in() || IsSigninToAdd())
194 return false;
195
196 return true;
197 }
198
199 void GetMultiProfilePolicy(const user_manager::User* user,
200 bool* out_is_allowed,
201 ash::mojom::MultiProfileUserBehavior* out_policy) {
202 const std::string& user_id = user->GetAccountId().GetUserEmail();
203 MultiProfileUserController* multi_profile_user_controller =
204 ChromeUserManager::Get()->GetMultiProfileUserController();
205 MultiProfileUserController::UserAllowedInSessionReason is_user_allowed_reason;
206 *out_is_allowed = multi_profile_user_controller->IsUserAllowedInSession(
207 user_id, &is_user_allowed_reason);
208
209 std::string policy;
210 if (is_user_allowed_reason ==
211 MultiProfileUserController::NOT_ALLOWED_OWNER_AS_SECONDARY) {
212 policy = MultiProfileUserController::kBehaviorOwnerPrimaryOnly;
213 } else {
214 policy = multi_profile_user_controller->GetCachedValue(user_id);
215 }
216 *out_policy = MultiProfileUserController::UserBehaviorStringToEnum(policy);
217 }
218
159 } // namespace 219 } // namespace
160 220
161 // Helper class to call cryptohome to check whether a user needs dircrypto 221 // Helper class to call cryptohome to check whether a user needs dircrypto
162 // migration. The check results are cached to limit calls to cryptohome. 222 // migration. The check results are cached to limit calls to cryptohome.
163 class UserSelectionScreen::DircryptoMigrationChecker { 223 class UserSelectionScreen::DircryptoMigrationChecker {
164 public: 224 public:
165 explicit DircryptoMigrationChecker(UserSelectionScreen* owner) 225 explicit DircryptoMigrationChecker(UserSelectionScreen* owner)
166 : owner_(owner), weak_ptr_factory_(this) {} 226 : owner_(owner), weak_ptr_factory_(this) {}
167 ~DircryptoMigrationChecker() = default; 227 ~DircryptoMigrationChecker() = default;
168 228
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void UserSelectionScreen::SetLoginDisplayDelegate( 327 void UserSelectionScreen::SetLoginDisplayDelegate(
268 LoginDisplay::Delegate* login_display_delegate) { 328 LoginDisplay::Delegate* login_display_delegate) {
269 login_display_delegate_ = login_display_delegate; 329 login_display_delegate_ = login_display_delegate;
270 } 330 }
271 331
272 // static 332 // static
273 void UserSelectionScreen::FillUserDictionary( 333 void UserSelectionScreen::FillUserDictionary(
274 user_manager::User* user, 334 user_manager::User* user,
275 bool is_owner, 335 bool is_owner,
276 bool is_signin_to_add, 336 bool is_signin_to_add,
277 AuthType auth_type, 337 proximity_auth::mojom::AuthType auth_type,
278 const std::vector<std::string>* public_session_recommended_locales, 338 const std::vector<std::string>* public_session_recommended_locales,
279 base::DictionaryValue* user_dict) { 339 base::DictionaryValue* user_dict) {
280 const bool is_public_session = 340 const bool is_public_session =
281 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; 341 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT;
282 const bool is_legacy_supervised_user = 342 const bool is_legacy_supervised_user =
283 user->GetType() == user_manager::USER_TYPE_SUPERVISED; 343 user->GetType() == user_manager::USER_TYPE_SUPERVISED;
284 const bool is_child_user = user->GetType() == user_manager::USER_TYPE_CHILD; 344 const bool is_child_user = user->GetType() == user_manager::USER_TYPE_CHILD;
285 345
286 user_dict->SetString(kKeyUsername, user->GetAccountId().Serialize()); 346 user_dict->SetString(kKeyUsername, user->GetAccountId().Serialize());
287 user_dict->SetString(kKeyEmailAddress, user->display_email()); 347 user_dict->SetString(kKeyEmailAddress, user->display_email());
288 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); 348 user_dict->SetString(kKeyDisplayName, user->GetDisplayName());
289 user_dict->SetBoolean(kKeyPublicAccount, is_public_session); 349 user_dict->SetBoolean(kKeyPublicAccount, is_public_session);
290 user_dict->SetBoolean(kKeyLegacySupervisedUser, is_legacy_supervised_user); 350 user_dict->SetBoolean(kKeyLegacySupervisedUser, is_legacy_supervised_user);
291 user_dict->SetBoolean(kKeyChildUser, is_child_user); 351 user_dict->SetBoolean(kKeyChildUser, is_child_user);
292 user_dict->SetBoolean(kKeyDesktopUser, false); 352 user_dict->SetBoolean(kKeyDesktopUser, false);
293 user_dict->SetInteger(kKeyInitialAuthType, auth_type); 353 user_dict->SetInteger(kKeyInitialAuthType, static_cast<int>(auth_type));
294 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); 354 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in());
295 user_dict->SetBoolean(kKeyIsOwner, is_owner); 355 user_dict->SetBoolean(kKeyIsOwner, is_owner);
296 user_dict->SetBoolean(kKeyIsActiveDirectory, user->IsActiveDirectoryUser()); 356 user_dict->SetBoolean(kKeyIsActiveDirectory, user->IsActiveDirectoryUser());
297 user_dict->SetBoolean(kKeyAllowFingerprint, AllowFingerprintForUser(user)); 357 user_dict->SetBoolean(kKeyAllowFingerprint, AllowFingerprintForUser(user));
298 358
299 FillMultiProfileUserPrefs(user, user_dict, is_signin_to_add); 359 FillMultiProfileUserPrefs(user, user_dict, is_signin_to_add);
300 FillKnownUserPrefs(user, user_dict); 360 FillKnownUserPrefs(user, user_dict);
301 361
302 if (is_public_session) { 362 if (is_public_session) {
303 AddPublicSessionDetailsToUserDictionaryEntry( 363 AddPublicSessionDetailsToUserDictionaryEntry(
304 user_dict, public_session_recommended_locales); 364 user_dict, public_session_recommended_locales);
305 } 365 }
306 } 366 }
307 367
308 // static 368 // static
309 void UserSelectionScreen::FillKnownUserPrefs(user_manager::User* user, 369 void UserSelectionScreen::FillKnownUserPrefs(user_manager::User* user,
310 base::DictionaryValue* user_dict) { 370 base::DictionaryValue* user_dict) {
311 std::string gaia_id; 371 std::string gaia_id;
312 if (user_manager::known_user::FindGaiaID(user->GetAccountId(), &gaia_id)) { 372 if (user_manager::known_user::FindGaiaID(user->GetAccountId(), &gaia_id)) {
313 user_dict->SetString(kKeyGaiaID, gaia_id); 373 user_dict->SetString(kKeyGaiaID, gaia_id);
314 } 374 }
315 } 375 }
316 376
317 // static 377 // static
318 void UserSelectionScreen::FillMultiProfileUserPrefs( 378 void UserSelectionScreen::FillMultiProfileUserPrefs(
319 user_manager::User* user, 379 user_manager::User* user,
320 base::DictionaryValue* user_dict, 380 base::DictionaryValue* user_dict,
321 bool is_signin_to_add) { 381 bool is_signin_to_add) {
322 const std::string& user_id = user->GetAccountId().GetUserEmail(); 382 if (!is_signin_to_add) {
383 user_dict->SetBoolean(kKeyMultiProfilesAllowed, true);
384 return;
385 }
323 386
324 if (is_signin_to_add) { 387 bool is_user_allowed;
325 MultiProfileUserController* multi_profile_user_controller = 388 ash::mojom::MultiProfileUserBehavior policy;
326 ChromeUserManager::Get()->GetMultiProfileUserController(); 389 GetMultiProfilePolicy(user, &is_user_allowed, &policy);
327 MultiProfileUserController::UserAllowedInSessionReason isUserAllowedReason; 390 user_dict->SetBoolean(kKeyMultiProfilesAllowed, is_user_allowed);
328 bool isUserAllowed = multi_profile_user_controller->IsUserAllowedInSession( 391 user_dict->SetInteger(kKeyMultiProfilesPolicy, static_cast<int>(policy));
329 user_id, &isUserAllowedReason);
330 user_dict->SetBoolean(kKeyMultiProfilesAllowed, isUserAllowed);
331
332 std::string behavior;
333 switch (isUserAllowedReason) {
334 case MultiProfileUserController::NOT_ALLOWED_OWNER_AS_SECONDARY:
335 behavior = MultiProfileUserController::kBehaviorOwnerPrimaryOnly;
336 break;
337 default:
338 behavior = multi_profile_user_controller->GetCachedValue(user_id);
339 }
340 MultiProfileUserController::MultiProfileUserBehavior user_behavior =
341 MultiProfileUserController::UserBehaviorStringToEnum(behavior);
342 user_dict->SetInteger(kKeyMultiProfilesPolicy,
343 static_cast<int>(user_behavior));
344 } else {
345 user_dict->SetBoolean(kKeyMultiProfilesAllowed, true);
346 }
347 } 392 }
348 393
349 // static 394 // static
350 bool UserSelectionScreen::ShouldForceOnlineSignIn( 395 bool UserSelectionScreen::ShouldForceOnlineSignIn(
351 const user_manager::User* user) { 396 const user_manager::User* user) {
352 // Public sessions are always allowed to log in offline. 397 // Public sessions are always allowed to log in offline.
353 // Supervised users are always allowed to log in offline. 398 // Supervised users are always allowed to log in offline.
354 // For all other users, force online sign in if: 399 // For all other users, force online sign in if:
355 // * The flag to force online sign-in is set for the user. 400 // * The flag to force online sign-in is set for the user.
356 // * The user's OAuth token is invalid or unknown. 401 // * The user's OAuth token is invalid or unknown.
(...skipping 23 matching lines...) Expand all
380 // We need to force an online signin if the user is marked as requiring it, 425 // We need to force an online signin if the user is marked as requiring it,
381 // or if the user's session never completed initialization (still need to 426 // or if the user's session never completed initialization (still need to
382 // check for policy/management state) or if there's an invalid OAUTH token 427 // check for policy/management state) or if there's an invalid OAUTH token
383 // that needs to be refreshed. 428 // that needs to be refreshed.
384 return user->force_online_signin() || !user->profile_ever_initialized() || 429 return user->force_online_signin() || !user->profile_ever_initialized() ||
385 (has_gaia_account && 430 (has_gaia_account &&
386 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID || 431 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID ||
387 token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN)); 432 token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN));
388 } 433 }
389 434
435 // static
436 void UserSelectionScreen::FillUserMojoStruct(
437 const user_manager::User* user,
438 bool is_owner,
439 bool is_signin_to_add,
440 proximity_auth::mojom::AuthType auth_type,
441 ash::mojom::LoginUserInfo* user_info) {
442 user_info->basic_user_info = ash::mojom::UserInfo::New();
443 user_info->basic_user_info->type = user->GetType();
444 user_info->basic_user_info->account_id = user->GetAccountId();
445 user_info->basic_user_info->display_name =
446 base::UTF16ToUTF8(user->GetDisplayName());
447 user_info->basic_user_info->display_email = user->display_email();
448 user_info->basic_user_info->avatar = user->GetImage();
449 if (user_info->basic_user_info->avatar.isNull()) {
450 user_info->basic_user_info->avatar =
451 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
452 IDR_PROFILE_PICTURE_LOADING);
453 }
454 user_info->auth_type = auth_type;
455 user_info->is_signed_in = user->is_logged_in();
456 user_info->is_device_owner = is_owner;
457 user_info->allow_fingerprint_unlock = AllowFingerprintForUser(user);
458
459 // Fill multi-profile data.
460 if (!is_signin_to_add) {
461 user_info->is_multiprofile_allowed = true;
462 } else {
463 GetMultiProfilePolicy(user, &user_info->is_multiprofile_allowed,
464 &user_info->multiprofile_policy);
465 }
466 }
467
390 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { 468 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) {
391 handler_ = handler; 469 handler_ = handler;
392 470
393 if (handler_) { 471 if (handler_) {
394 // Forcibly refresh all of the user images, as the |handler_| instance may 472 // Forcibly refresh all of the user images, as the |handler_| instance may
395 // have been reused. 473 // have been reused.
396 for (user_manager::User* user : users_) 474 for (user_manager::User* user : users_)
397 handler_->OnUserImageChanged(*user); 475 handler_->OnUserImageChanged(*user);
398 } 476 }
399 } 477 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 users_to_send.erase(users_to_send.begin() + kMaxUsers); 556 users_to_send.erase(users_to_send.begin() + kMaxUsers);
479 } else if (users_to_send.size() < kMaxUsers) { 557 } else if (users_to_send.size() < kMaxUsers) {
480 users_to_send.push_back(*it); 558 users_to_send.push_back(*it);
481 } 559 }
482 } 560 }
483 } 561 }
484 return users_to_send; 562 return users_to_send;
485 } 563 }
486 564
487 void UserSelectionScreen::SendUserList() { 565 void UserSelectionScreen::SendUserList() {
488 std::unique_ptr<base::ListValue> users_list = PrepareUserList(); 566 std::unique_ptr<base::ListValue> users_list =
567 UpdateAndReturnUserListForWebUI();
489 handler_->LoadUsers(users_to_send_, *users_list); 568 handler_->LoadUsers(users_to_send_, *users_list);
490 } 569 }
491 570
492 void UserSelectionScreen::HandleGetUsers() { 571 void UserSelectionScreen::HandleGetUsers() {
493 SendUserList(); 572 SendUserList();
494 } 573 }
495 574
496 void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) { 575 void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) {
497 // No checks on lock screen. 576 // No checks on lock screen.
498 if (ScreenLocker::default_screen_locker()) 577 if (ScreenLocker::default_screen_locker())
(...skipping 19 matching lines...) Expand all
518 dircrypto_migration_checker_->Check(account_id); 597 dircrypto_migration_checker_->Check(account_id);
519 } 598 }
520 } 599 }
521 600
522 void UserSelectionScreen::OnUserStatusChecked( 601 void UserSelectionScreen::OnUserStatusChecked(
523 const AccountId& account_id, 602 const AccountId& account_id,
524 TokenHandleUtil::TokenHandleStatus status) { 603 TokenHandleUtil::TokenHandleStatus status) {
525 if (status == TokenHandleUtil::INVALID) { 604 if (status == TokenHandleUtil::INVALID) {
526 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE); 605 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE);
527 token_handle_util_->MarkHandleInvalid(account_id); 606 token_handle_util_->MarkHandleInvalid(account_id);
528 SetAuthType(account_id, ONLINE_SIGN_IN, base::string16()); 607 SetAuthType(account_id, proximity_auth::mojom::AuthType::ONLINE_SIGN_IN,
608 base::string16());
529 } 609 }
530 } 610 }
531 611
532 // EasyUnlock stuff 612 // EasyUnlock stuff
533 613
534 void UserSelectionScreen::SetAuthType(const AccountId& account_id, 614 void UserSelectionScreen::SetAuthType(const AccountId& account_id,
535 AuthType auth_type, 615 proximity_auth::mojom::AuthType auth_type,
536 const base::string16& initial_value) { 616 const base::string16& initial_value) {
537 if (GetAuthType(account_id) == FORCE_OFFLINE_PASSWORD) 617 if (GetAuthType(account_id) ==
618 proximity_auth::mojom::AuthType::FORCE_OFFLINE_PASSWORD) {
538 return; 619 return;
539 DCHECK(GetAuthType(account_id) != FORCE_OFFLINE_PASSWORD || 620 }
540 auth_type == FORCE_OFFLINE_PASSWORD); 621
622 DCHECK(GetAuthType(account_id) !=
623 proximity_auth::mojom::AuthType::FORCE_OFFLINE_PASSWORD ||
624 auth_type == proximity_auth::mojom::AuthType::FORCE_OFFLINE_PASSWORD);
541 user_auth_type_map_[account_id] = auth_type; 625 user_auth_type_map_[account_id] = auth_type;
542 view_->SetAuthType(account_id, auth_type, initial_value); 626 view_->SetAuthType(account_id, auth_type, initial_value);
543 } 627 }
544 628
545 proximity_auth::ScreenlockBridge::LockHandler::AuthType 629 proximity_auth::mojom::AuthType UserSelectionScreen::GetAuthType(
546 UserSelectionScreen::GetAuthType(const AccountId& account_id) const { 630 const AccountId& account_id) const {
547 if (user_auth_type_map_.find(account_id) == user_auth_type_map_.end()) 631 if (user_auth_type_map_.find(account_id) == user_auth_type_map_.end())
548 return OFFLINE_PASSWORD; 632 return proximity_auth::mojom::AuthType::OFFLINE_PASSWORD;
549 return user_auth_type_map_.find(account_id)->second; 633 return user_auth_type_map_.find(account_id)->second;
550 } 634 }
551 635
552 proximity_auth::ScreenlockBridge::LockHandler::ScreenType 636 proximity_auth::ScreenlockBridge::LockHandler::ScreenType
553 UserSelectionScreen::GetScreenType() const { 637 UserSelectionScreen::GetScreenType() const {
554 if (display_type_ == OobeUI::kLockDisplay) 638 if (display_type_ == OobeUI::kLockDisplay)
555 return LOCK_SCREEN; 639 return LOCK_SCREEN;
556 640
557 if (display_type_ == OobeUI::kLoginDisplay) 641 if (display_type_ == OobeUI::kLoginDisplay)
558 return SIGNIN_SCREEN; 642 return SIGNIN_SCREEN;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // login display delegate not exist in views-based lock screen. 685 // login display delegate not exist in views-based lock screen.
602 if (login_display_delegate_) 686 if (login_display_delegate_)
603 login_display_delegate_->Login(user_context, SigninSpecifics()); 687 login_display_delegate_->Login(user_context, SigninSpecifics());
604 } 688 }
605 689
606 void UserSelectionScreen::Show() {} 690 void UserSelectionScreen::Show() {}
607 691
608 void UserSelectionScreen::Hide() {} 692 void UserSelectionScreen::Hide() {}
609 693
610 void UserSelectionScreen::HardLockPod(const AccountId& account_id) { 694 void UserSelectionScreen::HardLockPod(const AccountId& account_id) {
611 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16()); 695 view_->SetAuthType(account_id,
696 proximity_auth::mojom::AuthType::OFFLINE_PASSWORD,
697 base::string16());
612 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 698 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
613 if (!service) 699 if (!service)
614 return; 700 return;
615 service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); 701 service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK);
616 } 702 }
617 703
618 void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) { 704 void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) {
619 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 705 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
620 if (!service) 706 if (!service)
621 return; 707 return;
622 service->AttemptAuth(account_id); 708 service->AttemptAuth(account_id);
623 } 709 }
624 710
625 void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) { 711 void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) {
626 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 712 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
627 if (!service) 713 if (!service)
628 return; 714 return;
629 service->RecordClickOnLockIcon(); 715 service->RecordClickOnLockIcon();
630 } 716 }
631 717
632 std::unique_ptr<base::ListValue> UserSelectionScreen::PrepareUserList() { 718 std::unique_ptr<base::ListValue>
719 UserSelectionScreen::UpdateAndReturnUserListForWebUI() {
633 std::unique_ptr<base::ListValue> users_list = 720 std::unique_ptr<base::ListValue> users_list =
634 base::MakeUnique<base::ListValue>(); 721 base::MakeUnique<base::ListValue>();
635 722
636 // TODO(nkostylev): Move to a separate method in UserManager. 723 // TODO(nkostylev): Move to a separate method in UserManager.
637 // http://crbug.com/230852 724 // http://crbug.com/230852
638 bool single_user = users_.size() == 1; 725 const bool single_user = users_.size() == 1;
639 bool is_signin_to_add = LoginDisplayHost::default_host() && 726 const AccountId owner = GetOwnerAccountId();
640 user_manager::UserManager::Get()->IsUserLoggedIn(); 727 const bool is_signin_to_add = IsSigninToAdd();
641 std::string owner_email;
642 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner,
643 &owner_email);
644 const AccountId owner = user_manager::known_user::GetAccountId(
645 owner_email, std::string() /* id */, AccountType::UNKNOWN);
646
647 policy::BrowserPolicyConnectorChromeOS* connector =
648 g_browser_process->platform_part()->browser_policy_connector_chromeos();
649 bool is_enterprise_managed = connector->IsEnterpriseManaged();
650 728
651 users_to_send_ = PrepareUserListForSending(users_, owner, is_signin_to_add); 729 users_to_send_ = PrepareUserListForSending(users_, owner, is_signin_to_add);
652 730
653 user_auth_type_map_.clear(); 731 user_auth_type_map_.clear();
654 732
655 const std::vector<std::string> kEmptyRecommendedLocales; 733 const std::vector<std::string> kEmptyRecommendedLocales;
656 for (user_manager::UserList::const_iterator it = users_to_send_.begin(); 734 for (user_manager::UserList::const_iterator it = users_to_send_.begin();
657 it != users_to_send_.end(); ++it) { 735 it != users_to_send_.end(); ++it) {
658 const AccountId& account_id = (*it)->GetAccountId(); 736 const AccountId& account_id = (*it)->GetAccountId();
659 bool is_owner = (account_id == owner); 737 bool is_owner = (account_id == owner);
660 const bool is_public_account = 738 const bool is_public_account =
661 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); 739 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT);
662 const AuthType initial_auth_type = 740 const proximity_auth::mojom::AuthType initial_auth_type =
663 is_public_account ? EXPAND_THEN_USER_CLICK 741 is_public_account
664 : (ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN 742 ? proximity_auth::mojom::AuthType::EXPAND_THEN_USER_CLICK
665 : OFFLINE_PASSWORD); 743 : (ShouldForceOnlineSignIn(*it)
744 ? proximity_auth::mojom::AuthType::ONLINE_SIGN_IN
745 : proximity_auth::mojom::AuthType::OFFLINE_PASSWORD);
666 user_auth_type_map_[account_id] = initial_auth_type; 746 user_auth_type_map_[account_id] = initial_auth_type;
667 747
668 auto user_dict = base::MakeUnique<base::DictionaryValue>(); 748 auto user_dict = base::MakeUnique<base::DictionaryValue>();
669 const std::vector<std::string>* public_session_recommended_locales = 749 const std::vector<std::string>* public_session_recommended_locales =
670 public_session_recommended_locales_.find(account_id) == 750 public_session_recommended_locales_.find(account_id) ==
671 public_session_recommended_locales_.end() 751 public_session_recommended_locales_.end()
672 ? &kEmptyRecommendedLocales 752 ? &kEmptyRecommendedLocales
673 : &public_session_recommended_locales_[account_id]; 753 : &public_session_recommended_locales_[account_id];
674 FillUserDictionary(*it, is_owner, is_signin_to_add, initial_auth_type, 754 FillUserDictionary(*it, is_owner, is_signin_to_add, initial_auth_type,
675 public_session_recommended_locales, user_dict.get()); 755 public_session_recommended_locales, user_dict.get());
676 bool signed_in = (*it)->is_logged_in(); 756 user_dict->SetBoolean(kKeyCanRemove, CanRemoveUser(single_user, *it));
677
678 // Single user check here is necessary because owner info might not be
679 // available when running into login screen on first boot.
680 // See http://crosbug.com/12723
681 bool can_remove_user =
682 ((!single_user || is_enterprise_managed) && account_id.is_valid() &&
683 !is_owner && !is_public_account && !signed_in && !is_signin_to_add);
684 user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
685 users_list->Append(std::move(user_dict)); 757 users_list->Append(std::move(user_dict));
686 } 758 }
687 759
688 return users_list; 760 return users_list;
689 } 761 }
690 762
763 std::vector<ash::mojom::LoginUserInfoPtr>
764 UserSelectionScreen::UpdateAndReturnUserListForMojo() {
765 std::vector<ash::mojom::LoginUserInfoPtr> user_info_list;
766
767 const bool single_user = users_.size() == 1;
768 const AccountId owner = GetOwnerAccountId();
769 const bool is_signin_to_add = IsSigninToAdd();
770 users_to_send_ = PrepareUserListForSending(users_, owner, is_signin_to_add);
771
772 user_auth_type_map_.clear();
773
774 for (user_manager::UserList::const_iterator it = users_to_send_.begin();
775 it != users_to_send_.end(); ++it) {
776 const AccountId& account_id = (*it)->GetAccountId();
777 bool is_owner = owner == account_id;
778 const bool is_public_account =
779 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT);
780 const proximity_auth::mojom::AuthType initial_auth_type =
781 is_public_account
782 ? proximity_auth::mojom::AuthType::EXPAND_THEN_USER_CLICK
783 : (ShouldForceOnlineSignIn(*it)
784 ? proximity_auth::mojom::AuthType::ONLINE_SIGN_IN
785 : proximity_auth::mojom::AuthType::OFFLINE_PASSWORD);
786 user_auth_type_map_[account_id] = initial_auth_type;
787
788 ash::mojom::LoginUserInfoPtr login_user_info =
789 ash::mojom::LoginUserInfo::New();
790 FillUserMojoStruct(*it, is_owner, is_signin_to_add, initial_auth_type,
791 login_user_info.get());
792 login_user_info->can_remove = CanRemoveUser(single_user, *it);
793 user_info_list.push_back(std::move(login_user_info));
794 }
795
796 return user_info_list;
797 }
798
691 EasyUnlockService* UserSelectionScreen::GetEasyUnlockServiceForUser( 799 EasyUnlockService* UserSelectionScreen::GetEasyUnlockServiceForUser(
692 const AccountId& account_id) const { 800 const AccountId& account_id) const {
693 if (GetScreenType() == OTHER_SCREEN) 801 if (GetScreenType() == OTHER_SCREEN)
694 return nullptr; 802 return nullptr;
695 803
696 const user_manager::User* unlock_user = nullptr; 804 const user_manager::User* unlock_user = nullptr;
697 for (const user_manager::User* user : users_) { 805 for (const user_manager::User* user : users_) {
698 if (user->GetAccountId() == account_id) { 806 if (user->GetAccountId() == account_id) {
699 unlock_user = user; 807 unlock_user = user;
700 break; 808 break;
701 } 809 }
702 } 810 }
703 if (!unlock_user) 811 if (!unlock_user)
704 return nullptr; 812 return nullptr;
705 813
706 ProfileHelper* profile_helper = ProfileHelper::Get(); 814 ProfileHelper* profile_helper = ProfileHelper::Get();
707 Profile* profile = profile_helper->GetProfileByUser(unlock_user); 815 Profile* profile = profile_helper->GetProfileByUser(unlock_user);
708 816
709 // The user profile should exist if and only if this is the lock screen. 817 // The user profile should exist if and only if this is the lock screen.
710 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); 818 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN);
711 819
712 if (!profile) 820 if (!profile)
713 profile = profile_helper->GetSigninProfile(); 821 profile = profile_helper->GetSigninProfile();
714 822
715 return EasyUnlockService::Get(profile); 823 return EasyUnlockService::Get(profile);
716 } 824 }
717 825
718 } // namespace chromeos 826 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698