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

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

Issue 122453002: Allows deferral of a URLRequest just before talking to the network, at (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Potential fix of a memory leak due to a reference cycle. Created 6 years, 11 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 SSLCertRequestInfo* cert_request_info) { 191 SSLCertRequestInfo* cert_request_info) {
192 request->Cancel(); 192 request->Cancel();
193 } 193 }
194 194
195 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, 195 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request,
196 const SSLInfo& ssl_info, 196 const SSLInfo& ssl_info,
197 bool is_hsts_ok) { 197 bool is_hsts_ok) {
198 request->Cancel(); 198 request->Cancel();
199 } 199 }
200 200
201 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request,
202 bool* defer) {
203 }
204
201 /////////////////////////////////////////////////////////////////////////////// 205 ///////////////////////////////////////////////////////////////////////////////
202 // URLRequest 206 // URLRequest
203 207
204 URLRequest::URLRequest(const GURL& url, 208 URLRequest::URLRequest(const GURL& url,
205 RequestPriority priority, 209 RequestPriority priority,
206 Delegate* delegate, 210 Delegate* delegate,
207 const URLRequestContext* context) 211 const URLRequestContext* context)
208 : context_(context), 212 : context_(context),
209 network_delegate_(context->network_delegate()), 213 network_delegate_(context->network_delegate()),
210 net_log_(BoundNetLog::Make(context->net_log(), 214 net_log_(BoundNetLog::Make(context->net_log(),
211 NetLog::SOURCE_URL_REQUEST)), 215 NetLog::SOURCE_URL_REQUEST)),
212 url_chain_(1, url), 216 url_chain_(1, url),
213 method_("GET"), 217 method_("GET"),
214 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), 218 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
215 load_flags_(LOAD_NORMAL), 219 load_flags_(LOAD_NORMAL),
216 delegate_(delegate), 220 delegate_(delegate),
217 is_pending_(false), 221 is_pending_(false),
218 is_redirecting_(false), 222 is_redirecting_(false),
219 redirect_limit_(kMaxRedirects), 223 redirect_limit_(kMaxRedirects),
220 priority_(priority), 224 priority_(priority),
221 identifier_(GenerateURLRequestIdentifier()), 225 identifier_(GenerateURLRequestIdentifier()),
222 calling_delegate_(false), 226 calling_delegate_(false),
223 use_blocked_by_as_load_param_(false), 227 use_blocked_by_as_load_param_(false),
224 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, 228 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete,
225 base::Unretained(this))), 229 base::Unretained(this))),
226 has_notified_completion_(false), 230 has_notified_completion_(false),
227 received_response_content_length_(0), 231 received_response_content_length_(0),
228 creation_time_(base::TimeTicks::Now()) { 232 creation_time_(base::TimeTicks::Now()),
233 notified_before_network_start_(false) {
229 SIMPLE_STATS_COUNTER("URLRequestCount"); 234 SIMPLE_STATS_COUNTER("URLRequestCount");
230 235
231 // Sanity check out environment. 236 // Sanity check out environment.
232 DCHECK(base::MessageLoop::current()) 237 DCHECK(base::MessageLoop::current())
233 << "The current base::MessageLoop must exist"; 238 << "The current base::MessageLoop must exist";
234 239
235 CHECK(context); 240 CHECK(context);
236 context->url_requests()->insert(this); 241 context->url_requests()->insert(this);
237 242
238 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); 243 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 this, network_delegate_, location); 822 this, network_delegate_, location);
818 if (job) { 823 if (job) {
819 RestartWithJob(job); 824 RestartWithJob(job);
820 } else if (delegate_) { 825 } else if (delegate_) {
821 OnCallToDelegate(); 826 OnCallToDelegate();
822 delegate_->OnReceivedRedirect(this, location, defer_redirect); 827 delegate_->OnReceivedRedirect(this, location, defer_redirect);
823 // |this| may be have been destroyed here. 828 // |this| may be have been destroyed here.
824 } 829 }
825 } 830 }
826 831
832 void URLRequest::NotifyBeforeNetworkStart(bool* defer) {
833 if (delegate_ && !notified_before_network_start_) {
834 OnCallToDelegate();
835 delegate_->OnBeforeNetworkStart(this, defer);
836 if (!*defer)
837 OnCallToDelegateComplete();
838 notified_before_network_start_ = true;
839 }
840 }
841
842 void URLRequest::ResumeNetworkStart() {
843 DCHECK(job_);
844 DCHECK(notified_before_network_start_);
845
846 OnCallToDelegateComplete();
847 job_->ResumeNetworkStart();
848 }
849
827 void URLRequest::NotifyResponseStarted() { 850 void URLRequest::NotifyResponseStarted() {
828 int net_error = OK; 851 int net_error = OK;
829 if (!status_.is_success()) 852 if (!status_.is_success())
830 net_error = status_.error(); 853 net_error = status_.error();
831 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB, 854 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB,
832 net_error); 855 net_error);
833 856
834 URLRequestJob* job = 857 URLRequestJob* job =
835 URLRequestJobManager::GetInstance()->MaybeInterceptResponse( 858 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(
836 this, network_delegate_); 859 this, network_delegate_);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 new base::debug::StackTrace(NULL, 0); 1226 new base::debug::StackTrace(NULL, 0);
1204 *stack_trace_copy = stack_trace; 1227 *stack_trace_copy = stack_trace;
1205 stack_trace_.reset(stack_trace_copy); 1228 stack_trace_.reset(stack_trace_copy);
1206 } 1229 }
1207 1230
1208 const base::debug::StackTrace* URLRequest::stack_trace() const { 1231 const base::debug::StackTrace* URLRequest::stack_trace() const {
1209 return stack_trace_.get(); 1232 return stack_trace_.get();
1210 } 1233 }
1211 1234
1212 } // namespace net 1235 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698