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 whether a user needs dircrypto migration. | |
achuithb
2017/04/11 22:04:26
to check whether
xiyuan
2017/04/11 23:07:42
Done.
| |
159 // 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 if (needs_migration) { | |
achuithb
2017/04/11 22:04:27
ternary operator is worth considering here, but it
xiyuan
2017/04/11 23:07:42
Done.
| |
221 owner_->ShowBannerMessage(l10n_util::GetStringUTF16( | |
222 IDS_LOGIN_NEEDS_DIRCRYPTO_MIGRATION_BANNER)); | |
223 } else { | |
224 owner_->ShowBannerMessage(base::string16()); | |
achuithb
2017/04/11 22:04:26
So the only banner message about dircrypto migrati
xiyuan
2017/04/11 23:07:42
IIUC, it is only used for user adding screen now (
| |
225 } | |
226 } | |
227 | |
228 UserSelectionScreen* const owner_; | |
229 AccountId focused_user_ = EmptyAccountId(); | |
230 | |
231 // Cached result of NeedsDircryptoMigration cryptohome check. Key is the | |
232 // account id of users. True value means the user needs dircrypto migration | |
233 // and false means dircrypto migration is done. | |
234 std::map<AccountId, bool> needs_dircrypto_migration_cache_; | |
235 | |
236 base::WeakPtrFactory<DircryptoMigrationChecker> weak_ptr_factory_; | |
237 | |
238 DISALLOW_COPY_AND_ASSIGN(DircryptoMigrationChecker); | |
239 }; | |
240 | |
150 UserSelectionScreen::UserSelectionScreen(const std::string& display_type) | 241 UserSelectionScreen::UserSelectionScreen(const std::string& display_type) |
151 : BaseScreen(nullptr, OobeScreen::SCREEN_USER_SELECTION), | 242 : BaseScreen(nullptr, OobeScreen::SCREEN_USER_SELECTION), |
152 display_type_(display_type), | 243 display_type_(display_type), |
153 weak_factory_(this) {} | 244 weak_factory_(this) {} |
154 | 245 |
155 UserSelectionScreen::~UserSelectionScreen() { | 246 UserSelectionScreen::~UserSelectionScreen() { |
156 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); | 247 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); |
157 ui::UserActivityDetector* activity_detector = ui::UserActivityDetector::Get(); | 248 ui::UserActivityDetector* activity_detector = ui::UserActivityDetector::Get(); |
158 if (activity_detector && activity_detector->HasObserver(this)) | 249 if (activity_detector && activity_detector->HasObserver(this)) |
159 activity_detector->RemoveObserver(this); | 250 activity_detector->RemoveObserver(this); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 | 546 |
456 if (!token_handle_util_.get()) { | 547 if (!token_handle_util_.get()) { |
457 token_handle_util_.reset(new TokenHandleUtil()); | 548 token_handle_util_.reset(new TokenHandleUtil()); |
458 } | 549 } |
459 | 550 |
460 if (token_handle_util_->HasToken(account_id)) { | 551 if (token_handle_util_->HasToken(account_id)) { |
461 token_handle_util_->CheckToken( | 552 token_handle_util_->CheckToken( |
462 account_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, | 553 account_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, |
463 weak_factory_.GetWeakPtr())); | 554 weak_factory_.GetWeakPtr())); |
464 } | 555 } |
556 | |
557 // Run dircrypto migration check only on the login screen. | |
558 if (display_type_ == OobeUI::kLoginDisplay) { | |
559 if (!dircrypto_migration_checker_) { | |
560 dircrypto_migration_checker_ = | |
561 base::MakeUnique<DircryptoMigrationChecker>(this); | |
562 } | |
563 dircrypto_migration_checker_->Check(account_id); | |
564 } | |
465 } | 565 } |
466 | 566 |
467 void UserSelectionScreen::OnUserStatusChecked( | 567 void UserSelectionScreen::OnUserStatusChecked( |
468 const AccountId& account_id, | 568 const AccountId& account_id, |
469 TokenHandleUtil::TokenHandleStatus status) { | 569 TokenHandleUtil::TokenHandleStatus status) { |
470 if (status == TokenHandleUtil::INVALID) { | 570 if (status == TokenHandleUtil::INVALID) { |
471 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE); | 571 RecordReauthReason(account_id, ReauthReason::INVALID_TOKEN_HANDLE); |
472 token_handle_util_->MarkHandleInvalid(account_id); | 572 token_handle_util_->MarkHandleInvalid(account_id); |
473 SetAuthType(account_id, ONLINE_SIGN_IN, base::string16()); | 573 SetAuthType(account_id, ONLINE_SIGN_IN, base::string16()); |
474 } | 574 } |
(...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. | 697 // The user profile should exist if and only if this is the lock screen. |
598 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); | 698 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); |
599 | 699 |
600 if (!profile) | 700 if (!profile) |
601 profile = profile_helper->GetSigninProfile(); | 701 profile = profile_helper->GetSigninProfile(); |
602 | 702 |
603 return EasyUnlockService::Get(profile); | 703 return EasyUnlockService::Get(profile); |
604 } | 704 } |
605 | 705 |
606 } // namespace chromeos | 706 } // namespace chromeos |
OLD | NEW |