| 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 <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 13 matching lines...) Expand all Loading... |
| 24 #include "net/base/upload_bytes_element_reader.h" | 24 #include "net/base/upload_bytes_element_reader.h" |
| 25 #include "net/base/upload_data_stream.h" | 25 #include "net/base/upload_data_stream.h" |
| 26 #include "net/base/upload_file_element_reader.h" | 26 #include "net/base/upload_file_element_reader.h" |
| 27 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 28 #include "net/url_request/redirect_info.h" | 28 #include "net/url_request/redirect_info.h" |
| 29 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
| 30 #include "net/url_request/url_fetcher_response_writer.h" | 30 #include "net/url_request/url_fetcher_response_writer.h" |
| 31 #include "net/url_request/url_request_context.h" | 31 #include "net/url_request/url_request_context.h" |
| 32 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" |
| 33 #include "net/url_request/url_request_throttler_manager.h" | 33 #include "net/url_request/url_request_throttler_manager.h" |
| 34 #include "url/origin.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 const int kBufferSize = 4096; | 38 const int kBufferSize = 4096; |
| 38 const int kUploadProgressTimerInterval = 100; | 39 const int kUploadProgressTimerInterval = 100; |
| 39 bool g_ignore_certificate_requests = false; | 40 bool g_ignore_certificate_requests = false; |
| 40 | 41 |
| 41 void EmptyCompletionCallback(int result) {} | 42 void EmptyCompletionCallback(int result) {} |
| 42 | 43 |
| 43 } // namespace | 44 } // namespace |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 extra_request_headers_.AddHeaderFromString(header_line); | 240 extra_request_headers_.AddHeaderFromString(header_line); |
| 240 } | 241 } |
| 241 | 242 |
| 242 void URLFetcherCore::SetRequestContext( | 243 void URLFetcherCore::SetRequestContext( |
| 243 URLRequestContextGetter* request_context_getter) { | 244 URLRequestContextGetter* request_context_getter) { |
| 244 DCHECK(!request_context_getter_.get()); | 245 DCHECK(!request_context_getter_.get()); |
| 245 DCHECK(request_context_getter); | 246 DCHECK(request_context_getter); |
| 246 request_context_getter_ = request_context_getter; | 247 request_context_getter_ = request_context_getter; |
| 247 } | 248 } |
| 248 | 249 |
| 249 void URLFetcherCore::SetInitiatorURL(const GURL& initiator) { | 250 void URLFetcherCore::SetInitiator( |
| 250 DCHECK(initiator_.is_empty()); | 251 const base::Optional<url::Origin>& initiator) { |
| 252 DCHECK(!initiator_.has_value()); |
| 251 initiator_ = initiator; | 253 initiator_ = initiator; |
| 252 } | 254 } |
| 253 | 255 |
| 254 void URLFetcherCore::SetURLRequestUserData( | 256 void URLFetcherCore::SetURLRequestUserData( |
| 255 const void* key, | 257 const void* key, |
| 256 const URLFetcher::CreateDataCallback& create_data_callback) { | 258 const URLFetcher::CreateDataCallback& create_data_callback) { |
| 257 DCHECK(key); | 259 DCHECK(key); |
| 258 DCHECK(!create_data_callback.is_null()); | 260 DCHECK(!create_data_callback.is_null()); |
| 259 url_request_data_key_ = key; | 261 url_request_data_key_ = key; |
| 260 url_request_create_data_callback_ = create_data_callback; | 262 url_request_create_data_callback_ = create_data_callback; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 int flags = request_->load_flags() | load_flags_; | 554 int flags = request_->load_flags() | load_flags_; |
| 553 | 555 |
| 554 // TODO(mmenke): This should really be with the other code to set the upload | 556 // TODO(mmenke): This should really be with the other code to set the upload |
| 555 // body, below. | 557 // body, below. |
| 556 if (chunked_stream_) | 558 if (chunked_stream_) |
| 557 request_->set_upload(std::move(chunked_stream_)); | 559 request_->set_upload(std::move(chunked_stream_)); |
| 558 | 560 |
| 559 request_->SetLoadFlags(flags); | 561 request_->SetLoadFlags(flags); |
| 560 request_->SetReferrer(referrer_); | 562 request_->SetReferrer(referrer_); |
| 561 request_->set_referrer_policy(referrer_policy_); | 563 request_->set_referrer_policy(referrer_policy_); |
| 562 request_->set_first_party_for_cookies(initiator_.is_empty() ? original_url_ | 564 request_->set_first_party_for_cookies(initiator_.has_value() && |
| 563 : initiator_); | 565 !initiator_.value().unique() |
| 564 request_->set_initiator(initiator_.is_empty() ? url::Origin(original_url_) | 566 ? initiator_.value().GetURL() |
| 565 : url::Origin(initiator_)); | 567 : original_url_); |
| 568 request_->set_initiator(initiator_); |
| 566 if (url_request_data_key_ && !url_request_create_data_callback_.is_null()) { | 569 if (url_request_data_key_ && !url_request_create_data_callback_.is_null()) { |
| 567 request_->SetUserData(url_request_data_key_, | 570 request_->SetUserData(url_request_data_key_, |
| 568 url_request_create_data_callback_.Run()); | 571 url_request_create_data_callback_.Run()); |
| 569 } | 572 } |
| 570 | 573 |
| 571 switch (request_type_) { | 574 switch (request_type_) { |
| 572 case URLFetcher::GET: | 575 case URLFetcher::GET: |
| 573 break; | 576 break; |
| 574 | 577 |
| 575 case URLFetcher::POST: | 578 case URLFetcher::POST: |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 // URLRequestJob::NotifyDone(). But, because the request was released | 695 // URLRequestJob::NotifyDone(). But, because the request was released |
| 693 // immediately after being canceled, the request could not call | 696 // immediately after being canceled, the request could not call |
| 694 // OnReadCompleted() which overwrites |status_| with the error status. | 697 // OnReadCompleted() which overwrites |status_| with the error status. |
| 695 status_ = URLRequestStatus(URLRequestStatus::CANCELED, error); | 698 status_ = URLRequestStatus(URLRequestStatus::CANCELED, error); |
| 696 | 699 |
| 697 // Release the reference to the request context. There could be multiple | 700 // Release the reference to the request context. There could be multiple |
| 698 // references to URLFetcher::Core at this point so it may take a while to | 701 // references to URLFetcher::Core at this point so it may take a while to |
| 699 // delete the object, but we cannot delay the destruction of the request | 702 // delete the object, but we cannot delay the destruction of the request |
| 700 // context. | 703 // context. |
| 701 request_context_getter_ = NULL; | 704 request_context_getter_ = NULL; |
| 702 initiator_ = GURL(); | 705 initiator_.reset(); |
| 703 url_request_data_key_ = NULL; | 706 url_request_data_key_ = NULL; |
| 704 url_request_create_data_callback_.Reset(); | 707 url_request_create_data_callback_.Reset(); |
| 705 was_cancelled_ = true; | 708 was_cancelled_ = true; |
| 706 } | 709 } |
| 707 | 710 |
| 708 void URLFetcherCore::OnCompletedURLRequest( | 711 void URLFetcherCore::OnCompletedURLRequest( |
| 709 base::TimeDelta backoff_delay) { | 712 base::TimeDelta backoff_delay) { |
| 710 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 713 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 711 | 714 |
| 712 // Save the status and backoff_delay so that delegates can read it. | 715 // Save the status and backoff_delay so that delegates can read it. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 ++num_retries_on_network_changes_; | 786 ++num_retries_on_network_changes_; |
| 784 | 787 |
| 785 // Retry soon, after flushing all the current tasks which may include | 788 // Retry soon, after flushing all the current tasks which may include |
| 786 // further network change observers. | 789 // further network change observers. |
| 787 network_task_runner_->PostTask( | 790 network_task_runner_->PostTask( |
| 788 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); | 791 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); |
| 789 return; | 792 return; |
| 790 } | 793 } |
| 791 | 794 |
| 792 request_context_getter_ = NULL; | 795 request_context_getter_ = NULL; |
| 793 initiator_ = GURL(); | 796 initiator_.reset(); |
| 794 url_request_data_key_ = NULL; | 797 url_request_data_key_ = NULL; |
| 795 url_request_create_data_callback_.Reset(); | 798 url_request_create_data_callback_.Reset(); |
| 796 bool posted = delegate_task_runner_->PostTask( | 799 bool posted = delegate_task_runner_->PostTask( |
| 797 FROM_HERE, | 800 FROM_HERE, |
| 798 base::Bind(&URLFetcherCore::OnCompletedURLRequest, this, backoff_delay)); | 801 base::Bind(&URLFetcherCore::OnCompletedURLRequest, this, backoff_delay)); |
| 799 | 802 |
| 800 // If the delegate message loop does not exist any more, then the delegate | 803 // If the delegate message loop does not exist any more, then the delegate |
| 801 // should be gone too. | 804 // should be gone too. |
| 802 DCHECK(posted || !delegate_); | 805 DCHECK(posted || !delegate_); |
| 803 } | 806 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 } | 952 } |
| 950 | 953 |
| 951 void URLFetcherCore::AssertHasNoUploadData() const { | 954 void URLFetcherCore::AssertHasNoUploadData() const { |
| 952 DCHECK(!upload_content_set_); | 955 DCHECK(!upload_content_set_); |
| 953 DCHECK(upload_content_.empty()); | 956 DCHECK(upload_content_.empty()); |
| 954 DCHECK(upload_file_path_.empty()); | 957 DCHECK(upload_file_path_.empty()); |
| 955 DCHECK(upload_stream_factory_.is_null()); | 958 DCHECK(upload_stream_factory_.is_null()); |
| 956 } | 959 } |
| 957 | 960 |
| 958 } // namespace net | 961 } // namespace net |
| OLD | NEW |