| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 DownloadFileImpl::~DownloadFileImpl() { | 90 DownloadFileImpl::~DownloadFileImpl() { |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 91 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 92 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); | 92 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { | 95 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 96 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 97 | 97 |
| 98 update_timer_.reset(new base::RepeatingTimer()); | 98 update_timer_.reset(new base::RepeatingTimer()); |
| 99 int64_t bytes_so_far = 0; |
| 100 if (is_sparse_file_) { |
| 101 for (const auto& received_slice : received_slices_) { |
| 102 bytes_so_far += received_slice.received_bytes; |
| 103 } |
| 104 } else { |
| 105 bytes_so_far = save_info_->offset; |
| 106 } |
| 99 DownloadInterruptReason result = | 107 DownloadInterruptReason result = |
| 100 file_.Initialize(save_info_->file_path, default_download_directory_, | 108 file_.Initialize(save_info_->file_path, default_download_directory_, |
| 101 std::move(save_info_->file), save_info_->offset, | 109 std::move(save_info_->file), bytes_so_far, |
| 102 save_info_->hash_of_partial_file, | 110 save_info_->hash_of_partial_file, |
| 103 std::move(save_info_->hash_state), is_sparse_file_); | 111 std::move(save_info_->hash_state), is_sparse_file_); |
| 104 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 112 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 105 BrowserThread::PostTask( | 113 BrowserThread::PostTask( |
| 106 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 114 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 107 return; | 115 return; |
| 108 } | 116 } |
| 109 | 117 |
| 110 download_start_ = base::TimeTicks::Now(); | 118 download_start_ = base::TimeTicks::Now(); |
| 111 | 119 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 ByteStreamReader* stream_reader = source_stream->stream_reader(); | 411 ByteStreamReader* stream_reader = source_stream->stream_reader(); |
| 404 if (stream_reader) { | 412 if (stream_reader) { |
| 405 stream_reader->RegisterCallback(base::Bind(&DownloadFileImpl::StreamActive, | 413 stream_reader->RegisterCallback(base::Bind(&DownloadFileImpl::StreamActive, |
| 406 weak_factory_.GetWeakPtr(), | 414 weak_factory_.GetWeakPtr(), |
| 407 source_stream)); | 415 source_stream)); |
| 408 StreamActive(source_stream); | 416 StreamActive(source_stream); |
| 409 } | 417 } |
| 410 } | 418 } |
| 411 | 419 |
| 412 int64_t DownloadFileImpl::TotalBytesReceived() const { | 420 int64_t DownloadFileImpl::TotalBytesReceived() const { |
| 413 // TODO(xingliu): Use slice info to figure out total bytes received. | |
| 414 return file_.bytes_so_far(); | 421 return file_.bytes_so_far(); |
| 415 } | 422 } |
| 416 | 423 |
| 417 void DownloadFileImpl::SendUpdate() { | 424 void DownloadFileImpl::SendUpdate() { |
| 418 // TODO(qinmin): For each active stream, add the slice it has written so | 425 // TODO(qinmin): For each active stream, add the slice it has written so |
| 419 // far along with received_slices_. | 426 // far along with received_slices_. |
| 420 BrowserThread::PostTask( | 427 BrowserThread::PostTask( |
| 421 BrowserThread::UI, FROM_HERE, | 428 BrowserThread::UI, FROM_HERE, |
| 422 base::Bind(&DownloadDestinationObserver::DestinationUpdate, observer_, | 429 base::Bind(&DownloadDestinationObserver::DestinationUpdate, observer_, |
| 423 TotalBytesReceived(), rate_estimator_.GetCountPerSecond(), | 430 TotalBytesReceived(), rate_estimator_.GetCountPerSecond(), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 438 const base::FilePath& new_path, | 445 const base::FilePath& new_path, |
| 439 const RenameCompletionCallback& completion_callback) | 446 const RenameCompletionCallback& completion_callback) |
| 440 : option(option), | 447 : option(option), |
| 441 new_path(new_path), | 448 new_path(new_path), |
| 442 retries_left(kMaxRenameRetries), | 449 retries_left(kMaxRenameRetries), |
| 443 completion_callback(completion_callback) {} | 450 completion_callback(completion_callback) {} |
| 444 | 451 |
| 445 DownloadFileImpl::RenameParameters::~RenameParameters() {} | 452 DownloadFileImpl::RenameParameters::~RenameParameters() {} |
| 446 | 453 |
| 447 } // namespace content | 454 } // namespace content |
| OLD | NEW |