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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 int max_retries, | 43 int max_retries, |
44 GaiaOAuthClient::Delegate* delegate); | 44 GaiaOAuthClient::Delegate* delegate); |
45 | 45 |
46 // content::URLFetcherDelegate implementation. | 46 // content::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(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<content::URLFetcher> request_; |
(...skipping 23 matching lines...) Expand all Loading... |
87 "refresh_token=" + net::EscapeUrlEncodedData(refresh_token, true) + | 87 "refresh_token=" + net::EscapeUrlEncodedData(refresh_token, true) + |
88 "&client_id=" + net::EscapeUrlEncodedData(oauth_client_info.client_id, | 88 "&client_id=" + net::EscapeUrlEncodedData(oauth_client_info.client_id, |
89 true) + | 89 true) + |
90 "&client_secret=" + | 90 "&client_secret=" + |
91 net::EscapeUrlEncodedData(oauth_client_info.client_secret, true) + | 91 net::EscapeUrlEncodedData(oauth_client_info.client_secret, true) + |
92 "&grant_type=refresh_token"; | 92 "&grant_type=refresh_token"; |
93 MakeGaiaRequest(post_body, max_retries, delegate); | 93 MakeGaiaRequest(post_body, max_retries, delegate); |
94 } | 94 } |
95 | 95 |
96 void GaiaOAuthClient::Core::MakeGaiaRequest( | 96 void GaiaOAuthClient::Core::MakeGaiaRequest( |
97 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_, content::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); |
(...skipping 91 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 |