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

Unified Diff: google_apis/gaia/oauth2_access_token_fetcher.h

Issue 182573003: Extract OAuth2AccessTokenFetcher interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits Created 6 years, 10 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
« no previous file with comments | « google_apis/gaia/merge_session_helper.h ('k') | google_apis/gaia/oauth2_access_token_fetcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gaia/oauth2_access_token_fetcher.h
diff --git a/google_apis/gaia/oauth2_access_token_fetcher.h b/google_apis/gaia/oauth2_access_token_fetcher.h
index 90805c0996353a28d5c118e1403ec6071946c657..3165bdaafa0ed75d472f2e9a75f3bc43cd68e4cf 100644
--- a/google_apis/gaia/oauth2_access_token_fetcher.h
+++ b/google_apis/gaia/oauth2_access_token_fetcher.h
@@ -8,33 +8,12 @@
#include <string>
#include <vector>
-#include "base/gtest_prod_util.h"
-#include "base/memory/scoped_ptr.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "net/url_request/url_fetcher_delegate.h"
-#include "url/gurl.h"
-class OAuth2AccessTokenFetcherTest;
+class OAuth2AccessTokenConsumer;
-namespace base {
-class Time;
-}
-
-namespace net {
-class URLFetcher;
-class URLRequestContextGetter;
-class URLRequestStatus;
-}
-
-// Abstracts the details to get OAuth2 access token token from
-// OAuth2 refresh token.
-// See "Using the Refresh Token" section in:
-// http://code.google.com/apis/accounts/docs/OAuth2WebServer.html
-//
-// This class should be used on a single thread, but it can be whichever thread
-// that you like.
-// Also, do not reuse the same instance. Once Start() is called, the instance
-// should not be reused.
+// Interface of a OAuth2 access token fetcher.
//
// Usage:
// * Create an instance with a consumer.
@@ -44,10 +23,9 @@ class URLRequestStatus;
//
// This class can handle one request at a time. To parallelize requests,
// create multiple instances.
-class OAuth2AccessTokenFetcher : public net::URLFetcherDelegate {
+class OAuth2AccessTokenFetcher {
public:
- OAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer,
- net::URLRequestContextGetter* getter);
+ explicit OAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer);
virtual ~OAuth2AccessTokenFetcher();
// Starts the flow with the given parameters.
@@ -59,64 +37,21 @@ class OAuth2AccessTokenFetcher : public net::URLFetcherDelegate {
virtual void Start(const std::string& client_id,
const std::string& client_secret,
const std::string& refresh_token,
- const std::vector<std::string>& scopes);
-
- void CancelRequest();
-
- // Implementation of net::URLFetcherDelegate
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
-
- private:
- enum State {
- INITIAL,
- GET_ACCESS_TOKEN_STARTED,
- GET_ACCESS_TOKEN_DONE,
- ERROR_STATE,
- };
-
- // Helper methods for the flow.
- void StartGetAccessToken();
- void EndGetAccessToken(const net::URLFetcher* source);
-
- // Helper mehtods for reporting back results.
- void OnGetTokenSuccess(const std::string& access_token,
- const base::Time& expiration_time);
- void OnGetTokenFailure(const GoogleServiceAuthError& error);
+ const std::vector<std::string>& scopes) = 0;
- // Other helpers.
- static GURL MakeGetAccessTokenUrl();
- static std::string MakeGetAccessTokenBody(
- const std::string& client_id,
- const std::string& client_secret,
- const std::string& refresh_token,
- const std::vector<std::string>& scopes);
+ // Cancels the current request and informs the consumer.
+ virtual void CancelRequest() = 0;
- static bool ParseGetAccessTokenSuccessResponse(
- const net::URLFetcher* source,
- std::string* access_token,
- int* expires_in);
+ protected:
+ // Fires |OnGetTokenSuccess| on |consumer_|.
+ void FireOnGetTokenSuccess(const std::string& access_token,
+ const base::Time& expiration_time);
- static bool ParseGetAccessTokenFailureResponse(
- const net::URLFetcher* source,
- std::string* error);
+ // Fires |OnGetTokenFailure| on |consumer_|.
+ void FireOnGetTokenFailure(const GoogleServiceAuthError& error);
- // State that is set during construction.
- OAuth2AccessTokenConsumer* const consumer_;
- net::URLRequestContextGetter* const getter_;
- State state_;
-
- // While a fetch is in progress.
- scoped_ptr<net::URLFetcher> fetcher_;
- std::string client_id_;
- std::string client_secret_;
- std::string refresh_token_;
- std::vector<std::string> scopes_;
-
- friend class OAuth2AccessTokenFetcherTest;
- FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest,
- ParseGetAccessTokenResponse);
- FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenFetcherTest,
- MakeGetAccessTokenBody);
+ private:
+ OAuth2AccessTokenConsumer* consumer_;
Roger Tawa OOO till Jul 10th 2014/03/04 16:46:54 Can probably keep the "const" now like line 104 in
msarda 2014/03/04 16:49:50 Done.
DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher);
};
« no previous file with comments | « google_apis/gaia/merge_session_helper.h ('k') | google_apis/gaia/oauth2_access_token_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698