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

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

Issue 2480563002: Remove URLRequest::OrphanJob(). (Closed)
Patch Set: Response to comments Created 4 years, 1 month 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_request.h ('k') | net/url_request/url_request_http_job.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_request.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 URLRequest::~URLRequest() { 176 URLRequest::~URLRequest() {
177 Cancel(); 177 Cancel();
178 178
179 if (network_delegate_) { 179 if (network_delegate_) {
180 network_delegate_->NotifyURLRequestDestroyed(this); 180 network_delegate_->NotifyURLRequestDestroyed(this);
181 if (job_.get()) 181 if (job_.get())
182 job_->NotifyURLRequestDestroyed(); 182 job_->NotifyURLRequestDestroyed();
183 } 183 }
184 184
185 if (job_.get()) 185 // Delete job before |this|, since subclasses may do weird things, like depend
186 OrphanJob(); 186 // on UserData associated with |this| and poke at it during teardown.
187 job_.reset();
187 188
188 int deleted = context_->url_requests()->erase(this); 189 DCHECK_EQ(1u, context_->url_requests()->count(this));
189 CHECK_EQ(1, deleted); 190 context_->url_requests()->erase(this);
190 191
191 int net_error = OK; 192 int net_error = OK;
192 // Log error only on failure, not cancellation, as even successful requests 193 // Log error only on failure, not cancellation, as even successful requests
193 // are "cancelled" on destruction. 194 // are "cancelled" on destruction.
194 if (status_.status() == URLRequestStatus::FAILED) 195 if (status_.status() == URLRequestStatus::FAILED)
195 net_error = status_.error(); 196 net_error = status_.error();
196 net_log_.EndEventWithNetErrorCode(NetLogEventType::REQUEST_ALIVE, net_error); 197 net_log_.EndEventWithNetErrorCode(NetLogEventType::REQUEST_ALIVE, net_error);
197 } 198 }
198 199
199 void URLRequest::set_upload(std::unique_ptr<UploadDataStream> upload) { 200 void URLRequest::set_upload(std::unique_ptr<UploadDataStream> upload) {
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 job_->ContinueDespiteLastError(); 889 job_->ContinueDespiteLastError();
889 } 890 }
890 891
891 void URLRequest::PrepareToRestart() { 892 void URLRequest::PrepareToRestart() {
892 DCHECK(job_.get()); 893 DCHECK(job_.get());
893 894
894 // Close the current URL_REQUEST_START_JOB, since we will be starting a new 895 // Close the current URL_REQUEST_START_JOB, since we will be starting a new
895 // one. 896 // one.
896 net_log_.EndEvent(NetLogEventType::URL_REQUEST_START_JOB); 897 net_log_.EndEvent(NetLogEventType::URL_REQUEST_START_JOB);
897 898
898 OrphanJob(); 899 job_.reset();
899 900
900 response_info_ = HttpResponseInfo(); 901 response_info_ = HttpResponseInfo();
901 response_info_.request_time = base::Time::Now(); 902 response_info_.request_time = base::Time::Now();
902 903
903 load_timing_info_ = LoadTimingInfo(); 904 load_timing_info_ = LoadTimingInfo();
904 load_timing_info_.request_start_time = response_info_.request_time; 905 load_timing_info_.request_start_time = response_info_.request_time;
905 load_timing_info_.request_start = base::TimeTicks::Now(); 906 load_timing_info_.request_start = base::TimeTicks::Now();
906 907
907 status_ = URLRequestStatus(); 908 status_ = URLRequestStatus();
908 is_pending_ = false; 909 is_pending_ = false;
909 proxy_server_ = ProxyServer(); 910 proxy_server_ = ProxyServer();
910 } 911 }
911 912
912 void URLRequest::OrphanJob() {
913 // When calling this function, please check that URLRequestHttpJob is
914 // not in between calling NetworkDelegate::NotifyHeadersReceived receiving
915 // the call back. This is currently guaranteed by the following strategies:
916 // - OrphanJob is called on JobRestart, in this case the URLRequestJob cannot
917 // be receiving any headers at that time.
918 // - OrphanJob is called in ~URLRequest, in this case
919 // NetworkDelegate::NotifyURLRequestDestroyed notifies the NetworkDelegate
920 // that the callback becomes invalid.
921 job_->Kill();
922 job_ = NULL;
923 }
924
925 int URLRequest::Redirect(const RedirectInfo& redirect_info) { 913 int URLRequest::Redirect(const RedirectInfo& redirect_info) {
926 // Matches call in NotifyReceivedRedirect. 914 // Matches call in NotifyReceivedRedirect.
927 OnCallToDelegateComplete(); 915 OnCallToDelegateComplete();
928 if (net_log_.IsCapturing()) { 916 if (net_log_.IsCapturing()) {
929 net_log_.AddEvent( 917 net_log_.AddEvent(
930 NetLogEventType::URL_REQUEST_REDIRECTED, 918 NetLogEventType::URL_REQUEST_REDIRECTED,
931 NetLog::StringCallback("location", 919 NetLog::StringCallback("location",
932 &redirect_info.new_url.possibly_invalid_spec())); 920 &redirect_info.new_url.possibly_invalid_spec()));
933 } 921 }
934 922
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 out->clear(); 1211 out->clear();
1224 } 1212 }
1225 1213
1226 void URLRequest::set_status(URLRequestStatus status) { 1214 void URLRequest::set_status(URLRequestStatus status) {
1227 DCHECK(status_.is_io_pending() || status_.is_success() || 1215 DCHECK(status_.is_io_pending() || status_.is_success() ||
1228 (!status.is_success() && !status.is_io_pending())); 1216 (!status.is_success() && !status.is_io_pending()));
1229 status_ = status; 1217 status_ = status;
1230 } 1218 }
1231 1219
1232 } // namespace net 1220 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698