Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3828)

Unified Diff: chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address final comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..aa55a239e10a30faba89b0282925f2a68d6adc6e 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,24 +27,18 @@ 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:
+ 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
@@ -54,13 +47,18 @@ class DeviceOAuth2TokenService : public OAuth2TokenService,
void SetAndSaveRefreshToken(const std::string& refresh_token,
const StatusCallback& callback);
- static void RegisterPrefs(PrefRegistrySimple* registry);
+ // Pull the robot account ID from device policy.
+ std::string GetRobotAccountId() const;
- // 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 +68,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 ValidationStatusDelegate {
+ public:
+ virtual void OnValidationCompleted(GoogleServiceAuthError::State error) {}
+ };
+
// Describes the operational state of this object.
enum State {
// Pending system salt / refresh token load.
@@ -108,12 +96,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 +113,14 @@ 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 RequestValidation();
+
+ void SetValidationStatusDelegate(ValidationStatusDelegate* delegate);
+
+ void ReportServiceError(GoogleServiceAuthError::State error);
// Dependencies.
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
@@ -151,15 +132,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 validation_requested_;
+
+ // Validation status delegate
+ ValidationStatusDelegate* validation_status_delegate_;
+
// Cache the decrypted refresh token, so we only decrypt once.
std::string refresh_token_;
@@ -168,11 +151,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_

Powered by Google App Engine
This is Rietveld 408576698