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

Side by Side Diff: content/browser/download/download_file_impl.cc

Issue 2811293004: Fix an issue that we didn't clean url request properly. (Closed)
Patch Set: Fixed compiling for unit tests. Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/download/download_file_impl.h" 5 #include "content/browser/download/download_file_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 void DownloadFileImpl::SourceStream::TruncateLengthWithWrittenDataBlock( 73 void DownloadFileImpl::SourceStream::TruncateLengthWithWrittenDataBlock(
74 int64_t offset, 74 int64_t offset,
75 int64_t bytes_written) { 75 int64_t bytes_written) {
76 DCHECK_GT(bytes_written, 0); 76 DCHECK_GT(bytes_written, 0);
77 if (length_ == kNoBytesToWrite) 77 if (length_ == kNoBytesToWrite)
78 return; 78 return;
79 79
80 if (offset <= offset_) { 80 if (offset <= offset_) {
81 if (offset + bytes_written > offset_) { 81 if (offset + bytes_written > offset_) {
82 length_ = kNoBytesToWrite; 82 length_ = kNoBytesToWrite;
qinmin 2017/04/14 20:04:43 the stream_to_close can be added here rather than
xingliu 2017/04/15 00:26:29 We also truncate the length in next block, line 90
83 finished_ = true; 83 finished_ = true;
84 } 84 }
85 return; 85 return;
86 } 86 }
87 87
88 if (length_ == DownloadSaveInfo::kLengthFullContent || 88 if (length_ == DownloadSaveInfo::kLengthFullContent ||
89 length_ > offset - offset_) { 89 length_ > offset - offset_) {
90 length_ = offset - offset_; 90 length_ = offset - offset_;
91 } 91 }
92 } 92 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 parameters->source_url, 321 parameters->source_url,
322 parameters->referrer_url); 322 parameters->referrer_url);
323 } 323 }
324 324
325 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) { 325 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) {
326 // Make sure our information is updated, since we're about to 326 // Make sure our information is updated, since we're about to
327 // error out. 327 // error out.
328 SendUpdate(); 328 SendUpdate();
329 329
330 // Null out callback so that we don't do any more stream processing. 330 // Null out callback so that we don't do any more stream processing.
331 // The request that writes to the pipe should be canceled after
332 // download interrupted.
331 for (auto& stream : source_streams_) { 333 for (auto& stream : source_streams_) {
332 ByteStreamReader* stream_reader = stream.second->stream_reader(); 334 ByteStreamReader* stream_reader = stream.second->stream_reader();
333 if (stream_reader) 335 if (stream_reader)
334 stream_reader->RegisterCallback(base::Closure()); 336 stream_reader->RegisterCallback(base::Closure());
335 } 337 }
336 338
337 new_path.clear(); 339 new_path.clear();
338 } 340 }
339 341
340 BrowserThread::PostTask( 342 BrowserThread::PostTask(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 464
463 RecordContiguousWriteTime(now - start); 465 RecordContiguousWriteTime(now - start);
464 466
465 // Take care of communication with our observer. 467 // Take care of communication with our observer.
466 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) { 468 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) {
467 HandleStreamError(source_stream, reason); 469 HandleStreamError(source_stream, reason);
468 } else if (state == ByteStreamReader::STREAM_COMPLETE || should_terminate) { 470 } else if (state == ByteStreamReader::STREAM_COMPLETE || should_terminate) {
469 // Signal successful completion or termination of the current stream. 471 // Signal successful completion or termination of the current stream.
470 source_stream->stream_reader()->RegisterCallback(base::Closure()); 472 source_stream->stream_reader()->RegisterCallback(base::Closure());
471 source_stream->set_finished(true); 473 source_stream->set_finished(true);
474 streams_to_close_.emplace(source_stream->offset());
472 if (source_stream->length() == DownloadSaveInfo::kLengthFullContent) { 475 if (source_stream->length() == DownloadSaveInfo::kLengthFullContent) {
473 SetPotentialFileLength(source_stream->offset() + 476 SetPotentialFileLength(source_stream->offset() +
474 source_stream->bytes_written()); 477 source_stream->bytes_written());
475 } 478 }
476 num_active_streams_--; 479 num_active_streams_--;
477 480
478 // Inform observers. 481 // Inform observers.
479 SendUpdate(); 482 SendUpdate();
480 483
481 // All the stream reader are completed, shut down file IO processing. 484 // All the stream reader are completed, shut down file IO processing.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 return file_.bytes_so_far(); 529 return file_.bytes_so_far();
527 } 530 }
528 531
529 void DownloadFileImpl::SendUpdate() { 532 void DownloadFileImpl::SendUpdate() {
530 // TODO(qinmin): For each active stream, add the slice it has written so 533 // TODO(qinmin): For each active stream, add the slice it has written so
531 // far along with received_slices_. 534 // far along with received_slices_.
532 BrowserThread::PostTask( 535 BrowserThread::PostTask(
533 BrowserThread::UI, FROM_HERE, 536 BrowserThread::UI, FROM_HERE,
534 base::Bind(&DownloadDestinationObserver::DestinationUpdate, observer_, 537 base::Bind(&DownloadDestinationObserver::DestinationUpdate, observer_,
535 TotalBytesReceived(), rate_estimator_.GetCountPerSecond(), 538 TotalBytesReceived(), rate_estimator_.GetCountPerSecond(),
536 received_slices_)); 539 received_slices_, streams_to_close_));
540 streams_to_close_.clear();
537 } 541 }
538 542
539 void DownloadFileImpl::WillWriteToDisk(size_t data_len) { 543 void DownloadFileImpl::WillWriteToDisk(size_t data_len) {
540 if (!update_timer_->IsRunning()) { 544 if (!update_timer_->IsRunning()) {
541 update_timer_->Start(FROM_HERE, 545 update_timer_->Start(FROM_HERE,
542 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), 546 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs),
543 this, &DownloadFileImpl::SendUpdate); 547 this, &DownloadFileImpl::SendUpdate);
544 } 548 }
545 rate_estimator_.Increment(data_len); 549 rate_estimator_.Increment(data_len);
546 base::TimeTicks now = base::TimeTicks::Now(); 550 base::TimeTicks now = base::TimeTicks::Now();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 if (can_recover_from_error) { 638 if (can_recover_from_error) {
635 // Since the neighbor stream will download all data downloading from its 639 // Since the neighbor stream will download all data downloading from its
636 // offset to source_stream->offset(). Close all other streams in the 640 // offset to source_stream->offset(). Close all other streams in the
637 // middle. 641 // middle.
638 for (auto& stream : source_streams_) { 642 for (auto& stream : source_streams_) {
639 if (stream.second->offset() < source_stream->offset() && 643 if (stream.second->offset() < source_stream->offset() &&
640 stream.second->offset() > preceding_neighbor->offset()) { 644 stream.second->offset() > preceding_neighbor->offset()) {
641 DCHECK_EQ(stream.second->bytes_written(), 0); 645 DCHECK_EQ(stream.second->bytes_written(), 0);
642 stream.second->stream_reader()->RegisterCallback(base::Closure()); 646 stream.second->stream_reader()->RegisterCallback(base::Closure());
643 stream.second->set_finished(true); 647 stream.second->set_finished(true);
648 streams_to_close_.emplace(stream.second->offset());
644 num_active_streams_--; 649 num_active_streams_--;
645 } 650 }
646 } 651 }
647 } 652 }
648 } 653 }
649 654
650 SendUpdate(); // Make info up to date before error. 655 SendUpdate(); // Make info up to date before error.
651 656
652 if (!can_recover_from_error) { 657 if (!can_recover_from_error) {
653 // Error case for both upstream source and file write. 658 // Error case for both upstream source and file write.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 const base::FilePath& new_path, 703 const base::FilePath& new_path,
699 const RenameCompletionCallback& completion_callback) 704 const RenameCompletionCallback& completion_callback)
700 : option(option), 705 : option(option),
701 new_path(new_path), 706 new_path(new_path),
702 retries_left(kMaxRenameRetries), 707 retries_left(kMaxRenameRetries),
703 completion_callback(completion_callback) {} 708 completion_callback(completion_callback) {}
704 709
705 DownloadFileImpl::RenameParameters::~RenameParameters() {} 710 DownloadFileImpl::RenameParameters::~RenameParameters() {}
706 711
707 } // namespace content 712 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698