| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/load_flags.h" |
| 12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 14 #include "net/url_request/url_request_job_metrics.h" | 15 #include "net/url_request/url_request_job_metrics.h" |
| 15 #include "net/url_request/url_request_job_tracker.h" | 16 #include "net/url_request/url_request_job_tracker.h" |
| 16 | 17 |
| 17 using base::Time; | 18 using base::Time; |
| 18 using base::TimeTicks; | 19 using base::TimeTicks; |
| 19 | 20 |
| 20 // Buffer size allocated when de-compressing data. | 21 // Buffer size allocated when de-compressing data. |
| 21 // static | 22 // static |
| 22 const int URLRequestJob::kFilterBufSize = 32 * 1024; | 23 const int URLRequestJob::kFilterBufSize = 32 * 1024; |
| 23 | 24 |
| 24 URLRequestJob::URLRequestJob(URLRequest* request) | 25 URLRequestJob::URLRequestJob(URLRequest* request) |
| 25 : request_(request), | 26 : request_(request), |
| 26 done_(false), | 27 done_(false), |
| 27 filter_needs_more_output_space_(false), | 28 filter_needs_more_output_space_(false), |
| 28 read_buffer_(NULL), | 29 read_buffer_(NULL), |
| 29 read_buffer_len_(0), | 30 read_buffer_len_(0), |
| 30 has_handled_response_(false), | 31 has_handled_response_(false), |
| 31 expected_content_size_(-1), | 32 expected_content_size_(-1), |
| 32 filter_input_byte_count_(0) { | 33 filter_input_byte_count_(0) { |
| 34 load_flags_ = request_->load_flags(); |
| 33 is_profiling_ = request->enable_profiling(); | 35 is_profiling_ = request->enable_profiling(); |
| 34 if (is_profiling()) { | 36 if (is_profiling()) { |
| 35 metrics_.reset(new URLRequestJobMetrics()); | 37 metrics_.reset(new URLRequestJobMetrics()); |
| 36 metrics_->start_time_ = TimeTicks::Now(); | 38 metrics_->start_time_ = TimeTicks::Now(); |
| 37 } | 39 } |
| 38 g_url_request_job_tracker.AddNewJob(this); | 40 g_url_request_job_tracker.AddNewJob(this); |
| 39 } | 41 } |
| 40 | 42 |
| 41 URLRequestJob::~URLRequestJob() { | 43 URLRequestJob::~URLRequestJob() { |
| 42 g_url_request_job_tracker.RemoveJob(this); | 44 g_url_request_job_tracker.RemoveJob(this); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void URLRequestJob::Kill() { | 47 void URLRequestJob::Kill() { |
| 46 // Make sure the request is notified that we are done. We assume that the | 48 // Make sure the request is notified that we are done. We assume that the |
| 47 // request took care of setting its error status before calling Kill. | 49 // request took care of setting its error status before calling Kill. |
| 48 if (request_) | 50 if (request_) |
| 49 NotifyCanceled(); | 51 NotifyCanceled(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void URLRequestJob::DetachRequest() { | 54 void URLRequestJob::DetachRequest() { |
| 53 request_ = NULL; | 55 request_ = NULL; |
| 54 } | 56 } |
| 55 | 57 |
| 58 bool URLRequestJob::IsDownload() const { |
| 59 return (load_flags_ & net::LOAD_IS_DOWNLOAD) != 0; |
| 60 } |
| 61 |
| 56 void URLRequestJob::SetupFilter() { | 62 void URLRequestJob::SetupFilter() { |
| 57 std::vector<Filter::FilterType> encoding_types; | 63 std::vector<Filter::FilterType> encoding_types; |
| 58 if (GetContentEncodings(&encoding_types)) { | 64 if (GetContentEncodings(&encoding_types)) { |
| 59 filter_.reset(Filter::Factory(encoding_types, *this)); | 65 filter_.reset(Filter::Factory(encoding_types, *this)); |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| 63 void URLRequestJob::GetAuthChallengeInfo( | 69 void URLRequestJob::GetAuthChallengeInfo( |
| 64 scoped_refptr<net::AuthChallengeInfo>* auth_info) { | 70 scoped_refptr<net::AuthChallengeInfo>* auth_info) { |
| 65 // This will only be called if NeedsAuth() returns true, in which | 71 // This will only be called if NeedsAuth() returns true, in which |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 return request_->status(); | 525 return request_->status(); |
| 520 // If the request is gone, we must be cancelled. | 526 // If the request is gone, we must be cancelled. |
| 521 return URLRequestStatus(URLRequestStatus::CANCELED, | 527 return URLRequestStatus(URLRequestStatus::CANCELED, |
| 522 net::ERR_ABORTED); | 528 net::ERR_ABORTED); |
| 523 } | 529 } |
| 524 | 530 |
| 525 void URLRequestJob::SetStatus(const URLRequestStatus &status) { | 531 void URLRequestJob::SetStatus(const URLRequestStatus &status) { |
| 526 if (request_) | 532 if (request_) |
| 527 request_->set_status(status); | 533 request_->set_status(status); |
| 528 } | 534 } |
| OLD | NEW |