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

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

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased on top of URLRequest::Read CL Created 4 years, 3 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
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_request_context_builder.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 "net/url_request/url_fetcher_core.h" 5 #include "net/url_request/url_fetcher_core.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 bool* defer_redirect) { 400 bool* defer_redirect) {
401 DCHECK_EQ(request, request_.get()); 401 DCHECK_EQ(request, request_.get());
402 DCHECK(network_task_runner_->BelongsToCurrentThread()); 402 DCHECK(network_task_runner_->BelongsToCurrentThread());
403 if (stop_on_redirect_) { 403 if (stop_on_redirect_) {
404 stopped_on_redirect_ = true; 404 stopped_on_redirect_ = true;
405 url_ = redirect_info.new_url; 405 url_ = redirect_info.new_url;
406 response_code_ = request_->GetResponseCode(); 406 response_code_ = request_->GetResponseCode();
407 was_fetched_via_proxy_ = request_->was_fetched_via_proxy(); 407 was_fetched_via_proxy_ = request_->was_fetched_via_proxy();
408 was_cached_ = request_->was_cached(); 408 was_cached_ = request_->was_cached();
409 total_received_bytes_ += request_->GetTotalReceivedBytes(); 409 total_received_bytes_ += request_->GetTotalReceivedBytes();
410 request->Cancel(); 410 int result = request->Cancel();
411 OnReadCompleted(request, 0); 411 OnReadCompleted(request, result);
412 } 412 }
413 } 413 }
414 414
415 void URLFetcherCore::OnResponseStarted(URLRequest* request) { 415 void URLFetcherCore::OnResponseStarted(URLRequest* request, int net_error) {
416 DCHECK_EQ(request, request_.get()); 416 DCHECK_EQ(request, request_.get());
417 DCHECK(network_task_runner_->BelongsToCurrentThread()); 417 DCHECK(network_task_runner_->BelongsToCurrentThread());
418 if (request_->status().is_success()) { 418 DCHECK_NE(ERR_IO_PENDING, net_error);
419
420 if (net_error == OK) {
419 response_code_ = request_->GetResponseCode(); 421 response_code_ = request_->GetResponseCode();
420 response_headers_ = request_->response_headers(); 422 response_headers_ = request_->response_headers();
421 socket_address_ = request_->GetSocketAddress(); 423 socket_address_ = request_->GetSocketAddress();
422 was_fetched_via_proxy_ = request_->was_fetched_via_proxy(); 424 was_fetched_via_proxy_ = request_->was_fetched_via_proxy();
423 was_cached_ = request_->was_cached(); 425 was_cached_ = request_->was_cached();
424 total_response_bytes_ = request_->GetExpectedContentSize(); 426 total_response_bytes_ = request_->GetExpectedContentSize();
425 } 427 }
426 428
427 ReadResponse(); 429 ReadResponse();
428 } 430 }
(...skipping 16 matching lines...) Expand all
445 DCHECK_EQ(request, request_.get()); 447 DCHECK_EQ(request, request_.get());
446 DCHECK(network_task_runner_->BelongsToCurrentThread()); 448 DCHECK(network_task_runner_->BelongsToCurrentThread());
447 449
448 if (!stopped_on_redirect_) 450 if (!stopped_on_redirect_)
449 url_ = request->url(); 451 url_ = request->url();
450 URLRequestThrottlerManager* throttler_manager = 452 URLRequestThrottlerManager* throttler_manager =
451 request->context()->throttler_manager(); 453 request->context()->throttler_manager();
452 if (throttler_manager) 454 if (throttler_manager)
453 url_throttler_entry_ = throttler_manager->RegisterRequestUrl(url_); 455 url_throttler_entry_ = throttler_manager->RegisterRequestUrl(url_);
454 456
455 do { 457 while (bytes_read > 0) {
456 if (!request_->status().is_success() || bytes_read <= 0)
457 break;
458
459 current_response_bytes_ += bytes_read; 458 current_response_bytes_ += bytes_read;
460 InformDelegateDownloadProgress(); 459 InformDelegateDownloadProgress();
461 460
462 const int result = 461 const int result =
463 WriteBuffer(new DrainableIOBuffer(buffer_.get(), bytes_read)); 462 WriteBuffer(new DrainableIOBuffer(buffer_.get(), bytes_read));
464 if (result < 0) { 463 if (result < 0) {
465 // Write failed or waiting for write completion. 464 // Write failed or waiting for write completion.
466 return; 465 return;
467 } 466 }
468 } while (request_->Read(buffer_.get(), kBufferSize, &bytes_read)); 467 bytes_read = request_->Read(buffer_.get(), kBufferSize);
469 468 }
470 const URLRequestStatus status = request_->status();
471 469
472 // See comments re: HEAD requests in ReadResponse(). 470 // See comments re: HEAD requests in ReadResponse().
473 if (!status.is_io_pending() || request_type_ == URLFetcher::HEAD) { 471 if (bytes_read != ERR_IO_PENDING || request_type_ == URLFetcher::HEAD) {
474 status_ = status; 472 status_ = URLRequestStatus::FromError(bytes_read);
475 received_response_content_length_ = 473 received_response_content_length_ =
476 request_->received_response_content_length(); 474 request_->received_response_content_length();
477 total_received_bytes_ += request_->GetTotalReceivedBytes(); 475 total_received_bytes_ += request_->GetTotalReceivedBytes();
478 ReleaseRequest(); 476 ReleaseRequest();
479 477
480 // No more data to write. 478 // No more data to write.
481 const int result = response_writer_->Finish( 479 const int result = response_writer_->Finish(
482 base::Bind(&URLFetcherCore::DidFinishWriting, this)); 480 base::Bind(&URLFetcherCore::DidFinishWriting, this));
483 if (result != ERR_IO_PENDING) 481 if (result != ERR_IO_PENDING)
484 DidFinishWriting(result); 482 DidFinishWriting(result);
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 if (request_.get()) 877 if (request_.get())
880 ReadResponse(); 878 ReadResponse();
881 } 879 }
882 880
883 void URLFetcherCore::ReadResponse() { 881 void URLFetcherCore::ReadResponse() {
884 // Some servers may treat HEAD requests as GET requests. To free up the 882 // Some servers may treat HEAD requests as GET requests. To free up the
885 // network connection as soon as possible, signal that the request has 883 // network connection as soon as possible, signal that the request has
886 // completed immediately, without trying to read any data back (all we care 884 // completed immediately, without trying to read any data back (all we care
887 // about is the response code and headers, which we already have). 885 // about is the response code and headers, which we already have).
888 int bytes_read = 0; 886 int bytes_read = 0;
889 if (request_->status().is_success() && 887 if (request_type_ != URLFetcher::HEAD)
890 (request_type_ != URLFetcher::HEAD)) { 888 bytes_read = request_->Read(buffer_.get(), kBufferSize);
891 if (!request_->Read(buffer_.get(), kBufferSize, &bytes_read)) 889
892 bytes_read = -1; // Match OnReadCompleted() interface contract.
893 }
894 OnReadCompleted(request_.get(), bytes_read); 890 OnReadCompleted(request_.get(), bytes_read);
895 } 891 }
896 892
897 void URLFetcherCore::InformDelegateUploadProgress() { 893 void URLFetcherCore::InformDelegateUploadProgress() {
898 DCHECK(network_task_runner_->BelongsToCurrentThread()); 894 DCHECK(network_task_runner_->BelongsToCurrentThread());
899 if (request_.get()) { 895 if (request_.get()) {
900 int64_t current = request_->GetUploadProgress().position(); 896 int64_t current = request_->GetUploadProgress().position();
901 if (current_upload_bytes_ != current) { 897 if (current_upload_bytes_ != current) {
902 current_upload_bytes_ = current; 898 current_upload_bytes_ = current;
903 int64_t total = -1; 899 int64_t total = -1;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 } 945 }
950 946
951 void URLFetcherCore::AssertHasNoUploadData() const { 947 void URLFetcherCore::AssertHasNoUploadData() const {
952 DCHECK(!upload_content_set_); 948 DCHECK(!upload_content_set_);
953 DCHECK(upload_content_.empty()); 949 DCHECK(upload_content_.empty());
954 DCHECK(upload_file_path_.empty()); 950 DCHECK(upload_file_path_.empty());
955 DCHECK(upload_stream_factory_.is_null()); 951 DCHECK(upload_stream_factory_.is_null());
956 } 952 }
957 953
958 } // namespace net 954 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_request_context_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698