| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug/alias.h" |
| 12 #include "base/file_version_info.h" | 13 #include "base/file_version_info.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
| 17 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 done_(false), | 201 done_(false), |
| 201 bytes_observed_in_packets_(0), | 202 bytes_observed_in_packets_(0), |
| 202 request_time_snapshot_(), | 203 request_time_snapshot_(), |
| 203 final_packet_time_(), | 204 final_packet_time_(), |
| 204 filter_context_(new HttpFilterContext(this)), | 205 filter_context_(new HttpFilterContext(this)), |
| 205 on_headers_received_callback_( | 206 on_headers_received_callback_( |
| 206 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, | 207 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 207 base::Unretained(this))), | 208 base::Unretained(this))), |
| 208 awaiting_callback_(false), | 209 awaiting_callback_(false), |
| 209 http_user_agent_settings_(http_user_agent_settings), | 210 http_user_agent_settings_(http_user_agent_settings), |
| 211 transaction_state_(TRANSACTION_WAS_NOT_INITIALIZED), |
| 210 weak_factory_(this) { | 212 weak_factory_(this) { |
| 211 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 213 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 212 if (manager) | 214 if (manager) |
| 213 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 215 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 214 | 216 |
| 217 // TODO(battre) Remove this overriding once crbug.com/289715 has been |
| 218 // resolved. |
| 219 on_headers_received_callback_ = |
| 220 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallbackForDebugging, |
| 221 weak_factory_.GetWeakPtr()); |
| 222 |
| 215 ResetTimer(); | 223 ResetTimer(); |
| 216 } | 224 } |
| 217 | 225 |
| 218 URLRequestHttpJob::~URLRequestHttpJob() { | 226 URLRequestHttpJob::~URLRequestHttpJob() { |
| 219 CHECK(!awaiting_callback_); | 227 CHECK(!awaiting_callback_); |
| 220 | 228 |
| 221 DCHECK(!sdch_test_control_ || !sdch_test_activated_); | 229 DCHECK(!sdch_test_control_ || !sdch_test_activated_); |
| 222 if (!is_cached_content_) { | 230 if (!is_cached_content_) { |
| 223 if (sdch_test_control_) | 231 if (sdch_test_control_) |
| 224 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); | 232 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { | 408 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { |
| 401 DoneWithRequest(FINISHED); | 409 DoneWithRequest(FINISHED); |
| 402 URLRequestJob::NotifyDone(status); | 410 URLRequestJob::NotifyDone(status); |
| 403 } | 411 } |
| 404 | 412 |
| 405 void URLRequestHttpJob::DestroyTransaction() { | 413 void URLRequestHttpJob::DestroyTransaction() { |
| 406 DCHECK(transaction_.get()); | 414 DCHECK(transaction_.get()); |
| 407 | 415 |
| 408 DoneWithRequest(ABORTED); | 416 DoneWithRequest(ABORTED); |
| 409 transaction_.reset(); | 417 transaction_.reset(); |
| 418 transaction_state_ = TRANSACTION_WAS_DESTROYED; |
| 410 response_info_ = NULL; | 419 response_info_ = NULL; |
| 411 receive_headers_end_ = base::TimeTicks(); | 420 receive_headers_end_ = base::TimeTicks(); |
| 412 } | 421 } |
| 413 | 422 |
| 414 void URLRequestHttpJob::StartTransaction() { | 423 void URLRequestHttpJob::StartTransaction() { |
| 415 if (network_delegate()) { | 424 if (network_delegate()) { |
| 416 OnCallToDelegate(); | 425 OnCallToDelegate(); |
| 417 int rv = network_delegate()->NotifyBeforeSendHeaders( | 426 int rv = network_delegate()->NotifyBeforeSendHeaders( |
| 418 request_, notify_before_headers_sent_callback_, | 427 request_, notify_before_headers_sent_callback_, |
| 419 &request_info_.extra_headers); | 428 &request_info_.extra_headers); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 470 } |
| 462 | 471 |
| 463 if (transaction_.get()) { | 472 if (transaction_.get()) { |
| 464 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); | 473 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
| 465 auth_credentials_ = AuthCredentials(); | 474 auth_credentials_ = AuthCredentials(); |
| 466 } else { | 475 } else { |
| 467 DCHECK(request_->context()->http_transaction_factory()); | 476 DCHECK(request_->context()->http_transaction_factory()); |
| 468 | 477 |
| 469 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 478 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 470 priority_, &transaction_); | 479 priority_, &transaction_); |
| 480 if (rv == OK) |
| 481 transaction_state_ = TRANSACTION_WAS_INITIALIZED; |
| 471 | 482 |
| 472 if (rv == OK && request_info_.url.SchemeIsWSOrWSS()) { | 483 if (rv == OK && request_info_.url.SchemeIsWSOrWSS()) { |
| 473 base::SupportsUserData::Data* data = request_->GetUserData( | 484 base::SupportsUserData::Data* data = request_->GetUserData( |
| 474 WebSocketHandshakeStreamBase::CreateHelper::DataKey()); | 485 WebSocketHandshakeStreamBase::CreateHelper::DataKey()); |
| 475 if (data) { | 486 if (data) { |
| 476 transaction_->SetWebSocketHandshakeStreamCreateHelper( | 487 transaction_->SetWebSocketHandshakeStreamCreateHelper( |
| 477 static_cast<WebSocketHandshakeStreamBase::CreateHelper*>(data)); | 488 static_cast<WebSocketHandshakeStreamBase::CreateHelper*>(data)); |
| 478 } else { | 489 } else { |
| 479 rv = ERR_DISALLOWED_URL_SCHEME; | 490 rv = ERR_DISALLOWED_URL_SCHEME; |
| 480 } | 491 } |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 transaction_->GetResponseInfo()->cert_request_info.get()); | 937 transaction_->GetResponseInfo()->cert_request_info.get()); |
| 927 } else { | 938 } else { |
| 928 // Even on an error, there may be useful information in the response | 939 // Even on an error, there may be useful information in the response |
| 929 // info (e.g. whether there's a cached copy). | 940 // info (e.g. whether there's a cached copy). |
| 930 if (transaction_.get()) | 941 if (transaction_.get()) |
| 931 response_info_ = transaction_->GetResponseInfo(); | 942 response_info_ = transaction_->GetResponseInfo(); |
| 932 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 943 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 933 } | 944 } |
| 934 } | 945 } |
| 935 | 946 |
| 947 // TODO(battre) Use URLRequestHttpJob::OnHeadersReceivedCallback again, once |
| 948 // crbug.com/289715 has been resolved. |
| 949 // static |
| 950 void URLRequestHttpJob::OnHeadersReceivedCallbackForDebugging( |
| 951 base::WeakPtr<net::URLRequestHttpJob> job, |
| 952 int result) { |
| 953 CHECK(job.get()); |
| 954 net::URLRequestHttpJob::TransactionState state = job->transaction_state_; |
| 955 base::debug::Alias(&state); |
| 956 CHECK(job->transaction_.get()); |
| 957 job->OnHeadersReceivedCallback(result); |
| 958 } |
| 959 |
| 936 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { | 960 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { |
| 937 awaiting_callback_ = false; | 961 awaiting_callback_ = false; |
| 938 | 962 |
| 939 // Check that there are no callbacks to already canceled requests. | 963 // Check that there are no callbacks to already canceled requests. |
| 940 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); | 964 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 941 | 965 |
| 942 SaveCookiesAndNotifyHeadersComplete(result); | 966 SaveCookiesAndNotifyHeadersComplete(result); |
| 943 } | 967 } |
| 944 | 968 |
| 945 void URLRequestHttpJob::OnReadCompleted(int result) { | 969 void URLRequestHttpJob::OnReadCompleted(int result) { |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 return override_response_headers_.get() ? | 1598 return override_response_headers_.get() ? |
| 1575 override_response_headers_.get() : | 1599 override_response_headers_.get() : |
| 1576 transaction_->GetResponseInfo()->headers.get(); | 1600 transaction_->GetResponseInfo()->headers.get(); |
| 1577 } | 1601 } |
| 1578 | 1602 |
| 1579 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1603 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1580 awaiting_callback_ = false; | 1604 awaiting_callback_ = false; |
| 1581 } | 1605 } |
| 1582 | 1606 |
| 1583 } // namespace net | 1607 } // namespace net |
| OLD | NEW |