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