1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/easy_unlock/bootstrap_user_flow.h"
8 #include "base/sys_info.h"
9 #include "chrome/browser/chromeos/login/easy_unlock/bootstrap_manager.h"
10 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
11 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
12 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
13 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/signin/easy_unlock_service.h"
15 #include "chrome/browser/signin/easy_unlock_service_regular.h"
16 #include "components/proximity_auth/screenlock_bridge.h"
20 BootstrapUserFlow::BootstrapUserFlow(const UserContext
& user_context
,
22 : ExtendedUserFlow(user_context
.GetUserID()),
23 user_context_(user_context
),
24 is_new_account_(is_new_account
),
26 user_profile_(nullptr),
27 weak_ptr_factory_(this) {
28 ChromeUserManager::Get()->GetBootstrapManager()->AddPendingBootstrap(
29 user_context_
.GetUserID());
32 BootstrapUserFlow::~BootstrapUserFlow() {
35 void BootstrapUserFlow::StartAutoPairing() {
36 DCHECK(user_profile_
);
38 VLOG(2) << "BootstrapUserFlow StartAutoPairing";
40 EasyUnlockService
* service
= EasyUnlockService::Get(user_profile_
);
41 if (!service
->IsAllowed()) {
42 // TODO(xiyuan): Show error UI.
43 LOG(ERROR
) << "Bootstrapped failed because EasyUnlock service not allowed.";
44 chrome::AttemptUserExit();
48 service
->StartAutoPairing(base::Bind(&BootstrapUserFlow::SetAutoPairingResult
,
49 weak_ptr_factory_
.GetWeakPtr()));
52 void BootstrapUserFlow::SetAutoPairingResult(bool success
,
53 const std::string
& error_message
) {
54 VLOG(2) << "BootstrapUserFlow::SetAutoPairingResult"
55 << ", success=" << success
;
58 // TODO(xiyuan): Show error UI.
59 LOG(ERROR
) << "Easy bootstrap auto pairing failed, err=" << error_message
;
60 chrome::AttemptUserExit();
64 // TODO(xiyuan): Remove this and properly mock EasyUnlockKeyManager.
65 if (!base::SysInfo::IsRunningOnChromeOS()) {
70 chromeos::UserSessionManager::GetInstance()
71 ->GetEasyUnlockKeyManager()
74 *EasyUnlockService::Get(user_profile_
)->GetRemoteDevices(),
75 base::Bind(&BootstrapUserFlow::OnKeysRefreshed
,
76 weak_ptr_factory_
.GetWeakPtr()));
79 void BootstrapUserFlow::OnKeysRefreshed(bool success
) {
81 // TODO(xiyuan): Show error UI.
82 LOG(ERROR
) << "Easy bootstrap failed to refresh cryptohome keys.";
83 chrome::AttemptUserExit();
87 EasyUnlockService::Get(user_profile_
)
88 ->SetHardlockState(EasyUnlockScreenlockStateHandler::NO_HARDLOCK
);
89 RemoveBootstrapRandomKey();
92 void BootstrapUserFlow::RemoveBootstrapRandomKey() {
93 scoped_refptr
<ExtendedAuthenticator
> authenticator(
94 ExtendedAuthenticator::Create(this));
96 const char kLegacyKeyLabel
[] = "legacy-0";
97 authenticator
->RemoveKey(
100 base::Bind(&BootstrapUserFlow::OnBootstrapRandomKeyRemoved
,
101 weak_ptr_factory_
.GetWeakPtr()));
104 void BootstrapUserFlow::OnBootstrapRandomKeyRemoved() {
108 void BootstrapUserFlow::Finish() {
109 VLOG(2) << "BootstrapUserFlow::Finish";
112 ChromeUserManager::Get()->GetBootstrapManager()->FinishPendingBootstrap(
113 user_context_
.GetUserID());
114 UserSessionManager::GetInstance()->DoBrowserLaunch(user_profile_
, host());
116 user_profile_
= nullptr;
117 UnregisterFlowSoon();
120 bool BootstrapUserFlow::CanLockScreen() {
124 bool BootstrapUserFlow::ShouldLaunchBrowser() {
128 bool BootstrapUserFlow::ShouldSkipPostLoginScreens() {
132 bool BootstrapUserFlow::HandleLoginFailure(
133 const chromeos::AuthFailure
& failure
) {
138 void BootstrapUserFlow::HandleLoginSuccess(
139 const chromeos::UserContext
& context
) {
142 bool BootstrapUserFlow::HandlePasswordChangeDetected() {
147 void BootstrapUserFlow::HandleOAuthTokenStatusChange(
148 user_manager::User::OAuthTokenStatus status
) {
149 if (status
== user_manager::User::OAUTH2_TOKEN_STATUS_INVALID
) {
150 // TODO(xiyuan): Show error UI.
151 LOG(ERROR
) << "Bootstrapped failed because of bad refresh token.";
152 chrome::AttemptUserExit();
157 void BootstrapUserFlow::LaunchExtraSteps(Profile
* user_profile
) {
158 user_profile_
= user_profile
;
160 // Auto pairing only when a random key is used to boostrap cryptohome.
161 if (is_new_account_
) {
169 bool BootstrapUserFlow::SupportsEarlyRestartToApplyFlags() {
173 void BootstrapUserFlow::OnAuthenticationFailure(
174 ExtendedAuthenticator::AuthState state
) {
175 // TODO(xiyuan): Show error UI.
176 LOG(ERROR
) << "Bootstrapped failed because authenticator falure"
177 << ", state=" << state
;
178 chrome::AttemptUserExit();
181 } // namespace chromeos