| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 network_delegate, | 221 network_delegate, |
| 222 request->context()->http_user_agent_settings()); | 222 request->context()->http_user_agent_settings()); |
| 223 } | 223 } |
| 224 | 224 |
| 225 | 225 |
| 226 URLRequestHttpJob::URLRequestHttpJob( | 226 URLRequestHttpJob::URLRequestHttpJob( |
| 227 URLRequest* request, | 227 URLRequest* request, |
| 228 NetworkDelegate* network_delegate, | 228 NetworkDelegate* network_delegate, |
| 229 const HttpUserAgentSettings* http_user_agent_settings) | 229 const HttpUserAgentSettings* http_user_agent_settings) |
| 230 : URLRequestJob(request, network_delegate), | 230 : URLRequestJob(request, network_delegate), |
| 231 priority_(DEFAULT_PRIORITY), |
| 231 response_info_(NULL), | 232 response_info_(NULL), |
| 232 response_cookies_save_index_(0), | 233 response_cookies_save_index_(0), |
| 233 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 234 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 234 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 235 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 235 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 236 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
| 236 base::Bind(&URLRequestHttpJob::OnStartCompleted, | 237 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 237 base::Unretained(this)))), | 238 base::Unretained(this)))), |
| 238 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( | 239 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( |
| 239 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, | 240 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, |
| 240 base::Unretained(this)))), | 241 base::Unretained(this)))), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 261 http_transaction_delegate_(new HttpTransactionDelegateImpl( | 262 http_transaction_delegate_(new HttpTransactionDelegateImpl( |
| 262 request, network_delegate)), | 263 request, network_delegate)), |
| 263 http_user_agent_settings_(http_user_agent_settings) { | 264 http_user_agent_settings_(http_user_agent_settings) { |
| 264 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 265 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 265 if (manager) | 266 if (manager) |
| 266 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 267 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 267 | 268 |
| 268 ResetTimer(); | 269 ResetTimer(); |
| 269 } | 270 } |
| 270 | 271 |
| 272 URLRequestHttpJob::~URLRequestHttpJob() { |
| 273 CHECK(!awaiting_callback_); |
| 274 |
| 275 DCHECK(!sdch_test_control_ || !sdch_test_activated_); |
| 276 if (!is_cached_content_) { |
| 277 if (sdch_test_control_) |
| 278 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); |
| 279 if (sdch_test_activated_) |
| 280 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); |
| 281 } |
| 282 // Make sure SDCH filters are told to emit histogram data while |
| 283 // filter_context_ is still alive. |
| 284 DestroyFilters(); |
| 285 |
| 286 if (sdch_dictionary_url_.is_valid()) { |
| 287 // Prior to reaching the destructor, request_ has been set to a NULL |
| 288 // pointer, so request_->url() is no longer valid in the destructor, and we |
| 289 // use an alternate copy |request_info_.url|. |
| 290 SdchManager* manager = SdchManager::Global(); |
| 291 // To be extra safe, since this is a "different time" from when we decided |
| 292 // to get the dictionary, we'll validate that an SdchManager is available. |
| 293 // At shutdown time, care is taken to be sure that we don't delete this |
| 294 // globally useful instance "too soon," so this check is just defensive |
| 295 // coding to assure that IF the system is shutting down, we don't have any |
| 296 // problem if the manager was deleted ahead of time. |
| 297 if (manager) // Defensive programming. |
| 298 manager->FetchDictionary(request_info_.url, sdch_dictionary_url_); |
| 299 } |
| 300 DoneWithRequest(ABORTED); |
| 301 } |
| 302 |
| 303 void URLRequestHttpJob::SetPriority(RequestPriority priority) { |
| 304 priority_ = priority; |
| 305 if (transaction_) |
| 306 transaction_->SetPriority(priority_); |
| 307 } |
| 308 |
| 309 void URLRequestHttpJob::Start() { |
| 310 DCHECK(!transaction_.get()); |
| 311 |
| 312 // Ensure that we do not send username and password fields in the referrer. |
| 313 GURL referrer(request_->GetSanitizedReferrer()); |
| 314 |
| 315 request_info_.url = request_->url(); |
| 316 request_info_.method = request_->method(); |
| 317 request_info_.load_flags = request_->load_flags(); |
| 318 request_info_.request_id = request_->identifier(); |
| 319 |
| 320 // Strip Referer from request_info_.extra_headers to prevent, e.g., plugins |
| 321 // from overriding headers that are controlled using other means. Otherwise a |
| 322 // plugin could set a referrer although sending the referrer is inhibited. |
| 323 request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kReferer); |
| 324 |
| 325 // Our consumer should have made sure that this is a safe referrer. See for |
| 326 // instance WebCore::FrameLoader::HideReferrer. |
| 327 if (referrer.is_valid()) { |
| 328 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 329 referrer.spec()); |
| 330 } |
| 331 |
| 332 request_info_.extra_headers.SetHeaderIfMissing( |
| 333 HttpRequestHeaders::kUserAgent, |
| 334 http_user_agent_settings_ ? |
| 335 http_user_agent_settings_->GetUserAgent(request_->url()) : |
| 336 EmptyString()); |
| 337 |
| 338 AddExtraHeaders(); |
| 339 AddCookieHeaderAndStart(); |
| 340 } |
| 341 |
| 342 void URLRequestHttpJob::Kill() { |
| 343 http_transaction_delegate_->OnDetachRequest(); |
| 344 |
| 345 if (!transaction_.get()) |
| 346 return; |
| 347 |
| 348 weak_factory_.InvalidateWeakPtrs(); |
| 349 DestroyTransaction(); |
| 350 URLRequestJob::Kill(); |
| 351 } |
| 352 |
| 271 void URLRequestHttpJob::NotifyHeadersComplete() { | 353 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 272 DCHECK(!response_info_); | 354 DCHECK(!response_info_); |
| 273 | 355 |
| 274 response_info_ = transaction_->GetResponseInfo(); | 356 response_info_ = transaction_->GetResponseInfo(); |
| 275 | 357 |
| 276 // Save boolean, as we'll need this info at destruction time, and filters may | 358 // Save boolean, as we'll need this info at destruction time, and filters may |
| 277 // also need this info. | 359 // also need this info. |
| 278 is_cached_content_ = response_info_->was_cached; | 360 is_cached_content_ = response_info_->was_cached; |
| 279 | 361 |
| 280 if (!is_cached_content_ && throttling_entry_) { | 362 if (!is_cached_content_ && throttling_entry_) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 request_, request_info_.extra_headers); | 469 request_, request_info_.extra_headers); |
| 388 } | 470 } |
| 389 | 471 |
| 390 if (transaction_.get()) { | 472 if (transaction_.get()) { |
| 391 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); | 473 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
| 392 auth_credentials_ = AuthCredentials(); | 474 auth_credentials_ = AuthCredentials(); |
| 393 } else { | 475 } else { |
| 394 DCHECK(request_->context()->http_transaction_factory()); | 476 DCHECK(request_->context()->http_transaction_factory()); |
| 395 | 477 |
| 396 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 478 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 397 request_->priority(), &transaction_, http_transaction_delegate_.get()); | 479 priority_, &transaction_, http_transaction_delegate_.get()); |
| 398 if (rv == OK) { | 480 if (rv == OK) { |
| 399 if (!throttling_entry_ || | 481 if (!throttling_entry_ || |
| 400 !throttling_entry_->ShouldRejectRequest(*request_)) { | 482 !throttling_entry_->ShouldRejectRequest(*request_)) { |
| 401 rv = transaction_->Start( | 483 rv = transaction_->Start( |
| 402 &request_info_, start_callback_, request_->net_log()); | 484 &request_info_, start_callback_, request_->net_log()); |
| 403 start_time_ = base::TimeTicks::Now(); | 485 start_time_ = base::TimeTicks::Now(); |
| 404 } else { | 486 } else { |
| 405 // Special error code for the exponential back-off module. | 487 // Special error code for the exponential back-off module. |
| 406 rv = ERR_TEMPORARILY_THROTTLED; | 488 rv = ERR_TEMPORARILY_THROTTLED; |
| 407 } | 489 } |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 DCHECK(!transaction_.get()) << "cannot change once started"; | 934 DCHECK(!transaction_.get()) << "cannot change once started"; |
| 853 request_info_.upload_data_stream = upload; | 935 request_info_.upload_data_stream = upload; |
| 854 } | 936 } |
| 855 | 937 |
| 856 void URLRequestHttpJob::SetExtraRequestHeaders( | 938 void URLRequestHttpJob::SetExtraRequestHeaders( |
| 857 const HttpRequestHeaders& headers) { | 939 const HttpRequestHeaders& headers) { |
| 858 DCHECK(!transaction_.get()) << "cannot change once started"; | 940 DCHECK(!transaction_.get()) << "cannot change once started"; |
| 859 request_info_.extra_headers.CopyFrom(headers); | 941 request_info_.extra_headers.CopyFrom(headers); |
| 860 } | 942 } |
| 861 | 943 |
| 862 void URLRequestHttpJob::Start() { | |
| 863 DCHECK(!transaction_.get()); | |
| 864 | |
| 865 // Ensure that we do not send username and password fields in the referrer. | |
| 866 GURL referrer(request_->GetSanitizedReferrer()); | |
| 867 | |
| 868 request_info_.url = request_->url(); | |
| 869 request_info_.method = request_->method(); | |
| 870 request_info_.load_flags = request_->load_flags(); | |
| 871 request_info_.request_id = request_->identifier(); | |
| 872 | |
| 873 // Strip Referer from request_info_.extra_headers to prevent, e.g., plugins | |
| 874 // from overriding headers that are controlled using other means. Otherwise a | |
| 875 // plugin could set a referrer although sending the referrer is inhibited. | |
| 876 request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kReferer); | |
| 877 | |
| 878 // Our consumer should have made sure that this is a safe referrer. See for | |
| 879 // instance WebCore::FrameLoader::HideReferrer. | |
| 880 if (referrer.is_valid()) { | |
| 881 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, | |
| 882 referrer.spec()); | |
| 883 } | |
| 884 | |
| 885 request_info_.extra_headers.SetHeaderIfMissing( | |
| 886 HttpRequestHeaders::kUserAgent, | |
| 887 http_user_agent_settings_ ? | |
| 888 http_user_agent_settings_->GetUserAgent(request_->url()) : | |
| 889 EmptyString()); | |
| 890 | |
| 891 AddExtraHeaders(); | |
| 892 AddCookieHeaderAndStart(); | |
| 893 } | |
| 894 | |
| 895 void URLRequestHttpJob::Kill() { | |
| 896 http_transaction_delegate_->OnDetachRequest(); | |
| 897 | |
| 898 if (!transaction_.get()) | |
| 899 return; | |
| 900 | |
| 901 weak_factory_.InvalidateWeakPtrs(); | |
| 902 DestroyTransaction(); | |
| 903 URLRequestJob::Kill(); | |
| 904 } | |
| 905 | |
| 906 LoadState URLRequestHttpJob::GetLoadState() const { | 944 LoadState URLRequestHttpJob::GetLoadState() const { |
| 907 return transaction_.get() ? | 945 return transaction_.get() ? |
| 908 transaction_->GetLoadState() : LOAD_STATE_IDLE; | 946 transaction_->GetLoadState() : LOAD_STATE_IDLE; |
| 909 } | 947 } |
| 910 | 948 |
| 911 UploadProgress URLRequestHttpJob::GetUploadProgress() const { | 949 UploadProgress URLRequestHttpJob::GetUploadProgress() const { |
| 912 return transaction_.get() ? | 950 return transaction_.get() ? |
| 913 transaction_->GetUploadProgress() : UploadProgress(); | 951 transaction_->GetUploadProgress() : UploadProgress(); |
| 914 } | 952 } |
| 915 | 953 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 void URLRequestHttpJob::DoneReading() { | 1261 void URLRequestHttpJob::DoneReading() { |
| 1224 if (transaction_.get()) | 1262 if (transaction_.get()) |
| 1225 transaction_->DoneReading(); | 1263 transaction_->DoneReading(); |
| 1226 DoneWithRequest(FINISHED); | 1264 DoneWithRequest(FINISHED); |
| 1227 } | 1265 } |
| 1228 | 1266 |
| 1229 HostPortPair URLRequestHttpJob::GetSocketAddress() const { | 1267 HostPortPair URLRequestHttpJob::GetSocketAddress() const { |
| 1230 return response_info_ ? response_info_->socket_address : HostPortPair(); | 1268 return response_info_ ? response_info_->socket_address : HostPortPair(); |
| 1231 } | 1269 } |
| 1232 | 1270 |
| 1233 URLRequestHttpJob::~URLRequestHttpJob() { | |
| 1234 CHECK(!awaiting_callback_); | |
| 1235 | |
| 1236 DCHECK(!sdch_test_control_ || !sdch_test_activated_); | |
| 1237 if (!is_cached_content_) { | |
| 1238 if (sdch_test_control_) | |
| 1239 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); | |
| 1240 if (sdch_test_activated_) | |
| 1241 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); | |
| 1242 } | |
| 1243 // Make sure SDCH filters are told to emit histogram data while | |
| 1244 // filter_context_ is still alive. | |
| 1245 DestroyFilters(); | |
| 1246 | |
| 1247 if (sdch_dictionary_url_.is_valid()) { | |
| 1248 // Prior to reaching the destructor, request_ has been set to a NULL | |
| 1249 // pointer, so request_->url() is no longer valid in the destructor, and we | |
| 1250 // use an alternate copy |request_info_.url|. | |
| 1251 SdchManager* manager = SdchManager::Global(); | |
| 1252 // To be extra safe, since this is a "different time" from when we decided | |
| 1253 // to get the dictionary, we'll validate that an SdchManager is available. | |
| 1254 // At shutdown time, care is taken to be sure that we don't delete this | |
| 1255 // globally useful instance "too soon," so this check is just defensive | |
| 1256 // coding to assure that IF the system is shutting down, we don't have any | |
| 1257 // problem if the manager was deleted ahead of time. | |
| 1258 if (manager) // Defensive programming. | |
| 1259 manager->FetchDictionary(request_info_.url, sdch_dictionary_url_); | |
| 1260 } | |
| 1261 DoneWithRequest(ABORTED); | |
| 1262 } | |
| 1263 | |
| 1264 void URLRequestHttpJob::RecordTimer() { | 1271 void URLRequestHttpJob::RecordTimer() { |
| 1265 if (request_creation_time_.is_null()) { | 1272 if (request_creation_time_.is_null()) { |
| 1266 NOTREACHED() | 1273 NOTREACHED() |
| 1267 << "The same transaction shouldn't start twice without new timing."; | 1274 << "The same transaction shouldn't start twice without new timing."; |
| 1268 return; | 1275 return; |
| 1269 } | 1276 } |
| 1270 | 1277 |
| 1271 base::TimeDelta to_start = base::Time::Now() - request_creation_time_; | 1278 base::TimeDelta to_start = base::Time::Now() - request_creation_time_; |
| 1272 request_creation_time_ = base::Time(); | 1279 request_creation_time_ = base::Time(); |
| 1273 | 1280 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 | 1576 |
| 1570 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1577 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1571 awaiting_callback_ = false; | 1578 awaiting_callback_ = false; |
| 1572 } | 1579 } |
| 1573 | 1580 |
| 1574 void URLRequestHttpJob::OnDetachRequest() { | 1581 void URLRequestHttpJob::OnDetachRequest() { |
| 1575 http_transaction_delegate_->OnDetachRequest(); | 1582 http_transaction_delegate_->OnDetachRequest(); |
| 1576 } | 1583 } |
| 1577 | 1584 |
| 1578 } // namespace net | 1585 } // namespace net |
| OLD | NEW |