| 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/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
| 13 #include "net/url_request/url_request_job_metrics.h" | 14 #include "net/url_request/url_request_job_metrics.h" |
| 14 #include "net/url_request/url_request_job_tracker.h" | 15 #include "net/url_request/url_request_job_tracker.h" |
| 15 | 16 |
| 16 using base::Time; | 17 using base::Time; |
| 17 using base::TimeTicks; | 18 using base::TimeTicks; |
| 18 | 19 |
| 19 // Buffer size allocated when de-compressing data. | 20 // Buffer size allocated when de-compressing data. |
| 20 static const int kFilterBufSize = 32 * 1024; | 21 static const int kFilterBufSize = 32 * 1024; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 void URLRequestJob::ContinueDespiteLastError() { | 91 void URLRequestJob::ContinueDespiteLastError() { |
| 91 // Implementations should know how to recover from errors they generate. | 92 // Implementations should know how to recover from errors they generate. |
| 92 // If this code was reached, we are trying to recover from an error that | 93 // If this code was reached, we are trying to recover from an error that |
| 93 // we don't know how to recover from. | 94 // we don't know how to recover from. |
| 94 NOTREACHED(); | 95 NOTREACHED(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 // This function calls ReadData to get stream data. If a filter exists, passes | 98 // This function calls ReadData to get stream data. If a filter exists, passes |
| 98 // the data to the attached filter. Then returns the output from filter back to | 99 // the data to the attached filter. Then returns the output from filter back to |
| 99 // the caller. | 100 // the caller. |
| 100 bool URLRequestJob::Read(char* buf, int buf_size, int *bytes_read) { | 101 bool URLRequestJob::Read(net::IOBuffer* buf, int buf_size, int *bytes_read) { |
| 101 bool rv = false; | 102 bool rv = false; |
| 102 | 103 |
| 103 DCHECK_LT(buf_size, 1000000); // sanity check | 104 DCHECK_LT(buf_size, 1000000); // sanity check |
| 104 DCHECK(buf); | 105 DCHECK(buf); |
| 105 DCHECK(bytes_read); | 106 DCHECK(bytes_read); |
| 106 | 107 |
| 107 *bytes_read = 0; | 108 *bytes_read = 0; |
| 108 | 109 |
| 109 // Skip Filter if not present | 110 // Skip Filter if not present |
| 110 if (!filter_.get()) { | 111 if (!filter_.get()) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 133 | 134 |
| 134 DCHECK(bytes_read); | 135 DCHECK(bytes_read); |
| 135 DCHECK(filter_.get()); | 136 DCHECK(filter_.get()); |
| 136 | 137 |
| 137 *bytes_read = 0; | 138 *bytes_read = 0; |
| 138 | 139 |
| 139 // Get more pre-filtered data if needed. | 140 // Get more pre-filtered data if needed. |
| 140 // TODO(mbelshe): is it possible that the filter needs *MORE* data | 141 // TODO(mbelshe): is it possible that the filter needs *MORE* data |
| 141 // when there is some data already in the buffer? | 142 // when there is some data already in the buffer? |
| 142 if (!filter_->stream_data_len() && !is_done()) { | 143 if (!filter_->stream_data_len() && !is_done()) { |
| 143 char* stream_buffer = filter_->stream_buffer(); | 144 net::IOBuffer* stream_buffer = filter_->stream_buffer(); |
| 144 int stream_buffer_size = filter_->stream_buffer_size(); | 145 int stream_buffer_size = filter_->stream_buffer_size(); |
| 145 rv = ReadRawData(stream_buffer, stream_buffer_size, bytes_read); | 146 rv = ReadRawData(stream_buffer, stream_buffer_size, bytes_read); |
| 146 if (rv && *bytes_read > 0) | 147 if (rv && *bytes_read > 0) |
| 147 RecordBytesRead(*bytes_read); | 148 RecordBytesRead(*bytes_read); |
| 148 } | 149 } |
| 149 return rv; | 150 return rv; |
| 150 } | 151 } |
| 151 | 152 |
| 152 void URLRequestJob::FilteredDataRead(int bytes_read) { | 153 void URLRequestJob::FilteredDataRead(int bytes_read) { |
| 153 DCHECK(filter_.get()); // don't add data if there is no filter | 154 DCHECK(filter_.get()); // don't add data if there is no filter |
| (...skipping 25 matching lines...) Expand all Loading... |
| 179 } | 180 } |
| 180 } else { | 181 } else { |
| 181 return false; // IO Pending (or error) | 182 return false; // IO Pending (or error) |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 185 if (filter_->stream_data_len() && !is_done()) { | 186 if (filter_->stream_data_len() && !is_done()) { |
| 186 // Get filtered data | 187 // Get filtered data |
| 187 int filtered_data_len = read_buffer_len_; | 188 int filtered_data_len = read_buffer_len_; |
| 188 Filter::FilterStatus status; | 189 Filter::FilterStatus status; |
| 189 status = filter_->ReadData(read_buffer_, &filtered_data_len); | 190 status = filter_->ReadData(read_buffer_->data(), &filtered_data_len); |
| 190 switch (status) { | 191 switch (status) { |
| 191 case Filter::FILTER_DONE: { | 192 case Filter::FILTER_DONE: { |
| 192 *bytes_read = filtered_data_len; | 193 *bytes_read = filtered_data_len; |
| 193 rv = true; | 194 rv = true; |
| 194 break; | 195 break; |
| 195 } | 196 } |
| 196 case Filter::FILTER_NEED_MORE_DATA: { | 197 case Filter::FILTER_NEED_MORE_DATA: { |
| 197 // We have finished filtering all data currently in the buffer. | 198 // We have finished filtering all data currently in the buffer. |
| 198 // There might be some space left in the output buffer. One can | 199 // There might be some space left in the output buffer. One can |
| 199 // consider reading more data from the stream to feed the filter | 200 // consider reading more data from the stream to feed the filter |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (rv) { | 236 if (rv) { |
| 236 // When we successfully finished a read, we no longer need to | 237 // When we successfully finished a read, we no longer need to |
| 237 // save the caller's buffers. For debugging purposes, we clear | 238 // save the caller's buffers. For debugging purposes, we clear |
| 238 // them out. | 239 // them out. |
| 239 read_buffer_ = NULL; | 240 read_buffer_ = NULL; |
| 240 read_buffer_len_ = 0; | 241 read_buffer_len_ = 0; |
| 241 } | 242 } |
| 242 return rv; | 243 return rv; |
| 243 } | 244 } |
| 244 | 245 |
| 245 bool URLRequestJob::ReadRawData(char* buf, int buf_size, int *bytes_read) { | 246 bool URLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 247 int *bytes_read) { |
| 246 DCHECK(bytes_read); | 248 DCHECK(bytes_read); |
| 247 *bytes_read = 0; | 249 *bytes_read = 0; |
| 248 NotifyDone(URLRequestStatus()); | 250 NotifyDone(URLRequestStatus()); |
| 249 return false; | 251 return false; |
| 250 } | 252 } |
| 251 | 253 |
| 252 URLRequestJobMetrics* URLRequestJob::RetrieveMetrics() { | 254 URLRequestJobMetrics* URLRequestJob::RetrieveMetrics() { |
| 253 if (is_profiling()) | 255 if (is_profiling()) |
| 254 return metrics_.release(); | 256 return metrics_.release(); |
| 255 else | 257 else |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return request_->status(); | 486 return request_->status(); |
| 485 // If the request is gone, we must be cancelled. | 487 // If the request is gone, we must be cancelled. |
| 486 return URLRequestStatus(URLRequestStatus::CANCELED, | 488 return URLRequestStatus(URLRequestStatus::CANCELED, |
| 487 net::ERR_ABORTED); | 489 net::ERR_ABORTED); |
| 488 } | 490 } |
| 489 | 491 |
| 490 void URLRequestJob::SetStatus(const URLRequestStatus &status) { | 492 void URLRequestJob::SetStatus(const URLRequestStatus &status) { |
| 491 if (request_) | 493 if (request_) |
| 492 request_->set_status(status); | 494 request_->set_status(status); |
| 493 } | 495 } |
| OLD | NEW |