| OLD | NEW |
| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 RecordContiguousWriteTime(now - start); | 469 RecordContiguousWriteTime(now - start); |
| 470 | 470 |
| 471 // Take care of communication with our observer. | 471 // Take care of communication with our observer. |
| 472 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) { | 472 if (reason != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 473 HandleStreamError(source_stream, reason); | 473 HandleStreamError(source_stream, reason); |
| 474 } else if (state == ByteStreamReader::STREAM_COMPLETE || should_terminate) { | 474 } else if (state == ByteStreamReader::STREAM_COMPLETE || should_terminate) { |
| 475 // Signal successful completion or termination of the current stream. | 475 // Signal successful completion or termination of the current stream. |
| 476 source_stream->stream_reader()->RegisterCallback(base::Closure()); | 476 source_stream->stream_reader()->RegisterCallback(base::Closure()); |
| 477 source_stream->set_finished(true); | 477 source_stream->set_finished(true); |
| 478 if (should_terminate) | 478 if (should_terminate) |
| 479 CancelRequestOnUIThread(source_stream->offset()); | 479 CancelRequest(source_stream->offset()); |
| 480 if (source_stream->length() == DownloadSaveInfo::kLengthFullContent) { | 480 if (source_stream->length() == DownloadSaveInfo::kLengthFullContent) { |
| 481 SetPotentialFileLength(source_stream->offset() + | 481 SetPotentialFileLength(source_stream->offset() + |
| 482 source_stream->bytes_written()); | 482 source_stream->bytes_written()); |
| 483 } | 483 } |
| 484 num_active_streams_--; | 484 num_active_streams_--; |
| 485 | 485 |
| 486 // Inform observers. | 486 // Inform observers. |
| 487 SendUpdate(); | 487 SendUpdate(); |
| 488 | 488 |
| 489 // All the stream reader are completed, shut down file IO processing. | 489 // All the stream reader are completed, shut down file IO processing. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 if (can_recover_from_error) { | 643 if (can_recover_from_error) { |
| 644 // Since the neighbor stream will download all data downloading from its | 644 // Since the neighbor stream will download all data downloading from its |
| 645 // offset to source_stream->offset(). Close all other streams in the | 645 // offset to source_stream->offset(). Close all other streams in the |
| 646 // middle. | 646 // middle. |
| 647 for (auto& stream : source_streams_) { | 647 for (auto& stream : source_streams_) { |
| 648 if (stream.second->offset() < source_stream->offset() && | 648 if (stream.second->offset() < source_stream->offset() && |
| 649 stream.second->offset() > preceding_neighbor->offset()) { | 649 stream.second->offset() > preceding_neighbor->offset()) { |
| 650 DCHECK_EQ(stream.second->bytes_written(), 0); | 650 DCHECK_EQ(stream.second->bytes_written(), 0); |
| 651 stream.second->stream_reader()->RegisterCallback(base::Closure()); | 651 stream.second->stream_reader()->RegisterCallback(base::Closure()); |
| 652 stream.second->set_finished(true); | 652 stream.second->set_finished(true); |
| 653 CancelRequestOnUIThread(stream.second->offset()); | 653 CancelRequest(stream.second->offset()); |
| 654 num_active_streams_--; | 654 num_active_streams_--; |
| 655 } | 655 } |
| 656 } | 656 } |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 | 659 |
| 660 SendUpdate(); // Make info up to date before error. | 660 SendUpdate(); // Make info up to date before error. |
| 661 | 661 |
| 662 if (!can_recover_from_error) { | 662 if (!can_recover_from_error) { |
| 663 // Error case for both upstream source and file write. | 663 // Error case for both upstream source and file write. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 683 for (auto& stream : source_streams_) { | 683 for (auto& stream : source_streams_) { |
| 684 int64_t offset = stream.second->offset(); | 684 int64_t offset = stream.second->offset(); |
| 685 if (offset < source_stream->offset() && offset >= max_preceding_offset) { | 685 if (offset < source_stream->offset() && offset >= max_preceding_offset) { |
| 686 ret = stream.second.get(); | 686 ret = stream.second.get(); |
| 687 max_preceding_offset = offset; | 687 max_preceding_offset = offset; |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 return ret; | 690 return ret; |
| 691 } | 691 } |
| 692 | 692 |
| 693 void DownloadFileImpl::CancelRequestOnUIThread(int64_t offset) { | 693 void DownloadFileImpl::CancelRequest(int64_t offset) { |
| 694 if (!cancel_request_callback_.is_null()) { | 694 if (!cancel_request_callback_.is_null()) { |
| 695 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 695 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 696 base::Bind(cancel_request_callback_, offset)); | 696 base::Bind(cancel_request_callback_, offset)); |
| 697 } | 697 } |
| 698 } | 698 } |
| 699 | 699 |
| 700 void DownloadFileImpl::DebugStates() const { | 700 void DownloadFileImpl::DebugStates() const { |
| 701 DVLOG(1) << "### Debugging DownloadFile states:"; | 701 DVLOG(1) << "### Debugging DownloadFile states:"; |
| 702 DVLOG(1) << "Total source stream count = " << source_streams_.size(); | 702 DVLOG(1) << "Total source stream count = " << source_streams_.size(); |
| 703 for (const auto& stream : source_streams_) { | 703 for (const auto& stream : source_streams_) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 715 const base::FilePath& new_path, | 715 const base::FilePath& new_path, |
| 716 const RenameCompletionCallback& completion_callback) | 716 const RenameCompletionCallback& completion_callback) |
| 717 : option(option), | 717 : option(option), |
| 718 new_path(new_path), | 718 new_path(new_path), |
| 719 retries_left(kMaxRenameRetries), | 719 retries_left(kMaxRenameRetries), |
| 720 completion_callback(completion_callback) {} | 720 completion_callback(completion_callback) {} |
| 721 | 721 |
| 722 DownloadFileImpl::RenameParameters::~RenameParameters() {} | 722 DownloadFileImpl::RenameParameters::~RenameParameters() {} |
| 723 | 723 |
| 724 } // namespace content | 724 } // namespace content |
| OLD | NEW |