| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) | 196 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) |
| 197 : URLRequestJob(request), | 197 : URLRequestJob(request), |
| 198 response_info_(NULL), | 198 response_info_(NULL), |
| 199 response_cookies_save_index_(0), | 199 response_cookies_save_index_(0), |
| 200 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 200 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 201 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 201 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 202 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 202 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
| 203 this, &URLRequestHttpJob::OnStartCompleted)), | 203 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 204 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 204 base::Unretained(this)))), |
| 205 this, &URLRequestHttpJob::OnReadCompleted)), | |
| 206 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( | 205 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( |
| 207 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, | 206 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, |
| 208 base::Unretained(this)))), | 207 base::Unretained(this)))), |
| 209 read_in_progress_(false), | 208 read_in_progress_(false), |
| 210 transaction_(NULL), | 209 transaction_(NULL), |
| 211 throttling_entry_(URLRequestThrottlerManager::GetInstance()-> | 210 throttling_entry_(URLRequestThrottlerManager::GetInstance()-> |
| 212 RegisterRequestUrl(request->url())), | 211 RegisterRequestUrl(request->url())), |
| 213 sdch_dictionary_advertised_(false), | 212 sdch_dictionary_advertised_(false), |
| 214 sdch_test_activated_(false), | 213 sdch_test_activated_(false), |
| 215 sdch_test_control_(false), | 214 sdch_test_control_(false), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // with auth provided by auth_credentials_. | 331 // with auth provided by auth_credentials_. |
| 333 | 332 |
| 334 int rv; | 333 int rv; |
| 335 | 334 |
| 336 if (request_->context() && request_->context()->network_delegate()) { | 335 if (request_->context() && request_->context()->network_delegate()) { |
| 337 request_->context()->network_delegate()->NotifySendHeaders( | 336 request_->context()->network_delegate()->NotifySendHeaders( |
| 338 request_, request_info_.extra_headers); | 337 request_, request_info_.extra_headers); |
| 339 } | 338 } |
| 340 | 339 |
| 341 if (transaction_.get()) { | 340 if (transaction_.get()) { |
| 342 rv = transaction_->RestartWithAuth(auth_credentials_, &start_callback_); | 341 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
| 343 auth_credentials_ = AuthCredentials(); | 342 auth_credentials_ = AuthCredentials(); |
| 344 } else { | 343 } else { |
| 345 DCHECK(request_->context()); | 344 DCHECK(request_->context()); |
| 346 DCHECK(request_->context()->http_transaction_factory()); | 345 DCHECK(request_->context()->http_transaction_factory()); |
| 347 | 346 |
| 348 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 347 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 349 &transaction_); | 348 &transaction_); |
| 350 if (rv == OK) { | 349 if (rv == OK) { |
| 351 if (!URLRequestThrottlerManager::GetInstance()->enforce_throttling() || | 350 if (!URLRequestThrottlerManager::GetInstance()->enforce_throttling() || |
| 352 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { | 351 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { |
| 353 rv = transaction_->Start( | 352 rv = transaction_->Start( |
| 354 &request_info_, &start_callback_, request_->net_log()); | 353 &request_info_, start_callback_, request_->net_log()); |
| 355 start_time_ = base::TimeTicks::Now(); | 354 start_time_ = base::TimeTicks::Now(); |
| 356 } else { | 355 } else { |
| 357 // Special error code for the exponential back-off module. | 356 // Special error code for the exponential back-off module. |
| 358 rv = ERR_TEMPORARILY_THROTTLED; | 357 rv = ERR_TEMPORARILY_THROTTLED; |
| 359 } | 358 } |
| 360 // Make sure the context is alive for the duration of the | 359 // Make sure the context is alive for the duration of the |
| 361 // transaction. | 360 // transaction. |
| 362 context_ = request_->context(); | 361 context_ = request_->context(); |
| 363 } | 362 } |
| 364 } | 363 } |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 DCHECK(transaction_.get()); | 1018 DCHECK(transaction_.get()); |
| 1020 | 1019 |
| 1021 DCHECK(!response_info_) << "should not have a response yet"; | 1020 DCHECK(!response_info_) << "should not have a response yet"; |
| 1022 | 1021 |
| 1023 ResetTimer(); | 1022 ResetTimer(); |
| 1024 | 1023 |
| 1025 // No matter what, we want to report our status as IO pending since we will | 1024 // No matter what, we want to report our status as IO pending since we will |
| 1026 // be notifying our consumer asynchronously via OnStartCompleted. | 1025 // be notifying our consumer asynchronously via OnStartCompleted. |
| 1027 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 1026 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 1028 | 1027 |
| 1029 int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_); | 1028 int rv = transaction_->RestartWithCertificate(client_cert, start_callback_); |
| 1030 if (rv == ERR_IO_PENDING) | 1029 if (rv == ERR_IO_PENDING) |
| 1031 return; | 1030 return; |
| 1032 | 1031 |
| 1033 // The transaction started synchronously, but we need to notify the | 1032 // The transaction started synchronously, but we need to notify the |
| 1034 // URLRequest delegate via the message loop. | 1033 // URLRequest delegate via the message loop. |
| 1035 MessageLoop::current()->PostTask( | 1034 MessageLoop::current()->PostTask( |
| 1036 FROM_HERE, | 1035 FROM_HERE, |
| 1037 method_factory_.NewRunnableMethod( | 1036 method_factory_.NewRunnableMethod( |
| 1038 &URLRequestHttpJob::OnStartCompleted, rv)); | 1037 &URLRequestHttpJob::OnStartCompleted, rv)); |
| 1039 } | 1038 } |
| 1040 | 1039 |
| 1041 void URLRequestHttpJob::ContinueDespiteLastError() { | 1040 void URLRequestHttpJob::ContinueDespiteLastError() { |
| 1042 // If the transaction was destroyed, then the job was cancelled. | 1041 // If the transaction was destroyed, then the job was cancelled. |
| 1043 if (!transaction_.get()) | 1042 if (!transaction_.get()) |
| 1044 return; | 1043 return; |
| 1045 | 1044 |
| 1046 DCHECK(!response_info_) << "should not have a response yet"; | 1045 DCHECK(!response_info_) << "should not have a response yet"; |
| 1047 | 1046 |
| 1048 ResetTimer(); | 1047 ResetTimer(); |
| 1049 | 1048 |
| 1050 // No matter what, we want to report our status as IO pending since we will | 1049 // No matter what, we want to report our status as IO pending since we will |
| 1051 // be notifying our consumer asynchronously via OnStartCompleted. | 1050 // be notifying our consumer asynchronously via OnStartCompleted. |
| 1052 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 1051 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 1053 | 1052 |
| 1054 int rv = transaction_->RestartIgnoringLastError(&start_callback_); | 1053 int rv = transaction_->RestartIgnoringLastError(start_callback_); |
| 1055 if (rv == ERR_IO_PENDING) | 1054 if (rv == ERR_IO_PENDING) |
| 1056 return; | 1055 return; |
| 1057 | 1056 |
| 1058 // The transaction started synchronously, but we need to notify the | 1057 // The transaction started synchronously, but we need to notify the |
| 1059 // URLRequest delegate via the message loop. | 1058 // URLRequest delegate via the message loop. |
| 1060 MessageLoop::current()->PostTask( | 1059 MessageLoop::current()->PostTask( |
| 1061 FROM_HERE, | 1060 FROM_HERE, |
| 1062 method_factory_.NewRunnableMethod( | 1061 method_factory_.NewRunnableMethod( |
| 1063 &URLRequestHttpJob::OnStartCompleted, rv)); | 1062 &URLRequestHttpJob::OnStartCompleted, rv)); |
| 1064 } | 1063 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1084 } | 1083 } |
| 1085 return false; | 1084 return false; |
| 1086 } | 1085 } |
| 1087 | 1086 |
| 1088 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, | 1087 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, |
| 1089 int* bytes_read) { | 1088 int* bytes_read) { |
| 1090 DCHECK_NE(buf_size, 0); | 1089 DCHECK_NE(buf_size, 0); |
| 1091 DCHECK(bytes_read); | 1090 DCHECK(bytes_read); |
| 1092 DCHECK(!read_in_progress_); | 1091 DCHECK(!read_in_progress_); |
| 1093 | 1092 |
| 1094 int rv = transaction_->Read(buf, buf_size, &read_callback_); | 1093 int rv = transaction_->Read( |
| 1094 buf, buf_size, |
| 1095 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); |
| 1095 | 1096 |
| 1096 if (ShouldFixMismatchedContentLength(rv)) | 1097 if (ShouldFixMismatchedContentLength(rv)) |
| 1097 rv = 0; | 1098 rv = 0; |
| 1098 | 1099 |
| 1099 if (rv >= 0) { | 1100 if (rv >= 0) { |
| 1100 *bytes_read = rv; | 1101 *bytes_read = rv; |
| 1101 if (!rv) | 1102 if (!rv) |
| 1102 DoneWithRequest(FINISHED); | 1103 DoneWithRequest(FINISHED); |
| 1103 return true; | 1104 return true; |
| 1104 } | 1105 } |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 return override_response_headers_.get() ? | 1401 return override_response_headers_.get() ? |
| 1401 override_response_headers_ : | 1402 override_response_headers_ : |
| 1402 transaction_->GetResponseInfo()->headers; | 1403 transaction_->GetResponseInfo()->headers; |
| 1403 } | 1404 } |
| 1404 | 1405 |
| 1405 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1406 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1406 awaiting_callback_ = false; | 1407 awaiting_callback_ = false; |
| 1407 } | 1408 } |
| 1408 | 1409 |
| 1409 } // namespace net | 1410 } // namespace net |
| OLD | NEW |