| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 http_transaction_delegate_(new HttpTransactionDelegateImpl( | 261 http_transaction_delegate_(new HttpTransactionDelegateImpl( |
| 262 request, network_delegate)), | 262 request, network_delegate)), |
| 263 http_user_agent_settings_(http_user_agent_settings) { | 263 http_user_agent_settings_(http_user_agent_settings) { |
| 264 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 264 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 265 if (manager) | 265 if (manager) |
| 266 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 266 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 267 | 267 |
| 268 ResetTimer(); | 268 ResetTimer(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 URLRequestHttpJob::~URLRequestHttpJob() { |
| 272 CHECK(!awaiting_callback_); |
| 273 |
| 274 DCHECK(!sdch_test_control_ || !sdch_test_activated_); |
| 275 if (!is_cached_content_) { |
| 276 if (sdch_test_control_) |
| 277 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); |
| 278 if (sdch_test_activated_) |
| 279 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); |
| 280 } |
| 281 // Make sure SDCH filters are told to emit histogram data while |
| 282 // filter_context_ is still alive. |
| 283 DestroyFilters(); |
| 284 |
| 285 if (sdch_dictionary_url_.is_valid()) { |
| 286 // Prior to reaching the destructor, request_ has been set to a NULL |
| 287 // pointer, so request_->url() is no longer valid in the destructor, and we |
| 288 // use an alternate copy |request_info_.url|. |
| 289 SdchManager* manager = SdchManager::Global(); |
| 290 // To be extra safe, since this is a "different time" from when we decided |
| 291 // to get the dictionary, we'll validate that an SdchManager is available. |
| 292 // At shutdown time, care is taken to be sure that we don't delete this |
| 293 // globally useful instance "too soon," so this check is just defensive |
| 294 // coding to assure that IF the system is shutting down, we don't have any |
| 295 // problem if the manager was deleted ahead of time. |
| 296 if (manager) // Defensive programming. |
| 297 manager->FetchDictionary(request_info_.url, sdch_dictionary_url_); |
| 298 } |
| 299 DoneWithRequest(ABORTED); |
| 300 } |
| 301 |
| 271 void URLRequestHttpJob::NotifyHeadersComplete() { | 302 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 272 DCHECK(!response_info_); | 303 DCHECK(!response_info_); |
| 273 | 304 |
| 274 response_info_ = transaction_->GetResponseInfo(); | 305 response_info_ = transaction_->GetResponseInfo(); |
| 275 | 306 |
| 276 // Save boolean, as we'll need this info at destruction time, and filters may | 307 // Save boolean, as we'll need this info at destruction time, and filters may |
| 277 // also need this info. | 308 // also need this info. |
| 278 is_cached_content_ = response_info_->was_cached; | 309 is_cached_content_ = response_info_->was_cached; |
| 279 | 310 |
| 280 if (!is_cached_content_ && throttling_entry_) { | 311 if (!is_cached_content_ && throttling_entry_) { |
| (...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 void URLRequestHttpJob::DoneReading() { | 1261 void URLRequestHttpJob::DoneReading() { |
| 1231 if (transaction_.get()) | 1262 if (transaction_.get()) |
| 1232 transaction_->DoneReading(); | 1263 transaction_->DoneReading(); |
| 1233 DoneWithRequest(FINISHED); | 1264 DoneWithRequest(FINISHED); |
| 1234 } | 1265 } |
| 1235 | 1266 |
| 1236 HostPortPair URLRequestHttpJob::GetSocketAddress() const { | 1267 HostPortPair URLRequestHttpJob::GetSocketAddress() const { |
| 1237 return response_info_ ? response_info_->socket_address : HostPortPair(); | 1268 return response_info_ ? response_info_->socket_address : HostPortPair(); |
| 1238 } | 1269 } |
| 1239 | 1270 |
| 1240 URLRequestHttpJob::~URLRequestHttpJob() { | |
| 1241 CHECK(!awaiting_callback_); | |
| 1242 | |
| 1243 DCHECK(!sdch_test_control_ || !sdch_test_activated_); | |
| 1244 if (!is_cached_content_) { | |
| 1245 if (sdch_test_control_) | |
| 1246 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); | |
| 1247 if (sdch_test_activated_) | |
| 1248 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); | |
| 1249 } | |
| 1250 // Make sure SDCH filters are told to emit histogram data while | |
| 1251 // filter_context_ is still alive. | |
| 1252 DestroyFilters(); | |
| 1253 | |
| 1254 if (sdch_dictionary_url_.is_valid()) { | |
| 1255 // Prior to reaching the destructor, request_ has been set to a NULL | |
| 1256 // pointer, so request_->url() is no longer valid in the destructor, and we | |
| 1257 // use an alternate copy |request_info_.url|. | |
| 1258 SdchManager* manager = SdchManager::Global(); | |
| 1259 // To be extra safe, since this is a "different time" from when we decided | |
| 1260 // to get the dictionary, we'll validate that an SdchManager is available. | |
| 1261 // At shutdown time, care is taken to be sure that we don't delete this | |
| 1262 // globally useful instance "too soon," so this check is just defensive | |
| 1263 // coding to assure that IF the system is shutting down, we don't have any | |
| 1264 // problem if the manager was deleted ahead of time. | |
| 1265 if (manager) // Defensive programming. | |
| 1266 manager->FetchDictionary(request_info_.url, sdch_dictionary_url_); | |
| 1267 } | |
| 1268 DoneWithRequest(ABORTED); | |
| 1269 } | |
| 1270 | |
| 1271 void URLRequestHttpJob::RecordTimer() { | 1271 void URLRequestHttpJob::RecordTimer() { |
| 1272 if (request_creation_time_.is_null()) { | 1272 if (request_creation_time_.is_null()) { |
| 1273 NOTREACHED() | 1273 NOTREACHED() |
| 1274 << "The same transaction shouldn't start twice without new timing."; | 1274 << "The same transaction shouldn't start twice without new timing."; |
| 1275 return; | 1275 return; |
| 1276 } | 1276 } |
| 1277 | 1277 |
| 1278 base::TimeDelta to_start = base::Time::Now() - request_creation_time_; | 1278 base::TimeDelta to_start = base::Time::Now() - request_creation_time_; |
| 1279 request_creation_time_ = base::Time(); | 1279 request_creation_time_ = base::Time(); |
| 1280 | 1280 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 DCHECK(transaction_->GetResponseInfo()); | 1571 DCHECK(transaction_->GetResponseInfo()); |
| 1572 return override_response_headers_.get() ? | 1572 return override_response_headers_.get() ? |
| 1573 override_response_headers_ : | 1573 override_response_headers_ : |
| 1574 transaction_->GetResponseInfo()->headers; | 1574 transaction_->GetResponseInfo()->headers; |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1577 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1578 awaiting_callback_ = false; | 1578 awaiting_callback_ = false; |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 void URLRequestHttpJob::SetPriority(RequestPriority priority) { |
| 1582 request_info_.priority = priority; |
| 1583 if (transaction_) |
| 1584 transaction_->SetPriority(priority); |
| 1585 } |
| 1586 |
| 1581 void URLRequestHttpJob::OnDetachRequest() { | 1587 void URLRequestHttpJob::OnDetachRequest() { |
| 1582 http_transaction_delegate_->OnDetachRequest(); | 1588 http_transaction_delegate_->OnDetachRequest(); |
| 1583 } | 1589 } |
| 1584 | 1590 |
| 1585 } // namespace net | 1591 } // namespace net |
| OLD | NEW |