Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: google_apis/drive/base_requests.cc

Issue 443303003: Random cleanup around google_apis/drive and c/b/drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/drive/auth_service.cc ('k') | google_apis/drive/drive_api_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "google_apis/drive/base_requests.h" 5 #include "google_apis/drive/base_requests.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/sequenced_task_runner.h" 9 #include "base/sequenced_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const base::Callback<void(scoped_ptr<base::Value> value)>& callback) { 52 const base::Callback<void(scoped_ptr<base::Value> value)>& callback) {
53 base::PostTaskAndReplyWithResult( 53 base::PostTaskAndReplyWithResult(
54 blocking_task_runner, 54 blocking_task_runner,
55 FROM_HERE, 55 FROM_HERE,
56 base::Bind(&google_apis::ParseJson, json), 56 base::Bind(&google_apis::ParseJson, json),
57 callback); 57 callback);
58 } 58 }
59 59
60 // Returns response headers as a string. Returns a warning message if 60 // Returns response headers as a string. Returns a warning message if
61 // |url_fetcher| does not contain a valid response. Used only for debugging. 61 // |url_fetcher| does not contain a valid response. Used only for debugging.
62 std::string GetResponseHeadersAsString( 62 std::string GetResponseHeadersAsString(const URLFetcher* url_fetcher) {
63 const URLFetcher* url_fetcher) {
64 // net::HttpResponseHeaders::raw_headers(), as the name implies, stores 63 // net::HttpResponseHeaders::raw_headers(), as the name implies, stores
65 // all headers in their raw format, i.e each header is null-terminated. 64 // all headers in their raw format, i.e each header is null-terminated.
66 // So logging raw_headers() only shows the first header, which is probably 65 // So logging raw_headers() only shows the first header, which is probably
67 // the status line. GetNormalizedHeaders, on the other hand, will show all 66 // the status line. GetNormalizedHeaders, on the other hand, will show all
68 // the headers, one per line, which is probably what we want. 67 // the headers, one per line, which is probably what we want.
69 std::string headers; 68 std::string headers;
70 // Check that response code indicates response headers are valid (i.e. not 69 // Check that response code indicates response headers are valid (i.e. not
71 // malformed) before we retrieve the headers. 70 // malformed) before we retrieve the headers.
72 if (url_fetcher->GetResponseCode() == URLFetcher::RESPONSE_CODE_INVALID) { 71 if (url_fetcher->GetResponseCode() == URLFetcher::RESPONSE_CODE_INVALID) {
73 headers.assign("Response headers are malformed!!"); 72 headers.assign("Response headers are malformed!!");
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 182 }
184 183
185 if (!callback.is_null()) 184 if (!callback.is_null())
186 callback.Run(result); 185 callback.Run(result);
187 } 186 }
188 187
189 //============================ UrlFetchRequestBase =========================== 188 //============================ UrlFetchRequestBase ===========================
190 189
191 UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender) 190 UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender)
192 : re_authenticate_count_(0), 191 : re_authenticate_count_(0),
192 response_writer_(NULL),
193 sender_(sender), 193 sender_(sender),
194 error_code_(GDATA_OTHER_ERROR), 194 error_code_(GDATA_OTHER_ERROR),
195 weak_ptr_factory_(this) { 195 weak_ptr_factory_(this) {
196 } 196 }
197 197
198 UrlFetchRequestBase::~UrlFetchRequestBase() {} 198 UrlFetchRequestBase::~UrlFetchRequestBase() {}
199 199
200 void UrlFetchRequestBase::Start(const std::string& access_token, 200 void UrlFetchRequestBase::Start(const std::string& access_token,
201 const std::string& custom_user_agent, 201 const std::string& custom_user_agent,
202 const ReAuthenticateCallback& callback) { 202 const ReAuthenticateCallback& callback) {
203 DCHECK(CalledOnValidThread()); 203 DCHECK(CalledOnValidThread());
204 DCHECK(!access_token.empty()); 204 DCHECK(!access_token.empty());
205 DCHECK(!callback.is_null()); 205 DCHECK(!callback.is_null());
206 DCHECK(re_authenticate_callback_.is_null()); 206 DCHECK(re_authenticate_callback_.is_null());
207 207
208 re_authenticate_callback_ = callback; 208 re_authenticate_callback_ = callback;
209 209
210 GURL url = GetURL(); 210 GURL url = GetURL();
211 if (url.is_empty()) { 211 if (url.is_empty()) {
212 // Error is found on generating the url. Send the error message to the 212 // Error is found on generating the url. Send the error message to the
213 // callback, and then return immediately without trying to connect 213 // callback, and then return immediately without trying to connect
214 // to the server. 214 // to the server.
215 RunCallbackOnPrematureFailure(GDATA_OTHER_ERROR); 215 RunCallbackOnPrematureFailure(GDATA_OTHER_ERROR);
216 return; 216 return;
217 } 217 }
218 DVLOG(1) << "URL: " << url.spec(); 218 DVLOG(1) << "URL: " << url.spec();
219 219
220 URLFetcher::RequestType request_type = GetRequestType(); 220 URLFetcher::RequestType request_type = GetRequestType();
221 url_fetcher_.reset( 221 url_fetcher_.reset(URLFetcher::Create(url, request_type, this));
222 URLFetcher::Create(url, request_type, this));
223 url_fetcher_->SetRequestContext(sender_->url_request_context_getter()); 222 url_fetcher_->SetRequestContext(sender_->url_request_context_getter());
224 // Always set flags to neither send nor save cookies. 223 // Always set flags to neither send nor save cookies.
225 url_fetcher_->SetLoadFlags( 224 url_fetcher_->SetLoadFlags(
226 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | 225 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES |
227 net::LOAD_DISABLE_CACHE); 226 net::LOAD_DISABLE_CACHE);
228 227
229 base::FilePath output_file_path; 228 base::FilePath output_file_path;
230 GetContentCallback get_content_callback; 229 GetContentCallback get_content_callback;
231 GetOutputFilePath(&output_file_path, &get_content_callback); 230 GetOutputFilePath(&output_file_path, &get_content_callback);
232 if (!get_content_callback.is_null()) 231 if (!get_content_callback.is_null())
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 download_action_callback_.Run(code, temp_file); 739 download_action_callback_.Run(code, temp_file);
741 OnProcessURLFetchResultsComplete(); 740 OnProcessURLFetchResultsComplete();
742 } 741 }
743 742
744 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( 743 void DownloadFileRequestBase::RunCallbackOnPrematureFailure(
745 GDataErrorCode code) { 744 GDataErrorCode code) {
746 download_action_callback_.Run(code, base::FilePath()); 745 download_action_callback_.Run(code, base::FilePath());
747 } 746 }
748 747
749 } // namespace google_apis 748 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/auth_service.cc ('k') | google_apis/drive/drive_api_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698