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 407093011: Allow URLRequests from one context to have different NetworkDelegates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: And fix more stuff... Created 6 years, 5 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 | Annotate | Revision Log
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request, 193 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request,
194 bool* defer) { 194 bool* defer) {
195 } 195 }
196 196
197 /////////////////////////////////////////////////////////////////////////////// 197 ///////////////////////////////////////////////////////////////////////////////
198 // URLRequest 198 // URLRequest
199 199
200 URLRequest::URLRequest(const GURL& url, 200 URLRequest::URLRequest(const GURL& url,
201 RequestPriority priority, 201 RequestPriority priority,
202 Delegate* delegate, 202 Delegate* delegate,
203 const URLRequestContext* context)
204 : identifier_(GenerateURLRequestIdentifier()) {
205 Init(url, priority, delegate, context, NULL);
206 }
207
208 URLRequest::URLRequest(const GURL& url,
209 RequestPriority priority,
210 Delegate* delegate,
211 const URLRequestContext* context, 203 const URLRequestContext* context,
212 CookieStore* cookie_store) 204 CookieStore* cookie_store,
213 : identifier_(GenerateURLRequestIdentifier()) { 205 NetworkDelegate* network_delegate)
214 Init(url, priority, delegate, context, cookie_store); 206 : context_(context),
207 network_delegate_(network_delegate ? network_delegate
208 : context->network_delegate()),
209 net_log_(BoundNetLog::Make(context->net_log(),
210 NetLog::SOURCE_URL_REQUEST)),
211 url_chain_(1, url),
212 method_("GET"),
213 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
214 load_flags_(LOAD_NORMAL),
215 delegate_(delegate),
216 is_pending_(false),
217 is_redirecting_(false),
218 redirect_limit_(kMaxRedirects),
219 priority_(priority),
220 identifier_(GenerateURLRequestIdentifier()),
221 calling_delegate_(false),
222 use_blocked_by_as_load_param_(false),
223 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete,
224 base::Unretained(this))),
225 has_notified_completion_(false),
226 received_response_content_length_(0),
227 creation_time_(base::TimeTicks::Now()),
228 notified_before_network_start_(false),
229 cookie_store_(cookie_store ? cookie_store : context->cookie_store()) {
230 SIMPLE_STATS_COUNTER("URLRequestCount");
231
232 // Sanity check out environment.
233 DCHECK(base::MessageLoop::current())
234 << "The current base::MessageLoop must exist";
235
236 DCHECK(context);
pauljensen 2014/07/31 15:38:17 I see you lightened this from CHECK to DCHECK. I
mmenke 2014/07/31 16:03:14 Done.
237 context->url_requests()->insert(this);
238
239 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
215 } 240 }
216 241
217 URLRequest::~URLRequest() { 242 URLRequest::~URLRequest() {
218 Cancel(); 243 Cancel();
219 244
220 if (network_delegate_) { 245 if (network_delegate_) {
221 network_delegate_->NotifyURLRequestDestroyed(this); 246 network_delegate_->NotifyURLRequestDestroyed(this);
222 if (job_.get()) 247 if (job_.get())
223 job_->NotifyURLRequestDestroyed(); 248 job_->NotifyURLRequestDestroyed();
224 } 249 }
(...skipping 16 matching lines...) Expand all
241 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { 266 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) {
242 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); 267 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor);
243 } 268 }
244 269
245 // static 270 // static
246 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { 271 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) {
247 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( 272 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor(
248 interceptor); 273 interceptor);
249 } 274 }
250 275
251 void URLRequest::Init(const GURL& url,
252 RequestPriority priority,
253 Delegate* delegate,
254 const URLRequestContext* context,
255 CookieStore* cookie_store) {
256 context_ = context;
257 network_delegate_ = context->network_delegate();
258 net_log_ = BoundNetLog::Make(context->net_log(), NetLog::SOURCE_URL_REQUEST);
259 url_chain_.push_back(url);
260 method_ = "GET";
261 referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
262 load_flags_ = LOAD_NORMAL;
263 delegate_ = delegate;
264 is_pending_ = false;
265 is_redirecting_ = false;
266 redirect_limit_ = kMaxRedirects;
267 priority_ = priority;
268 calling_delegate_ = false;
269 use_blocked_by_as_load_param_ =false;
270 before_request_callback_ = base::Bind(&URLRequest::BeforeRequestComplete,
271 base::Unretained(this));
272 has_notified_completion_ = false;
273 received_response_content_length_ = 0;
274 creation_time_ = base::TimeTicks::Now();
275 notified_before_network_start_ = false;
276
277 SIMPLE_STATS_COUNTER("URLRequestCount");
278
279 // Sanity check out environment.
280 DCHECK(base::MessageLoop::current())
281 << "The current base::MessageLoop must exist";
282
283 CHECK(context);
284 context->url_requests()->insert(this);
285 cookie_store_ = cookie_store;
286 if (cookie_store_ == NULL)
287 cookie_store_ = context->cookie_store();
288
289 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
290 }
291
292 void URLRequest::EnableChunkedUpload() { 276 void URLRequest::EnableChunkedUpload() {
293 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); 277 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked());
294 if (!upload_data_stream_) { 278 if (!upload_data_stream_) {
295 upload_data_stream_.reset( 279 upload_data_stream_.reset(
296 new UploadDataStream(UploadDataStream::CHUNKED, 0)); 280 new UploadDataStream(UploadDataStream::CHUNKED, 0));
297 } 281 }
298 } 282 }
299 283
300 void URLRequest::AppendChunkToUpload(const char* bytes, 284 void URLRequest::AppendChunkToUpload(const char* bytes,
301 int bytes_len, 285 int bytes_len,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 591 }
608 592
609 void URLRequest::set_delegate(Delegate* delegate) { 593 void URLRequest::set_delegate(Delegate* delegate) {
610 delegate_ = delegate; 594 delegate_ = delegate;
611 } 595 }
612 596
613 void URLRequest::Start() { 597 void URLRequest::Start() {
614 // Some values can be NULL, but the job factory must not be. 598 // Some values can be NULL, but the job factory must not be.
615 DCHECK(context_->job_factory()); 599 DCHECK(context_->job_factory());
616 600
617 DCHECK_EQ(network_delegate_, context_->network_delegate());
618 // Anything that sets |blocked_by_| before start should have cleaned up after 601 // Anything that sets |blocked_by_| before start should have cleaned up after
619 // itself. 602 // itself.
620 DCHECK(blocked_by_.empty()); 603 DCHECK(blocked_by_.empty());
621 604
622 g_url_requests_started = true; 605 g_url_requests_started = true;
623 response_info_.request_time = base::Time::Now(); 606 response_info_.request_time = base::Time::Now();
624 607
625 load_timing_info_ = LoadTimingInfo(); 608 load_timing_info_ = LoadTimingInfo();
626 load_timing_info_.request_start_time = response_info_.request_time; 609 load_timing_info_.request_start_time = response_info_.request_time;
627 load_timing_info_.request_start = base::TimeTicks::Now(); 610 load_timing_info_.request_start = base::TimeTicks::Now();
(...skipping 12 matching lines...) Expand all
640 623
641 StartJob(URLRequestJobManager::GetInstance()->CreateJob( 624 StartJob(URLRequestJobManager::GetInstance()->CreateJob(
642 this, network_delegate_)); 625 this, network_delegate_));
643 } 626 }
644 627
645 /////////////////////////////////////////////////////////////////////////////// 628 ///////////////////////////////////////////////////////////////////////////////
646 629
647 void URLRequest::BeforeRequestComplete(int error) { 630 void URLRequest::BeforeRequestComplete(int error) {
648 DCHECK(!job_.get()); 631 DCHECK(!job_.get());
649 DCHECK_NE(ERR_IO_PENDING, error); 632 DCHECK_NE(ERR_IO_PENDING, error);
650 DCHECK_EQ(network_delegate_, context_->network_delegate());
651 633
652 // Check that there are no callbacks to already canceled requests. 634 // Check that there are no callbacks to already canceled requests.
653 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); 635 DCHECK_NE(URLRequestStatus::CANCELED, status_.status());
654 636
655 OnCallToDelegateComplete(); 637 OnCallToDelegateComplete();
656 638
657 if (error != OK) { 639 if (error != OK) {
658 std::string source("delegate"); 640 std::string source("delegate");
659 net_log_.AddEvent(NetLog::TYPE_CANCELLED, 641 net_log_.AddEvent(NetLog::TYPE_CANCELLED,
660 NetLog::StringCallback("source", &source)); 642 NetLog::StringCallback("source", &source));
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 new base::debug::StackTrace(NULL, 0); 1214 new base::debug::StackTrace(NULL, 0);
1233 *stack_trace_copy = stack_trace; 1215 *stack_trace_copy = stack_trace;
1234 stack_trace_.reset(stack_trace_copy); 1216 stack_trace_.reset(stack_trace_copy);
1235 } 1217 }
1236 1218
1237 const base::debug::StackTrace* URLRequest::stack_trace() const { 1219 const base::debug::StackTrace* URLRequest::stack_trace() const {
1238 return stack_trace_.get(); 1220 return stack_trace_.get();
1239 } 1221 }
1240 1222
1241 } // namespace net 1223 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698