| 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 #include "chrome/common/net/gaia/gaia_oauth_client.h" | 5 #include "chrome/common/net/gaia/gaia_oauth_client.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "content/public/common/url_fetcher.h" | 11 #include "content/public/common/url_fetcher.h" |
| 12 #include "content/public/common/url_fetcher_delegate.h" | |
| 13 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 15 #include "net/http/http_status_code.h" | 14 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 const char kAccessTokenValue[] = "access_token"; | 19 const char kAccessTokenValue[] = "access_token"; |
| 20 const char kRefreshTokenValue[] = "refresh_token"; | 20 const char kRefreshTokenValue[] = "refresh_token"; |
| 21 const char kExpiresInValue[] = "expires_in"; | 21 const char kExpiresInValue[] = "expires_in"; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace gaia { | 24 namespace gaia { |
| 25 | 25 |
| 26 class GaiaOAuthClient::Core | 26 class GaiaOAuthClient::Core |
| 27 : public base::RefCountedThreadSafe<GaiaOAuthClient::Core>, | 27 : public base::RefCountedThreadSafe<GaiaOAuthClient::Core>, |
| 28 public content::URLFetcherDelegate { | 28 public net::URLFetcherDelegate { |
| 29 public: | 29 public: |
| 30 Core(const std::string& gaia_url, | 30 Core(const std::string& gaia_url, |
| 31 net::URLRequestContextGetter* request_context_getter) | 31 net::URLRequestContextGetter* request_context_getter) |
| 32 : gaia_url_(gaia_url), | 32 : gaia_url_(gaia_url), |
| 33 num_retries_(0), | 33 num_retries_(0), |
| 34 request_context_getter_(request_context_getter), | 34 request_context_getter_(request_context_getter), |
| 35 delegate_(NULL) {} | 35 delegate_(NULL) {} |
| 36 | 36 |
| 37 void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, | 37 void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, |
| 38 const std::string& auth_code, | 38 const std::string& auth_code, |
| 39 int max_retries, | 39 int max_retries, |
| 40 GaiaOAuthClient::Delegate* delegate); | 40 GaiaOAuthClient::Delegate* delegate); |
| 41 void RefreshToken(const OAuthClientInfo& oauth_client_info, | 41 void RefreshToken(const OAuthClientInfo& oauth_client_info, |
| 42 const std::string& refresh_token, | 42 const std::string& refresh_token, |
| 43 int max_retries, | 43 int max_retries, |
| 44 GaiaOAuthClient::Delegate* delegate); | 44 GaiaOAuthClient::Delegate* delegate); |
| 45 | 45 |
| 46 // content::URLFetcherDelegate implementation. | 46 // net::URLFetcherDelegate implementation. |
| 47 virtual void OnURLFetchComplete(const net::URLFetcher* source); | 47 virtual void OnURLFetchComplete(const net::URLFetcher* source); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 friend class base::RefCountedThreadSafe<Core>; | 50 friend class base::RefCountedThreadSafe<Core>; |
| 51 virtual ~Core() {} | 51 virtual ~Core() {} |
| 52 | 52 |
| 53 void MakeGaiaRequest(const std::string& post_body, | 53 void MakeGaiaRequest(const std::string& post_body, |
| 54 int max_retries, | 54 int max_retries, |
| 55 GaiaOAuthClient::Delegate* delegate); | 55 GaiaOAuthClient::Delegate* delegate); |
| 56 void HandleResponse(const net::URLFetcher* source, | 56 void HandleResponse(const net::URLFetcher* source, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const std::string& refresh_token, | 199 const std::string& refresh_token, |
| 200 int max_retries, | 200 int max_retries, |
| 201 Delegate* delegate) { | 201 Delegate* delegate) { |
| 202 return core_->RefreshToken(oauth_client_info, | 202 return core_->RefreshToken(oauth_client_info, |
| 203 refresh_token, | 203 refresh_token, |
| 204 max_retries, | 204 max_retries, |
| 205 delegate); | 205 delegate); |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace gaia | 208 } // namespace gaia |
| OLD | NEW |