Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: net/url_request/url_request_job.cc

Issue 6881106: Treat ERR_CONNECTION_CLOSED as end-of-data marker for downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed issues with tracking number of bytes received & decompressed. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // The headers should be complete before reads complete 299 // The headers should be complete before reads complete
300 DCHECK(has_handled_response_); 300 DCHECK(has_handled_response_);
301 301
302 OnRawReadComplete(bytes_read); 302 OnRawReadComplete(bytes_read);
303 303
304 // Don't notify if we had an error. 304 // Don't notify if we had an error.
305 if (!request_->status().is_success()) 305 if (!request_->status().is_success())
306 return; 306 return;
307 307
308 // When notifying the delegate, the delegate can release the request 308 // When notifying the delegate, the delegate can release the request
309 // (and thus release 'this'). After calling to the delgate, we must 309 // (and thus release 'this'). After calling to the delegate, we must
310 // check the request pointer to see if it still exists, and return 310 // check the request pointer to see if it still exists, and return
311 // immediately if it has been destroyed. self_preservation ensures our 311 // immediately if it has been destroyed. self_preservation ensures our
312 // survival until we can get out of this method. 312 // survival until we can get out of this method.
313 scoped_refptr<URLRequestJob> self_preservation(this); 313 scoped_refptr<URLRequestJob> self_preservation(this);
314 314
315 // If we get here, |prefilter_bytes_read_| was not updated in
316 // |ReadRawDataHelper()|.
315 prefilter_bytes_read_ += bytes_read; 317 prefilter_bytes_read_ += bytes_read;
316 if (filter_.get()) { 318 if (filter_.get()) {
317 // Tell the filter that it has more data 319 // Tell the filter that it has more data
318 FilteredDataRead(bytes_read); 320 FilteredDataRead(bytes_read);
319 321
320 // Filter the data. 322 // Filter the data.
321 int filter_bytes_read = 0; 323 int filter_bytes_read = 0;
322 if (ReadFilteredData(&filter_bytes_read)) { 324 if (ReadFilteredData(&filter_bytes_read)) {
323 postfilter_bytes_read_ += filter_bytes_read;
324 request_->delegate()->OnReadCompleted(request_, filter_bytes_read); 325 request_->delegate()->OnReadCompleted(request_, filter_bytes_read);
325 } 326 }
326 } else { 327 } else {
328 // If we get here, |postfilter_bytes_read_| was not updated in
329 // |ReadRawDataHelper()|.
327 postfilter_bytes_read_ += bytes_read; 330 postfilter_bytes_read_ += bytes_read;
328 request_->delegate()->OnReadCompleted(request_, bytes_read); 331 request_->delegate()->OnReadCompleted(request_, bytes_read);
329 } 332 }
333 VLOG(21) << __FUNCTION__ << "() "
334 << "\"" << (request_ ? request_->url().spec() : "???") << "\""
335 << " pre bytes read = " << bytes_read
336 << " pre total = " << prefilter_bytes_read_
337 << " post total = " << postfilter_bytes_read_;
330 } 338 }
331 339
332 void URLRequestJob::NotifyStartError(const URLRequestStatus &status) { 340 void URLRequestJob::NotifyStartError(const URLRequestStatus &status) {
333 DCHECK(!has_handled_response_); 341 DCHECK(!has_handled_response_);
334 has_handled_response_ = true; 342 has_handled_response_ = true;
335 if (request_) { 343 if (request_) {
336 request_->set_status(status); 344 request_->set_status(status);
337 request_->ResponseStarted(); 345 request_->ResponseStarted();
338 } 346 }
339 } 347 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 // and we should have at least tried to fill up the filter's input buffer. 469 // and we should have at least tried to fill up the filter's input buffer.
462 // Correct the state, and try again. 470 // Correct the state, and try again.
463 filter_needs_more_output_space_ = false; 471 filter_needs_more_output_space_ = false;
464 return ReadFilteredData(bytes_read); 472 return ReadFilteredData(bytes_read);
465 } 473 }
466 474
467 switch (status) { 475 switch (status) {
468 case Filter::FILTER_DONE: { 476 case Filter::FILTER_DONE: {
469 filter_needs_more_output_space_ = false; 477 filter_needs_more_output_space_ = false;
470 *bytes_read = filtered_data_len; 478 *bytes_read = filtered_data_len;
479 postfilter_bytes_read_ += filtered_data_len;
471 rv = true; 480 rv = true;
472 break; 481 break;
473 } 482 }
474 case Filter::FILTER_NEED_MORE_DATA: { 483 case Filter::FILTER_NEED_MORE_DATA: {
475 filter_needs_more_output_space_ = 484 filter_needs_more_output_space_ =
476 (filtered_data_len == output_buffer_size); 485 (filtered_data_len == output_buffer_size);
477 // We have finished filtering all data currently in the buffer. 486 // We have finished filtering all data currently in the buffer.
478 // There might be some space left in the output buffer. One can 487 // There might be some space left in the output buffer. One can
479 // consider reading more data from the stream to feed the filter 488 // consider reading more data from the stream to feed the filter
480 // and filling up the output buffer. This leads to more complicated 489 // and filling up the output buffer. This leads to more complicated
481 // buffer management and data notification mechanisms. 490 // buffer management and data notification mechanisms.
482 // We can revisit this issue if there is a real perf need. 491 // We can revisit this issue if there is a real perf need.
483 if (filtered_data_len > 0) { 492 if (filtered_data_len > 0) {
484 *bytes_read = filtered_data_len; 493 *bytes_read = filtered_data_len;
494 postfilter_bytes_read_ += filtered_data_len;
485 rv = true; 495 rv = true;
486 } else { 496 } else {
487 // Read again since we haven't received enough data yet (e.g., we may 497 // Read again since we haven't received enough data yet (e.g., we may
488 // not have a complete gzip header yet) 498 // not have a complete gzip header yet)
489 rv = ReadFilteredData(bytes_read); 499 rv = ReadFilteredData(bytes_read);
490 } 500 }
491 break; 501 break;
492 } 502 }
493 case Filter::FILTER_OK: { 503 case Filter::FILTER_OK: {
494 filter_needs_more_output_space_ = 504 filter_needs_more_output_space_ =
495 (filtered_data_len == output_buffer_size); 505 (filtered_data_len == output_buffer_size);
496 *bytes_read = filtered_data_len; 506 *bytes_read = filtered_data_len;
507 postfilter_bytes_read_ += filtered_data_len;
497 rv = true; 508 rv = true;
498 break; 509 break;
499 } 510 }
500 case Filter::FILTER_ERROR: { 511 case Filter::FILTER_ERROR: {
501 filter_needs_more_output_space_ = false; 512 filter_needs_more_output_space_ = false;
502 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 513 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
503 ERR_CONTENT_DECODING_FAILED)); 514 ERR_CONTENT_DECODING_FAILED));
504 rv = false; 515 rv = false;
505 break; 516 break;
506 } 517 }
507 default: { 518 default: {
508 NOTREACHED(); 519 NOTREACHED();
509 filter_needs_more_output_space_ = false; 520 filter_needs_more_output_space_ = false;
510 rv = false; 521 rv = false;
511 break; 522 break;
512 } 523 }
513 } 524 }
525 VLOG(21) << __FUNCTION__ << "() "
526 << "\"" << (request_ ? request_->url().spec() : "???") << "\""
527 << " rv = " << rv
528 << " post bytes read = " << filtered_data_len
529 << " pre total = " << prefilter_bytes_read_
530 << " post total = "
531 << postfilter_bytes_read_;
514 } else { 532 } else {
515 // we are done, or there is no data left. 533 // we are done, or there is no data left.
516 rv = true; 534 rv = true;
517 } 535 }
518 536
519 if (rv) { 537 if (rv) {
520 // When we successfully finished a read, we no longer need to 538 // When we successfully finished a read, we no longer need to
521 // save the caller's buffers. Release our reference. 539 // save the caller's buffers. Release our reference.
522 filtered_read_buffer_ = NULL; 540 filtered_read_buffer_ = NULL;
523 filtered_read_buffer_len_ = 0; 541 filtered_read_buffer_len_ = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 int* bytes_read) { 579 int* bytes_read) {
562 DCHECK(!request_->status().is_io_pending()); 580 DCHECK(!request_->status().is_io_pending());
563 DCHECK(raw_read_buffer_ == NULL); 581 DCHECK(raw_read_buffer_ == NULL);
564 582
565 // Keep a pointer to the read buffer, so we have access to it in the 583 // Keep a pointer to the read buffer, so we have access to it in the
566 // OnRawReadComplete() callback in the event that the read completes 584 // OnRawReadComplete() callback in the event that the read completes
567 // asynchronously. 585 // asynchronously.
568 raw_read_buffer_ = buf; 586 raw_read_buffer_ = buf;
569 bool rv = ReadRawData(buf, buf_size, bytes_read); 587 bool rv = ReadRawData(buf, buf_size, bytes_read);
570 588
589 // If |*bytes_read == 0|, that means we have data pending, so we will need to
590 // update |prefilter_bytes_read_| in |NotifyReadComplete()|.
591 if (*bytes_read > 0) {
rvargas (doing something else) 2011/05/19 19:30:36 You cannot evaluate bytes_read without first looki
ahendrickson 2011/05/19 22:29:34 Done.
592 prefilter_bytes_read_ += *bytes_read;
593 if (!filter_.get())
594 postfilter_bytes_read_ += *bytes_read;
595 VLOG(21) << __FUNCTION__ << "() "
596 << "\"" << (request_ ? request_->url().spec() : "???") << "\""
597 << " pre bytes read = " << *bytes_read
598 << " pre total = " << prefilter_bytes_read_
599 << " post total = " << postfilter_bytes_read_;
600 } else {
601 VLOG(21) << __FUNCTION__ << "() "
602 << "\"" << (request_ ? request_->url().spec() : "???") << "\""
603 << " error code = " << *bytes_read
604 << " io pending = " << request_->status().is_io_pending();
605 }
606
571 if (!request_->status().is_io_pending()) { 607 if (!request_->status().is_io_pending()) {
572 // If the read completes synchronously, either success or failure, 608 // If the read completes synchronously, either success or failure,
573 // invoke the OnRawReadComplete callback so we can account for the 609 // invoke the OnRawReadComplete callback so we can account for the
574 // completed read. 610 // completed read.
575 OnRawReadComplete(*bytes_read); 611 OnRawReadComplete(*bytes_read);
576 } 612 }
577 return rv; 613 return rv;
578 } 614 }
579 615
580 void URLRequestJob::FollowRedirect(const GURL& location, int http_status_code) { 616 void URLRequestJob::FollowRedirect(const GURL& location, int http_status_code) {
(...skipping 20 matching lines...) Expand all
601 } 637 }
602 638
603 bool URLRequestJob::FilterHasData() { 639 bool URLRequestJob::FilterHasData() {
604 return filter_.get() && filter_->stream_data_len(); 640 return filter_.get() && filter_->stream_data_len();
605 } 641 }
606 642
607 void URLRequestJob::UpdatePacketReadTimes() { 643 void URLRequestJob::UpdatePacketReadTimes() {
608 } 644 }
609 645
610 } // namespace net 646 } // namespace net
OLDNEW
« net/url_request/url_request_http_job.cc ('K') | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698