Chromium Code Reviews| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 extra_request_headers_.AddHeaderFromString(header_line); | 238 extra_request_headers_.AddHeaderFromString(header_line); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void URLFetcherCore::SetRequestContext( | 241 void URLFetcherCore::SetRequestContext( |
| 242 URLRequestContextGetter* request_context_getter) { | 242 URLRequestContextGetter* request_context_getter) { |
| 243 DCHECK(!request_context_getter_.get()); | 243 DCHECK(!request_context_getter_.get()); |
| 244 DCHECK(request_context_getter); | 244 DCHECK(request_context_getter); |
| 245 request_context_getter_ = request_context_getter; | 245 request_context_getter_ = request_context_getter; |
| 246 } | 246 } |
| 247 | 247 |
| 248 void URLFetcherCore::SetFirstPartyForCookies( | 248 void URLFetcherCore::SetInitiatorURL(const GURL& initiator) { |
| 249 const GURL& first_party_for_cookies) { | 249 DCHECK(initiator_.is_empty()); |
| 250 DCHECK(first_party_for_cookies_.is_empty()); | 250 initiator_ = initiator; |
| 251 first_party_for_cookies_ = first_party_for_cookies; | |
| 252 } | 251 } |
| 253 | 252 |
| 254 void URLFetcherCore::SetURLRequestUserData( | 253 void URLFetcherCore::SetURLRequestUserData( |
| 255 const void* key, | 254 const void* key, |
| 256 const URLFetcher::CreateDataCallback& create_data_callback) { | 255 const URLFetcher::CreateDataCallback& create_data_callback) { |
| 257 DCHECK(key); | 256 DCHECK(key); |
| 258 DCHECK(!create_data_callback.is_null()); | 257 DCHECK(!create_data_callback.is_null()); |
| 259 url_request_data_key_ = key; | 258 url_request_data_key_ = key; |
| 260 url_request_create_data_callback_ = create_data_callback; | 259 url_request_create_data_callback_ = create_data_callback; |
| 261 } | 260 } |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 request_ = request_context_getter_->GetURLRequestContext()->CreateRequest( | 548 request_ = request_context_getter_->GetURLRequestContext()->CreateRequest( |
| 550 original_url_, DEFAULT_PRIORITY, this); | 549 original_url_, DEFAULT_PRIORITY, this); |
| 551 request_->set_stack_trace(stack_trace_); | 550 request_->set_stack_trace(stack_trace_); |
| 552 int flags = request_->load_flags() | load_flags_; | 551 int flags = request_->load_flags() | load_flags_; |
| 553 | 552 |
| 554 if (is_chunked_upload_) | 553 if (is_chunked_upload_) |
| 555 request_->EnableChunkedUpload(); | 554 request_->EnableChunkedUpload(); |
| 556 request_->SetLoadFlags(flags); | 555 request_->SetLoadFlags(flags); |
| 557 request_->SetReferrer(referrer_); | 556 request_->SetReferrer(referrer_); |
| 558 request_->set_referrer_policy(referrer_policy_); | 557 request_->set_referrer_policy(referrer_policy_); |
| 559 request_->set_first_party_for_cookies(first_party_for_cookies_.is_empty() ? | 558 request_->set_first_party_for_cookies(initiator_.is_empty() ? original_url_ |
| 560 original_url_ : first_party_for_cookies_); | 559 : initiator_); |
|
mmenke
2016/01/14 16:47:42
Hrm...wasn't even aware of this code. :(
| |
| 560 request_->set_initiator(initiator_.is_empty() ? url::Origin(original_url_) | |
| 561 : url::Origin(initiator_)); | |
| 561 if (url_request_data_key_ && !url_request_create_data_callback_.is_null()) { | 562 if (url_request_data_key_ && !url_request_create_data_callback_.is_null()) { |
| 562 request_->SetUserData(url_request_data_key_, | 563 request_->SetUserData(url_request_data_key_, |
| 563 url_request_create_data_callback_.Run()); | 564 url_request_create_data_callback_.Run()); |
| 564 } | 565 } |
| 565 | 566 |
| 566 switch (request_type_) { | 567 switch (request_type_) { |
| 567 case URLFetcher::GET: | 568 case URLFetcher::GET: |
| 568 break; | 569 break; |
| 569 | 570 |
| 570 case URLFetcher::POST: | 571 case URLFetcher::POST: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 // URLRequestJob::NotifyDone(). But, because the request was released | 690 // URLRequestJob::NotifyDone(). But, because the request was released |
| 690 // immediately after being canceled, the request could not call | 691 // immediately after being canceled, the request could not call |
| 691 // OnReadCompleted() which overwrites |status_| with the error status. | 692 // OnReadCompleted() which overwrites |status_| with the error status. |
| 692 status_ = URLRequestStatus(URLRequestStatus::CANCELED, error); | 693 status_ = URLRequestStatus(URLRequestStatus::CANCELED, error); |
| 693 | 694 |
| 694 // Release the reference to the request context. There could be multiple | 695 // Release the reference to the request context. There could be multiple |
| 695 // references to URLFetcher::Core at this point so it may take a while to | 696 // references to URLFetcher::Core at this point so it may take a while to |
| 696 // delete the object, but we cannot delay the destruction of the request | 697 // delete the object, but we cannot delay the destruction of the request |
| 697 // context. | 698 // context. |
| 698 request_context_getter_ = NULL; | 699 request_context_getter_ = NULL; |
| 699 first_party_for_cookies_ = GURL(); | 700 initiator_ = GURL(); |
| 700 url_request_data_key_ = NULL; | 701 url_request_data_key_ = NULL; |
| 701 url_request_create_data_callback_.Reset(); | 702 url_request_create_data_callback_.Reset(); |
| 702 was_cancelled_ = true; | 703 was_cancelled_ = true; |
| 703 } | 704 } |
| 704 | 705 |
| 705 void URLFetcherCore::OnCompletedURLRequest( | 706 void URLFetcherCore::OnCompletedURLRequest( |
| 706 base::TimeDelta backoff_delay) { | 707 base::TimeDelta backoff_delay) { |
| 707 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 708 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 708 | 709 |
| 709 // Save the status and backoff_delay so that delegates can read it. | 710 // 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... | |
| 780 ++num_retries_on_network_changes_; | 781 ++num_retries_on_network_changes_; |
| 781 | 782 |
| 782 // Retry soon, after flushing all the current tasks which may include | 783 // Retry soon, after flushing all the current tasks which may include |
| 783 // further network change observers. | 784 // further network change observers. |
| 784 network_task_runner_->PostTask( | 785 network_task_runner_->PostTask( |
| 785 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); | 786 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); |
| 786 return; | 787 return; |
| 787 } | 788 } |
| 788 | 789 |
| 789 request_context_getter_ = NULL; | 790 request_context_getter_ = NULL; |
| 790 first_party_for_cookies_ = GURL(); | 791 initiator_ = GURL(); |
| 791 url_request_data_key_ = NULL; | 792 url_request_data_key_ = NULL; |
| 792 url_request_create_data_callback_.Reset(); | 793 url_request_create_data_callback_.Reset(); |
| 793 bool posted = delegate_task_runner_->PostTask( | 794 bool posted = delegate_task_runner_->PostTask( |
| 794 FROM_HERE, | 795 FROM_HERE, |
| 795 base::Bind(&URLFetcherCore::OnCompletedURLRequest, this, backoff_delay)); | 796 base::Bind(&URLFetcherCore::OnCompletedURLRequest, this, backoff_delay)); |
| 796 | 797 |
| 797 // If the delegate message loop does not exist any more, then the delegate | 798 // If the delegate message loop does not exist any more, then the delegate |
| 798 // should be gone too. | 799 // should be gone too. |
| 799 DCHECK(posted || !delegate_); | 800 DCHECK(posted || !delegate_); |
| 800 } | 801 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 } | 953 } |
| 953 | 954 |
| 954 void URLFetcherCore::AssertHasNoUploadData() const { | 955 void URLFetcherCore::AssertHasNoUploadData() const { |
| 955 DCHECK(!upload_content_set_); | 956 DCHECK(!upload_content_set_); |
| 956 DCHECK(upload_content_.empty()); | 957 DCHECK(upload_content_.empty()); |
| 957 DCHECK(upload_file_path_.empty()); | 958 DCHECK(upload_file_path_.empty()); |
| 958 DCHECK(upload_stream_factory_.is_null()); | 959 DCHECK(upload_stream_factory_.is_null()); |
| 959 } | 960 } |
| 960 | 961 |
| 961 } // namespace net | 962 } // namespace net |
| OLD | NEW |