| 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 "net/url_request/url_fetcher_core.h" | 5 #include "net/url_request/url_fetcher_core.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 max_retries_on_5xx_(0), | 91 max_retries_on_5xx_(0), |
| 92 num_retries_on_network_changes_(0), | 92 num_retries_on_network_changes_(0), |
| 93 max_retries_on_network_changes_(0), | 93 max_retries_on_network_changes_(0), |
| 94 current_upload_bytes_(-1), | 94 current_upload_bytes_(-1), |
| 95 current_response_bytes_(0), | 95 current_response_bytes_(0), |
| 96 total_response_bytes_(-1) { | 96 total_response_bytes_(-1) { |
| 97 CHECK(original_url_.is_valid()); | 97 CHECK(original_url_.is_valid()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void URLFetcherCore::Start() { | 100 void URLFetcherCore::Start() { |
| 101 DCHECK(delegate_task_runner_); | 101 DCHECK(delegate_task_runner_.get()); |
| 102 DCHECK(request_context_getter_) << "We need an URLRequestContext!"; | 102 DCHECK(request_context_getter_.get()) << "We need an URLRequestContext!"; |
| 103 if (network_task_runner_) { | 103 if (network_task_runner_.get()) { |
| 104 DCHECK_EQ(network_task_runner_, | 104 DCHECK_EQ(network_task_runner_, |
| 105 request_context_getter_->GetNetworkTaskRunner()); | 105 request_context_getter_->GetNetworkTaskRunner()); |
| 106 } else { | 106 } else { |
| 107 network_task_runner_ = request_context_getter_->GetNetworkTaskRunner(); | 107 network_task_runner_ = request_context_getter_->GetNetworkTaskRunner(); |
| 108 } | 108 } |
| 109 DCHECK(network_task_runner_.get()) << "We need an IO task runner"; | 109 DCHECK(network_task_runner_.get()) << "We need an IO task runner"; |
| 110 | 110 |
| 111 network_task_runner_->PostTask( | 111 network_task_runner_->PostTask( |
| 112 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); | 112 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void URLFetcherCore::Stop() { | 115 void URLFetcherCore::Stop() { |
| 116 if (delegate_task_runner_) // May be NULL in tests. | 116 if (delegate_task_runner_.get()) // May be NULL in tests. |
| 117 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 117 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 118 | 118 |
| 119 delegate_ = NULL; | 119 delegate_ = NULL; |
| 120 fetcher_ = NULL; | 120 fetcher_ = NULL; |
| 121 if (!network_task_runner_.get()) | 121 if (!network_task_runner_.get()) |
| 122 return; | 122 return; |
| 123 if (network_task_runner_->RunsTasksOnCurrentThread()) { | 123 if (network_task_runner_->RunsTasksOnCurrentThread()) { |
| 124 CancelURLRequest(); | 124 CancelURLRequest(); |
| 125 } else { | 125 } else { |
| 126 network_task_runner_->PostTask( | 126 network_task_runner_->PostTask( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // to ensure non-empty upload content as it is not yet supplied. | 176 // to ensure non-empty upload content as it is not yet supplied. |
| 177 DCHECK(!content_type.empty()); | 177 DCHECK(!content_type.empty()); |
| 178 | 178 |
| 179 upload_content_type_ = content_type; | 179 upload_content_type_ = content_type; |
| 180 upload_content_.clear(); | 180 upload_content_.clear(); |
| 181 is_chunked_upload_ = true; | 181 is_chunked_upload_ = true; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void URLFetcherCore::AppendChunkToUpload(const std::string& content, | 184 void URLFetcherCore::AppendChunkToUpload(const std::string& content, |
| 185 bool is_last_chunk) { | 185 bool is_last_chunk) { |
| 186 DCHECK(delegate_task_runner_); | 186 DCHECK(delegate_task_runner_.get()); |
| 187 DCHECK(network_task_runner_.get()); | 187 DCHECK(network_task_runner_.get()); |
| 188 network_task_runner_->PostTask( | 188 network_task_runner_->PostTask( |
| 189 FROM_HERE, | 189 FROM_HERE, |
| 190 base::Bind(&URLFetcherCore::CompleteAddingUploadDataChunk, this, content, | 190 base::Bind(&URLFetcherCore::CompleteAddingUploadDataChunk, this, content, |
| 191 is_last_chunk)); | 191 is_last_chunk)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void URLFetcherCore::SetLoadFlags(int load_flags) { | 194 void URLFetcherCore::SetLoadFlags(int load_flags) { |
| 195 load_flags_ = load_flags; | 195 load_flags_ = load_flags; |
| 196 } | 196 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 213 extra_request_headers_.AddHeaderFromString(header_line); | 213 extra_request_headers_.AddHeaderFromString(header_line); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void URLFetcherCore::GetExtraRequestHeaders( | 216 void URLFetcherCore::GetExtraRequestHeaders( |
| 217 HttpRequestHeaders* headers) const { | 217 HttpRequestHeaders* headers) const { |
| 218 headers->CopyFrom(extra_request_headers_); | 218 headers->CopyFrom(extra_request_headers_); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void URLFetcherCore::SetRequestContext( | 221 void URLFetcherCore::SetRequestContext( |
| 222 URLRequestContextGetter* request_context_getter) { | 222 URLRequestContextGetter* request_context_getter) { |
| 223 DCHECK(!request_context_getter_); | 223 DCHECK(!request_context_getter_.get()); |
| 224 DCHECK(request_context_getter); | 224 DCHECK(request_context_getter); |
| 225 request_context_getter_ = request_context_getter; | 225 request_context_getter_ = request_context_getter; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void URLFetcherCore::SetFirstPartyForCookies( | 228 void URLFetcherCore::SetFirstPartyForCookies( |
| 229 const GURL& first_party_for_cookies) { | 229 const GURL& first_party_for_cookies) { |
| 230 DCHECK(first_party_for_cookies_.is_empty()); | 230 DCHECK(first_party_for_cookies_.is_empty()); |
| 231 first_party_for_cookies_ = first_party_for_cookies; | 231 first_party_for_cookies_ = first_party_for_cookies; |
| 232 } | 232 } |
| 233 | 233 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 void URLFetcherCore::SaveResponseToTemporaryFile( | 276 void URLFetcherCore::SaveResponseToTemporaryFile( |
| 277 scoped_refptr<base::TaskRunner> file_task_runner) { | 277 scoped_refptr<base::TaskRunner> file_task_runner) { |
| 278 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 278 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 279 file_task_runner_ = file_task_runner; | 279 file_task_runner_ = file_task_runner; |
| 280 response_destination_ = URLFetcherCore::TEMP_FILE; | 280 response_destination_ = URLFetcherCore::TEMP_FILE; |
| 281 } | 281 } |
| 282 | 282 |
| 283 HttpResponseHeaders* URLFetcherCore::GetResponseHeaders() const { | 283 HttpResponseHeaders* URLFetcherCore::GetResponseHeaders() const { |
| 284 return response_headers_; | 284 return response_headers_.get(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 // TODO(panayiotis): socket_address_ is written in the IO thread, | 287 // TODO(panayiotis): socket_address_ is written in the IO thread, |
| 288 // if this is accessed in the UI thread, this could result in a race. | 288 // if this is accessed in the UI thread, this could result in a race. |
| 289 // Same for response_headers_ above and was_fetched_via_proxy_ below. | 289 // Same for response_headers_ above and was_fetched_via_proxy_ below. |
| 290 HostPortPair URLFetcherCore::GetSocketAddress() const { | 290 HostPortPair URLFetcherCore::GetSocketAddress() const { |
| 291 return socket_address_; | 291 return socket_address_; |
| 292 } | 292 } |
| 293 | 293 |
| 294 bool URLFetcherCore::WasFetchedViaProxy() const { | 294 bool URLFetcherCore::WasFetchedViaProxy() const { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 424 |
| 425 bool waiting_on_write = false; | 425 bool waiting_on_write = false; |
| 426 do { | 426 do { |
| 427 if (!request_->status().is_success() || bytes_read <= 0) | 427 if (!request_->status().is_success() || bytes_read <= 0) |
| 428 break; | 428 break; |
| 429 | 429 |
| 430 current_response_bytes_ += bytes_read; | 430 current_response_bytes_ += bytes_read; |
| 431 InformDelegateDownloadProgress(); | 431 InformDelegateDownloadProgress(); |
| 432 InformDelegateDownloadDataIfNecessary(bytes_read); | 432 InformDelegateDownloadDataIfNecessary(bytes_read); |
| 433 | 433 |
| 434 const int result = WriteBuffer(new DrainableIOBuffer(buffer_, bytes_read)); | 434 const int result = |
| 435 WriteBuffer(new DrainableIOBuffer(buffer_.get(), bytes_read)); |
| 435 if (result < 0) { | 436 if (result < 0) { |
| 436 // Write failed or waiting for write completion. | 437 // Write failed or waiting for write completion. |
| 437 if (result == ERR_IO_PENDING) | 438 if (result == ERR_IO_PENDING) |
| 438 waiting_on_write = true; | 439 waiting_on_write = true; |
| 439 break; | 440 break; |
| 440 } | 441 } |
| 441 } while (request_->Read(buffer_, kBufferSize, &bytes_read)); | 442 } while (request_->Read(buffer_.get(), kBufferSize, &bytes_read)); |
| 442 | 443 |
| 443 const URLRequestStatus status = request_->status(); | 444 const URLRequestStatus status = request_->status(); |
| 444 | 445 |
| 445 if (status.is_success()) | 446 if (status.is_success()) |
| 446 request_->GetResponseCookies(&cookies_); | 447 request_->GetResponseCookies(&cookies_); |
| 447 | 448 |
| 448 // See comments re: HEAD requests in ReadResponse(). | 449 // See comments re: HEAD requests in ReadResponse(). |
| 449 if ((!status.is_io_pending() && !waiting_on_write) || | 450 if ((!status.is_io_pending() && !waiting_on_write) || |
| 450 (request_type_ == URLFetcher::HEAD)) { | 451 (request_type_ == URLFetcher::HEAD)) { |
| 451 status_ = status; | 452 status_ = status; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 518 |
| 518 void URLFetcherCore::StartURLRequest() { | 519 void URLFetcherCore::StartURLRequest() { |
| 519 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 520 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 520 | 521 |
| 521 if (was_cancelled_) { | 522 if (was_cancelled_) { |
| 522 // Since StartURLRequest() is posted as a *delayed* task, it may | 523 // Since StartURLRequest() is posted as a *delayed* task, it may |
| 523 // run after the URLFetcher was already stopped. | 524 // run after the URLFetcher was already stopped. |
| 524 return; | 525 return; |
| 525 } | 526 } |
| 526 | 527 |
| 527 DCHECK(request_context_getter_); | 528 DCHECK(request_context_getter_.get()); |
| 528 DCHECK(!request_.get()); | 529 DCHECK(!request_.get()); |
| 529 | 530 |
| 530 g_registry.Get().AddURLFetcherCore(this); | 531 g_registry.Get().AddURLFetcherCore(this); |
| 531 current_response_bytes_ = 0; | 532 current_response_bytes_ = 0; |
| 532 request_.reset(request_context_getter_->GetURLRequestContext()->CreateRequest( | 533 request_.reset(request_context_getter_->GetURLRequestContext()->CreateRequest( |
| 533 original_url_, this)); | 534 original_url_, this)); |
| 534 request_->set_stack_trace(stack_trace_); | 535 request_->set_stack_trace(stack_trace_); |
| 535 int flags = request_->load_flags() | load_flags_; | 536 int flags = request_->load_flags() | load_flags_; |
| 536 if (!g_interception_enabled) | 537 if (!g_interception_enabled) |
| 537 flags = flags | LOAD_DISABLE_INTERCEPT; | 538 flags = flags | LOAD_DISABLE_INTERCEPT; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 565 if (!upload_content_type_.empty()) { | 566 if (!upload_content_type_.empty()) { |
| 566 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, | 567 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, |
| 567 upload_content_type_); | 568 upload_content_type_); |
| 568 } | 569 } |
| 569 if (!upload_content_.empty()) { | 570 if (!upload_content_.empty()) { |
| 570 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( | 571 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( |
| 571 upload_content_.data(), upload_content_.size())); | 572 upload_content_.data(), upload_content_.size())); |
| 572 request_->set_upload(make_scoped_ptr( | 573 request_->set_upload(make_scoped_ptr( |
| 573 UploadDataStream::CreateWithReader(reader.Pass(), 0))); | 574 UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
| 574 } else if (!upload_file_path_.empty()) { | 575 } else if (!upload_file_path_.empty()) { |
| 575 scoped_ptr<UploadElementReader> reader(new UploadFileElementReader( | 576 scoped_ptr<UploadElementReader> reader( |
| 576 upload_file_task_runner_, | 577 new UploadFileElementReader(upload_file_task_runner_.get(), |
| 577 upload_file_path_, | 578 upload_file_path_, |
| 578 upload_range_offset_, | 579 upload_range_offset_, |
| 579 upload_range_length_, | 580 upload_range_length_, |
| 580 base::Time())); | 581 base::Time())); |
| 581 request_->set_upload(make_scoped_ptr( | 582 request_->set_upload(make_scoped_ptr( |
| 582 UploadDataStream::CreateWithReader(reader.Pass(), 0))); | 583 UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
| 583 } | 584 } |
| 584 | 585 |
| 585 current_upload_bytes_ = -1; | 586 current_upload_bytes_ = -1; |
| 586 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the | 587 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the |
| 587 // layer and avoid using timer here. | 588 // layer and avoid using timer here. |
| 588 upload_progress_checker_timer_.reset( | 589 upload_progress_checker_timer_.reset( |
| 589 new base::RepeatingTimer<URLFetcherCore>()); | 590 new base::RepeatingTimer<URLFetcherCore>()); |
| 590 upload_progress_checker_timer_->Start( | 591 upload_progress_checker_timer_->Start( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 } | 629 } |
| 629 StartURLRequestWhenAppropriate(); | 630 StartURLRequestWhenAppropriate(); |
| 630 } | 631 } |
| 631 | 632 |
| 632 void URLFetcherCore::StartURLRequestWhenAppropriate() { | 633 void URLFetcherCore::StartURLRequestWhenAppropriate() { |
| 633 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 634 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 634 | 635 |
| 635 if (was_cancelled_) | 636 if (was_cancelled_) |
| 636 return; | 637 return; |
| 637 | 638 |
| 638 DCHECK(request_context_getter_); | 639 DCHECK(request_context_getter_.get()); |
| 639 | 640 |
| 640 int64 delay = 0LL; | 641 int64 delay = 0LL; |
| 641 if (original_url_throttler_entry_ == NULL) { | 642 if (original_url_throttler_entry_.get() == NULL) { |
| 642 URLRequestThrottlerManager* manager = | 643 URLRequestThrottlerManager* manager = |
| 643 request_context_getter_->GetURLRequestContext()->throttler_manager(); | 644 request_context_getter_->GetURLRequestContext()->throttler_manager(); |
| 644 if (manager) { | 645 if (manager) { |
| 645 original_url_throttler_entry_ = | 646 original_url_throttler_entry_ = |
| 646 manager->RegisterRequestUrl(original_url_); | 647 manager->RegisterRequestUrl(original_url_); |
| 647 } | 648 } |
| 648 } | 649 } |
| 649 if (original_url_throttler_entry_ != NULL) { | 650 if (original_url_throttler_entry_.get() != NULL) { |
| 650 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( | 651 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( |
| 651 GetBackoffReleaseTime()); | 652 GetBackoffReleaseTime()); |
| 652 } | 653 } |
| 653 | 654 |
| 654 if (delay == 0) { | 655 if (delay == 0) { |
| 655 StartURLRequest(); | 656 StartURLRequest(); |
| 656 } else { | 657 } else { |
| 657 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 658 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 658 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), | 659 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), |
| 659 base::TimeDelta::FromMilliseconds(delay)); | 660 base::TimeDelta::FromMilliseconds(delay)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 } | 693 } |
| 693 | 694 |
| 694 void URLFetcherCore::InformDelegateFetchIsComplete() { | 695 void URLFetcherCore::InformDelegateFetchIsComplete() { |
| 695 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 696 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 696 if (delegate_) | 697 if (delegate_) |
| 697 delegate_->OnURLFetchComplete(fetcher_); | 698 delegate_->OnURLFetchComplete(fetcher_); |
| 698 } | 699 } |
| 699 | 700 |
| 700 void URLFetcherCore::NotifyMalformedContent() { | 701 void URLFetcherCore::NotifyMalformedContent() { |
| 701 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 702 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 702 if (url_throttler_entry_ != NULL) { | 703 if (url_throttler_entry_.get() != NULL) { |
| 703 int status_code = response_code_; | 704 int status_code = response_code_; |
| 704 if (status_code == URLFetcher::RESPONSE_CODE_INVALID) { | 705 if (status_code == URLFetcher::RESPONSE_CODE_INVALID) { |
| 705 // The status code will generally be known by the time clients | 706 // The status code will generally be known by the time clients |
| 706 // call the |ReceivedContentWasMalformed()| function (which ends up | 707 // call the |ReceivedContentWasMalformed()| function (which ends up |
| 707 // calling the current function) but if it's not, we need to assume | 708 // calling the current function) but if it's not, we need to assume |
| 708 // the response was successful so that the total failure count | 709 // the response was successful so that the total failure count |
| 709 // used to calculate exponential back-off goes up. | 710 // used to calculate exponential back-off goes up. |
| 710 status_code = 200; | 711 status_code = 200; |
| 711 } | 712 } |
| 712 url_throttler_entry_->ReceivedContentWasMalformed(status_code); | 713 url_throttler_entry_->ReceivedContentWasMalformed(status_code); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 782 |
| 782 void URLFetcherCore::ReleaseRequest() { | 783 void URLFetcherCore::ReleaseRequest() { |
| 783 upload_progress_checker_timer_.reset(); | 784 upload_progress_checker_timer_.reset(); |
| 784 request_.reset(); | 785 request_.reset(); |
| 785 g_registry.Get().RemoveURLFetcherCore(this); | 786 g_registry.Get().RemoveURLFetcherCore(this); |
| 786 } | 787 } |
| 787 | 788 |
| 788 base::TimeTicks URLFetcherCore::GetBackoffReleaseTime() { | 789 base::TimeTicks URLFetcherCore::GetBackoffReleaseTime() { |
| 789 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 790 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 790 | 791 |
| 791 if (original_url_throttler_entry_) { | 792 if (original_url_throttler_entry_.get()) { |
| 792 base::TimeTicks original_url_backoff = | 793 base::TimeTicks original_url_backoff = |
| 793 original_url_throttler_entry_->GetExponentialBackoffReleaseTime(); | 794 original_url_throttler_entry_->GetExponentialBackoffReleaseTime(); |
| 794 base::TimeTicks destination_url_backoff; | 795 base::TimeTicks destination_url_backoff; |
| 795 if (url_throttler_entry_ != NULL && | 796 if (url_throttler_entry_.get() != NULL && |
| 796 original_url_throttler_entry_ != url_throttler_entry_) { | 797 original_url_throttler_entry_.get() != url_throttler_entry_.get()) { |
| 797 destination_url_backoff = | 798 destination_url_backoff = |
| 798 url_throttler_entry_->GetExponentialBackoffReleaseTime(); | 799 url_throttler_entry_->GetExponentialBackoffReleaseTime(); |
| 799 } | 800 } |
| 800 | 801 |
| 801 return original_url_backoff > destination_url_backoff ? | 802 return original_url_backoff > destination_url_backoff ? |
| 802 original_url_backoff : destination_url_backoff; | 803 original_url_backoff : destination_url_backoff; |
| 803 } else { | 804 } else { |
| 804 return base::TimeTicks(); | 805 return base::TimeTicks(); |
| 805 } | 806 } |
| 806 } | 807 } |
| 807 | 808 |
| 808 void URLFetcherCore::CompleteAddingUploadDataChunk( | 809 void URLFetcherCore::CompleteAddingUploadDataChunk( |
| 809 const std::string& content, bool is_last_chunk) { | 810 const std::string& content, bool is_last_chunk) { |
| 810 if (was_cancelled_) { | 811 if (was_cancelled_) { |
| 811 // Since CompleteAddingUploadDataChunk() is posted as a *delayed* task, it | 812 // Since CompleteAddingUploadDataChunk() is posted as a *delayed* task, it |
| 812 // may run after the URLFetcher was already stopped. | 813 // may run after the URLFetcher was already stopped. |
| 813 return; | 814 return; |
| 814 } | 815 } |
| 815 DCHECK(is_chunked_upload_); | 816 DCHECK(is_chunked_upload_); |
| 816 DCHECK(request_.get()); | 817 DCHECK(request_.get()); |
| 817 DCHECK(!content.empty()); | 818 DCHECK(!content.empty()); |
| 818 request_->AppendChunkToUpload(content.data(), | 819 request_->AppendChunkToUpload(content.data(), |
| 819 static_cast<int>(content.length()), | 820 static_cast<int>(content.length()), |
| 820 is_last_chunk); | 821 is_last_chunk); |
| 821 } | 822 } |
| 822 | 823 |
| 823 int URLFetcherCore::WriteBuffer(scoped_refptr<DrainableIOBuffer> data) { | 824 int URLFetcherCore::WriteBuffer(scoped_refptr<DrainableIOBuffer> data) { |
| 824 while (data->BytesRemaining() > 0) { | 825 while (data->BytesRemaining() > 0) { |
| 825 const int result = response_writer_->Write( | 826 const int result = response_writer_->Write( |
| 826 data, data->BytesRemaining(), | 827 data.get(), |
| 828 data->BytesRemaining(), |
| 827 base::Bind(&URLFetcherCore::DidWriteBuffer, this, data)); | 829 base::Bind(&URLFetcherCore::DidWriteBuffer, this, data)); |
| 828 if (result < 0) | 830 if (result < 0) |
| 829 return result; | 831 return result; |
| 830 data->DidConsume(result); | 832 data->DidConsume(result); |
| 831 } | 833 } |
| 832 return OK; | 834 return OK; |
| 833 } | 835 } |
| 834 | 836 |
| 835 void URLFetcherCore::DidWriteBuffer(scoped_refptr<DrainableIOBuffer> data, | 837 void URLFetcherCore::DidWriteBuffer(scoped_refptr<DrainableIOBuffer> data, |
| 836 int result) { | 838 int result) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 853 } | 855 } |
| 854 | 856 |
| 855 void URLFetcherCore::ReadResponse() { | 857 void URLFetcherCore::ReadResponse() { |
| 856 // Some servers may treat HEAD requests as GET requests. To free up the | 858 // Some servers may treat HEAD requests as GET requests. To free up the |
| 857 // network connection as soon as possible, signal that the request has | 859 // network connection as soon as possible, signal that the request has |
| 858 // completed immediately, without trying to read any data back (all we care | 860 // completed immediately, without trying to read any data back (all we care |
| 859 // about is the response code and headers, which we already have). | 861 // about is the response code and headers, which we already have). |
| 860 int bytes_read = 0; | 862 int bytes_read = 0; |
| 861 if (request_->status().is_success() && | 863 if (request_->status().is_success() && |
| 862 (request_type_ != URLFetcher::HEAD)) | 864 (request_type_ != URLFetcher::HEAD)) |
| 863 request_->Read(buffer_, kBufferSize, &bytes_read); | 865 request_->Read(buffer_.get(), kBufferSize, &bytes_read); |
| 864 OnReadCompleted(request_.get(), bytes_read); | 866 OnReadCompleted(request_.get(), bytes_read); |
| 865 } | 867 } |
| 866 | 868 |
| 867 void URLFetcherCore::DisownFile() { | 869 void URLFetcherCore::DisownFile() { |
| 868 DCHECK(file_writer_); | 870 DCHECK(file_writer_); |
| 869 file_writer_->DisownFile(); | 871 file_writer_->DisownFile(); |
| 870 } | 872 } |
| 871 | 873 |
| 872 void URLFetcherCore::InformDelegateUploadProgress() { | 874 void URLFetcherCore::InformDelegateUploadProgress() { |
| 873 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 875 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 } | 931 } |
| 930 | 932 |
| 931 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( | 933 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( |
| 932 scoped_ptr<std::string> download_data) { | 934 scoped_ptr<std::string> download_data) { |
| 933 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 935 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 934 if (delegate_) | 936 if (delegate_) |
| 935 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); | 937 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); |
| 936 } | 938 } |
| 937 | 939 |
| 938 } // namespace net | 940 } // namespace net |
| OLD | NEW |