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/easy_unlock/bootstrap_user_context_initi
alizer.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/bootstrap_user_context_initi
alizer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 client_info.client_id = gaia_urls->oauth2_chrome_client_id(); | 61 client_info.client_id = gaia_urls->oauth2_chrome_client_id(); |
62 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret(); | 62 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret(); |
63 | 63 |
64 token_fetcher_.reset( | 64 token_fetcher_.reset( |
65 new gaia::GaiaOAuthClient(g_browser_process->system_request_context())); | 65 new gaia::GaiaOAuthClient(g_browser_process->system_request_context())); |
66 token_fetcher_->GetTokensFromAuthCode(client_info, auth_code, kMaxGaiaRetries, | 66 token_fetcher_->GetTokensFromAuthCode(client_info, auth_code, kMaxGaiaRetries, |
67 this); | 67 this); |
68 } | 68 } |
69 | 69 |
70 void BootstrapUserContextInitializer::StartCheckExistingKeys() { | 70 void BootstrapUserContextInitializer::StartCheckExistingKeys() { |
71 const std::string& user_id = user_context_.GetUserID(); | |
72 | |
73 // Use random key for the first time user. | 71 // Use random key for the first time user. |
74 if (!user_manager::UserManager::Get()->IsKnownUser(user_id)) { | 72 if (!user_manager::UserManager::Get()->IsKnownUser( |
| 73 user_context_.GetAccountId())) { |
75 CreateRandomKey(); | 74 CreateRandomKey(); |
76 return; | 75 return; |
77 } | 76 } |
78 | 77 |
79 EasyUnlockKeyManager* key_manager = | 78 EasyUnlockKeyManager* key_manager = |
80 UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); | 79 UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); |
81 key_manager->GetDeviceDataList( | 80 key_manager->GetDeviceDataList( |
82 UserContext(user_id), | 81 UserContext(user_context_.GetAccountId()), |
83 base::Bind(&BootstrapUserContextInitializer::OnGetEasyUnlockData, | 82 base::Bind(&BootstrapUserContextInitializer::OnGetEasyUnlockData, |
84 weak_ptr_factory_.GetWeakPtr())); | 83 weak_ptr_factory_.GetWeakPtr())); |
85 } | 84 } |
86 | 85 |
87 void BootstrapUserContextInitializer::OnGetEasyUnlockData( | 86 void BootstrapUserContextInitializer::OnGetEasyUnlockData( |
88 bool success, | 87 bool success, |
89 const EasyUnlockDeviceKeyDataList& data_list) { | 88 const EasyUnlockDeviceKeyDataList& data_list) { |
90 // Existing user must have Smart lock keys to use bootstrap flow. | 89 // Existing user must have Smart lock keys to use bootstrap flow. |
91 if (!success || data_list.empty()) { | 90 if (!success || data_list.empty()) { |
92 LOG(ERROR) << "Unable to get Easy unlock key data."; | 91 LOG(ERROR) << "Unable to get Easy unlock key data."; |
93 Notify(false); | 92 Notify(false); |
94 return; | 93 return; |
95 } | 94 } |
96 | 95 |
97 EasyUnlockService* service = | 96 EasyUnlockService* service = |
98 EasyUnlockService::Get(ProfileHelper::GetSigninProfile()); | 97 EasyUnlockService::Get(ProfileHelper::GetSigninProfile()); |
99 service->AddObserver(this); | 98 service->AddObserver(this); |
100 | 99 |
101 static_cast<EasyUnlockServiceSignin*>(service) | 100 static_cast<EasyUnlockServiceSignin*>(service) |
102 ->SetCurrentUser(user_context_.GetUserID()); | 101 ->SetCurrentUser(user_context_.GetAccountId().GetUserEmail()); |
103 OnScreenlockStateChanged(service->GetScreenlockState()); | 102 OnScreenlockStateChanged(service->GetScreenlockState()); |
104 } | 103 } |
105 | 104 |
106 void BootstrapUserContextInitializer::OnEasyUnlockAuthenticated( | 105 void BootstrapUserContextInitializer::OnEasyUnlockAuthenticated( |
107 EasyUnlockAuthAttempt::Type auth_attempt_type, | 106 EasyUnlockAuthAttempt::Type auth_attempt_type, |
108 bool success, | 107 bool success, |
109 const std::string& user_id, | 108 const std::string& user_id, |
110 const std::string& key_secret, | 109 const std::string& key_secret, |
111 const std::string& key_label) { | 110 const std::string& key_label) { |
112 DCHECK_EQ(EasyUnlockAuthAttempt::TYPE_SIGNIN, auth_attempt_type); | 111 DCHECK_EQ(EasyUnlockAuthAttempt::TYPE_SIGNIN, auth_attempt_type); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // TODO(xiyuan): Add timeout and hook up with error UI after | 195 // TODO(xiyuan): Add timeout and hook up with error UI after |
197 // http://crbug.com/471067. | 196 // http://crbug.com/471067. |
198 if (state != proximity_auth::ScreenlockState::AUTHENTICATED) | 197 if (state != proximity_auth::ScreenlockState::AUTHENTICATED) |
199 return; | 198 return; |
200 | 199 |
201 EasyUnlockService* service = | 200 EasyUnlockService* service = |
202 EasyUnlockService::Get(ProfileHelper::GetSigninProfile()); | 201 EasyUnlockService::Get(ProfileHelper::GetSigninProfile()); |
203 service->RemoveObserver(this); | 202 service->RemoveObserver(this); |
204 | 203 |
205 service->AttemptAuth( | 204 service->AttemptAuth( |
206 user_context_.GetUserID(), | 205 user_context_.GetAccountId().GetUserEmail(), |
207 base::Bind(&BootstrapUserContextInitializer::OnEasyUnlockAuthenticated, | 206 base::Bind(&BootstrapUserContextInitializer::OnEasyUnlockAuthenticated, |
208 weak_ptr_factory_.GetWeakPtr())); | 207 weak_ptr_factory_.GetWeakPtr())); |
209 } | 208 } |
210 | 209 |
211 } // namespace chromeos | 210 } // namespace chromeos |
OLD | NEW |