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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
| 11 #include "base/bind.h" |
| 12 #include "base/callback.h" |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
14 #include "base/values.h" | 16 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/browser_process_platform_part.h" | 18 #include "chrome/browser/browser_process_platform_part.h" |
17 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 19 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
18 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" | 20 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" |
19 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" | 21 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" |
20 #include "chrome/browser/chromeos/login/reauth_stats.h" | 22 #include "chrome/browser/chromeos/login/reauth_stats.h" |
21 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 23 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
22 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" | 24 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" |
23 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 25 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
24 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 26 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
25 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 27 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
26 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
27 #include "chrome/browser/signin/easy_unlock_service.h" | 29 #include "chrome/browser/signin/easy_unlock_service.h" |
28 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" | 30 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
29 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 31 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 32 #include "chrome/grit/generated_resources.h" |
| 33 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 34 #include "chromeos/dbus/cryptohome_client.h" |
| 35 #include "chromeos/dbus/dbus_method_call_status.h" |
| 36 #include "chromeos/dbus/dbus_thread_manager.h" |
30 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
31 #include "components/proximity_auth/screenlock_bridge.h" | 38 #include "components/proximity_auth/screenlock_bridge.h" |
32 #include "components/signin/core/account_id/account_id.h" | 39 #include "components/signin/core/account_id/account_id.h" |
33 #include "components/user_manager/known_user.h" | 40 #include "components/user_manager/known_user.h" |
34 #include "components/user_manager/user_manager.h" | 41 #include "components/user_manager/user_manager.h" |
35 #include "components/user_manager/user_type.h" | 42 #include "components/user_manager/user_type.h" |
| 43 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/user_activity/user_activity_detector.h" | 44 #include "ui/base/user_activity/user_activity_detector.h" |
37 | 45 |
38 namespace chromeos { | 46 namespace chromeos { |
39 | 47 |
40 namespace { | 48 namespace { |
41 | 49 |
42 // User dictionary keys. | 50 // User dictionary keys. |
43 const char kKeyUsername[] = "username"; | 51 const char kKeyUsername[] = "username"; |
44 const char kKeyGaiaID[] = "gaiaId"; | 52 const char kKeyGaiaID[] = "gaiaId"; |
45 const char kKeyDisplayName[] = "displayName"; | 53 const char kKeyDisplayName[] = "displayName"; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 quick_unlock::QuickUnlockStorage* quick_unlock_storage = | 148 quick_unlock::QuickUnlockStorage* quick_unlock_storage = |
141 quick_unlock::QuickUnlockFactory::GetForUser(user); | 149 quick_unlock::QuickUnlockFactory::GetForUser(user); |
142 if (!quick_unlock_storage) | 150 if (!quick_unlock_storage) |
143 return false; | 151 return false; |
144 | 152 |
145 return quick_unlock_storage->IsFingerprintAuthenticationAvailable(); | 153 return quick_unlock_storage->IsFingerprintAuthenticationAvailable(); |
146 } | 154 } |
147 | 155 |
148 } // namespace | 156 } // namespace |
149 | 157 |
| 158 // Helper class to call cryptohome to check whether a user needs dircrypto |
| 159 // migration. The check results are cached to limit calls to cryptohome. |
| 160 class UserSelectionScreen::DircryptoMigrationChecker { |
| 161 public: |
| 162 explicit DircryptoMigrationChecker(UserSelectionScreen* owner) |
| 163 : owner_(owner), weak_ptr_factory_(this) {} |
| 164 ~DircryptoMigrationChecker() = default; |
| 165 |
| 166 // Start to check whether the given user needs dircrypto migration. |
| 167 void Check(const AccountId& account_id) { |
| 168 focused_user_ = account_id; |
| 169 |
| 170 auto it = needs_dircrypto_migration_cache_.find(account_id); |
| 171 if (it != needs_dircrypto_migration_cache_.end()) { |
| 172 UpdateUI(account_id, it->second); |
| 173 return; |
| 174 } |
| 175 |
| 176 DBusThreadManager::Get() |
| 177 ->GetCryptohomeClient() |
| 178 ->WaitForServiceToBeAvailable( |
| 179 base::Bind(&DircryptoMigrationChecker::RunCryptohomeCheck, |
| 180 weak_ptr_factory_.GetWeakPtr(), account_id)); |
| 181 } |
| 182 |
| 183 private: |
| 184 // WaitForServiceToBeAvailable callback to invoke NeedsDircryptoMigration when |
| 185 // cryptohome service is available. |
| 186 void RunCryptohomeCheck(const AccountId& account_id, bool service_is_ready) { |
| 187 if (!service_is_ready) { |
| 188 LOG(ERROR) << "Cryptohome is not available."; |
| 189 return; |
| 190 } |
| 191 |
| 192 const cryptohome::Identification cryptohome_id(account_id); |
| 193 DBusThreadManager::Get()->GetCryptohomeClient()->NeedsDircryptoMigration( |
| 194 cryptohome_id, |
| 195 base::Bind(&DircryptoMigrationChecker:: |
| 196 OnCryptohomeNeedsDircryptoMigrationCallback, |
| 197 weak_ptr_factory_.GetWeakPtr(), account_id)); |
| 198 } |
| 199 |
| 200 // Callback invoked when NeedsDircryptoMigration call is finished. |
| 201 void OnCryptohomeNeedsDircryptoMigrationCallback( |
| 202 const AccountId& account_id, |
| 203 DBusMethodCallStatus call_status, |
| 204 bool needs_migration) { |
| 205 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
| 206 LOG(ERROR) << "Failed to call cryptohome NeedsDircryptoMigration."; |
| 207 return; |
| 208 } |
| 209 |
| 210 needs_dircrypto_migration_cache_[account_id] = needs_migration; |
| 211 UpdateUI(account_id, needs_migration); |
| 212 } |
| 213 |
| 214 // Update UI for the given user when the check result is available. |
| 215 void UpdateUI(const AccountId& account_id, bool needs_migration) { |
| 216 // Bail if the user is not the currently focused. |
| 217 if (account_id != focused_user_) |
| 218 return; |
| 219 |
| 220 owner_->ShowBannerMessage( |
| 221 needs_migration ? l10n_util::GetStringUTF16( |
| 222 IDS_LOGIN_NEEDS_DIRCRYPTO_MIGRATION_BANNER) |
| 223 : base::string16()); |
| 224 } |
| 225 |
| 226 UserSelectionScreen* const owner_; |
| 227 AccountId focused_user_ = EmptyAccountId(); |
| 228 |
| 229 // Cached result of NeedsDircryptoMigration cryptohome check. Key is the |
| 230 // account id of users. True value means the user needs dircrypto migration |
| 231 // and false means dircrypto migration is done. |
| 232 std::map<AccountId, bool> needs_dircrypto_migration_cache_; |
| 233 |
| 234 base::WeakPtrFactory<DircryptoMigrationChecker> weak_ptr_factory_; |
| 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(DircryptoMigrationChecker); |
| 237 }; |
| 238 |
150 UserSelectionScreen::UserSelectionScreen(const std::string& display_type) | 239 UserSelectionScreen::UserSelectionScreen(const std::string& display_type) |
151 : BaseScreen(nullptr, OobeScreen::SCREEN_USER_SELECTION), | 240 : BaseScreen(nullptr, OobeScreen::SCREEN_USER_SELECTION), |
152 display_type_(display_type), | 241 display_type_(display_type), |
153 weak_factory_(this) {} | 242 weak_factory_(this) {} |
154 | 243 |
155 UserSelectionScreen::~UserSelectionScreen() { | 244 UserSelectionScreen::~UserSelectionScreen() { |
156 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); | 245 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); |
157 ui::UserActivityDetector* activity_detector = ui::UserActivityDetector::Get(); | 246 ui::UserActivityDetector* activity_detector = ui::UserActivityDetector::Get(); |
158 if (activity_detector && activity_detector->HasObserver(this)) | 247 if (activity_detector && activity_detector->HasObserver(this)) |
159 activity_detector->RemoveObserver(this); | 248 activity_detector->RemoveObserver(this); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 544 |
456 if (!token_handle_util_.get()) { | 545 if (!token_handle_util_.get()) { |
457 token_handle_util_.reset(new TokenHandleUtil()); | 546 token_handle_util_.reset(new TokenHandleUtil()); |
458 } | 547 } |
459 | 548 |
460 if (token_handle_util_->HasToken(account_id)) { | 549 if (token_handle_util_->HasToken(account_id)) { |
461 token_handle_util_->CheckToken( | 550 token_handle_util_->CheckToken( |
462 account_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, | 551 account_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, |
463 weak_factory_.GetWeakPtr())); | 552 weak_factory_.GetWeakPtr())); |
464 } | 553 } |
| 554 |
| 555 // Run dircrypto migration check only on the login screen. |
| 556 if (display_type_ == OobeUI::kLoginDisplay) { |
| 557 if (!dircrypto_migration_checker_) { |
| 558 dircrypto_migration_checker_ = |
| 559 base::MakeUnique<DircryptoMigrationChecker>(this); |
| 560 } |
| 561 dircrypto_migration_checker_->Check(account_id); |
| 562 } |
465 } | 563 } |
466 | 564 |
467 void UserSelectionScreen::OnUserStatusChecked( | 565 void UserSelectionScreen::OnUserStatusChecked( |
468 const AccountId& account_id, | 566 const AccountId& account_id, |
469 TokenHandleUtil::TokenHandleStatus status) { | 567 TokenHandleUtil::TokenHandleStatus status) { |
470 if (status == TokenHandleUtil::INVALID) { | 568 if (status == TokenHandleUtil::INVALID) { |
471 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE); | 569 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE); |
472 token_handle_util_->MarkHandleInvalid(account_id); | 570 token_handle_util_->MarkHandleInvalid(account_id); |
473 SetAuthType(account_id, ONLINE_SIGN_IN, base::string16()); | 571 SetAuthType(account_id, ONLINE_SIGN_IN, base::string16()); |
474 } | 572 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // The user profile should exist if and only if this is the lock screen. | 695 // The user profile should exist if and only if this is the lock screen. |
598 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); | 696 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); |
599 | 697 |
600 if (!profile) | 698 if (!profile) |
601 profile = profile_helper->GetSigninProfile(); | 699 profile = profile_helper->GetSigninProfile(); |
602 | 700 |
603 return EasyUnlockService::Get(profile); | 701 return EasyUnlockService::Get(profile); |
604 } | 702 } |
605 | 703 |
606 } // namespace chromeos | 704 } // namespace chromeos |
OLD | NEW |