| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GAIA_OAUTH_CLIENT_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ |
| 6 #define CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ | 6 #define CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 struct OAuthClientInfo { | 24 struct OAuthClientInfo { |
| 25 std::string client_id; | 25 std::string client_id; |
| 26 std::string client_secret; | 26 std::string client_secret; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 class GaiaOAuthClient { | 29 class GaiaOAuthClient { |
| 30 public: | 30 public: |
| 31 class Delegate { | 31 class Delegate { |
| 32 public: | 32 public: |
| 33 virtual ~Delegate() { } | |
| 34 | |
| 35 // Invoked on a successful response to the GetTokensFromAuthCode request. | 33 // Invoked on a successful response to the GetTokensFromAuthCode request. |
| 36 virtual void OnGetTokensResponse(const std::string& refresh_token, | 34 virtual void OnGetTokensResponse(const std::string& refresh_token, |
| 37 const std::string& access_token, | 35 const std::string& access_token, |
| 38 int expires_in_seconds) = 0; | 36 int expires_in_seconds) = 0; |
| 39 // Invoked on a successful response to the RefreshToken request. | 37 // Invoked on a successful response to the RefreshToken request. |
| 40 virtual void OnRefreshTokenResponse(const std::string& access_token, | 38 virtual void OnRefreshTokenResponse(const std::string& access_token, |
| 41 int expires_in_seconds) = 0; | 39 int expires_in_seconds) = 0; |
| 42 // Invoked when there is an OAuth error with one of the requests. | 40 // Invoked when there is an OAuth error with one of the requests. |
| 43 virtual void OnOAuthError() = 0; | 41 virtual void OnOAuthError() = 0; |
| 44 // Invoked when there is a network error or upon receiving an invalid | 42 // Invoked when there is a network error or upon receiving an invalid |
| 45 // response. This is invoked when the maximum number of retries have been | 43 // response. This is invoked when the maximum number of retries have been |
| 46 // exhausted. If max_retries is -1, this is never invoked. | 44 // exhausted. If max_retries is -1, this is never invoked. |
| 47 virtual void OnNetworkError(int response_code) = 0; | 45 virtual void OnNetworkError(int response_code) = 0; |
| 46 |
| 47 protected: |
| 48 virtual ~Delegate() {} |
| 48 }; | 49 }; |
| 49 GaiaOAuthClient(const std::string& gaia_url, | 50 GaiaOAuthClient(const std::string& gaia_url, |
| 50 net::URLRequestContextGetter* context_getter); | 51 net::URLRequestContextGetter* context_getter); |
| 51 ~GaiaOAuthClient(); | 52 ~GaiaOAuthClient(); |
| 52 | 53 |
| 53 // In the below methods, |max_retries| specifies the maximum number of times | 54 // In the below methods, |max_retries| specifies the maximum number of times |
| 54 // we should retry on a network error in invalid response. This does not | 55 // we should retry on a network error in invalid response. This does not |
| 55 // apply in the case of an OAuth error (i.e. there was something wrong with | 56 // apply in the case of an OAuth error (i.e. there was something wrong with |
| 56 // the input arguments). Setting |max_retries| to -1 implies infinite retries. | 57 // the input arguments). Setting |max_retries| to -1 implies infinite retries. |
| 57 void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, | 58 void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, |
| 58 const std::string& auth_code, | 59 const std::string& auth_code, |
| 59 int max_retries, | 60 int max_retries, |
| 60 Delegate* delegate); | 61 Delegate* delegate); |
| 61 void RefreshToken(const OAuthClientInfo& oauth_client_info, | 62 void RefreshToken(const OAuthClientInfo& oauth_client_info, |
| 62 const std::string& refresh_token, | 63 const std::string& refresh_token, |
| 63 int max_retries, | 64 int max_retries, |
| 64 Delegate* delegate); | 65 Delegate* delegate); |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 // The guts of the implementation live in this class. | 68 // The guts of the implementation live in this class. |
| 68 class Core; | 69 class Core; |
| 69 scoped_refptr<Core> core_; | 70 scoped_refptr<Core> core_; |
| 70 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); | 71 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); |
| 71 }; | 72 }; |
| 72 } | 73 } |
| 73 | 74 |
| 74 #endif // CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ | 75 #endif // CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ |
| OLD | NEW |