Commit bd2da733 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Cancel watching the mojo data pipe on download pause

When download is paused, watching the mojo data pipe for data ready
callback is not needed. As the callback will trigger an early return
and do nothing. We can register the callback later when download is
resumed.

BUG=927530

Change-Id: Ifc225241978cb34991846ffb4a6a40166e5fc953
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1748122Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686590}
parent cd38506a
......@@ -555,6 +555,8 @@ void DownloadFileImpl::Pause() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
is_paused_ = true;
record_stream_bandwidth_ = false;
for (auto& stream : source_streams_)
stream.second->ClearDataReadyCallback();
}
void DownloadFileImpl::Resume() {
......@@ -565,7 +567,7 @@ void DownloadFileImpl::Resume() {
for (auto& stream : source_streams_) {
SourceStream* source_stream = stream.second.get();
if (!source_stream->is_finished()) {
StreamActive(source_stream, MOJO_RESULT_OK);
ActivateStream(source_stream);
}
}
}
......@@ -722,15 +724,19 @@ void DownloadFileImpl::RegisterAndActivateStream(SourceStream* source_stream) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
source_stream->Initialize();
source_stream->RegisterDataReadyCallback(
base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr(),
source_stream));
// Truncate |source_stream|'s length if necessary.
for (const auto& received_slice : received_slices_) {
source_stream->TruncateLengthWithWrittenDataBlock(
received_slice.offset, received_slice.received_bytes);
}
num_active_streams_++;
ActivateStream(source_stream);
}
void DownloadFileImpl::ActivateStream(SourceStream* source_stream) {
source_stream->RegisterDataReadyCallback(
base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr(),
source_stream));
StreamActive(source_stream, MOJO_RESULT_OK);
}
......
......@@ -277,6 +277,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile {
// Register callback and start to read data from the stream.
void RegisterAndActivateStream(SourceStream* source_stream);
// Helper method to activate a stream and start reading from it.
void ActivateStream(SourceStream* source_stream);
// Called when a stream completes.
void OnStreamCompleted(SourceStream* source_stream);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment