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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, |
57 bool* should_retry_request); | 57 bool* should_retry_request); |
58 | 58 |
59 GURL gaia_url_; | 59 GURL gaia_url_; |
60 int num_retries_; | 60 int num_retries_; |
61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
62 GaiaOAuthClient::Delegate* delegate_; | 62 GaiaOAuthClient::Delegate* delegate_; |
63 scoped_ptr<content::URLFetcher> request_; | 63 scoped_ptr<net::URLFetcher> request_; |
64 }; | 64 }; |
65 | 65 |
66 void GaiaOAuthClient::Core::GetTokensFromAuthCode( | 66 void GaiaOAuthClient::Core::GetTokensFromAuthCode( |
67 const OAuthClientInfo& oauth_client_info, | 67 const OAuthClientInfo& oauth_client_info, |
68 const std::string& auth_code, | 68 const std::string& auth_code, |
69 int max_retries, | 69 int max_retries, |
70 GaiaOAuthClient::Delegate* delegate) { | 70 GaiaOAuthClient::Delegate* delegate) { |
71 std::string post_body = | 71 std::string post_body = |
72 "code=" + net::EscapeUrlEncodedData(auth_code, true) + | 72 "code=" + net::EscapeUrlEncodedData(auth_code, true) + |
73 "&client_id=" + net::EscapeUrlEncodedData(oauth_client_info.client_id, | 73 "&client_id=" + net::EscapeUrlEncodedData(oauth_client_info.client_id, |
(...skipping 20 matching lines...) Expand all Loading... |
94 } | 94 } |
95 | 95 |
96 void GaiaOAuthClient::Core::MakeGaiaRequest( | 96 void GaiaOAuthClient::Core::MakeGaiaRequest( |
97 const std::string& post_body, | 97 const std::string& post_body, |
98 int max_retries, | 98 int max_retries, |
99 GaiaOAuthClient::Delegate* delegate) { | 99 GaiaOAuthClient::Delegate* delegate) { |
100 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; | 100 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; |
101 delegate_ = delegate; | 101 delegate_ = delegate; |
102 num_retries_ = 0; | 102 num_retries_ = 0; |
103 request_.reset(content::URLFetcher::Create( | 103 request_.reset(content::URLFetcher::Create( |
104 0, gaia_url_, content::URLFetcher::POST, this)); | 104 0, gaia_url_, net::URLFetcher::POST, this)); |
105 request_->SetRequestContext(request_context_getter_); | 105 request_->SetRequestContext(request_context_getter_); |
106 request_->SetUploadData("application/x-www-form-urlencoded", post_body); | 106 request_->SetUploadData("application/x-www-form-urlencoded", post_body); |
107 request_->SetMaxRetries(max_retries); | 107 request_->SetMaxRetries(max_retries); |
108 request_->Start(); | 108 request_->Start(); |
109 } | 109 } |
110 | 110 |
111 // URLFetcher::Delegate implementation. | 111 // URLFetcher::Delegate implementation. |
112 void GaiaOAuthClient::Core::OnURLFetchComplete( | 112 void GaiaOAuthClient::Core::OnURLFetchComplete( |
113 const net::URLFetcher* source) { | 113 const net::URLFetcher* source) { |
114 bool should_retry = false; | 114 bool should_retry = false; |
(...skipping 84 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 |