| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 void URLRequestJob::DetachRequest() { | 54 void URLRequestJob::DetachRequest() { |
| 55 request_ = NULL; | 55 request_ = NULL; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // This function calls ReadData to get stream data. If a filter exists, passes | 58 // This function calls ReadData to get stream data. If a filter exists, passes |
| 59 // the data to the attached filter. Then returns the output from filter back to | 59 // the data to the attached filter. Then returns the output from filter back to |
| 60 // the caller. | 60 // the caller. |
| 61 bool URLRequestJob::Read(IOBuffer* buf, int buf_size, int *bytes_read) { | 61 bool URLRequestJob::Read(IOBuffer* buf, int buf_size, int *bytes_read) { |
| 62 bool rv = false; | 62 bool rv = false; |
| 63 | 63 |
| 64 DCHECK_LT(buf_size, 1000000); // sanity check | 64 DCHECK_LT(buf_size, 1000000); // Sanity check. |
| 65 DCHECK(buf); | 65 DCHECK(buf); |
| 66 DCHECK(bytes_read); | 66 DCHECK(bytes_read); |
| 67 DCHECK(filtered_read_buffer_ == NULL); | 67 DCHECK(filtered_read_buffer_ == NULL); |
| 68 DCHECK_EQ(0, filtered_read_buffer_len_); | 68 DCHECK_EQ(0, filtered_read_buffer_len_); |
| 69 | 69 |
| 70 *bytes_read = 0; | 70 *bytes_read = 0; |
| 71 | 71 |
| 72 // Skip Filter if not present | 72 // Skip Filter if not present. |
| 73 if (!filter_.get()) { | 73 if (!filter_.get()) { |
| 74 rv = ReadRawDataHelper(buf, buf_size, bytes_read); | 74 rv = ReadRawDataHelper(buf, buf_size, bytes_read); |
| 75 } else { | 75 } else { |
| 76 // Save the caller's buffers while we do IO | 76 // Save the caller's buffers while we do IO |
| 77 // in the filter's buffers. | 77 // in the filter's buffers. |
| 78 filtered_read_buffer_ = buf; | 78 filtered_read_buffer_ = buf; |
| 79 filtered_read_buffer_len_ = buf_size; | 79 filtered_read_buffer_len_ = buf_size; |
| 80 | 80 |
| 81 if (ReadFilteredData(bytes_read)) { | 81 if (ReadFilteredData(bytes_read)) { |
| 82 rv = true; // we have data to return | 82 rv = true; // We have data to return. |
| 83 |
| 84 // It is fine to call DoneReading even if ReadFilteredData receives 0 |
| 85 // bytes from the net, but we avoid making that call if we know for |
| 86 // sure that's the case (ReadRawDataHelper path). |
| 87 if (*bytes_read == 0) |
| 88 DoneReading(); |
| 83 } else { | 89 } else { |
| 84 rv = false; // error, or a new IO is pending | 90 rv = false; // Error, or a new IO is pending. |
| 85 } | 91 } |
| 86 } | 92 } |
| 87 if (rv && *bytes_read == 0) | 93 if (rv && *bytes_read == 0) |
| 88 NotifyDone(URLRequestStatus()); | 94 NotifyDone(URLRequestStatus()); |
| 89 return rv; | 95 return rv; |
| 90 } | 96 } |
| 91 | 97 |
| 92 void URLRequestJob::StopCaching() { | 98 void URLRequestJob::StopCaching() { |
| 93 // Nothing to do here. | 99 // Nothing to do here. |
| 94 } | 100 } |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // survival until we can get out of this method. | 357 // survival until we can get out of this method. |
| 352 scoped_refptr<URLRequestJob> self_preservation(this); | 358 scoped_refptr<URLRequestJob> self_preservation(this); |
| 353 | 359 |
| 354 if (filter_.get()) { | 360 if (filter_.get()) { |
| 355 // Tell the filter that it has more data | 361 // Tell the filter that it has more data |
| 356 FilteredDataRead(bytes_read); | 362 FilteredDataRead(bytes_read); |
| 357 | 363 |
| 358 // Filter the data. | 364 // Filter the data. |
| 359 int filter_bytes_read = 0; | 365 int filter_bytes_read = 0; |
| 360 if (ReadFilteredData(&filter_bytes_read)) { | 366 if (ReadFilteredData(&filter_bytes_read)) { |
| 367 if (!filter_bytes_read) |
| 368 DoneReading(); |
| 361 request_->NotifyReadCompleted(filter_bytes_read); | 369 request_->NotifyReadCompleted(filter_bytes_read); |
| 362 } | 370 } |
| 363 } else { | 371 } else { |
| 364 request_->NotifyReadCompleted(bytes_read); | 372 request_->NotifyReadCompleted(bytes_read); |
| 365 } | 373 } |
| 366 DVLOG(1) << __FUNCTION__ << "() " | 374 DVLOG(1) << __FUNCTION__ << "() " |
| 367 << "\"" << (request_ ? request_->url().spec() : "???") << "\"" | 375 << "\"" << (request_ ? request_->url().spec() : "???") << "\"" |
| 368 << " pre bytes read = " << bytes_read | 376 << " pre bytes read = " << bytes_read |
| 369 << " pre total = " << prefilter_bytes_read_ | 377 << " pre total = " << prefilter_bytes_read_ |
| 370 << " post total = " << postfilter_bytes_read_; | 378 << " post total = " << postfilter_bytes_read_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 request_->Restart(); | 447 request_->Restart(); |
| 440 } | 448 } |
| 441 | 449 |
| 442 bool URLRequestJob::ReadRawData(IOBuffer* buf, int buf_size, | 450 bool URLRequestJob::ReadRawData(IOBuffer* buf, int buf_size, |
| 443 int *bytes_read) { | 451 int *bytes_read) { |
| 444 DCHECK(bytes_read); | 452 DCHECK(bytes_read); |
| 445 *bytes_read = 0; | 453 *bytes_read = 0; |
| 446 return true; | 454 return true; |
| 447 } | 455 } |
| 448 | 456 |
| 457 void URLRequestJob::DoneReading() { |
| 458 // Do nothing. |
| 459 } |
| 460 |
| 449 void URLRequestJob::FilteredDataRead(int bytes_read) { | 461 void URLRequestJob::FilteredDataRead(int bytes_read) { |
| 450 DCHECK(filter_.get()); // don't add data if there is no filter | 462 DCHECK(filter_.get()); // don't add data if there is no filter |
| 451 filter_->FlushStreamBuffer(bytes_read); | 463 filter_->FlushStreamBuffer(bytes_read); |
| 452 } | 464 } |
| 453 | 465 |
| 454 bool URLRequestJob::ReadFilteredData(int* bytes_read) { | 466 bool URLRequestJob::ReadFilteredData(int* bytes_read) { |
| 455 DCHECK(filter_.get()); // don't add data if there is no filter | 467 DCHECK(filter_.get()); // don't add data if there is no filter |
| 456 DCHECK(filtered_read_buffer_ != NULL); // we need to have a buffer to fill | 468 DCHECK(filtered_read_buffer_ != NULL); // we need to have a buffer to fill |
| 457 DCHECK_GT(filtered_read_buffer_len_, 0); // sanity check | 469 DCHECK_GT(filtered_read_buffer_len_, 0); // sanity check |
| 458 DCHECK_LT(filtered_read_buffer_len_, 1000000); // sanity check | 470 DCHECK_LT(filtered_read_buffer_len_, 1000000); // sanity check |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 } | 681 } |
| 670 | 682 |
| 671 bool URLRequestJob::FilterHasData() { | 683 bool URLRequestJob::FilterHasData() { |
| 672 return filter_.get() && filter_->stream_data_len(); | 684 return filter_.get() && filter_->stream_data_len(); |
| 673 } | 685 } |
| 674 | 686 |
| 675 void URLRequestJob::UpdatePacketReadTimes() { | 687 void URLRequestJob::UpdatePacketReadTimes() { |
| 676 } | 688 } |
| 677 | 689 |
| 678 } // namespace net | 690 } // namespace net |
| OLD | NEW |