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/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
15 #include "chrome/browser/chromeos/settings/token_encryptor.h" | 15 #include "chrome/browser/chromeos/settings/token_encryptor.h" |
16 #include "chrome/browser/policy/browser_policy_connector.h" | 16 #include "chrome/browser/policy/browser_policy_connector.h" |
17 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 17 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chromeos/cryptohome/system_salt_getter.h" | 19 #include "chromeos/cryptohome/system_salt_getter.h" |
hashimoto
2013/10/25 05:17:03
nit: No need to include this?
satorux1
2013/10/25 05:23:57
Done.
hashimoto
2013/10/25 05:25:39
I see no changes here.
Is this include needed in t
satorux1
2013/10/25 05:30:37
oops. I forgot about this one. removed.
hashimoto
2013/10/25 05:31:56
Ah, you removed the one in startup_app_launcher.cc
| |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "google_apis/gaia/gaia_urls.h" | 21 #include "google_apis/gaia/gaia_urls.h" |
22 #include "google_apis/gaia/google_service_auth_error.h" | 22 #include "google_apis/gaia/google_service_auth_error.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 const char kServiceScopeGetUserInfo[] = | 25 const char kServiceScopeGetUserInfo[] = |
26 "https://www.googleapis.com/auth/userinfo.email"; | 26 "https://www.googleapis.com/auth/userinfo.email"; |
27 } | 27 } |
28 | 28 |
29 namespace chromeos { | 29 namespace chromeos { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 // static | 230 // static |
231 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) { | 231 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) { |
232 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken, | 232 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken, |
233 std::string()); | 233 std::string()); |
234 } | 234 } |
235 | 235 |
236 void DeviceOAuth2TokenService::SetAndSaveRefreshToken( | 236 void DeviceOAuth2TokenService::SetAndSaveRefreshToken( |
237 const std::string& refresh_token) { | 237 const std::string& refresh_token) { |
238 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 238 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
239 | 239 |
240 // TODO(xiyuan): Use async GetSystemSalt after merging to M31. | |
241 const std::string system_salt = SystemSaltGetter::Get()->GetSystemSaltSync(); | |
242 if (system_salt.empty()) { | |
243 const int64 kRequestSystemSaltDelayMs = 500; | |
244 content::BrowserThread::PostDelayedTask( | |
245 content::BrowserThread::UI, | |
246 FROM_HERE, | |
247 base::Bind(&DeviceOAuth2TokenService::SetAndSaveRefreshToken, | |
248 weak_ptr_factory_.GetWeakPtr(), | |
249 refresh_token), | |
250 base::TimeDelta::FromMilliseconds(kRequestSystemSaltDelayMs)); | |
251 return; | |
252 } | |
253 | |
254 std::string encrypted_refresh_token = | 240 std::string encrypted_refresh_token = |
255 token_encryptor_->EncryptWithSystemSalt(refresh_token); | 241 token_encryptor_->EncryptWithSystemSalt(refresh_token); |
256 | 242 |
257 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken, | 243 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken, |
258 encrypted_refresh_token); | 244 encrypted_refresh_token); |
259 } | 245 } |
260 | 246 |
261 std::string DeviceOAuth2TokenService::GetRefreshToken( | 247 std::string DeviceOAuth2TokenService::GetRefreshToken( |
262 const std::string& account_id) { | 248 const std::string& account_id) { |
263 DCHECK_EQ(account_id, GetRobotAccountId()); | 249 DCHECK_EQ(account_id, GetRobotAccountId()); |
264 if (refresh_token_.empty()) { | 250 if (refresh_token_.empty()) { |
265 std::string encrypted_refresh_token = | 251 std::string encrypted_refresh_token = |
266 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); | 252 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); |
267 | 253 |
268 // TODO(xiyuan): This needs a proper fix after M31. | |
269 LOG_IF(ERROR, SystemSaltGetter::Get()->GetSystemSaltSync().empty()) | |
270 << "System salt is not available for decryption"; | |
271 | |
272 refresh_token_ = token_encryptor_->DecryptWithSystemSalt( | 254 refresh_token_ = token_encryptor_->DecryptWithSystemSalt( |
273 encrypted_refresh_token); | 255 encrypted_refresh_token); |
274 } | 256 } |
275 return refresh_token_; | 257 return refresh_token_; |
276 } | 258 } |
277 | 259 |
278 std::string DeviceOAuth2TokenService::GetRobotAccountId() { | 260 std::string DeviceOAuth2TokenService::GetRobotAccountId() { |
279 policy::BrowserPolicyConnector* connector = | 261 policy::BrowserPolicyConnector* connector = |
280 g_browser_process->browser_policy_connector(); | 262 g_browser_process->browser_policy_connector(); |
281 if (connector) | 263 if (connector) |
(...skipping 12 matching lines...) Expand all Loading... | |
294 return OAuth2TokenService::CreateRequest(consumer); | 276 return OAuth2TokenService::CreateRequest(consumer); |
295 | 277 |
296 // Substitute our own consumer to wait for refresh token validation. | 278 // Substitute our own consumer to wait for refresh token validation. |
297 scoped_ptr<ValidatingConsumer> validating_consumer( | 279 scoped_ptr<ValidatingConsumer> validating_consumer( |
298 new ValidatingConsumer(this, consumer)); | 280 new ValidatingConsumer(this, consumer)); |
299 validating_consumer->StartValidation(); | 281 validating_consumer->StartValidation(); |
300 return validating_consumer.PassAs<RequestImpl>(); | 282 return validating_consumer.PassAs<RequestImpl>(); |
301 } | 283 } |
302 | 284 |
303 } // namespace chromeos | 285 } // namespace chromeos |
OLD | NEW |