OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 headers->RemoveHeader(HttpRequestHeaders::kContentType); | 56 headers->RemoveHeader(HttpRequestHeaders::kContentType); |
57 headers->RemoveHeader(HttpRequestHeaders::kOrigin); | 57 headers->RemoveHeader(HttpRequestHeaders::kOrigin); |
58 } | 58 } |
59 | 59 |
60 // TODO(battre): Delete this, see http://crbug.com/89321: | 60 // TODO(battre): Delete this, see http://crbug.com/89321: |
61 // This counter keeps track of the identifiers used for URL requests so far. | 61 // This counter keeps track of the identifiers used for URL requests so far. |
62 // 0 is reserved to represent an invalid ID. | 62 // 0 is reserved to represent an invalid ID. |
63 uint64 g_next_url_request_identifier = 1; | 63 uint64 g_next_url_request_identifier = 1; |
64 | 64 |
65 // This lock protects g_next_url_request_identifier. | 65 // This lock protects g_next_url_request_identifier. |
66 base::LazyInstance<base::Lock>::Leaky | 66 base::LazyInstance<base::Lock>::Leaky g_next_url_request_identifier_lock = |
67 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; | 67 LAZY_INSTANCE_INITIALIZER; |
68 | 68 |
69 // Returns an prior unused identifier for URL requests. | 69 // Returns an prior unused identifier for URL requests. |
70 uint64 GenerateURLRequestIdentifier() { | 70 uint64 GenerateURLRequestIdentifier() { |
71 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); | 71 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); |
72 return g_next_url_request_identifier++; | 72 return g_next_url_request_identifier++; |
73 } | 73 } |
74 | 74 |
75 // True once the first URLRequest was started. | 75 // True once the first URLRequest was started. |
76 bool g_url_requests_started = false; | 76 bool g_url_requests_started = false; |
77 | 77 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 DCHECK(!connect_timing->ssl_end.is_null()); | 135 DCHECK(!connect_timing->ssl_end.is_null()); |
136 if (connect_timing->ssl_start < block_on_connect) | 136 if (connect_timing->ssl_start < block_on_connect) |
137 connect_timing->ssl_start = block_on_connect; | 137 connect_timing->ssl_start = block_on_connect; |
138 if (connect_timing->ssl_end < block_on_connect) | 138 if (connect_timing->ssl_end < block_on_connect) |
139 connect_timing->ssl_end = block_on_connect; | 139 connect_timing->ssl_end = block_on_connect; |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 } // namespace | 143 } // namespace |
144 | 144 |
145 URLRequest::ProtocolFactory* | 145 URLRequest::ProtocolFactory* URLRequest::Deprecated::RegisterProtocolFactory( |
146 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, | 146 const std::string& scheme, |
147 ProtocolFactory* factory) { | 147 ProtocolFactory* factory) { |
148 return URLRequest::RegisterProtocolFactory(scheme, factory); | 148 return URLRequest::RegisterProtocolFactory(scheme, factory); |
149 } | 149 } |
150 | 150 |
151 void URLRequest::Deprecated::RegisterRequestInterceptor( | 151 void URLRequest::Deprecated::RegisterRequestInterceptor( |
152 Interceptor* interceptor) { | 152 Interceptor* interceptor) { |
153 URLRequest::RegisterRequestInterceptor(interceptor); | 153 URLRequest::RegisterRequestInterceptor(interceptor); |
154 } | 154 } |
155 | 155 |
156 void URLRequest::Deprecated::UnregisterRequestInterceptor( | 156 void URLRequest::Deprecated::UnregisterRequestInterceptor( |
157 Interceptor* interceptor) { | 157 Interceptor* interceptor) { |
158 URLRequest::UnregisterRequestInterceptor(interceptor); | 158 URLRequest::UnregisterRequestInterceptor(interceptor); |
159 } | 159 } |
160 | 160 |
161 /////////////////////////////////////////////////////////////////////////////// | 161 /////////////////////////////////////////////////////////////////////////////// |
162 // URLRequest::Interceptor | 162 // URLRequest::Interceptor |
163 | 163 |
164 URLRequestJob* URLRequest::Interceptor::MaybeInterceptRedirect( | 164 URLRequestJob* URLRequest::Interceptor::MaybeInterceptRedirect( |
165 URLRequest* request, | 165 URLRequest* request, |
166 NetworkDelegate* network_delegate, | 166 NetworkDelegate* network_delegate, |
167 const GURL& location) { | 167 const GURL& location) { |
168 return NULL; | 168 return NULL; |
169 } | 169 } |
170 | 170 |
171 URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse( | 171 URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse( |
172 URLRequest* request, NetworkDelegate* network_delegate) { | 172 URLRequest* request, |
| 173 NetworkDelegate* network_delegate) { |
173 return NULL; | 174 return NULL; |
174 } | 175 } |
175 | 176 |
176 /////////////////////////////////////////////////////////////////////////////// | 177 /////////////////////////////////////////////////////////////////////////////// |
177 // URLRequest::Delegate | 178 // URLRequest::Delegate |
178 | 179 |
179 void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request, | 180 void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request, |
180 const GURL& new_url, | 181 const GURL& new_url, |
181 bool* defer_redirect) { | 182 bool* defer_redirect) { |
182 } | 183 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 int net_error = OK; | 241 int net_error = OK; |
241 // Log error only on failure, not cancellation, as even successful requests | 242 // Log error only on failure, not cancellation, as even successful requests |
242 // are "cancelled" on destruction. | 243 // are "cancelled" on destruction. |
243 if (status_.status() == URLRequestStatus::FAILED) | 244 if (status_.status() == URLRequestStatus::FAILED) |
244 net_error = status_.error(); | 245 net_error = status_.error(); |
245 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); | 246 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); |
246 } | 247 } |
247 | 248 |
248 // static | 249 // static |
249 URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory( | 250 URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory( |
250 const string& scheme, ProtocolFactory* factory) { | 251 const string& scheme, |
| 252 ProtocolFactory* factory) { |
251 return URLRequestJobManager::GetInstance()->RegisterProtocolFactory(scheme, | 253 return URLRequestJobManager::GetInstance()->RegisterProtocolFactory(scheme, |
252 factory); | 254 factory); |
253 } | 255 } |
254 | 256 |
255 // static | 257 // static |
256 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { | 258 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { |
257 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); | 259 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); |
258 } | 260 } |
259 | 261 |
260 // static | 262 // static |
(...skipping 13 matching lines...) Expand all Loading... |
274 url_chain_.push_back(url); | 276 url_chain_.push_back(url); |
275 method_ = "GET"; | 277 method_ = "GET"; |
276 referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; | 278 referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; |
277 load_flags_ = LOAD_NORMAL; | 279 load_flags_ = LOAD_NORMAL; |
278 delegate_ = delegate; | 280 delegate_ = delegate; |
279 is_pending_ = false; | 281 is_pending_ = false; |
280 is_redirecting_ = false; | 282 is_redirecting_ = false; |
281 redirect_limit_ = kMaxRedirects; | 283 redirect_limit_ = kMaxRedirects; |
282 priority_ = priority; | 284 priority_ = priority; |
283 calling_delegate_ = false; | 285 calling_delegate_ = false; |
284 use_blocked_by_as_load_param_ =false; | 286 use_blocked_by_as_load_param_ = false; |
285 before_request_callback_ = base::Bind(&URLRequest::BeforeRequestComplete, | 287 before_request_callback_ = |
286 base::Unretained(this)); | 288 base::Bind(&URLRequest::BeforeRequestComplete, base::Unretained(this)); |
287 has_notified_completion_ = false; | 289 has_notified_completion_ = false; |
288 received_response_content_length_ = 0; | 290 received_response_content_length_ = 0; |
289 creation_time_ = base::TimeTicks::Now(); | 291 creation_time_ = base::TimeTicks::Now(); |
290 notified_before_network_start_ = false; | 292 notified_before_network_start_ = false; |
291 | 293 |
292 SIMPLE_STATS_COUNTER("URLRequestCount"); | 294 SIMPLE_STATS_COUNTER("URLRequestCount"); |
293 | 295 |
294 // Sanity check out environment. | 296 // Sanity check out environment. |
295 DCHECK(base::MessageLoop::current()) | 297 DCHECK(base::MessageLoop::current()) |
296 << "The current base::MessageLoop must exist"; | 298 << "The current base::MessageLoop must exist"; |
(...skipping 30 matching lines...) Expand all Loading... |
327 } | 329 } |
328 | 330 |
329 const UploadDataStream* URLRequest::get_upload() const { | 331 const UploadDataStream* URLRequest::get_upload() const { |
330 return upload_data_stream_.get(); | 332 return upload_data_stream_.get(); |
331 } | 333 } |
332 | 334 |
333 bool URLRequest::has_upload() const { | 335 bool URLRequest::has_upload() const { |
334 return upload_data_stream_.get() != NULL; | 336 return upload_data_stream_.get() != NULL; |
335 } | 337 } |
336 | 338 |
337 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, | 339 void URLRequest::SetExtraRequestHeaderById(int id, |
| 340 const string& value, |
338 bool overwrite) { | 341 bool overwrite) { |
339 DCHECK(!is_pending_ || is_redirecting_); | 342 DCHECK(!is_pending_ || is_redirecting_); |
340 NOTREACHED() << "implement me!"; | 343 NOTREACHED() << "implement me!"; |
341 } | 344 } |
342 | 345 |
343 void URLRequest::SetExtraRequestHeaderByName(const string& name, | 346 void URLRequest::SetExtraRequestHeaderByName(const string& name, |
344 const string& value, | 347 const string& value, |
345 bool overwrite) { | 348 bool overwrite) { |
346 DCHECK(!is_pending_ || is_redirecting_); | 349 DCHECK(!is_pending_ || is_redirecting_); |
347 if (overwrite) { | 350 if (overwrite) { |
348 extra_request_headers_.SetHeader(name, value); | 351 extra_request_headers_.SetHeader(name, value); |
349 } else { | 352 } else { |
350 extra_request_headers_.SetHeaderIfMissing(name, value); | 353 extra_request_headers_.SetHeaderIfMissing(name, value); |
351 } | 354 } |
352 } | 355 } |
353 | 356 |
354 void URLRequest::RemoveRequestHeaderByName(const string& name) { | 357 void URLRequest::RemoveRequestHeaderByName(const string& name) { |
355 DCHECK(!is_pending_ || is_redirecting_); | 358 DCHECK(!is_pending_ || is_redirecting_); |
356 extra_request_headers_.RemoveHeader(name); | 359 extra_request_headers_.RemoveHeader(name); |
357 } | 360 } |
358 | 361 |
359 void URLRequest::SetExtraRequestHeaders( | 362 void URLRequest::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { |
360 const HttpRequestHeaders& headers) { | |
361 DCHECK(!is_pending_); | 363 DCHECK(!is_pending_); |
362 extra_request_headers_ = headers; | 364 extra_request_headers_ = headers; |
363 | 365 |
364 // NOTE: This method will likely become non-trivial once the other setters | 366 // NOTE: This method will likely become non-trivial once the other setters |
365 // for request headers are implemented. | 367 // for request headers are implemented. |
366 } | 368 } |
367 | 369 |
368 bool URLRequest::GetFullRequestHeaders(HttpRequestHeaders* headers) const { | 370 bool URLRequest::GetFullRequestHeaders(HttpRequestHeaders* headers) const { |
369 if (!job_.get()) | 371 if (!job_.get()) |
370 return false; | 372 return false; |
371 | 373 |
372 return job_->GetFullRequestHeaders(headers); | 374 return job_->GetFullRequestHeaders(headers); |
373 } | 375 } |
374 | 376 |
375 int64 URLRequest::GetTotalReceivedBytes() const { | 377 int64 URLRequest::GetTotalReceivedBytes() const { |
376 if (!job_.get()) | 378 if (!job_.get()) |
377 return 0; | 379 return 0; |
378 | 380 |
379 return job_->GetTotalReceivedBytes(); | 381 return job_->GetTotalReceivedBytes(); |
380 } | 382 } |
381 | 383 |
382 LoadStateWithParam URLRequest::GetLoadState() const { | 384 LoadStateWithParam URLRequest::GetLoadState() const { |
383 // The !blocked_by_.empty() check allows |this| to report it's blocked on a | 385 // The !blocked_by_.empty() check allows |this| to report it's blocked on a |
384 // delegate before it has been started. | 386 // delegate before it has been started. |
385 if (calling_delegate_ || !blocked_by_.empty()) { | 387 if (calling_delegate_ || !blocked_by_.empty()) { |
386 return LoadStateWithParam( | 388 return LoadStateWithParam(LOAD_STATE_WAITING_FOR_DELEGATE, |
387 LOAD_STATE_WAITING_FOR_DELEGATE, | 389 use_blocked_by_as_load_param_ |
388 use_blocked_by_as_load_param_ ? base::UTF8ToUTF16(blocked_by_) : | 390 ? base::UTF8ToUTF16(blocked_by_) |
389 base::string16()); | 391 : base::string16()); |
390 } | 392 } |
391 return LoadStateWithParam(job_.get() ? job_->GetLoadState() : LOAD_STATE_IDLE, | 393 return LoadStateWithParam(job_.get() ? job_->GetLoadState() : LOAD_STATE_IDLE, |
392 base::string16()); | 394 base::string16()); |
393 } | 395 } |
394 | 396 |
395 base::Value* URLRequest::GetStateAsValue() const { | 397 base::Value* URLRequest::GetStateAsValue() const { |
396 base::DictionaryValue* dict = new base::DictionaryValue(); | 398 base::DictionaryValue* dict = new base::DictionaryValue(); |
397 dict->SetString("url", original_url().possibly_invalid_spec()); | 399 dict->SetString("url", original_url().possibly_invalid_spec()); |
398 | 400 |
399 if (url_chain_.size() > 1) { | 401 if (url_chain_.size() > 1) { |
400 base::ListValue* list = new base::ListValue(); | 402 base::ListValue* list = new base::ListValue(); |
401 for (std::vector<GURL>::const_iterator url = url_chain_.begin(); | 403 for (std::vector<GURL>::const_iterator url = url_chain_.begin(); |
402 url != url_chain_.end(); ++url) { | 404 url != url_chain_.end(); |
| 405 ++url) { |
403 list->AppendString(url->possibly_invalid_spec()); | 406 list->AppendString(url->possibly_invalid_spec()); |
404 } | 407 } |
405 dict->Set("url_chain", list); | 408 dict->Set("url_chain", list); |
406 } | 409 } |
407 | 410 |
408 dict->SetInteger("load_flags", load_flags_); | 411 dict->SetInteger("load_flags", load_flags_); |
409 | 412 |
410 LoadStateWithParam load_state = GetLoadState(); | 413 LoadStateWithParam load_state = GetLoadState(); |
411 dict->SetInteger("load_state", load_state.state); | 414 dict->SetInteger("load_state", load_state.state); |
412 if (!load_state.param.empty()) | 415 if (!load_state.param.empty()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 449 |
447 // Only log information to NetLog during startup and certain deferring calls | 450 // Only log information to NetLog during startup and certain deferring calls |
448 // to delegates. For all reads but the first, do nothing. | 451 // to delegates. For all reads but the first, do nothing. |
449 if (!calling_delegate_ && !response_info_.request_time.is_null()) | 452 if (!calling_delegate_ && !response_info_.request_time.is_null()) |
450 return; | 453 return; |
451 | 454 |
452 LogUnblocked(); | 455 LogUnblocked(); |
453 blocked_by_ = blocked_by; | 456 blocked_by_ = blocked_by; |
454 use_blocked_by_as_load_param_ = false; | 457 use_blocked_by_as_load_param_ = false; |
455 | 458 |
456 net_log_.BeginEvent( | 459 net_log_.BeginEvent(NetLog::TYPE_DELEGATE_INFO, |
457 NetLog::TYPE_DELEGATE_INFO, | 460 NetLog::StringCallback("delegate_info", &blocked_by_)); |
458 NetLog::StringCallback("delegate_info", &blocked_by_)); | |
459 } | 461 } |
460 | 462 |
461 void URLRequest::LogAndReportBlockedBy(const char* source) { | 463 void URLRequest::LogAndReportBlockedBy(const char* source) { |
462 LogBlockedBy(source); | 464 LogBlockedBy(source); |
463 use_blocked_by_as_load_param_ = true; | 465 use_blocked_by_as_load_param_ = true; |
464 } | 466 } |
465 | 467 |
466 void URLRequest::LogUnblocked() { | 468 void URLRequest::LogUnblocked() { |
467 if (blocked_by_.empty()) | 469 if (blocked_by_.empty()) |
468 return; | 470 return; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 const GURL& first_party_for_cookies) { | 582 const GURL& first_party_for_cookies) { |
581 first_party_for_cookies_ = first_party_for_cookies; | 583 first_party_for_cookies_ = first_party_for_cookies; |
582 } | 584 } |
583 | 585 |
584 void URLRequest::set_method(const std::string& method) { | 586 void URLRequest::set_method(const std::string& method) { |
585 DCHECK(!is_pending_); | 587 DCHECK(!is_pending_); |
586 method_ = method; | 588 method_ = method; |
587 } | 589 } |
588 | 590 |
589 // static | 591 // static |
590 std::string URLRequest::ComputeMethodForRedirect( | 592 std::string URLRequest::ComputeMethodForRedirect(const std::string& method, |
591 const std::string& method, | 593 int http_status_code) { |
592 int http_status_code) { | |
593 // For 303 redirects, all request methods except HEAD are converted to GET, | 594 // For 303 redirects, all request methods except HEAD are converted to GET, |
594 // as per the latest httpbis draft. The draft also allows POST requests to | 595 // as per the latest httpbis draft. The draft also allows POST requests to |
595 // be converted to GETs when following 301/302 redirects, for historical | 596 // be converted to GETs when following 301/302 redirects, for historical |
596 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and | 597 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and |
597 // the httpbis draft say to prompt the user to confirm the generation of new | 598 // the httpbis draft say to prompt the user to confirm the generation of new |
598 // requests, other than GET and HEAD requests, but IE omits these prompts and | 599 // requests, other than GET and HEAD requests, but IE omits these prompts and |
599 // so shall we. | 600 // so shall we. |
600 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio
n-7.3 | 601 // See: |
| 602 // https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3 |
601 if ((http_status_code == 303 && method != "HEAD") || | 603 if ((http_status_code == 303 && method != "HEAD") || |
602 ((http_status_code == 301 || http_status_code == 302) && | 604 ((http_status_code == 301 || http_status_code == 302) && |
603 method == "POST")) { | 605 method == "POST")) { |
604 return "GET"; | 606 return "GET"; |
605 } | 607 } |
606 return method; | 608 return method; |
607 } | 609 } |
608 | 610 |
609 void URLRequest::SetReferrer(const std::string& referrer) { | 611 void URLRequest::SetReferrer(const std::string& referrer) { |
610 DCHECK(!is_pending_); | 612 DCHECK(!is_pending_); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 OnCallToDelegate(); | 647 OnCallToDelegate(); |
646 int error = network_delegate_->NotifyBeforeURLRequest( | 648 int error = network_delegate_->NotifyBeforeURLRequest( |
647 this, before_request_callback_, &delegate_redirect_url_); | 649 this, before_request_callback_, &delegate_redirect_url_); |
648 // If ERR_IO_PENDING is returned, the delegate will invoke | 650 // If ERR_IO_PENDING is returned, the delegate will invoke |
649 // |before_request_callback_| later. | 651 // |before_request_callback_| later. |
650 if (error != ERR_IO_PENDING) | 652 if (error != ERR_IO_PENDING) |
651 BeforeRequestComplete(error); | 653 BeforeRequestComplete(error); |
652 return; | 654 return; |
653 } | 655 } |
654 | 656 |
655 StartJob(URLRequestJobManager::GetInstance()->CreateJob( | 657 StartJob( |
656 this, network_delegate_)); | 658 URLRequestJobManager::GetInstance()->CreateJob(this, network_delegate_)); |
657 } | 659 } |
658 | 660 |
659 /////////////////////////////////////////////////////////////////////////////// | 661 /////////////////////////////////////////////////////////////////////////////// |
660 | 662 |
661 void URLRequest::BeforeRequestComplete(int error) { | 663 void URLRequest::BeforeRequestComplete(int error) { |
662 DCHECK(!job_.get()); | 664 DCHECK(!job_.get()); |
663 DCHECK_NE(ERR_IO_PENDING, error); | 665 DCHECK_NE(ERR_IO_PENDING, error); |
664 DCHECK_EQ(network_delegate_, context_->network_delegate()); | 666 DCHECK_EQ(network_delegate_, context_->network_delegate()); |
665 | 667 |
666 // Check that there are no callbacks to already canceled requests. | 668 // Check that there are no callbacks to already canceled requests. |
667 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); | 669 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); |
668 | 670 |
669 OnCallToDelegateComplete(); | 671 OnCallToDelegateComplete(); |
670 | 672 |
671 if (error != OK) { | 673 if (error != OK) { |
672 std::string source("delegate"); | 674 std::string source("delegate"); |
673 net_log_.AddEvent(NetLog::TYPE_CANCELLED, | 675 net_log_.AddEvent(NetLog::TYPE_CANCELLED, |
674 NetLog::StringCallback("source", &source)); | 676 NetLog::StringCallback("source", &source)); |
675 StartJob(new URLRequestErrorJob(this, network_delegate_, error)); | 677 StartJob(new URLRequestErrorJob(this, network_delegate_, error)); |
676 } else if (!delegate_redirect_url_.is_empty()) { | 678 } else if (!delegate_redirect_url_.is_empty()) { |
677 GURL new_url; | 679 GURL new_url; |
678 new_url.Swap(&delegate_redirect_url_); | 680 new_url.Swap(&delegate_redirect_url_); |
679 | 681 |
680 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 682 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
681 this, network_delegate_, new_url, | 683 this, |
| 684 network_delegate_, |
| 685 new_url, |
682 // Use status code 307 to preserve the method, so POST requests work. | 686 // Use status code 307 to preserve the method, so POST requests work. |
683 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Delegate"); | 687 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, |
| 688 "Delegate"); |
684 StartJob(job); | 689 StartJob(job); |
685 } else { | 690 } else { |
686 StartJob(URLRequestJobManager::GetInstance()->CreateJob( | 691 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this, |
687 this, network_delegate_)); | 692 network_delegate_)); |
688 } | 693 } |
689 } | 694 } |
690 | 695 |
691 void URLRequest::StartJob(URLRequestJob* job) { | 696 void URLRequest::StartJob(URLRequestJob* job) { |
692 DCHECK(!is_pending_); | 697 DCHECK(!is_pending_); |
693 DCHECK(!job_.get()); | 698 DCHECK(!job_.get()); |
694 | 699 |
695 net_log_.BeginEvent( | 700 net_log_.BeginEvent( |
696 NetLog::TYPE_URL_REQUEST_START_JOB, | 701 NetLog::TYPE_URL_REQUEST_START_JOB, |
697 base::Bind(&NetLogURLRequestStartCallback, | 702 base::Bind(&NetLogURLRequestStartCallback, |
698 &url(), &method_, load_flags_, priority_, | 703 &url(), |
| 704 &method_, |
| 705 load_flags_, |
| 706 priority_, |
699 upload_data_stream_ ? upload_data_stream_->identifier() : -1)); | 707 upload_data_stream_ ? upload_data_stream_->identifier() : -1)); |
700 | 708 |
701 job_ = job; | 709 job_ = job; |
702 job_->SetExtraRequestHeaders(extra_request_headers_); | 710 job_->SetExtraRequestHeaders(extra_request_headers_); |
703 job_->SetPriority(priority_); | 711 job_->SetPriority(priority_); |
704 | 712 |
705 if (upload_data_stream_.get()) | 713 if (upload_data_stream_.get()) |
706 job_->SetUpload(upload_data_stream_.get()); | 714 job_->SetUpload(upload_data_stream_.get()); |
707 | 715 |
708 is_pending_ = true; | 716 is_pending_ = true; |
(...skipping 22 matching lines...) Expand all Loading... |
731 job_->Start(); | 739 job_->Start(); |
732 } | 740 } |
733 | 741 |
734 void URLRequest::Restart() { | 742 void URLRequest::Restart() { |
735 // Should only be called if the original job didn't make any progress. | 743 // Should only be called if the original job didn't make any progress. |
736 DCHECK(job_.get() && !job_->has_response_started()); | 744 DCHECK(job_.get() && !job_->has_response_started()); |
737 RestartWithJob( | 745 RestartWithJob( |
738 URLRequestJobManager::GetInstance()->CreateJob(this, network_delegate_)); | 746 URLRequestJobManager::GetInstance()->CreateJob(this, network_delegate_)); |
739 } | 747 } |
740 | 748 |
741 void URLRequest::RestartWithJob(URLRequestJob *job) { | 749 void URLRequest::RestartWithJob(URLRequestJob* job) { |
742 DCHECK(job->request() == this); | 750 DCHECK(job->request() == this); |
743 PrepareToRestart(); | 751 PrepareToRestart(); |
744 StartJob(job); | 752 StartJob(job); |
745 } | 753 } |
746 | 754 |
747 void URLRequest::Cancel() { | 755 void URLRequest::Cancel() { |
748 DoCancel(ERR_ABORTED, SSLInfo()); | 756 DoCancel(ERR_ABORTED, SSLInfo()); |
749 } | 757 } |
750 | 758 |
751 void URLRequest::CancelWithError(int error) { | 759 void URLRequest::CancelWithError(int error) { |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 } | 1175 } |
1168 | 1176 |
1169 bool URLRequest::CanEnablePrivacyMode() const { | 1177 bool URLRequest::CanEnablePrivacyMode() const { |
1170 if (network_delegate_) { | 1178 if (network_delegate_) { |
1171 return network_delegate_->CanEnablePrivacyMode(url(), | 1179 return network_delegate_->CanEnablePrivacyMode(url(), |
1172 first_party_for_cookies_); | 1180 first_party_for_cookies_); |
1173 } | 1181 } |
1174 return !g_default_can_use_cookies; | 1182 return !g_default_can_use_cookies; |
1175 } | 1183 } |
1176 | 1184 |
1177 | |
1178 void URLRequest::NotifyReadCompleted(int bytes_read) { | 1185 void URLRequest::NotifyReadCompleted(int bytes_read) { |
1179 // Notify in case the entire URL Request has been finished. | 1186 // Notify in case the entire URL Request has been finished. |
1180 if (bytes_read <= 0) | 1187 if (bytes_read <= 0) |
1181 NotifyRequestCompleted(); | 1188 NotifyRequestCompleted(); |
1182 | 1189 |
1183 // Notify NetworkChangeNotifier that we just received network data. | 1190 // Notify NetworkChangeNotifier that we just received network data. |
1184 // This is to identify cases where the NetworkChangeNotifier thinks we | 1191 // This is to identify cases where the NetworkChangeNotifier thinks we |
1185 // are off-line but we are still receiving network data (crbug.com/124069), | 1192 // are off-line but we are still receiving network data (crbug.com/124069), |
1186 // and to get rough network connection measurements. | 1193 // and to get rough network connection measurements. |
1187 if (bytes_read > 0 && !was_cached()) | 1194 if (bytes_read > 0 && !was_cached()) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 new base::debug::StackTrace(NULL, 0); | 1255 new base::debug::StackTrace(NULL, 0); |
1249 *stack_trace_copy = stack_trace; | 1256 *stack_trace_copy = stack_trace; |
1250 stack_trace_.reset(stack_trace_copy); | 1257 stack_trace_.reset(stack_trace_copy); |
1251 } | 1258 } |
1252 | 1259 |
1253 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1260 const base::debug::StackTrace* URLRequest::stack_trace() const { |
1254 return stack_trace_.get(); | 1261 return stack_trace_.get(); |
1255 } | 1262 } |
1256 | 1263 |
1257 } // namespace net | 1264 } // namespace net |
OLD | NEW |