| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 169 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 170 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 170 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 171 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 171 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
| 172 base::Bind(&URLRequestHttpJob::OnStartCompleted, | 172 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 173 base::Unretained(this)))), | 173 base::Unretained(this)))), |
| 174 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( | 174 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( |
| 175 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, | 175 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, |
| 176 base::Unretained(this)))), | 176 base::Unretained(this)))), |
| 177 read_in_progress_(false), | 177 read_in_progress_(false), |
| 178 transaction_(NULL), | 178 transaction_(NULL), |
| 179 throttling_entry_(URLRequestThrottlerManager::GetInstance()-> | 179 throttling_entry_(NULL), |
| 180 RegisterRequestUrl(request->url())), | |
| 181 sdch_dictionary_advertised_(false), | 180 sdch_dictionary_advertised_(false), |
| 182 sdch_test_activated_(false), | 181 sdch_test_activated_(false), |
| 183 sdch_test_control_(false), | 182 sdch_test_control_(false), |
| 184 is_cached_content_(false), | 183 is_cached_content_(false), |
| 185 request_creation_time_(), | 184 request_creation_time_(), |
| 186 packet_timing_enabled_(false), | 185 packet_timing_enabled_(false), |
| 187 done_(false), | 186 done_(false), |
| 188 bytes_observed_in_packets_(0), | 187 bytes_observed_in_packets_(0), |
| 189 request_time_snapshot_(), | 188 request_time_snapshot_(), |
| 190 final_packet_time_(), | 189 final_packet_time_(), |
| 191 ALLOW_THIS_IN_INITIALIZER_LIST( | 190 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 192 filter_context_(new HttpFilterContext(this))), | 191 filter_context_(new HttpFilterContext(this))), |
| 193 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 192 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 194 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( | 193 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( |
| 195 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, | 194 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 196 base::Unretained(this)))), | 195 base::Unretained(this)))), |
| 197 awaiting_callback_(false) { | 196 awaiting_callback_(false) { |
| 197 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 198 if (manager) |
| 199 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 200 |
| 198 ResetTimer(); | 201 ResetTimer(); |
| 199 } | 202 } |
| 200 | 203 |
| 201 void URLRequestHttpJob::NotifyHeadersComplete() { | 204 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 202 DCHECK(!response_info_); | 205 DCHECK(!response_info_); |
| 203 | 206 |
| 204 response_info_ = transaction_->GetResponseInfo(); | 207 response_info_ = transaction_->GetResponseInfo(); |
| 205 | 208 |
| 206 // Save boolean, as we'll need this info at destruction time, and filters may | 209 // Save boolean, as we'll need this info at destruction time, and filters may |
| 207 // also need this info. | 210 // also need this info. |
| 208 is_cached_content_ = response_info_->was_cached; | 211 is_cached_content_ = response_info_->was_cached; |
| 209 | 212 |
| 210 if (!is_cached_content_) { | 213 if (!is_cached_content_ && throttling_entry_) { |
| 211 URLRequestThrottlerHeaderAdapter response_adapter(GetResponseHeaders()); | 214 URLRequestThrottlerHeaderAdapter response_adapter(GetResponseHeaders()); |
| 212 throttling_entry_->UpdateWithResponse(request_info_.url.host(), | 215 throttling_entry_->UpdateWithResponse(request_info_.url.host(), |
| 213 &response_adapter); | 216 &response_adapter); |
| 214 } | 217 } |
| 215 | 218 |
| 216 // The ordering of these calls is not important. | 219 // The ordering of these calls is not important. |
| 217 ProcessStrictTransportSecurityHeader(); | 220 ProcessStrictTransportSecurityHeader(); |
| 218 ProcessPublicKeyPinsHeader(); | 221 ProcessPublicKeyPinsHeader(); |
| 219 | 222 |
| 220 if (SdchManager::Global() && | 223 if (SdchManager::Global() && |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 DCHECK(request_->context()->http_transaction_factory()); | 321 DCHECK(request_->context()->http_transaction_factory()); |
| 319 | 322 |
| 320 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 323 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 321 &transaction_); | 324 &transaction_); |
| 322 if (rv == OK) { | 325 if (rv == OK) { |
| 323 // TODO(joi): The hard-coded check for "chrome-extension" is | 326 // TODO(joi): The hard-coded check for "chrome-extension" is |
| 324 // temporary (as of 2012/3/21), intended only to make sure this | 327 // temporary (as of 2012/3/21), intended only to make sure this |
| 325 // change (to throttle only requests originating from | 328 // change (to throttle only requests originating from |
| 326 // extensions) gets into M19. Right after the M19 branch point, | 329 // extensions) gets into M19. Right after the M19 branch point, |
| 327 // I will sort this out in a more architecturally-sound way. | 330 // I will sort this out in a more architecturally-sound way. |
| 328 if (!URLRequestThrottlerManager::GetInstance()->enforce_throttling() || | 331 URLRequestThrottlerManager* manager = |
| 332 request_->context()->throttler_manager(); |
| 333 DCHECK(!manager || throttling_entry_); |
| 334 if (!manager || |
| 335 !manager->enforce_throttling() || |
| 329 request_->first_party_for_cookies().scheme() != "chrome-extension" || | 336 request_->first_party_for_cookies().scheme() != "chrome-extension" || |
| 330 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { | 337 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { |
| 331 rv = transaction_->Start( | 338 rv = transaction_->Start( |
| 332 &request_info_, start_callback_, request_->net_log()); | 339 &request_info_, start_callback_, request_->net_log()); |
| 333 start_time_ = base::TimeTicks::Now(); | 340 start_time_ = base::TimeTicks::Now(); |
| 334 } else { | 341 } else { |
| 335 // Special error code for the exponential back-off module. | 342 // Special error code for the exponential back-off module. |
| 336 rv = ERR_TEMPORARILY_THROTTLED; | 343 rv = ERR_TEMPORARILY_THROTTLED; |
| 337 } | 344 } |
| 338 // Make sure the context is alive for the duration of the | 345 // Make sure the context is alive for the duration of the |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 return override_response_headers_.get() ? | 1413 return override_response_headers_.get() ? |
| 1407 override_response_headers_ : | 1414 override_response_headers_ : |
| 1408 transaction_->GetResponseInfo()->headers; | 1415 transaction_->GetResponseInfo()->headers; |
| 1409 } | 1416 } |
| 1410 | 1417 |
| 1411 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1418 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1412 awaiting_callback_ = false; | 1419 awaiting_callback_ = false; |
| 1413 } | 1420 } |
| 1414 | 1421 |
| 1415 } // namespace net | 1422 } // namespace net |
| OLD | NEW |