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

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: Fix new tests Created 6 years, 4 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
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_context.h » ('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 "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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request, 194 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request,
195 bool* defer) { 195 bool* defer) {
196 } 196 }
197 197
198 /////////////////////////////////////////////////////////////////////////////// 198 ///////////////////////////////////////////////////////////////////////////////
199 // URLRequest 199 // URLRequest
200 200
201 URLRequest::URLRequest(const GURL& url, 201 URLRequest::URLRequest(const GURL& url,
202 RequestPriority priority, 202 RequestPriority priority,
203 Delegate* delegate, 203 Delegate* delegate,
204 const URLRequestContext* context)
205 : identifier_(GenerateURLRequestIdentifier()) {
206 Init(url, priority, delegate, context, NULL);
207 }
208
209 URLRequest::URLRequest(const GURL& url,
210 RequestPriority priority,
211 Delegate* delegate,
212 const URLRequestContext* context, 204 const URLRequestContext* context,
213 CookieStore* cookie_store) 205 CookieStore* cookie_store,
214 : identifier_(GenerateURLRequestIdentifier()) { 206 NetworkDelegate* network_delegate)
215 Init(url, priority, delegate, context, cookie_store); 207 : context_(context),
208 network_delegate_(network_delegate ? network_delegate
209 : context->network_delegate()),
210 net_log_(BoundNetLog::Make(context->net_log(),
211 NetLog::SOURCE_URL_REQUEST)),
212 url_chain_(1, url),
213 method_("GET"),
214 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
215 first_party_url_policy_(NEVER_CHANGE_FIRST_PARTY_URL),
216 load_flags_(LOAD_NORMAL),
217 delegate_(delegate),
218 is_pending_(false),
219 is_redirecting_(false),
220 redirect_limit_(kMaxRedirects),
221 priority_(priority),
222 identifier_(GenerateURLRequestIdentifier()),
223 calling_delegate_(false),
224 use_blocked_by_as_load_param_(false),
225 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete,
226 base::Unretained(this))),
227 has_notified_completion_(false),
228 received_response_content_length_(0),
229 creation_time_(base::TimeTicks::Now()),
230 notified_before_network_start_(false),
231 cookie_store_(cookie_store ? cookie_store : context->cookie_store()) {
232 SIMPLE_STATS_COUNTER("URLRequestCount");
233
234 // Sanity check out environment.
235 DCHECK(base::MessageLoop::current())
236 << "The current base::MessageLoop must exist";
237
238 context->url_requests()->insert(this);
239 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
216 } 240 }
217 241
218 URLRequest::~URLRequest() { 242 URLRequest::~URLRequest() {
219 Cancel(); 243 Cancel();
220 244
221 if (network_delegate_) { 245 if (network_delegate_) {
222 network_delegate_->NotifyURLRequestDestroyed(this); 246 network_delegate_->NotifyURLRequestDestroyed(this);
223 if (job_.get()) 247 if (job_.get())
224 job_->NotifyURLRequestDestroyed(); 248 job_->NotifyURLRequestDestroyed();
225 } 249 }
(...skipping 16 matching lines...) Expand all
242 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { 266 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) {
243 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); 267 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor);
244 } 268 }
245 269
246 // static 270 // static
247 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { 271 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) {
248 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( 272 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor(
249 interceptor); 273 interceptor);
250 } 274 }
251 275
252 void URLRequest::Init(const GURL& url,
253 RequestPriority priority,
254 Delegate* delegate,
255 const URLRequestContext* context,
256 CookieStore* cookie_store) {
257 context_ = context;
258 network_delegate_ = context->network_delegate();
259 net_log_ = BoundNetLog::Make(context->net_log(), NetLog::SOURCE_URL_REQUEST);
260 url_chain_.push_back(url);
261 method_ = "GET";
262 referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
263 first_party_url_policy_ = NEVER_CHANGE_FIRST_PARTY_URL;
264 load_flags_ = LOAD_NORMAL;
265 delegate_ = delegate;
266 is_pending_ = false;
267 is_redirecting_ = false;
268 redirect_limit_ = kMaxRedirects;
269 priority_ = priority;
270 calling_delegate_ = false;
271 use_blocked_by_as_load_param_ =false;
272 before_request_callback_ = base::Bind(&URLRequest::BeforeRequestComplete,
273 base::Unretained(this));
274 has_notified_completion_ = false;
275 received_response_content_length_ = 0;
276 creation_time_ = base::TimeTicks::Now();
277 notified_before_network_start_ = false;
278
279 SIMPLE_STATS_COUNTER("URLRequestCount");
280
281 // Sanity check out environment.
282 DCHECK(base::MessageLoop::current())
283 << "The current base::MessageLoop must exist";
284
285 CHECK(context);
286 context->url_requests()->insert(this);
287 cookie_store_ = cookie_store;
288 if (cookie_store_ == NULL)
289 cookie_store_ = context->cookie_store();
290
291 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
292 }
293
294 void URLRequest::EnableChunkedUpload() { 276 void URLRequest::EnableChunkedUpload() {
295 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); 277 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked());
296 if (!upload_data_stream_) { 278 if (!upload_data_stream_) {
297 upload_data_stream_.reset( 279 upload_data_stream_.reset(
298 new UploadDataStream(UploadDataStream::CHUNKED, 0)); 280 new UploadDataStream(UploadDataStream::CHUNKED, 0));
299 } 281 }
300 } 282 }
301 283
302 void URLRequest::AppendChunkToUpload(const char* bytes, 284 void URLRequest::AppendChunkToUpload(const char* bytes,
303 int bytes_len, 285 int bytes_len,
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 598 }
617 599
618 void URLRequest::set_delegate(Delegate* delegate) { 600 void URLRequest::set_delegate(Delegate* delegate) {
619 delegate_ = delegate; 601 delegate_ = delegate;
620 } 602 }
621 603
622 void URLRequest::Start() { 604 void URLRequest::Start() {
623 // Some values can be NULL, but the job factory must not be. 605 // Some values can be NULL, but the job factory must not be.
624 DCHECK(context_->job_factory()); 606 DCHECK(context_->job_factory());
625 607
626 DCHECK_EQ(network_delegate_, context_->network_delegate());
627 // Anything that sets |blocked_by_| before start should have cleaned up after 608 // Anything that sets |blocked_by_| before start should have cleaned up after
628 // itself. 609 // itself.
629 DCHECK(blocked_by_.empty()); 610 DCHECK(blocked_by_.empty());
630 611
631 g_url_requests_started = true; 612 g_url_requests_started = true;
632 response_info_.request_time = base::Time::Now(); 613 response_info_.request_time = base::Time::Now();
633 614
634 load_timing_info_ = LoadTimingInfo(); 615 load_timing_info_ = LoadTimingInfo();
635 load_timing_info_.request_start_time = response_info_.request_time; 616 load_timing_info_.request_start_time = response_info_.request_time;
636 load_timing_info_.request_start = base::TimeTicks::Now(); 617 load_timing_info_.request_start = base::TimeTicks::Now();
(...skipping 12 matching lines...) Expand all
649 630
650 StartJob(URLRequestJobManager::GetInstance()->CreateJob( 631 StartJob(URLRequestJobManager::GetInstance()->CreateJob(
651 this, network_delegate_)); 632 this, network_delegate_));
652 } 633 }
653 634
654 /////////////////////////////////////////////////////////////////////////////// 635 ///////////////////////////////////////////////////////////////////////////////
655 636
656 void URLRequest::BeforeRequestComplete(int error) { 637 void URLRequest::BeforeRequestComplete(int error) {
657 DCHECK(!job_.get()); 638 DCHECK(!job_.get());
658 DCHECK_NE(ERR_IO_PENDING, error); 639 DCHECK_NE(ERR_IO_PENDING, error);
659 DCHECK_EQ(network_delegate_, context_->network_delegate());
660 640
661 // Check that there are no callbacks to already canceled requests. 641 // Check that there are no callbacks to already canceled requests.
662 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); 642 DCHECK_NE(URLRequestStatus::CANCELED, status_.status());
663 643
664 OnCallToDelegateComplete(); 644 OnCallToDelegateComplete();
665 645
666 if (error != OK) { 646 if (error != OK) {
667 std::string source("delegate"); 647 std::string source("delegate");
668 net_log_.AddEvent(NetLog::TYPE_CANCELLED, 648 net_log_.AddEvent(NetLog::TYPE_CANCELLED,
669 NetLog::StringCallback("source", &source)); 649 NetLog::StringCallback("source", &source));
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 new base::debug::StackTrace(NULL, 0); 1220 new base::debug::StackTrace(NULL, 0);
1241 *stack_trace_copy = stack_trace; 1221 *stack_trace_copy = stack_trace;
1242 stack_trace_.reset(stack_trace_copy); 1222 stack_trace_.reset(stack_trace_copy);
1243 } 1223 }
1244 1224
1245 const base::debug::StackTrace* URLRequest::stack_trace() const { 1225 const base::debug::StackTrace* URLRequest::stack_trace() const {
1246 return stack_trace_.get(); 1226 return stack_trace_.get();
1247 } 1227 }
1248 1228
1249 } // namespace net 1229 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698