| 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 16 matching lines...) Expand all Loading... |
| 27 #include "net/base/network_delegate.h" | 27 #include "net/base/network_delegate.h" |
| 28 #include "net/base/sdch_manager.h" | 28 #include "net/base/sdch_manager.h" |
| 29 #include "net/base/ssl_cert_request_info.h" | 29 #include "net/base/ssl_cert_request_info.h" |
| 30 #include "net/base/ssl_config_service.h" | 30 #include "net/base/ssl_config_service.h" |
| 31 #include "net/cookies/cookie_monster.h" | 31 #include "net/cookies/cookie_monster.h" |
| 32 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 33 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 34 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
| 35 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 36 #include "net/http/http_transaction.h" | 36 #include "net/http/http_transaction.h" |
| 37 #include "net/http/http_transaction_delegate.h" |
| 37 #include "net/http/http_transaction_factory.h" | 38 #include "net/http/http_transaction_factory.h" |
| 38 #include "net/http/http_util.h" | 39 #include "net/http/http_util.h" |
| 39 #include "net/url_request/fraudulent_certificate_reporter.h" | 40 #include "net/url_request/fraudulent_certificate_reporter.h" |
| 40 #include "net/url_request/url_request.h" | 41 #include "net/url_request/url_request.h" |
| 41 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
| 42 #include "net/url_request/url_request_error_job.h" | 43 #include "net/url_request/url_request_error_job.h" |
| 43 #include "net/url_request/url_request_redirect_job.h" | 44 #include "net/url_request/url_request_redirect_job.h" |
| 44 #include "net/url_request/url_request_throttler_header_adapter.h" | 45 #include "net/url_request/url_request_throttler_header_adapter.h" |
| 45 #include "net/url_request/url_request_throttler_manager.h" | 46 #include "net/url_request/url_request_throttler_manager.h" |
| 46 | 47 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 // Method to allow us to reset filter context for a response that should have | 68 // Method to allow us to reset filter context for a response that should have |
| 68 // been SDCH encoded when there is an update due to an explicit HTTP header. | 69 // been SDCH encoded when there is an update due to an explicit HTTP header. |
| 69 void ResetSdchResponseToFalse(); | 70 void ResetSdchResponseToFalse(); |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 URLRequestHttpJob* job_; | 73 URLRequestHttpJob* job_; |
| 73 | 74 |
| 74 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 75 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
| 75 }; | 76 }; |
| 76 | 77 |
| 78 class URLRequestHttpJob::HttpTransactionDelegateImpl |
| 79 : public HttpTransactionDelegate { |
| 80 public: |
| 81 explicit HttpTransactionDelegateImpl(URLRequest* request) |
| 82 : request_(request), |
| 83 network_delegate_(request->context()->network_delegate()) { |
| 84 } |
| 85 virtual ~HttpTransactionDelegateImpl() { |
| 86 OnDetachRequest(); |
| 87 } |
| 88 void OnDetachRequest() { |
| 89 if (request_ == NULL || network_delegate_ == NULL) |
| 90 return; |
| 91 network_delegate_->NotifyCacheWaitStateChange( |
| 92 *request_, |
| 93 NetworkDelegate::CACHE_WAIT_STATE_RESET); |
| 94 request_ = NULL; |
| 95 } |
| 96 virtual void OnCacheActionStart() OVERRIDE { |
| 97 if (request_ == NULL || network_delegate_ == NULL) |
| 98 return; |
| 99 network_delegate_->NotifyCacheWaitStateChange( |
| 100 *request_, |
| 101 NetworkDelegate::CACHE_WAIT_STATE_START); |
| 102 } |
| 103 virtual void OnCacheActionFinish() OVERRIDE { |
| 104 if (request_ == NULL || network_delegate_ == NULL) |
| 105 return; |
| 106 network_delegate_->NotifyCacheWaitStateChange( |
| 107 *request_, |
| 108 NetworkDelegate::CACHE_WAIT_STATE_FINISH); |
| 109 } |
| 110 private: |
| 111 URLRequest* request_; |
| 112 NetworkDelegate* network_delegate_; |
| 113 }; |
| 114 |
| 77 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) | 115 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) |
| 78 : job_(job) { | 116 : job_(job) { |
| 79 DCHECK(job_); | 117 DCHECK(job_); |
| 80 } | 118 } |
| 81 | 119 |
| 82 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { | 120 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { |
| 83 } | 121 } |
| 84 | 122 |
| 85 bool URLRequestHttpJob::HttpFilterContext::GetMimeType( | 123 bool URLRequestHttpJob::HttpFilterContext::GetMimeType( |
| 86 std::string* mime_type) const { | 124 std::string* mime_type) const { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 done_(false), | 209 done_(false), |
| 172 bytes_observed_in_packets_(0), | 210 bytes_observed_in_packets_(0), |
| 173 request_time_snapshot_(), | 211 request_time_snapshot_(), |
| 174 final_packet_time_(), | 212 final_packet_time_(), |
| 175 ALLOW_THIS_IN_INITIALIZER_LIST( | 213 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 176 filter_context_(new HttpFilterContext(this))), | 214 filter_context_(new HttpFilterContext(this))), |
| 177 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 215 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 178 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( | 216 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( |
| 179 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, | 217 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 180 base::Unretained(this)))), | 218 base::Unretained(this)))), |
| 181 awaiting_callback_(false) { | 219 awaiting_callback_(false), |
| 220 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)) { |
| 182 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 221 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 183 if (manager) | 222 if (manager) |
| 184 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 223 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 185 | 224 |
| 186 ResetTimer(); | 225 ResetTimer(); |
| 187 } | 226 } |
| 188 | 227 |
| 189 void URLRequestHttpJob::NotifyHeadersComplete() { | 228 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 190 DCHECK(!response_info_); | 229 DCHECK(!response_info_); |
| 191 | 230 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 338 } |
| 300 | 339 |
| 301 if (transaction_.get()) { | 340 if (transaction_.get()) { |
| 302 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); | 341 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
| 303 auth_credentials_ = AuthCredentials(); | 342 auth_credentials_ = AuthCredentials(); |
| 304 } else { | 343 } else { |
| 305 DCHECK(request_->context()); | 344 DCHECK(request_->context()); |
| 306 DCHECK(request_->context()->http_transaction_factory()); | 345 DCHECK(request_->context()->http_transaction_factory()); |
| 307 | 346 |
| 308 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 347 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 309 &transaction_); | 348 &transaction_, http_transaction_delegate_.get()); |
| 310 if (rv == OK) { | 349 if (rv == OK) { |
| 311 if (!throttling_entry_ || | 350 if (!throttling_entry_ || |
| 312 !throttling_entry_->ShouldRejectRequest(*request_)) { | 351 !throttling_entry_->ShouldRejectRequest(*request_)) { |
| 313 rv = transaction_->Start( | 352 rv = transaction_->Start( |
| 314 &request_info_, start_callback_, request_->net_log()); | 353 &request_info_, start_callback_, request_->net_log()); |
| 315 start_time_ = base::TimeTicks::Now(); | 354 start_time_ = base::TimeTicks::Now(); |
| 316 } else { | 355 } else { |
| 317 // Special error code for the exponential back-off module. | 356 // Special error code for the exponential back-off module. |
| 318 rv = ERR_TEMPORARILY_THROTTLED; | 357 rv = ERR_TEMPORARILY_THROTTLED; |
| 319 } | 358 } |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 DCHECK(transaction_->GetResponseInfo()); | 1469 DCHECK(transaction_->GetResponseInfo()); |
| 1431 return override_response_headers_.get() ? | 1470 return override_response_headers_.get() ? |
| 1432 override_response_headers_ : | 1471 override_response_headers_ : |
| 1433 transaction_->GetResponseInfo()->headers; | 1472 transaction_->GetResponseInfo()->headers; |
| 1434 } | 1473 } |
| 1435 | 1474 |
| 1436 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1475 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1437 awaiting_callback_ = false; | 1476 awaiting_callback_ = false; |
| 1438 } | 1477 } |
| 1439 | 1478 |
| 1479 void URLRequestHttpJob::OnDetachRequest() { |
| 1480 http_transaction_delegate_->OnDetachRequest(); |
| 1481 } |
| 1482 |
| 1440 } // namespace net | 1483 } // namespace net |
| OLD | NEW |