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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/settings/device_oauth2_token_service.cc
diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service.cc b/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42517c3eeee542bdb0eb32f508ab5beff8f93b13
--- /dev/null
+++ b/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
@@ -0,0 +1,56 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
+
+#include "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/cros/cert_library.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace chromeos {
+
+DeviceOAuth2TokenService::DeviceOAuth2TokenService(
+ net::URLRequestContextGetter* getter,
+ PrefService* local_state)
+ : OAuth2TokenService(getter),
+ local_state_(local_state) {
+}
+
+DeviceOAuth2TokenService::~DeviceOAuth2TokenService() {
+}
+
+// static
+void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterStringPref(prefs::kDeviceRobotAnyApiRefreshToken,
+ std::string());
+}
+
+void DeviceOAuth2TokenService::SetAndSaveRefreshToken(
+ const std::string& refresh_token) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ std::string encrypted_refresh_token =
+ CrosLibrary::Get()->GetCertLibrary()->EncryptWithSystemSalt(
+ refresh_token);
+
+ local_state_->SetString(prefs::kDeviceRobotAnyApiRefreshToken,
+ encrypted_refresh_token);
+}
+
+std::string DeviceOAuth2TokenService::GetRefreshToken() {
+ if (refresh_token_.empty()) {
+ std::string encrypted_refresh_token =
+ local_state_->GetString(prefs::kDeviceRobotAnyApiRefreshToken);
+
+ refresh_token_ =
+ CrosLibrary::Get()->GetCertLibrary()->DecryptWithSystemSalt(
+ encrypted_refresh_token);
+ }
+ return refresh_token_;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698