Chromium Code Reviews| Index: chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h |
| diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service.h b/chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h |
| similarity index 62% |
| copy from chrome/browser/chromeos/settings/device_oauth2_token_service.h |
| copy to chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h |
| index 4941c0279dcdc79bfffde0d230cdb730ad1d42be..882f43e223db2c7e6e2a86f8a914e5261235a345 100644 |
| --- a/chrome/browser/chromeos/settings/device_oauth2_token_service.h |
| +++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h |
| @@ -1,9 +1,9 @@ |
| -// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Copyright 2015 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_ |
| +#ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| +#define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| #include <string> |
| #include <vector> |
| @@ -14,10 +14,9 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/stl_util.h" |
| -#include "base/time/time.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #include "google_apis/gaia/gaia_oauth_client.h" |
| -#include "google_apis/gaia/oauth2_token_service.h" |
| +#include "google_apis/gaia/oauth2_token_service_delegate.h" |
| #include "net/url_request/url_request_context_getter.h" |
| namespace gaia { |
| @@ -28,39 +27,36 @@ namespace net { |
| class URLRequestContextGetter; |
| } |
| -class PrefRegistrySimple; |
| class PrefService; |
| 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. |
| -// |
| -// When using DeviceOAuth2TokenService, a value of |GetRobotAccountId| should |
| -// be used in places where API expects |account_id|. |
| -// |
| -// Note that requests must be made from the UI thread. |
| -class DeviceOAuth2TokenService : public OAuth2TokenService, |
| - public gaia::GaiaOAuthClient::Delegate { |
| +class DeviceOAuth2TokenServiceDelegate |
| + : public OAuth2TokenServiceDelegate, |
| + public gaia::GaiaOAuthClient::Delegate { |
| public: |
| - typedef base::Callback<void(bool)> StatusCallback; |
| + DeviceOAuth2TokenServiceDelegate(net::URLRequestContextGetter* getter, |
| + PrefService* local_state); |
| + ~DeviceOAuth2TokenServiceDelegate() override; |
| + typedef base::Callback<void(bool)> StatusCallback; |
| // Persist the given refresh token on the device. Overwrites any previous |
| // value. Should only be called during initial device setup. Signals |
| // completion via the given callback, passing true if the operation succeeded. |
| void SetAndSaveRefreshToken(const std::string& refresh_token, |
| const StatusCallback& callback); |
|
Mattias Nissler (ping if slow)
2015/07/01 12:34:13
nit: blank line before comment
gogerald1
2015/07/01 17:58:42
Done.
|
| + // Pull the robot account ID from device policy. |
| + std::string GetRobotAccountId() const; |
| - static void RegisterPrefs(PrefRegistrySimple* registry); |
| - |
| - // Implementation of OAuth2TokenService. |
| + // Implementation of OAuth2TokenServiceDelegate. |
| bool RefreshTokenIsAvailable(const std::string& account_id) const override; |
| - // Pull the robot account ID from device policy. |
| - virtual std::string GetRobotAccountId() const; |
| + net::URLRequestContextGetter* GetRequestContext() const override; |
| + |
| + OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| + const std::string& account_id, |
| + net::URLRequestContextGetter* getter, |
| + OAuth2AccessTokenConsumer* consumer) override; |
| // gaia::GaiaOAuthClient::Delegate implementation. |
| void OnRefreshTokenResponse(const std::string& access_token, |
| @@ -70,25 +66,15 @@ class DeviceOAuth2TokenService : public OAuth2TokenService, |
| void OnOAuthError() override; |
| void OnNetworkError(int response_code) override; |
| - protected: |
| - // Implementation of OAuth2TokenService. |
| - net::URLRequestContextGetter* GetRequestContext() override; |
| - void FetchOAuth2Token(RequestImpl* request, |
| - const std::string& account_id, |
| - net::URLRequestContextGetter* getter, |
| - const std::string& client_id, |
| - const std::string& client_secret, |
| - const ScopeSet& scopes) override; |
| - OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| - const std::string& account_id, |
| - net::URLRequestContextGetter* getter, |
| - OAuth2AccessTokenConsumer* consumer) override; |
| - |
| private: |
| - struct PendingRequest; |
| - friend class DeviceOAuth2TokenServiceFactory; |
| + friend class DeviceOAuth2TokenService; |
| friend class DeviceOAuth2TokenServiceTest; |
| + class ServiceErrorStatusObserver { |
|
Mattias Nissler (ping if slow)
2015/07/01 12:34:14
This should be renamed to ValidationStatusDelegate
gogerald1
2015/07/01 17:58:42
Done.
|
| + public: |
| + virtual void OnServiceError(GoogleServiceAuthError::State error) {} |
|
Mattias Nissler (ping if slow)
2015/07/01 12:34:14
And this to OnValidationCompleted
gogerald1
2015/07/01 17:58:42
Done.
|
| + }; |
| + |
| // Describes the operational state of this object. |
| enum State { |
| // Pending system salt / refresh token load. |
| @@ -108,12 +94,6 @@ class DeviceOAuth2TokenService : public OAuth2TokenService, |
| // Invoked by CrosSettings when the robot account ID becomes available. |
| void OnServiceAccountIdentityChanged(); |
| - // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. |
| - // Ownership of |token_encryptor| will be taken. |
| - explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, |
| - PrefService* local_state); |
| - ~DeviceOAuth2TokenService() override; |
| - |
| // Returns the refresh token for account_id. |
| std::string GetRefreshToken(const std::string& account_id) const; |
| @@ -131,15 +111,10 @@ class DeviceOAuth2TokenService : public OAuth2TokenService, |
| // Starts the token validation flow, i.e. token info fetch. |
| void StartValidation(); |
| - // Flushes |pending_requests_|, indicating the specified result. |
| - void FlushPendingRequests(bool token_is_valid, |
| - GoogleServiceAuthError::State error); |
| - |
| // Flushes |token_save_callbacks_|, indicating the specified result. |
| void FlushTokenSaveCallbacks(bool result); |
| - // Signals failure on the specified request, passing |error| as the reason. |
| - void FailRequest(RequestImpl* request, GoogleServiceAuthError::State error); |
| + void HasPendingRequests(bool has); |
| // Dependencies. |
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| @@ -151,15 +126,17 @@ class DeviceOAuth2TokenService : public OAuth2TokenService, |
| // Token save callbacks waiting to be completed. |
| std::vector<StatusCallback> token_save_callbacks_; |
| - // Currently open requests that are waiting while loading the system salt or |
| - // validating the token. |
| - std::vector<PendingRequest*> pending_requests_; |
| - |
| // The system salt for encrypting and decrypting the refresh token. |
| std::string system_salt_; |
| int max_refresh_token_validation_retries_; |
| + // Flag to indicate whether there are pending requests. |
| + bool has_pending_requests_; |
| + |
| + // Service error status observer |
| + ServiceErrorStatusObserver* service_error_status_observer_; |
| + |
| // Cache the decrypted refresh token, so we only decrypt once. |
| std::string refresh_token_; |
| @@ -168,11 +145,11 @@ class DeviceOAuth2TokenService : public OAuth2TokenService, |
| scoped_ptr<CrosSettings::ObserverSubscription> |
| service_account_identity_subscription_; |
| - base::WeakPtrFactory<DeviceOAuth2TokenService> weak_ptr_factory_; |
| + base::WeakPtrFactory<DeviceOAuth2TokenServiceDelegate> weak_ptr_factory_; |
| - DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); |
| + DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenServiceDelegate); |
| }; |
| } // namespace chromeos |
| -#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ |
| +#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |