Chromium Code Reviews| 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_ = base::Bind( | |
| 220 &OnHeadersReceivedCallbackForDebugging, weak_factory_.GetWeakPtr()); | |
| 221 | |
| 215 ResetTimer(); | 222 ResetTimer(); |
| 216 } | 223 } |
| 217 | 224 |
| 218 URLRequestHttpJob::~URLRequestHttpJob() { | 225 URLRequestHttpJob::~URLRequestHttpJob() { |
| 219 CHECK(!awaiting_callback_); | 226 CHECK(!awaiting_callback_); |
| 220 | 227 |
| 221 DCHECK(!sdch_test_control_ || !sdch_test_activated_); | 228 DCHECK(!sdch_test_control_ || !sdch_test_activated_); |
| 222 if (!is_cached_content_) { | 229 if (!is_cached_content_) { |
| 223 if (sdch_test_control_) | 230 if (sdch_test_control_) |
| 224 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); | 231 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) { | 407 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { |
| 401 DoneWithRequest(FINISHED); | 408 DoneWithRequest(FINISHED); |
| 402 URLRequestJob::NotifyDone(status); | 409 URLRequestJob::NotifyDone(status); |
| 403 } | 410 } |
| 404 | 411 |
| 405 void URLRequestHttpJob::DestroyTransaction() { | 412 void URLRequestHttpJob::DestroyTransaction() { |
| 406 DCHECK(transaction_.get()); | 413 DCHECK(transaction_.get()); |
| 407 | 414 |
| 408 DoneWithRequest(ABORTED); | 415 DoneWithRequest(ABORTED); |
| 409 transaction_.reset(); | 416 transaction_.reset(); |
| 417 transaction_state_ = TRANSACTION_WAS_DESTROYED; | |
| 410 response_info_ = NULL; | 418 response_info_ = NULL; |
| 411 receive_headers_end_ = base::TimeTicks(); | 419 receive_headers_end_ = base::TimeTicks(); |
| 412 } | 420 } |
| 413 | 421 |
| 414 void URLRequestHttpJob::StartTransaction() { | 422 void URLRequestHttpJob::StartTransaction() { |
| 415 if (network_delegate()) { | 423 if (network_delegate()) { |
| 416 OnCallToDelegate(); | 424 OnCallToDelegate(); |
| 417 int rv = network_delegate()->NotifyBeforeSendHeaders( | 425 int rv = network_delegate()->NotifyBeforeSendHeaders( |
| 418 request_, notify_before_headers_sent_callback_, | 426 request_, notify_before_headers_sent_callback_, |
| 419 &request_info_.extra_headers); | 427 &request_info_.extra_headers); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 } | 469 } |
| 462 | 470 |
| 463 if (transaction_.get()) { | 471 if (transaction_.get()) { |
| 464 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); | 472 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
| 465 auth_credentials_ = AuthCredentials(); | 473 auth_credentials_ = AuthCredentials(); |
| 466 } else { | 474 } else { |
| 467 DCHECK(request_->context()->http_transaction_factory()); | 475 DCHECK(request_->context()->http_transaction_factory()); |
| 468 | 476 |
| 469 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 477 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 470 priority_, &transaction_); | 478 priority_, &transaction_); |
| 479 if (rv == OK) { | |
| 480 transaction_state_ = TRANSACTION_WAS_INITIALIZED; | |
| 481 } | |
|
mmenke
2015/01/09 16:54:51
nit: No braces when if and body are both one line
battre
2015/01/09 18:02:30
Done.
| |
| 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 void OnHeadersReceivedCallbackForDebugging( | |
|
mmenke
2015/01/09 16:54:51
Definition order should match declaration order (W
battre
2015/01/09 18:02:30
Done.
| |
| 950 base::WeakPtr<net::URLRequestHttpJob> job, | |
| 951 int result) { | |
| 952 CHECK(job.get()); | |
|
mmenke
2015/01/09 16:54:51
Does this work, or does base::Bind cancel the call
battre
2015/01/09 18:02:30
I verified that this:
class AAA {
public:
AAA()
| |
| 953 net::URLRequestHttpJob::TransactionState state = job->transaction_state_; | |
| 954 base::debug::Alias(&state); | |
| 955 CHECK(job->transaction_.get()); | |
| 956 job->OnHeadersReceivedCallback(result); | |
| 957 } | |
| 958 | |
| 936 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { | 959 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { |
| 937 awaiting_callback_ = false; | 960 awaiting_callback_ = false; |
| 938 | 961 |
| 939 // Check that there are no callbacks to already canceled requests. | 962 // Check that there are no callbacks to already canceled requests. |
| 940 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); | 963 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 941 | 964 |
| 942 SaveCookiesAndNotifyHeadersComplete(result); | 965 SaveCookiesAndNotifyHeadersComplete(result); |
| 943 } | 966 } |
| 944 | 967 |
| 945 void URLRequestHttpJob::OnReadCompleted(int result) { | 968 void URLRequestHttpJob::OnReadCompleted(int result) { |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1574 return override_response_headers_.get() ? | 1597 return override_response_headers_.get() ? |
| 1575 override_response_headers_.get() : | 1598 override_response_headers_.get() : |
| 1576 transaction_->GetResponseInfo()->headers.get(); | 1599 transaction_->GetResponseInfo()->headers.get(); |
| 1577 } | 1600 } |
| 1578 | 1601 |
| 1579 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1602 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1580 awaiting_callback_ = false; | 1603 awaiting_callback_ = false; |
| 1581 } | 1604 } |
| 1582 | 1605 |
| 1583 } // namespace net | 1606 } // namespace net |
| OLD | NEW |