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

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: Formatting nits 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 *defer = false;
mmenke 2014/01/07 15:26:23 "OnReceivedRedirect" assumes defer is initialized
jkarlin 2014/01/07 16:19:32 Done.
204 }
205
201 /////////////////////////////////////////////////////////////////////////////// 206 ///////////////////////////////////////////////////////////////////////////////
202 // URLRequest 207 // URLRequest
203 208
204 URLRequest::URLRequest(const GURL& url, 209 URLRequest::URLRequest(const GURL& url,
205 RequestPriority priority, 210 RequestPriority priority,
206 Delegate* delegate, 211 Delegate* delegate,
207 const URLRequestContext* context) 212 const URLRequestContext* context)
208 : context_(context), 213 : context_(context),
209 network_delegate_(context->network_delegate()), 214 network_delegate_(context->network_delegate()),
210 net_log_(BoundNetLog::Make(context->net_log(), 215 net_log_(BoundNetLog::Make(context->net_log(),
211 NetLog::SOURCE_URL_REQUEST)), 216 NetLog::SOURCE_URL_REQUEST)),
212 url_chain_(1, url), 217 url_chain_(1, url),
213 method_("GET"), 218 method_("GET"),
214 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), 219 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
215 load_flags_(LOAD_NORMAL), 220 load_flags_(LOAD_NORMAL),
216 delegate_(delegate), 221 delegate_(delegate),
217 is_pending_(false), 222 is_pending_(false),
218 is_redirecting_(false), 223 is_redirecting_(false),
219 redirect_limit_(kMaxRedirects), 224 redirect_limit_(kMaxRedirects),
220 priority_(priority), 225 priority_(priority),
221 identifier_(GenerateURLRequestIdentifier()), 226 identifier_(GenerateURLRequestIdentifier()),
222 calling_delegate_(false), 227 calling_delegate_(false),
223 use_blocked_by_as_load_param_(false), 228 use_blocked_by_as_load_param_(false),
224 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, 229 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete,
225 base::Unretained(this))), 230 base::Unretained(this))),
226 has_notified_completion_(false), 231 has_notified_completion_(false),
227 received_response_content_length_(0), 232 received_response_content_length_(0),
228 creation_time_(base::TimeTicks::Now()) { 233 creation_time_(base::TimeTicks::Now()),
234 notified_before_network_start_(false) {
229 SIMPLE_STATS_COUNTER("URLRequestCount"); 235 SIMPLE_STATS_COUNTER("URLRequestCount");
230 236
231 // Sanity check out environment. 237 // Sanity check out environment.
232 DCHECK(base::MessageLoop::current()) 238 DCHECK(base::MessageLoop::current())
233 << "The current base::MessageLoop must exist"; 239 << "The current base::MessageLoop must exist";
234 240
235 CHECK(context); 241 CHECK(context);
236 context->url_requests()->insert(this); 242 context->url_requests()->insert(this);
237 243
238 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); 244 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 this, network_delegate_, location); 823 this, network_delegate_, location);
818 if (job) { 824 if (job) {
819 RestartWithJob(job); 825 RestartWithJob(job);
820 } else if (delegate_) { 826 } else if (delegate_) {
821 OnCallToDelegate(); 827 OnCallToDelegate();
822 delegate_->OnReceivedRedirect(this, location, defer_redirect); 828 delegate_->OnReceivedRedirect(this, location, defer_redirect);
823 // |this| may be have been destroyed here. 829 // |this| may be have been destroyed here.
824 } 830 }
825 } 831 }
826 832
833 void URLRequest::NotifyBeforeNetworkStart(bool* defer) {
834 if (delegate_ && !notified_before_network_start_) {
835 notified_before_network_start_ = true;
836 OnCallToDelegate();
837 delegate_->OnBeforeNetworkStart(this, defer);
838 if (!(*defer))
mmenke 2014/01/07 15:26:23 optional nit: I think !*defer is more common in n
jkarlin 2014/01/07 16:19:32 Done.
839 OnCallToDelegateComplete();
840 }
841 }
842
843 void URLRequest::ResumeNetworkStart() {
844 DCHECK(job_);
mmenke 2014/01/07 15:26:23 Maybe DCHECK(notified_network_create_stream_);? I
jkarlin 2014/01/07 16:19:32 Done.
845 OnCallToDelegateComplete();
846 job_->ResumeNetworkStart();
847 }
848
827 void URLRequest::NotifyResponseStarted() { 849 void URLRequest::NotifyResponseStarted() {
828 int net_error = OK; 850 int net_error = OK;
829 if (!status_.is_success()) 851 if (!status_.is_success())
830 net_error = status_.error(); 852 net_error = status_.error();
831 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB, 853 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB,
832 net_error); 854 net_error);
833 855
834 URLRequestJob* job = 856 URLRequestJob* job =
835 URLRequestJobManager::GetInstance()->MaybeInterceptResponse( 857 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(
836 this, network_delegate_); 858 this, network_delegate_);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 new base::debug::StackTrace(NULL, 0); 1225 new base::debug::StackTrace(NULL, 0);
1204 *stack_trace_copy = stack_trace; 1226 *stack_trace_copy = stack_trace;
1205 stack_trace_.reset(stack_trace_copy); 1227 stack_trace_.reset(stack_trace_copy);
1206 } 1228 }
1207 1229
1208 const base::debug::StackTrace* URLRequest::stack_trace() const { 1230 const base::debug::StackTrace* URLRequest::stack_trace() const {
1209 return stack_trace_.get(); 1231 return stack_trace_.get();
1210 } 1232 }
1211 1233
1212 } // namespace net 1234 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698