OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/settings/device_oauth2_token_service.h" | 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // If the token has been set meanwhile, write it to |local_state_|. | 228 // If the token has been set meanwhile, write it to |local_state_|. |
229 if (!refresh_token_.empty()) { | 229 if (!refresh_token_.empty()) { |
230 EncryptAndSaveToken(); | 230 EncryptAndSaveToken(); |
231 FireRefreshTokensLoaded(); | 231 FireRefreshTokensLoaded(); |
232 return; | 232 return; |
233 } | 233 } |
234 | 234 |
235 // Otherwise, load the refresh token from |local_state_|. | 235 // Otherwise, load the refresh token from |local_state_|. |
236 std::string encrypted_refresh_token = | 236 std::string encrypted_refresh_token = |
237 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); | 237 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); |
238 CryptohomeTokenEncryptor encryptor(system_salt_); | 238 if (!encrypted_refresh_token.empty()) { |
239 refresh_token_ = encryptor.DecryptWithSystemSalt(encrypted_refresh_token); | 239 CryptohomeTokenEncryptor encryptor(system_salt_); |
240 if (!encrypted_refresh_token.empty() && refresh_token_.empty()) { | 240 refresh_token_ = encryptor.DecryptWithSystemSalt(encrypted_refresh_token); |
241 LOG(ERROR) << "Failed to decrypt refresh token."; | 241 if (refresh_token_.empty()) { |
242 state_ = STATE_NO_TOKEN; | 242 LOG(ERROR) << "Failed to decrypt refresh token."; |
243 FireRefreshTokensLoaded(); | 243 state_ = STATE_NO_TOKEN; |
244 return; | 244 FireRefreshTokensLoaded(); |
| 245 return; |
| 246 } |
245 } | 247 } |
246 | 248 |
247 state_ = STATE_VALIDATION_PENDING; | 249 state_ = STATE_VALIDATION_PENDING; |
248 | 250 |
249 // If there are pending requests, start a validation. | 251 // If there are pending requests, start a validation. |
250 if (!pending_requests_.empty()) | 252 if (!pending_requests_.empty()) |
251 StartValidation(); | 253 StartValidation(); |
252 | 254 |
253 // Announce the token. | 255 // Announce the token. |
254 FireRefreshTokenAvailable(GetRobotAccountId()); | 256 FireRefreshTokenAvailable(GetRobotAccountId()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 GoogleServiceAuthError auth_error(error); | 380 GoogleServiceAuthError auth_error(error); |
379 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 381 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
380 &RequestImpl::InformConsumer, | 382 &RequestImpl::InformConsumer, |
381 request->AsWeakPtr(), | 383 request->AsWeakPtr(), |
382 auth_error, | 384 auth_error, |
383 std::string(), | 385 std::string(), |
384 base::Time())); | 386 base::Time())); |
385 } | 387 } |
386 | 388 |
387 } // namespace chromeos | 389 } // namespace chromeos |
OLD | NEW |