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 "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/chromeos/cros/cert_library.h" | |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | |
12 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "chromeos/cryptohome/cryptohome_library.h" |
13 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
14 | 12 |
15 namespace chromeos { | 13 namespace chromeos { |
16 | 14 |
17 DeviceOAuth2TokenService::DeviceOAuth2TokenService( | 15 DeviceOAuth2TokenService::DeviceOAuth2TokenService( |
18 net::URLRequestContextGetter* getter, | 16 net::URLRequestContextGetter* getter, |
19 PrefService* local_state) | 17 PrefService* local_state) |
20 : OAuth2TokenService(getter), | 18 : OAuth2TokenService(getter), |
21 local_state_(local_state) { | 19 local_state_(local_state) { |
22 } | 20 } |
23 | 21 |
24 DeviceOAuth2TokenService::~DeviceOAuth2TokenService() { | 22 DeviceOAuth2TokenService::~DeviceOAuth2TokenService() { |
25 } | 23 } |
26 | 24 |
27 // static | 25 // static |
28 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) { | 26 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) { |
29 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken, | 27 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken, |
30 std::string()); | 28 std::string()); |
31 } | 29 } |
32 | 30 |
33 void DeviceOAuth2TokenService::SetAndSaveRefreshToken( | 31 void DeviceOAuth2TokenService::SetAndSaveRefreshToken( |
34 const std::string& refresh_token) { | 32 const std::string& refresh_token) { |
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 33 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
36 std::string encrypted_refresh_token = | 34 std::string encrypted_refresh_token = |
37 CrosLibrary::Get()->GetCertLibrary()->EncryptWithSystemSalt( | 35 CryptohomeLibrary::Get()->EncryptWithSystemSalt(refresh_token); |
38 refresh_token); | |
39 | 36 |
40 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken, | 37 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken, |
41 encrypted_refresh_token); | 38 encrypted_refresh_token); |
42 } | 39 } |
43 | 40 |
44 std::string DeviceOAuth2TokenService::GetRefreshToken() { | 41 std::string DeviceOAuth2TokenService::GetRefreshToken() { |
45 if (refresh_token_.empty()) { | 42 if (refresh_token_.empty()) { |
46 std::string encrypted_refresh_token = | 43 std::string encrypted_refresh_token = |
47 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); | 44 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken); |
48 | 45 |
49 refresh_token_ = | 46 refresh_token_ = CryptohomeLibrary::Get()->DecryptWithSystemSalt( |
50 CrosLibrary::Get()->GetCertLibrary()->DecryptWithSystemSalt( | 47 encrypted_refresh_token); |
51 encrypted_refresh_token); | |
52 } | 48 } |
53 return refresh_token_; | 49 return refresh_token_; |
54 } | 50 } |
55 | 51 |
56 } // namespace chromeos | 52 } // namespace chromeos |
OLD | NEW |