| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_COMMON_NET_GAIA_OAUTH2_API_CALL_FLOW_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_OAUTH2_API_CALL_FLOW_H_ |
| 6 #define CHROME_COMMON_NET_GAIA_OAUTH2_API_CALL_FLOW_H_ | 6 #define CHROME_COMMON_NET_GAIA_OAUTH2_API_CALL_FLOW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 11 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
| 12 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 12 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
| 13 #include "chrome/common/net/gaia/oauth2_mint_token_consumer.h" | 13 #include "chrome/common/net/gaia/oauth2_mint_token_consumer.h" |
| 14 #include "chrome/common/net/gaia/oauth2_mint_token_fetcher.h" | 14 #include "chrome/common/net/gaia/oauth2_mint_token_fetcher.h" |
| 15 #include "content/public/common/url_fetcher.h" | 15 #include "content/public/common/url_fetcher.h" |
| 16 #include "content/public/common/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 17 | 17 |
| 18 class GoogleServiceAuthError; | 18 class GoogleServiceAuthError; |
| 19 class OAuth2MintTokenFlowTest; | 19 class OAuth2MintTokenFlowTest; |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Base class for all classes that implement a flow to call OAuth2 | 25 // Base class for all classes that implement a flow to call OAuth2 |
| 26 // enabled APIs. | 26 // enabled APIs. |
| 27 // | 27 // |
| 28 // Given a refresh token, an access token, and a list of scopes an OAuth2 | 28 // Given a refresh token, an access token, and a list of scopes an OAuth2 |
| 29 // enabled API is called in the following way: | 29 // enabled API is called in the following way: |
| 30 // 1. Try the given access token to call the API. | 30 // 1. Try the given access token to call the API. |
| 31 // 2. If that does not work, use the refresh token and scopes to generate | 31 // 2. If that does not work, use the refresh token and scopes to generate |
| 32 // a new access token. | 32 // a new access token. |
| 33 // 3. Try the new access token to call the API. | 33 // 3. Try the new access token to call the API. |
| 34 // | 34 // |
| 35 // This class abstracts the basic steps and exposes template methods | 35 // This class abstracts the basic steps and exposes template methods |
| 36 // for sub-classes to implement for API specific details. | 36 // for sub-classes to implement for API specific details. |
| 37 class OAuth2ApiCallFlow | 37 class OAuth2ApiCallFlow |
| 38 : public content::URLFetcherDelegate, | 38 : public net::URLFetcherDelegate, |
| 39 public OAuth2AccessTokenConsumer { | 39 public OAuth2AccessTokenConsumer { |
| 40 public: | 40 public: |
| 41 // Creates an instance that works with the given data. | 41 // Creates an instance that works with the given data. |
| 42 // Note that |access_token| can be empty. In that case, the flow will skip | 42 // Note that |access_token| can be empty. In that case, the flow will skip |
| 43 // the first step (of trying an existing access token). | 43 // the first step (of trying an existing access token). |
| 44 OAuth2ApiCallFlow( | 44 OAuth2ApiCallFlow( |
| 45 net::URLRequestContextGetter* context, | 45 net::URLRequestContextGetter* context, |
| 46 const std::string& refresh_token, | 46 const std::string& refresh_token, |
| 47 const std::string& access_token, | 47 const std::string& access_token, |
| 48 const std::vector<std::string>& scopes); | 48 const std::vector<std::string>& scopes); |
| 49 | 49 |
| 50 virtual ~OAuth2ApiCallFlow(); | 50 virtual ~OAuth2ApiCallFlow(); |
| 51 | 51 |
| 52 // Start the flow. | 52 // Start the flow. |
| 53 virtual void Start(); | 53 virtual void Start(); |
| 54 | 54 |
| 55 // OAuth2AccessTokenFetcher implementation. | 55 // OAuth2AccessTokenFetcher implementation. |
| 56 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; | 56 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; |
| 57 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 57 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
| 58 | 58 |
| 59 // content::URLFetcherDelegate implementation. | 59 // net::URLFetcherDelegate implementation. |
| 60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 // Template methods for sub-classes. | 63 // Template methods for sub-classes. |
| 64 | 64 |
| 65 // Methods to help create HTTP request. | 65 // Methods to help create HTTP request. |
| 66 virtual GURL CreateApiCallUrl() = 0; | 66 virtual GURL CreateApiCallUrl() = 0; |
| 67 virtual std::string CreateApiCallBody() = 0; | 67 virtual std::string CreateApiCallBody() = 0; |
| 68 | 68 |
| 69 // Sub-classes can expose an appropriate observer interface by implementing | 69 // Sub-classes can expose an appropriate observer interface by implementing |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // Whether we have already tried minting an access token once. | 118 // Whether we have already tried minting an access token once. |
| 119 bool tried_mint_access_token_; | 119 bool tried_mint_access_token_; |
| 120 | 120 |
| 121 scoped_ptr<content::URLFetcher> url_fetcher_; | 121 scoped_ptr<content::URLFetcher> url_fetcher_; |
| 122 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 122 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(OAuth2ApiCallFlow); | 124 DISALLOW_COPY_AND_ASSIGN(OAuth2ApiCallFlow); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_API_CALL_FLOW_H_ | 127 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_API_CALL_FLOW_H_ |
| OLD | NEW |