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 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/values.h" |
13 #include "chrome/browser/signin/oauth2_token_service.h" | 15 #include "chrome/browser/signin/oauth2_token_service.h" |
| 16 #include "google_apis/gaia/gaia_oauth_client.h" |
14 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
15 | 18 |
16 namespace net { | 19 namespace net { |
17 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
18 } | 21 } |
19 | 22 |
20 class GoogleServiceAuthError; | 23 class GoogleServiceAuthError; |
21 class PrefRegistrySimple; | 24 class PrefRegistrySimple; |
22 class PrefService; | 25 class PrefService; |
23 class Profile; | 26 class Profile; |
24 | 27 |
25 namespace chromeos { | 28 namespace chromeos { |
26 | 29 |
27 // DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given | 30 // DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given |
28 // set of scopes using the device-level OAuth2 any-api refresh token | 31 // set of scopes using the device-level OAuth2 any-api refresh token |
29 // obtained during enterprise device enrollment. | 32 // obtained during enterprise device enrollment. |
30 // | 33 // |
31 // See |OAuth2TokenService| for usage details. | 34 // See |OAuth2TokenService| for usage details. |
32 // | 35 // |
33 // Note that requests must be made from the UI thread. | 36 // Note that requests must be made from the UI thread. |
34 class DeviceOAuth2TokenService : public OAuth2TokenService { | 37 class DeviceOAuth2TokenService : public OAuth2TokenService, |
| 38 public gaia::GaiaOAuthClient::Delegate { |
35 public: | 39 public: |
36 // Persist the given refresh token on the device. Overwrites any previous | 40 // Persist the given refresh token on the device. Overwrites any previous |
37 // value. Should only be called during initial device setup. | 41 // value. Should only be called during initial device setup. |
38 void SetAndSaveRefreshToken(const std::string& refresh_token); | 42 void SetAndSaveRefreshToken(const std::string& refresh_token); |
39 | 43 |
40 static void RegisterPrefs(PrefRegistrySimple* registry); | 44 static void RegisterPrefs(PrefRegistrySimple* registry); |
41 | 45 |
42 virtual std::string GetRefreshToken() OVERRIDE; | 46 virtual std::string GetRefreshToken() OVERRIDE; |
43 | 47 |
| 48 virtual bool StartRefreshTokenValidation( |
| 49 const std::string refresh_token, |
| 50 RefreshTokenValidationConsumer* consumer) OVERRIDE; |
| 51 |
| 52 // gaia::GaiaOAuthClient::Delegate implementation. |
| 53 virtual void OnRefreshTokenResponse(const std::string& access_token, |
| 54 int expires_in_seconds) OVERRIDE; |
| 55 virtual void OnGetTokenInfoResponse(scoped_ptr<DictionaryValue> token_info) |
| 56 OVERRIDE; |
| 57 virtual void OnOAuthError() OVERRIDE; |
| 58 virtual void OnNetworkError(int response_code) OVERRIDE; |
| 59 |
44 private: | 60 private: |
45 friend class DeviceOAuth2TokenServiceFactory; | 61 friend class DeviceOAuth2TokenServiceFactory; |
46 FRIEND_TEST_ALL_PREFIXES(DeviceOAuth2TokenServiceTest, SaveEncryptedToken); | 62 FRIEND_TEST_ALL_PREFIXES(DeviceOAuth2TokenServiceTest, SaveEncryptedToken); |
47 | 63 |
48 // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. | 64 // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. |
49 explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, | 65 explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, |
50 PrefService* local_state); | 66 PrefService* local_state); |
51 virtual ~DeviceOAuth2TokenService(); | 67 virtual ~DeviceOAuth2TokenService(); |
52 | 68 |
| 69 // Inform all waiting RefreshTokenValidationConsumer instances of the current |
| 70 // value of refresh_token_is_valid_. |
| 71 void InformAllConsumers(); |
| 72 |
| 73 std::vector<RefreshTokenValidationConsumer*> |
| 74 refresh_token_validation_consumers_; |
| 75 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; |
| 76 bool refresh_token_is_valid_; |
| 77 |
53 // Cache the decrypted refresh token, so we only decrypt once. | 78 // Cache the decrypted refresh token, so we only decrypt once. |
54 std::string refresh_token_; | 79 std::string refresh_token_; |
55 PrefService* local_state_; | 80 PrefService* local_state_; |
56 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); | 81 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); |
57 }; | 82 }; |
58 | 83 |
59 } // namespace chromeos | 84 } // namespace chromeos |
60 | 85 |
61 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ | 86 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |