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

Side by Side Diff: net/url_request/url_request_ftp_job.cc

Issue 1410643007: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review Created 5 years, 2 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
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 "net/url_request/url_request_ftp_job.h" 5 #include "net/url_request/url_request_ftp_job.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 HandleAuthNeededResponse(); 229 HandleAuthNeededResponse();
230 return; 230 return;
231 } 231 }
232 } 232 }
233 NotifyHeadersComplete(); 233 NotifyHeadersComplete();
234 } else if (ftp_transaction_ && 234 } else if (ftp_transaction_ &&
235 ftp_transaction_->GetResponseInfo()->needs_auth) { 235 ftp_transaction_->GetResponseInfo()->needs_auth) {
236 HandleAuthNeededResponse(); 236 HandleAuthNeededResponse();
237 return; 237 return;
238 } else { 238 } else {
239 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 239 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
240 } 240 }
241 } 241 }
242 242
243 void URLRequestFtpJob::OnStartCompletedAsync(int result) { 243 void URLRequestFtpJob::OnStartCompletedAsync(int result) {
244 base::ThreadTaskRunnerHandle::Get()->PostTask( 244 base::ThreadTaskRunnerHandle::Get()->PostTask(
245 FROM_HERE, base::Bind(&URLRequestFtpJob::OnStartCompleted, 245 FROM_HERE, base::Bind(&URLRequestFtpJob::OnStartCompleted,
246 weak_factory_.GetWeakPtr(), result)); 246 weak_factory_.GetWeakPtr(), result));
247 } 247 }
248 248
249 void URLRequestFtpJob::OnReadCompleted(int result) { 249 void URLRequestFtpJob::OnReadCompleted(int result) {
250 read_in_progress_ = false; 250 read_in_progress_ = false;
251 if (result == 0) { 251 ReadRawDataComplete(result);
252 NotifyDone(URLRequestStatus());
253 } else if (result < 0) {
254 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
255 } else {
256 // Clear the IO_PENDING status
257 SetStatus(URLRequestStatus());
258 }
259 NotifyReadComplete(result);
260 } 252 }
261 253
262 void URLRequestFtpJob::RestartTransactionWithAuth() { 254 void URLRequestFtpJob::RestartTransactionWithAuth() {
263 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH); 255 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH);
264 256
265 // No matter what, we want to report our status as IO pending since we will 257 // No matter what, we want to report our status as IO pending since we will
266 // be notifying our consumer asynchronously via OnStartCompleted. 258 // be notifying our consumer asynchronously via OnStartCompleted.
267 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 259 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
268 260
269 int rv; 261 int rv;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Once the auth is cancelled, we proceed with the request as though 332 // Once the auth is cancelled, we proceed with the request as though
341 // there were no auth. Schedule this for later so that we don't cause 333 // there were no auth. Schedule this for later so that we don't cause
342 // any recursing into the caller as a result of this call. 334 // any recursing into the caller as a result of this call.
343 OnStartCompletedAsync(OK); 335 OnStartCompletedAsync(OK);
344 } 336 }
345 337
346 UploadProgress URLRequestFtpJob::GetUploadProgress() const { 338 UploadProgress URLRequestFtpJob::GetUploadProgress() const {
347 return UploadProgress(); 339 return UploadProgress();
348 } 340 }
349 341
350 bool URLRequestFtpJob::ReadRawData(IOBuffer* buf, 342 int URLRequestFtpJob::ReadRawData(IOBuffer* buf, int buf_size) {
351 int buf_size,
352 int *bytes_read) {
353 DCHECK_NE(buf_size, 0); 343 DCHECK_NE(buf_size, 0);
354 DCHECK(bytes_read);
355 DCHECK(!read_in_progress_); 344 DCHECK(!read_in_progress_);
356 345
357 int rv; 346 int rv;
347
358 if (proxy_info_.is_direct()) { 348 if (proxy_info_.is_direct()) {
359 rv = ftp_transaction_->Read(buf, buf_size, 349 rv = ftp_transaction_->Read(buf, buf_size,
360 base::Bind(&URLRequestFtpJob::OnReadCompleted, 350 base::Bind(&URLRequestFtpJob::OnReadCompleted,
361 base::Unretained(this))); 351 base::Unretained(this)));
362 } else { 352 } else {
363 rv = http_transaction_->Read(buf, buf_size, 353 rv = http_transaction_->Read(buf, buf_size,
364 base::Bind(&URLRequestFtpJob::OnReadCompleted, 354 base::Bind(&URLRequestFtpJob::OnReadCompleted,
365 base::Unretained(this))); 355 base::Unretained(this)));
366 } 356 }
367 357
368 if (rv >= 0) { 358 if (rv == ERR_IO_PENDING)
369 *bytes_read = rv;
370 return true;
371 }
372
373 if (rv == ERR_IO_PENDING) {
374 read_in_progress_ = true; 359 read_in_progress_ = true;
375 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 360 return rv;
376 } else {
377 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
378 }
379 return false;
380 } 361 }
381 362
382 void URLRequestFtpJob::HandleAuthNeededResponse() { 363 void URLRequestFtpJob::HandleAuthNeededResponse() {
383 GURL origin = request_->url().GetOrigin(); 364 GURL origin = request_->url().GetOrigin();
384 365
385 if (auth_data_.get()) { 366 if (auth_data_.get()) {
386 if (auth_data_->state == AUTH_STATE_CANCELED) { 367 if (auth_data_->state == AUTH_STATE_CANCELED) {
387 NotifyHeadersComplete(); 368 NotifyHeadersComplete();
388 return; 369 return;
389 } 370 }
(...skipping 11 matching lines...) Expand all
401 if (cached_auth) { 382 if (cached_auth) {
402 // Retry using cached auth data. 383 // Retry using cached auth data.
403 SetAuth(cached_auth->credentials); 384 SetAuth(cached_auth->credentials);
404 } else { 385 } else {
405 // Prompt for a username/password. 386 // Prompt for a username/password.
406 NotifyHeadersComplete(); 387 NotifyHeadersComplete();
407 } 388 }
408 } 389 }
409 390
410 } // namespace net 391 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698