OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 void URLRequest::set_delegate(Delegate* delegate) { | 397 void URLRequest::set_delegate(Delegate* delegate) { |
398 delegate_ = delegate; | 398 delegate_ = delegate; |
399 } | 399 } |
400 | 400 |
401 void URLRequest::Start() { | 401 void URLRequest::Start() { |
402 response_info_.request_time = Time::Now(); | 402 response_info_.request_time = Time::Now(); |
403 | 403 |
404 // Only notify the delegate for the initial request. | 404 // Only notify the delegate for the initial request. |
405 if (context_ && context_->network_delegate()) { | 405 if (context_ && context_->network_delegate()) { |
406 if (context_->network_delegate()->NotifyBeforeURLRequest( | 406 int error = context_->network_delegate()->NotifyBeforeURLRequest( |
407 this, &before_request_callback_, &delegate_redirect_url_) == | 407 this, &before_request_callback_, &delegate_redirect_url_); |
408 net::ERR_IO_PENDING) { | 408 if (error != net::OK) { |
409 SetBlockedOnDelegate(); | 409 if (error == net::ERR_IO_PENDING) { |
410 return; // paused | 410 // Paused on the delegate, will invoke |before_request_callback_| later. |
| 411 SetBlockedOnDelegate(); |
| 412 } else { |
| 413 // The delegate immediately returned some error code. |
| 414 BeforeRequestComplete(error); |
| 415 } |
| 416 return; |
411 } | 417 } |
412 } | 418 } |
413 | 419 |
414 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 420 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); |
415 } | 421 } |
416 | 422 |
417 /////////////////////////////////////////////////////////////////////////////// | 423 /////////////////////////////////////////////////////////////////////////////// |
418 | 424 |
419 void URLRequest::BeforeRequestComplete(int error) { | 425 void URLRequest::BeforeRequestComplete(int error) { |
420 DCHECK(!job_); | 426 DCHECK(!job_); |
421 DCHECK_NE(ERR_IO_PENDING, error); | 427 DCHECK_NE(ERR_IO_PENDING, error); |
422 | 428 |
423 SetUnblockedOnDelegate(); | 429 if (blocked_on_delegate_) |
| 430 SetUnblockedOnDelegate(); |
424 if (error != OK) { | 431 if (error != OK) { |
425 net_log_.AddEvent(NetLog::TYPE_CANCELLED, | 432 net_log_.AddEvent(NetLog::TYPE_CANCELLED, |
426 make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); | 433 make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); |
427 StartJob(new URLRequestErrorJob(this, error)); | 434 StartJob(new URLRequestErrorJob(this, error)); |
428 } else if (!delegate_redirect_url_.is_empty()) { | 435 } else if (!delegate_redirect_url_.is_empty()) { |
429 GURL new_url; | 436 GURL new_url; |
430 new_url.Swap(&delegate_redirect_url_); | 437 new_url.Swap(&delegate_redirect_url_); |
431 StartJob(new URLRequestRedirectJob(this, new_url)); | 438 StartJob(new URLRequestRedirectJob(this, new_url)); |
432 } else { | 439 } else { |
433 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 440 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 827 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
821 } | 828 } |
822 | 829 |
823 void URLRequest::SetUnblockedOnDelegate() { | 830 void URLRequest::SetUnblockedOnDelegate() { |
824 blocked_on_delegate_ = false; | 831 blocked_on_delegate_ = false; |
825 load_state_param_.clear(); | 832 load_state_param_.clear(); |
826 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 833 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
827 } | 834 } |
828 | 835 |
829 } // namespace net | 836 } // namespace net |
OLD | NEW |