Chromium Code Reviews| 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_job.h" | 5 #include "net/url_request/url_request_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/auth.h" | 11 #include "net/base/auth.h" |
| 12 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/load_states.h" | 14 #include "net/base/load_states.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/base/network_delegate.h" | 16 #include "net/base/network_delegate.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_job_tracker.h" | |
| 21 | 20 |
| 22 namespace net { | 21 namespace net { |
| 23 | 22 |
| 24 URLRequestJob::URLRequestJob(URLRequest* request) | 23 URLRequestJob::URLRequestJob(URLRequest* request) |
| 25 : request_(request), | 24 : request_(request), |
| 26 done_(false), | 25 done_(false), |
| 27 prefilter_bytes_read_(0), | 26 prefilter_bytes_read_(0), |
| 28 postfilter_bytes_read_(0), | 27 postfilter_bytes_read_(0), |
| 29 filter_input_byte_count_(0), | 28 filter_input_byte_count_(0), |
| 30 filter_needs_more_output_space_(false), | 29 filter_needs_more_output_space_(false), |
| 31 filtered_read_buffer_len_(0), | 30 filtered_read_buffer_len_(0), |
| 32 has_handled_response_(false), | 31 has_handled_response_(false), |
| 33 expected_content_size_(-1), | 32 expected_content_size_(-1), |
| 34 deferred_redirect_status_code_(-1), | 33 deferred_redirect_status_code_(-1), |
| 35 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 34 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
|
rvargas (doing something else)
2011/05/18 21:45:18
nit: Could you move the closing bracket to the nex
willchan no longer on Chromium
2011/05/18 23:55:55
Done.
| |
| 36 g_url_request_job_tracker.AddNewJob(this); | |
| 37 } | |
| 38 | 35 |
| 39 void URLRequestJob::SetUpload(UploadData* upload) { | 36 void URLRequestJob::SetUpload(UploadData* upload) { |
| 40 } | 37 } |
| 41 | 38 |
| 42 void URLRequestJob::SetExtraRequestHeaders( | 39 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) {} |
| 43 const HttpRequestHeaders& headers) { | |
| 44 } | |
| 45 | 40 |
| 46 void URLRequestJob::Kill() { | 41 void URLRequestJob::Kill() { |
| 47 // Make sure the request is notified that we are done. We assume that the | 42 // Make sure the request is notified that we are done. We assume that the |
| 48 // request took care of setting its error status before calling Kill. | 43 // request took care of setting its error status before calling Kill. |
| 49 if (request_) | 44 if (request_) |
| 50 NotifyCanceled(); | 45 NotifyCanceled(); |
| 51 } | 46 } |
| 52 | 47 |
| 53 void URLRequestJob::DetachRequest() { | 48 void URLRequestJob::DetachRequest() { |
| 54 request_ = NULL; | 49 request_ = NULL; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 } | 191 } |
| 197 | 192 |
| 198 int URLRequestJob::GetResponseCode() const { | 193 int URLRequestJob::GetResponseCode() const { |
| 199 return -1; | 194 return -1; |
| 200 } | 195 } |
| 201 | 196 |
| 202 HostPortPair URLRequestJob::GetSocketAddress() const { | 197 HostPortPair URLRequestJob::GetSocketAddress() const { |
| 203 return HostPortPair(); | 198 return HostPortPair(); |
| 204 } | 199 } |
| 205 | 200 |
| 206 URLRequestJob::~URLRequestJob() { | 201 void URLRequestJob::OnSuspend() { |
| 207 g_url_request_job_tracker.RemoveJob(this); | 202 Kill(); |
| 208 } | 203 } |
| 209 | 204 |
| 205 URLRequestJob::~URLRequestJob() {} | |
| 206 | |
| 210 void URLRequestJob::NotifyHeadersComplete() { | 207 void URLRequestJob::NotifyHeadersComplete() { |
| 211 if (!request_ || !request_->delegate()) | 208 if (!request_ || !request_->delegate()) |
| 212 return; // The request was destroyed, so there is no more work to do. | 209 return; // The request was destroyed, so there is no more work to do. |
| 213 | 210 |
| 214 if (has_handled_response_) | 211 if (has_handled_response_) |
| 215 return; | 212 return; |
| 216 | 213 |
| 217 DCHECK(!request_->status().is_io_pending()); | 214 DCHECK(!request_->status().is_io_pending()); |
| 218 | 215 |
| 219 // Initialize to the current time, and let the subclass optionally override | 216 // Initialize to the current time, and let the subclass optionally override |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 // With async IO, it's quite possible to have a few outstanding | 352 // With async IO, it's quite possible to have a few outstanding |
| 356 // requests. We could receive a request to Cancel, followed shortly | 353 // requests. We could receive a request to Cancel, followed shortly |
| 357 // by a successful IO. For tracking the status(), once there is | 354 // by a successful IO. For tracking the status(), once there is |
| 358 // an error, we do not change the status back to success. To | 355 // an error, we do not change the status back to success. To |
| 359 // enforce this, only set the status if the job is so far | 356 // enforce this, only set the status if the job is so far |
| 360 // successful. | 357 // successful. |
| 361 if (request_->status().is_success()) | 358 if (request_->status().is_success()) |
| 362 request_->set_status(status); | 359 request_->set_status(status); |
| 363 } | 360 } |
| 364 | 361 |
| 365 g_url_request_job_tracker.OnJobDone(this, status); | |
| 366 | |
| 367 if (request_ && request_->context() && | 362 if (request_ && request_->context() && |
| 368 request_->context()->network_delegate()) { | 363 request_->context()->network_delegate()) { |
| 369 request_->context()->network_delegate()->NotifyCompleted(request_); | 364 request_->context()->network_delegate()->NotifyCompleted(request_); |
| 370 } | 365 } |
| 371 | 366 |
| 372 // Complete this notification later. This prevents us from re-entering the | 367 // Complete this notification later. This prevents us from re-entering the |
| 373 // delegate if we're done because of a synchronous call. | 368 // delegate if we're done because of a synchronous call. |
| 374 MessageLoop::current()->PostTask( | 369 MessageLoop::current()->PostTask( |
| 375 FROM_HERE, | 370 FROM_HERE, |
| 376 method_factory_.NewRunnableMethod(&URLRequestJob::CompleteNotifyDone)); | 371 method_factory_.NewRunnableMethod(&URLRequestJob::CompleteNotifyDone)); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 if (!request_->status().is_io_pending()) { | 566 if (!request_->status().is_io_pending()) { |
| 572 // If the read completes synchronously, either success or failure, | 567 // If the read completes synchronously, either success or failure, |
| 573 // invoke the OnRawReadComplete callback so we can account for the | 568 // invoke the OnRawReadComplete callback so we can account for the |
| 574 // completed read. | 569 // completed read. |
| 575 OnRawReadComplete(*bytes_read); | 570 OnRawReadComplete(*bytes_read); |
| 576 } | 571 } |
| 577 return rv; | 572 return rv; |
| 578 } | 573 } |
| 579 | 574 |
| 580 void URLRequestJob::FollowRedirect(const GURL& location, int http_status_code) { | 575 void URLRequestJob::FollowRedirect(const GURL& location, int http_status_code) { |
| 581 g_url_request_job_tracker.OnJobRedirect(this, location, http_status_code); | |
| 582 | |
| 583 int rv = request_->Redirect(location, http_status_code); | 576 int rv = request_->Redirect(location, http_status_code); |
| 584 if (rv != OK) | 577 if (rv != OK) |
| 585 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 578 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 586 } | 579 } |
| 587 | 580 |
| 588 void URLRequestJob::OnRawReadComplete(int bytes_read) { | 581 void URLRequestJob::OnRawReadComplete(int bytes_read) { |
| 589 DCHECK(raw_read_buffer_); | 582 DCHECK(raw_read_buffer_); |
| 590 if (bytes_read > 0) { | 583 if (bytes_read > 0) { |
| 591 RecordBytesRead(bytes_read); | 584 RecordBytesRead(bytes_read); |
| 592 } | 585 } |
| 593 raw_read_buffer_ = NULL; | 586 raw_read_buffer_ = NULL; |
| 594 } | 587 } |
| 595 | 588 |
| 596 void URLRequestJob::RecordBytesRead(int bytes_read) { | 589 void URLRequestJob::RecordBytesRead(int bytes_read) { |
| 597 filter_input_byte_count_ += bytes_read; | 590 filter_input_byte_count_ += bytes_read; |
| 598 UpdatePacketReadTimes(); // Facilitate stats recording if it is active. | 591 UpdatePacketReadTimes(); // Facilitate stats recording if it is active. |
| 599 g_url_request_job_tracker.OnBytesRead(this, raw_read_buffer_->data(), | 592 const URLRequestContext* context = request_->context(); |
| 600 bytes_read); | 593 if (context && context->network_delegate()) |
| 594 context->network_delegate()->NotifyBytesRead(*request_, bytes_read); | |
| 601 } | 595 } |
| 602 | 596 |
| 603 bool URLRequestJob::FilterHasData() { | 597 bool URLRequestJob::FilterHasData() { |
| 604 return filter_.get() && filter_->stream_data_len(); | 598 return filter_.get() && filter_->stream_data_len(); |
| 605 } | 599 } |
| 606 | 600 |
| 607 void URLRequestJob::UpdatePacketReadTimes() { | 601 void URLRequestJob::UpdatePacketReadTimes() { |
| 608 } | 602 } |
| 609 | 603 |
| 610 } // namespace net | 604 } // namespace net |
| OLD | NEW |