Index: chrome/browser/chromeos/settings/device_oauth2_token_service.h |
diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service.h b/chrome/browser/chromeos/settings/device_oauth2_token_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..097008090d8d63114f418dcaf3e89b4a45086e34 |
--- /dev/null |
+++ b/chrome/browser/chromeos/settings/device_oauth2_token_service.h |
@@ -0,0 +1,62 @@ |
+// 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. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
+#define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/gtest_prod_util.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "chrome/browser/signin/oauth2_token_service.h" |
+#include "net/url_request/url_request_context_getter.h" |
+ |
+namespace net { |
+class URLRequestContextGetter; |
+} |
+ |
+class GoogleServiceAuthError; |
+class PrefRegistrySimple; |
+class PrefService; |
+class Profile; |
+ |
+namespace chromeos { |
+ |
+// DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given |
+// set of scopes using the device-level OAuth2 any-api refresh token |
+// obtained during enterprise device enrollment. |
+// |
+// See |OAuth2TokenService| for usage details. |
+// |
+// Note that requests must be made from the UI thread. |
+class DeviceOAuth2TokenService : public OAuth2TokenService { |
+ public: |
+ // Persist the given refresh token on the device. Overwrites any previous |
+ // value. Should only be called during initial device setup. |
+ void SetAndSaveRefreshToken(const std::string& refresh_token); |
+ |
+ static void RegisterPrefs(PrefRegistrySimple* registry); |
+ |
+ protected: |
+ virtual std::string GetRefreshToken() OVERRIDE; |
+ |
+ private: |
+ friend class DeviceOAuth2TokenServiceFactory; |
+ FRIEND_TEST_ALL_PREFIXES(DeviceOAuth2TokenServiceTest, SaveEncryptedToken); |
+ |
+ // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. |
+ explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, |
+ PrefService* local_state); |
+ virtual ~DeviceOAuth2TokenService(); |
+ |
+ // Cache the decrypted refresh token, so we only decrypt once. |
+ std::string refresh_token_; |
+ PrefService* local_state_; |
+ DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |