| 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 #include <vector> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 // Persist the given refresh token on the device. Overwrites any previous | 50 // Persist the given refresh token on the device. Overwrites any previous |
| 51 // value. Should only be called during initial device setup. Signals | 51 // value. Should only be called during initial device setup. Signals |
| 52 // completion via the given callback, passing true if the operation succeeded. | 52 // completion via the given callback, passing true if the operation succeeded. |
| 53 void SetAndSaveRefreshToken(const std::string& refresh_token, | 53 void SetAndSaveRefreshToken(const std::string& refresh_token, |
| 54 const StatusCallback& callback); | 54 const StatusCallback& callback); |
| 55 | 55 |
| 56 static void RegisterPrefs(PrefRegistrySimple* registry); | 56 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 57 | 57 |
| 58 // Implementation of OAuth2TokenService. | 58 // Implementation of OAuth2TokenService. |
| 59 virtual bool RefreshTokenIsAvailable(const std::string& account_id) | 59 bool RefreshTokenIsAvailable(const std::string& account_id) const override; |
| 60 const override; | |
| 61 | 60 |
| 62 // Pull the robot account ID from device policy. | 61 // Pull the robot account ID from device policy. |
| 63 virtual std::string GetRobotAccountId() const; | 62 virtual std::string GetRobotAccountId() const; |
| 64 | 63 |
| 65 // gaia::GaiaOAuthClient::Delegate implementation. | 64 // gaia::GaiaOAuthClient::Delegate implementation. |
| 66 virtual void OnRefreshTokenResponse(const std::string& access_token, | 65 void OnRefreshTokenResponse(const std::string& access_token, |
| 67 int expires_in_seconds) override; | 66 int expires_in_seconds) override; |
| 68 virtual void OnGetTokenInfoResponse( | 67 void OnGetTokenInfoResponse( |
| 69 scoped_ptr<base::DictionaryValue> token_info) override; | 68 scoped_ptr<base::DictionaryValue> token_info) override; |
| 70 virtual void OnOAuthError() override; | 69 void OnOAuthError() override; |
| 71 virtual void OnNetworkError(int response_code) override; | 70 void OnNetworkError(int response_code) override; |
| 72 | 71 |
| 73 protected: | 72 protected: |
| 74 // Implementation of OAuth2TokenService. | 73 // Implementation of OAuth2TokenService. |
| 75 virtual net::URLRequestContextGetter* GetRequestContext() override; | 74 net::URLRequestContextGetter* GetRequestContext() override; |
| 76 virtual void FetchOAuth2Token(RequestImpl* request, | 75 void FetchOAuth2Token(RequestImpl* request, |
| 77 const std::string& account_id, | 76 const std::string& account_id, |
| 78 net::URLRequestContextGetter* getter, | 77 net::URLRequestContextGetter* getter, |
| 79 const std::string& client_id, | 78 const std::string& client_id, |
| 80 const std::string& client_secret, | 79 const std::string& client_secret, |
| 81 const ScopeSet& scopes) override; | 80 const ScopeSet& scopes) override; |
| 82 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 81 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 83 const std::string& account_id, | 82 const std::string& account_id, |
| 84 net::URLRequestContextGetter* getter, | 83 net::URLRequestContextGetter* getter, |
| 85 OAuth2AccessTokenConsumer* consumer) override; | 84 OAuth2AccessTokenConsumer* consumer) override; |
| 86 | 85 |
| 87 private: | 86 private: |
| 88 struct PendingRequest; | 87 struct PendingRequest; |
| 89 friend class DeviceOAuth2TokenServiceFactory; | 88 friend class DeviceOAuth2TokenServiceFactory; |
| 90 friend class DeviceOAuth2TokenServiceTest; | 89 friend class DeviceOAuth2TokenServiceTest; |
| 91 | 90 |
| 92 // Describes the operational state of this object. | 91 // Describes the operational state of this object. |
| 93 enum State { | 92 enum State { |
| 94 // Pending system salt / refresh token load. | 93 // Pending system salt / refresh token load. |
| 95 STATE_LOADING, | 94 STATE_LOADING, |
| 96 // No token available. | 95 // No token available. |
| 97 STATE_NO_TOKEN, | 96 STATE_NO_TOKEN, |
| 98 // System salt loaded, validation not started yet. | 97 // System salt loaded, validation not started yet. |
| 99 STATE_VALIDATION_PENDING, | 98 STATE_VALIDATION_PENDING, |
| 100 // Refresh token validation underway. | 99 // Refresh token validation underway. |
| 101 STATE_VALIDATION_STARTED, | 100 STATE_VALIDATION_STARTED, |
| 102 // Token validation failed. | 101 // Token validation failed. |
| 103 STATE_TOKEN_INVALID, | 102 STATE_TOKEN_INVALID, |
| 104 // Refresh token is valid. | 103 // Refresh token is valid. |
| 105 STATE_TOKEN_VALID, | 104 STATE_TOKEN_VALID, |
| 106 }; | 105 }; |
| 107 | 106 |
| 108 // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. | 107 // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. |
| 109 // Ownership of |token_encryptor| will be taken. | 108 // Ownership of |token_encryptor| will be taken. |
| 110 explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, | 109 explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, |
| 111 PrefService* local_state); | 110 PrefService* local_state); |
| 112 virtual ~DeviceOAuth2TokenService(); | 111 ~DeviceOAuth2TokenService() override; |
| 113 | 112 |
| 114 // Returns the refresh token for account_id. | 113 // Returns the refresh token for account_id. |
| 115 std::string GetRefreshToken(const std::string& account_id) const; | 114 std::string GetRefreshToken(const std::string& account_id) const; |
| 116 | 115 |
| 117 // Handles completion of the system salt input. | 116 // Handles completion of the system salt input. |
| 118 void DidGetSystemSalt(const std::string& system_salt); | 117 void DidGetSystemSalt(const std::string& system_salt); |
| 119 | 118 |
| 120 // Checks whether |gaia_robot_id| matches the expected account ID indicated in | 119 // Checks whether |gaia_robot_id| matches the expected account ID indicated in |
| 121 // device settings. | 120 // device settings. |
| 122 void CheckRobotAccountId(const std::string& gaia_robot_id); | 121 void CheckRobotAccountId(const std::string& gaia_robot_id); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; | 162 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; |
| 164 | 163 |
| 165 base::WeakPtrFactory<DeviceOAuth2TokenService> weak_ptr_factory_; | 164 base::WeakPtrFactory<DeviceOAuth2TokenService> weak_ptr_factory_; |
| 166 | 165 |
| 167 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); | 166 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); |
| 168 }; | 167 }; |
| 169 | 168 |
| 170 } // namespace chromeos | 169 } // namespace chromeos |
| 171 | 170 |
| 172 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ | 171 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |