Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/browser/chromeos/settings/device_oauth2_token_service.cc

Issue 12647008: Refactor OAuth2TokenService to have profile- and device-based implementations. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase again Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
6
7 #include "base/prefs/pref_registry_simple.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"
13 #include "content/public/browser/browser_thread.h"
14
15 namespace chromeos {
16
17 DeviceOAuth2TokenService::DeviceOAuth2TokenService(
18 net::URLRequestContextGetter* getter,
19 PrefService* local_state)
20 : OAuth2TokenService(getter),
21 local_state_(local_state) {
22 }
23
24 DeviceOAuth2TokenService::~DeviceOAuth2TokenService() {
25 }
26
27 // static
28 void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) {
29 registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken,
30 std::string());
31 }
32
33 void DeviceOAuth2TokenService::SetAndSaveRefreshToken(
34 const std::string& refresh_token) {
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
36 std::string encrypted_refresh_token =
37 CrosLibrary::Get()->GetCertLibrary()->EncryptWithSystemSalt(
38 refresh_token);
39
40 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken,
41 encrypted_refresh_token);
42 }
43
44 std::string DeviceOAuth2TokenService::GetRefreshToken() {
45 if (refresh_token_.empty()) {
46 std::string encrypted_refresh_token =
47 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken);
48
49 refresh_token_ =
50 CrosLibrary::Get()->GetCertLibrary()->DecryptWithSystemSalt(
51 encrypted_refresh_token);
52 }
53 return refresh_token_;
54 }
55
56 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698