Index: google_apis/gaia/oauth2_token_service_request.h |
diff --git a/chrome/browser/signin/profile_oauth2_token_service_request.h b/google_apis/gaia/oauth2_token_service_request.h |
similarity index 14% |
rename from chrome/browser/signin/profile_oauth2_token_service_request.h |
rename to google_apis/gaia/oauth2_token_service_request.h |
index e7f628dde3f11e9601de33aaf4221942b903c715..972e5184b85c811cf04609cb75f95e1a46cc3004 100644 |
--- a/chrome/browser/signin/profile_oauth2_token_service_request.h |
+++ b/google_apis/gaia/oauth2_token_service_request.h |
@@ -1,55 +1,96 @@ |
-// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2014 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_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
-#define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
+#ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
+#define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
#include <set> |
#include <string> |
+#include "base/memory/scoped_ptr.h" |
+#include "base/single_thread_task_runner.h" |
#include "base/threading/non_thread_safe.h" |
#include "google_apis/gaia/oauth2_token_service.h" |
-class Profile; |
- |
-// ProfileOAuth2TokenServiceRequest represents a request to fetch an |
-// OAuth2 access token for a given set of |scopes| by calling |profile|'s |
-// ProfileOAuth2TokenService. A request can be created and started from |
-// any thread with an object |consumer| that will be called back on the |
-// same thread when fetching completes. If the request is destructed |
-// before |consumer| is called, |consumer| will never be called back. (Note |
-// the actual network activities are not canceled and the cache in |
-// ProfileOAuth2TokenService will be populated with the fetched results.) |
-class ProfileOAuth2TokenServiceRequest : public OAuth2TokenService::Request, |
- public base::NonThreadSafe { |
+// OAuth2TokenServiceRequest represents an asynchronous request to an |
+// OAuth2TokenService that may live in another thread. |
+// |
+// An OAuth2TokenServiceRequest can be created and started from any thread. |
+class OAuth2TokenServiceRequest : public OAuth2TokenService::Request, |
+ public base::NonThreadSafe { |
public: |
- // Creates and starts a request for |account_id| and |scopes|. |
- // Uses the primary account id if |account_id| is the empty string. |
- static ProfileOAuth2TokenServiceRequest* CreateAndStart( |
- Profile* profile, |
+ class Core; |
+ |
+ // Interface for providing an OAuth2TokenService. |
+ class TokenServiceProvider { |
+ public: |
+ TokenServiceProvider(); |
+ virtual ~TokenServiceProvider(); |
+ |
+ // Returns the task runner on which the token service lives. |
+ // |
+ // This method may be called from any thread. |
+ virtual scoped_refptr<base::SingleThreadTaskRunner> |
+ GetTokenServiceTaskRunner() = 0; |
+ |
+ // Returns a pointer to a token service. |
+ // |
+ // Caller does not own the token service and must not delete it. The token |
+ // service must outlive all instances of OAuth2TokenServiceRequest. |
+ // |
+ // This method may only be called from the task runner returned by |
+ // |GetTokenServiceTaskRunner|. |
+ virtual OAuth2TokenService* GetTokenService() = 0; |
+ }; |
+ |
+ // Creates and starts an access token request for |account_id| and |scopes|. |
+ // |
+ // |provider| is used to get the OAuth2TokenService and must outlive the |
+ // returned request object. |
+ // |
+ // |account_id| must not be empty. |
+ // |
+ // |scopes| must not be empty. |
+ // |
+ // |consumer| will be invoked in the same thread that invoked CreateAndStart |
+ // and must outlive the returned request object. Destroying the request |
+ // object ensure that |consumer| will not be called. However, the actual |
+ // network activities may not be canceled and the cache in OAuth2TokenService |
+ // may be populated with the fetched results. |
+ static scoped_ptr<OAuth2TokenServiceRequest> CreateAndStart( |
+ TokenServiceProvider* provider, |
const std::string& account_id, |
const OAuth2TokenService::ScopeSet& scopes, |
OAuth2TokenService::Consumer* consumer); |
- virtual ~ProfileOAuth2TokenServiceRequest(); |
+ // Invalidates |access_token| for |account_id| and |scopes|. |
+ // |
+ // |provider| is used to get the OAuth2TokenService and must outlive the |
+ // returned request object. |
+ // |
+ // |account_id| must not be empty. |
+ // |
+ // |scopes| must not be empty. |
+ static void InvalidateToken(TokenServiceProvider* provider, |
+ const std::string& account_id, |
+ const OAuth2TokenService::ScopeSet& scopes, |
+ const std::string& access_token); |
+ |
+ virtual ~OAuth2TokenServiceRequest(); |
- // Overridden from Request: |
+ // OAuth2TokenService::Request. |
virtual std::string GetAccountId() const OVERRIDE; |
private: |
- class Core; |
- friend class Core; |
+ OAuth2TokenServiceRequest(const std::string& account_id); |
- ProfileOAuth2TokenServiceRequest(Profile* profile, |
- const std::string& account_id, |
- const OAuth2TokenService::ScopeSet& scopes, |
- OAuth2TokenService::Consumer* consumer); |
+ void StartWithCore(const scoped_refptr<Core>& core); |
- OAuth2TokenService::Consumer* const consumer_; |
+ const std::string account_id_; |
scoped_refptr<Core> core_; |
- DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceRequest); |
+ DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceRequest); |
}; |
-#endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |
+#endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_REQUEST_H_ |