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)) { |
36 g_url_request_job_tracker.AddNewJob(this); | 35 base::SystemMonitor::Get()->AddObserver(this); |
rvargas (doing something else)
2011/05/21 01:00:44
We probably should allow the case of Get() returni
| |
37 } | 36 } |
38 | 37 |
39 void URLRequestJob::SetUpload(UploadData* upload) { | 38 void URLRequestJob::SetUpload(UploadData* upload) { |
40 } | 39 } |
41 | 40 |
42 void URLRequestJob::SetExtraRequestHeaders( | 41 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { |
43 const HttpRequestHeaders& headers) { | |
44 } | 42 } |
45 | 43 |
46 void URLRequestJob::Kill() { | 44 void URLRequestJob::Kill() { |
47 // Make sure the request is notified that we are done. We assume that the | 45 // 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. | 46 // request took care of setting its error status before calling Kill. |
49 if (request_) | 47 if (request_) |
50 NotifyCanceled(); | 48 NotifyCanceled(); |
51 } | 49 } |
52 | 50 |
53 void URLRequestJob::DetachRequest() { | 51 void URLRequestJob::DetachRequest() { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 } | 194 } |
197 | 195 |
198 int URLRequestJob::GetResponseCode() const { | 196 int URLRequestJob::GetResponseCode() const { |
199 return -1; | 197 return -1; |
200 } | 198 } |
201 | 199 |
202 HostPortPair URLRequestJob::GetSocketAddress() const { | 200 HostPortPair URLRequestJob::GetSocketAddress() const { |
203 return HostPortPair(); | 201 return HostPortPair(); |
204 } | 202 } |
205 | 203 |
204 void URLRequestJob::OnSuspend() { | |
205 Kill(); | |
206 } | |
207 | |
206 URLRequestJob::~URLRequestJob() { | 208 URLRequestJob::~URLRequestJob() { |
207 g_url_request_job_tracker.RemoveJob(this); | 209 base::SystemMonitor::Get()->RemoveObserver(this); |
208 } | 210 } |
209 | 211 |
210 void URLRequestJob::NotifyHeadersComplete() { | 212 void URLRequestJob::NotifyHeadersComplete() { |
211 if (!request_ || !request_->delegate()) | 213 if (!request_ || !request_->delegate()) |
212 return; // The request was destroyed, so there is no more work to do. | 214 return; // The request was destroyed, so there is no more work to do. |
213 | 215 |
214 if (has_handled_response_) | 216 if (has_handled_response_) |
215 return; | 217 return; |
216 | 218 |
217 DCHECK(!request_->status().is_io_pending()); | 219 DCHECK(!request_->status().is_io_pending()); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 // With async IO, it's quite possible to have a few outstanding | 357 // With async IO, it's quite possible to have a few outstanding |
356 // requests. We could receive a request to Cancel, followed shortly | 358 // requests. We could receive a request to Cancel, followed shortly |
357 // by a successful IO. For tracking the status(), once there is | 359 // by a successful IO. For tracking the status(), once there is |
358 // an error, we do not change the status back to success. To | 360 // 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 | 361 // enforce this, only set the status if the job is so far |
360 // successful. | 362 // successful. |
361 if (request_->status().is_success()) | 363 if (request_->status().is_success()) |
362 request_->set_status(status); | 364 request_->set_status(status); |
363 } | 365 } |
364 | 366 |
365 g_url_request_job_tracker.OnJobDone(this, status); | |
366 | |
367 if (request_ && request_->context() && | 367 if (request_ && request_->context() && |
368 request_->context()->network_delegate()) { | 368 request_->context()->network_delegate()) { |
369 request_->context()->network_delegate()->NotifyCompleted(request_); | 369 request_->context()->network_delegate()->NotifyCompleted(request_); |
370 } | 370 } |
371 | 371 |
372 // Complete this notification later. This prevents us from re-entering the | 372 // Complete this notification later. This prevents us from re-entering the |
373 // delegate if we're done because of a synchronous call. | 373 // delegate if we're done because of a synchronous call. |
374 MessageLoop::current()->PostTask( | 374 MessageLoop::current()->PostTask( |
375 FROM_HERE, | 375 FROM_HERE, |
376 method_factory_.NewRunnableMethod(&URLRequestJob::CompleteNotifyDone)); | 376 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()) { | 571 if (!request_->status().is_io_pending()) { |
572 // If the read completes synchronously, either success or failure, | 572 // If the read completes synchronously, either success or failure, |
573 // invoke the OnRawReadComplete callback so we can account for the | 573 // invoke the OnRawReadComplete callback so we can account for the |
574 // completed read. | 574 // completed read. |
575 OnRawReadComplete(*bytes_read); | 575 OnRawReadComplete(*bytes_read); |
576 } | 576 } |
577 return rv; | 577 return rv; |
578 } | 578 } |
579 | 579 |
580 void URLRequestJob::FollowRedirect(const GURL& location, int http_status_code) { | 580 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); | 581 int rv = request_->Redirect(location, http_status_code); |
584 if (rv != OK) | 582 if (rv != OK) |
585 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 583 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
586 } | 584 } |
587 | 585 |
588 void URLRequestJob::OnRawReadComplete(int bytes_read) { | 586 void URLRequestJob::OnRawReadComplete(int bytes_read) { |
589 DCHECK(raw_read_buffer_); | 587 DCHECK(raw_read_buffer_); |
590 if (bytes_read > 0) { | 588 if (bytes_read > 0) { |
591 RecordBytesRead(bytes_read); | 589 RecordBytesRead(bytes_read); |
592 } | 590 } |
593 raw_read_buffer_ = NULL; | 591 raw_read_buffer_ = NULL; |
594 } | 592 } |
595 | 593 |
596 void URLRequestJob::RecordBytesRead(int bytes_read) { | 594 void URLRequestJob::RecordBytesRead(int bytes_read) { |
597 filter_input_byte_count_ += bytes_read; | 595 filter_input_byte_count_ += bytes_read; |
598 UpdatePacketReadTimes(); // Facilitate stats recording if it is active. | 596 UpdatePacketReadTimes(); // Facilitate stats recording if it is active. |
599 g_url_request_job_tracker.OnBytesRead(this, raw_read_buffer_->data(), | 597 const URLRequestContext* context = request_->context(); |
600 bytes_read); | 598 if (context && context->network_delegate()) |
599 context->network_delegate()->NotifyRawBytesRead(*request_, bytes_read); | |
601 } | 600 } |
602 | 601 |
603 bool URLRequestJob::FilterHasData() { | 602 bool URLRequestJob::FilterHasData() { |
604 return filter_.get() && filter_->stream_data_len(); | 603 return filter_.get() && filter_->stream_data_len(); |
605 } | 604 } |
606 | 605 |
607 void URLRequestJob::UpdatePacketReadTimes() { | 606 void URLRequestJob::UpdatePacketReadTimes() { |
608 } | 607 } |
609 | 608 |
610 } // namespace net | 609 } // namespace net |
OLD | NEW |