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_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 URLRequestHttpJob* job_; | 73 URLRequestHttpJob* job_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 75 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
76 }; | 76 }; |
77 | 77 |
78 class URLRequestHttpJob::HttpTransactionDelegateImpl | 78 class URLRequestHttpJob::HttpTransactionDelegateImpl |
79 : public HttpTransactionDelegate { | 79 : public HttpTransactionDelegate { |
80 public: | 80 public: |
81 explicit HttpTransactionDelegateImpl(URLRequest* request) | 81 explicit HttpTransactionDelegateImpl(URLRequest* request) |
82 : request_(request), | 82 : request_(request), |
83 network_delegate_(request->context()->network_delegate()) { | 83 network_delegate_(request->context()->network_delegate()), |
| 84 cache_active_(false), |
| 85 network_active_(false) { |
84 } | 86 } |
85 virtual ~HttpTransactionDelegateImpl() { | 87 virtual ~HttpTransactionDelegateImpl() { |
86 OnDetachRequest(); | 88 OnDetachRequest(); |
87 } | 89 } |
88 void OnDetachRequest() { | 90 void OnDetachRequest() { |
89 if (request_ == NULL || network_delegate_ == NULL) | 91 if (request_ == NULL || network_delegate_ == NULL) |
90 return; | 92 return; |
91 network_delegate_->NotifyCacheWaitStateChange( | 93 network_delegate_->NotifyRequestWaitStateChange( |
92 *request_, | 94 *request_, |
93 NetworkDelegate::CACHE_WAIT_STATE_RESET); | 95 NetworkDelegate::REQUEST_WAIT_STATE_RESET); |
| 96 cache_active_ = false; |
| 97 network_active_ = false; |
94 request_ = NULL; | 98 request_ = NULL; |
95 } | 99 } |
96 virtual void OnCacheActionStart() OVERRIDE { | 100 virtual void OnCacheActionStart() OVERRIDE { |
97 if (request_ == NULL || network_delegate_ == NULL) | 101 if (request_ == NULL || network_delegate_ == NULL) |
98 return; | 102 return; |
99 network_delegate_->NotifyCacheWaitStateChange( | 103 DCHECK(!cache_active_ && !network_active_); |
| 104 cache_active_ = true; |
| 105 network_delegate_->NotifyRequestWaitStateChange( |
100 *request_, | 106 *request_, |
101 NetworkDelegate::CACHE_WAIT_STATE_START); | 107 NetworkDelegate::REQUEST_WAIT_STATE_CACHE_START); |
102 } | 108 } |
103 virtual void OnCacheActionFinish() OVERRIDE { | 109 virtual void OnCacheActionFinish() OVERRIDE { |
104 if (request_ == NULL || network_delegate_ == NULL) | 110 if (request_ == NULL || network_delegate_ == NULL) |
105 return; | 111 return; |
106 network_delegate_->NotifyCacheWaitStateChange( | 112 DCHECK(cache_active_ && !network_active_); |
| 113 cache_active_ = false; |
| 114 network_delegate_->NotifyRequestWaitStateChange( |
107 *request_, | 115 *request_, |
108 NetworkDelegate::CACHE_WAIT_STATE_FINISH); | 116 NetworkDelegate::REQUEST_WAIT_STATE_CACHE_FINISH); |
| 117 } |
| 118 virtual void OnNetworkActionStart() OVERRIDE { |
| 119 if (request_ == NULL || network_delegate_ == NULL) |
| 120 return; |
| 121 DCHECK(!cache_active_ && !network_active_); |
| 122 network_active_ = true; |
| 123 network_delegate_->NotifyRequestWaitStateChange( |
| 124 *request_, |
| 125 NetworkDelegate::REQUEST_WAIT_STATE_NETWORK_START); |
| 126 } |
| 127 virtual void OnNetworkActionFinish() OVERRIDE { |
| 128 if (request_ == NULL || network_delegate_ == NULL) |
| 129 return; |
| 130 DCHECK(!cache_active_ && network_active_); |
| 131 network_active_ = false; |
| 132 network_delegate_->NotifyRequestWaitStateChange( |
| 133 *request_, |
| 134 NetworkDelegate::REQUEST_WAIT_STATE_NETWORK_FINISH); |
109 } | 135 } |
110 private: | 136 private: |
111 URLRequest* request_; | 137 URLRequest* request_; |
112 NetworkDelegate* network_delegate_; | 138 NetworkDelegate* network_delegate_; |
| 139 bool cache_active_; |
| 140 bool network_active_; |
113 }; | 141 }; |
114 | 142 |
115 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) | 143 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) |
116 : job_(job) { | 144 : job_(job) { |
117 DCHECK(job_); | 145 DCHECK(job_); |
118 } | 146 } |
119 | 147 |
120 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { | 148 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { |
121 } | 149 } |
122 | 150 |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 request_info_.extra_headers.SetHeaderIfMissing( | 908 request_info_.extra_headers.SetHeaderIfMissing( |
881 HttpRequestHeaders::kUserAgent, | 909 HttpRequestHeaders::kUserAgent, |
882 request_->context()->GetUserAgent(request_->url())); | 910 request_->context()->GetUserAgent(request_->url())); |
883 } | 911 } |
884 | 912 |
885 AddExtraHeaders(); | 913 AddExtraHeaders(); |
886 AddCookieHeaderAndStart(); | 914 AddCookieHeaderAndStart(); |
887 } | 915 } |
888 | 916 |
889 void URLRequestHttpJob::Kill() { | 917 void URLRequestHttpJob::Kill() { |
| 918 http_transaction_delegate_->OnDetachRequest(); |
| 919 |
890 if (!transaction_.get()) | 920 if (!transaction_.get()) |
891 return; | 921 return; |
892 | 922 |
893 weak_factory_.InvalidateWeakPtrs(); | 923 weak_factory_.InvalidateWeakPtrs(); |
894 DestroyTransaction(); | 924 DestroyTransaction(); |
895 URLRequestJob::Kill(); | 925 URLRequestJob::Kill(); |
896 } | 926 } |
897 | 927 |
898 LoadState URLRequestHttpJob::GetLoadState() const { | 928 LoadState URLRequestHttpJob::GetLoadState() const { |
899 return transaction_.get() ? | 929 return transaction_.get() ? |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 | 1504 |
1475 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1505 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1476 awaiting_callback_ = false; | 1506 awaiting_callback_ = false; |
1477 } | 1507 } |
1478 | 1508 |
1479 void URLRequestHttpJob::OnDetachRequest() { | 1509 void URLRequestHttpJob::OnDetachRequest() { |
1480 http_transaction_delegate_->OnDetachRequest(); | 1510 http_transaction_delegate_->OnDetachRequest(); |
1481 } | 1511 } |
1482 | 1512 |
1483 } // namespace net | 1513 } // namespace net |
OLD | NEW |