| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 class Profile; | 27 class Profile; |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 // DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given | 31 // DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given |
| 32 // set of scopes using the device-level OAuth2 any-api refresh token | 32 // set of scopes using the device-level OAuth2 any-api refresh token |
| 33 // obtained during enterprise device enrollment. | 33 // obtained during enterprise device enrollment. |
| 34 // | 34 // |
| 35 // See |OAuth2TokenService| for usage details. | 35 // See |OAuth2TokenService| for usage details. |
| 36 // | 36 // |
| 37 // When using DeviceOAuth2TokenSerivce, a value of |GetDeviceAccountId| should |
| 38 // be used in places where API expects |account_id|. |
| 39 // |
| 37 // Note that requests must be made from the UI thread. | 40 // Note that requests must be made from the UI thread. |
| 38 class DeviceOAuth2TokenService : public OAuth2TokenService { | 41 class DeviceOAuth2TokenService : public OAuth2TokenService { |
| 39 public: | 42 public: |
| 40 // Specialization of StartRequest that in parallel validates that the refresh | 43 // Specialization of StartRequest that in parallel validates that the refresh |
| 41 // token stored on the device is owned by the device service account. | 44 // token stored on the device is owned by the device service account. |
| 42 virtual scoped_ptr<Request> StartRequest(const ScopeSet& scopes, | 45 // TODO(fgorski): Remove override of StartRequest to make the method |
| 46 // non-virtual. See crbug.com/282454 for details. |
| 47 virtual scoped_ptr<Request> StartRequest(const std::string& account_id, |
| 48 const ScopeSet& scopes, |
| 43 Consumer* consumer) OVERRIDE; | 49 Consumer* consumer) OVERRIDE; |
| 44 | 50 |
| 45 // Persist the given refresh token on the device. Overwrites any previous | 51 // Persist the given refresh token on the device. Overwrites any previous |
| 46 // value. Should only be called during initial device setup. | 52 // value. Should only be called during initial device setup. |
| 47 void SetAndSaveRefreshToken(const std::string& refresh_token); | 53 void SetAndSaveRefreshToken(const std::string& refresh_token); |
| 48 | 54 |
| 49 static void RegisterPrefs(PrefRegistrySimple* registry); | 55 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 50 | 56 |
| 51 virtual std::string GetRefreshToken() OVERRIDE; | 57 // Gets the refresh token used by the service. |account_id| is expected to be |
| 58 // a value of |GetDeviceAccountId|. |
| 59 virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE; |
| 60 |
| 61 // Gets the device account id for use with |StartRequest| and |
| 62 // |IsRefreshTokenAvailable| methods. |
| 63 const std::string& GetDeviceAccountId() const; |
| 52 | 64 |
| 53 protected: | 65 protected: |
| 54 // Pull the robot account ID from device policy. | 66 // Pull the robot account ID from device policy. |
| 55 virtual std::string GetRobotAccountId(); | 67 virtual std::string GetRobotAccountId(); |
| 56 | 68 |
| 57 // Implementation of OAuth2TokenService. | 69 // Implementation of OAuth2TokenService. |
| 58 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 70 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
| 59 | 71 |
| 60 private: | 72 private: |
| 61 class ValidatingConsumer; | 73 class ValidatingConsumer; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 72 void OnValidationComplete(bool token_is_valid); | 84 void OnValidationComplete(bool token_is_valid); |
| 73 | 85 |
| 74 bool refresh_token_is_valid_; | 86 bool refresh_token_is_valid_; |
| 75 int max_refresh_token_validation_retries_; | 87 int max_refresh_token_validation_retries_; |
| 76 | 88 |
| 77 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 89 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 78 | 90 |
| 79 // Cache the decrypted refresh token, so we only decrypt once. | 91 // Cache the decrypted refresh token, so we only decrypt once. |
| 80 std::string refresh_token_; | 92 std::string refresh_token_; |
| 81 PrefService* local_state_; | 93 PrefService* local_state_; |
| 94 std::string device_account_id_; |
| 82 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); | 95 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); |
| 83 }; | 96 }; |
| 84 | 97 |
| 85 } // namespace chromeos | 98 } // namespace chromeos |
| 86 | 99 |
| 87 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ | 100 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |