| 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(); | 71 const user_manager::UserID& user_id = user_context_.GetUserID(); |
| 72 | 72 |
| 73 // Use random key for the first time user. | 73 // Use random key for the first time user. |
| 74 if (!user_manager::UserManager::Get()->IsKnownUser(user_id)) { | 74 if (!user_manager::UserManager::Get()->IsKnownUser(user_id)) { |
| 75 CreateRandomKey(); | 75 CreateRandomKey(); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 EasyUnlockKeyManager* key_manager = | 79 EasyUnlockKeyManager* key_manager = |
| 80 UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); | 80 UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); |
| 81 key_manager->GetDeviceDataList( | 81 key_manager->GetDeviceDataList( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 service->AddObserver(this); | 99 service->AddObserver(this); |
| 100 | 100 |
| 101 static_cast<EasyUnlockServiceSignin*>(service) | 101 static_cast<EasyUnlockServiceSignin*>(service) |
| 102 ->SetCurrentUser(user_context_.GetUserID()); | 102 ->SetCurrentUser(user_context_.GetUserID()); |
| 103 OnScreenlockStateChanged(service->GetScreenlockState()); | 103 OnScreenlockStateChanged(service->GetScreenlockState()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void BootstrapUserContextInitializer::OnEasyUnlockAuthenticated( | 106 void BootstrapUserContextInitializer::OnEasyUnlockAuthenticated( |
| 107 EasyUnlockAuthAttempt::Type auth_attempt_type, | 107 EasyUnlockAuthAttempt::Type auth_attempt_type, |
| 108 bool success, | 108 bool success, |
| 109 const std::string& user_id, | 109 const user_manager::UserID& user_id, |
| 110 const std::string& key_secret, | 110 const std::string& key_secret, |
| 111 const std::string& key_label) { | 111 const std::string& key_label) { |
| 112 DCHECK_EQ(EasyUnlockAuthAttempt::TYPE_SIGNIN, auth_attempt_type); | 112 DCHECK_EQ(EasyUnlockAuthAttempt::TYPE_SIGNIN, auth_attempt_type); |
| 113 if (!success || key_secret.empty()) { | 113 if (!success || key_secret.empty()) { |
| 114 LOG(ERROR) << "Failed to sign-in using existing Smart lock key."; | 114 LOG(ERROR) << "Failed to sign-in using existing Smart lock key."; |
| 115 Notify(false); | 115 Notify(false); |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 | 118 |
| 119 user_context_.SetKey(Key(key_secret)); | 119 user_context_.SetKey(Key(key_secret)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 scoped_ptr<base::DictionaryValue> user_info) { | 169 scoped_ptr<base::DictionaryValue> user_info) { |
| 170 std::string email; | 170 std::string email; |
| 171 std::string gaia_id; | 171 std::string gaia_id; |
| 172 if (!user_info->GetString("email", &email) || | 172 if (!user_info->GetString("email", &email) || |
| 173 !user_info->GetString("id", &gaia_id)) { | 173 !user_info->GetString("id", &gaia_id)) { |
| 174 LOG(ERROR) << "Bad user info."; | 174 LOG(ERROR) << "Bad user info."; |
| 175 Notify(false); | 175 Notify(false); |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 | 178 |
| 179 user_context_.SetUserID(email); | 179 const user_manager::UserID user_id(gaia_id, email); |
| 180 user_context_.SetGaiaID(gaia_id); | 180 |
| 181 user_context_.SetUserID(user_id); |
| 181 StartCheckExistingKeys(); | 182 StartCheckExistingKeys(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void BootstrapUserContextInitializer::OnOAuthError() { | 185 void BootstrapUserContextInitializer::OnOAuthError() { |
| 185 LOG(ERROR) << "Auth error."; | 186 LOG(ERROR) << "Auth error."; |
| 186 Notify(false); | 187 Notify(false); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void BootstrapUserContextInitializer::OnNetworkError(int response_code) { | 190 void BootstrapUserContextInitializer::OnNetworkError(int response_code) { |
| 190 LOG(ERROR) << "Network error."; | 191 LOG(ERROR) << "Network error."; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 202 EasyUnlockService::Get(ProfileHelper::GetSigninProfile()); | 203 EasyUnlockService::Get(ProfileHelper::GetSigninProfile()); |
| 203 service->RemoveObserver(this); | 204 service->RemoveObserver(this); |
| 204 | 205 |
| 205 service->AttemptAuth( | 206 service->AttemptAuth( |
| 206 user_context_.GetUserID(), | 207 user_context_.GetUserID(), |
| 207 base::Bind(&BootstrapUserContextInitializer::OnEasyUnlockAuthenticated, | 208 base::Bind(&BootstrapUserContextInitializer::OnEasyUnlockAuthenticated, |
| 208 weak_ptr_factory_.GetWeakPtr())); | 209 weak_ptr_factory_.GetWeakPtr())); |
| 209 } | 210 } |
| 210 | 211 |
| 211 } // namespace chromeos | 212 } // namespace chromeos |
| OLD | NEW |