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

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: Small tweak; handle double Shutdown calls robustly. 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 }
31
32 void DeviceOAuth2TokenService::SetAndSaveRefreshToken(
33 const std::string& refresh_token) {
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
35 std::string encrypted_refresh_token =
36 CrosLibrary::Get()->GetCertLibrary()->EncryptWithSystemSalt(
37 refresh_token);
38
39 local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken,
40 encrypted_refresh_token);
41 }
42
43 std::string DeviceOAuth2TokenService::GetRefreshToken() {
44 if (refresh_token_.empty()) {
45 std::string encrypted_refresh_token =
46 local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken);
47
48 refresh_token_ =
49 CrosLibrary::Get()->GetCertLibrary()->DecryptWithSystemSalt(
50 encrypted_refresh_token);
51 }
52 return refresh_token_;
53 }
54
55 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698