Commit d1f09384 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Added checks to prune out redundant download updates

Download file keeps sending us updates about its status in a loop even
though the download can be in a paused state. Added a check to prune out
these updates if there is no change to the bytes received. This will
enable us to clean up the code to avoid the state-dependent
AddObserver/RemoveObserver calls in the download observers such as
DownloadController.

Bug: 913085
Change-Id: I915de9d8f95ba5320529ddfe761404c008678576
Reviewed-on: https://chromium-review.googlesource.com/c/1368650Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615361}
parent f5f61903
......@@ -301,6 +301,7 @@ void DownloadController::CreateAndroidDownload(
}
void DownloadController::AboutToResumeDownload(DownloadItem* download_item) {
download_item->RemoveObserver(this);
download_item->AddObserver(this);
// If a download is resumed from an interrupted state, record its strong
......@@ -411,8 +412,6 @@ void DownloadController::OnDownloadUpdated(DownloadItem* item) {
switch (item->GetState()) {
case DownloadItem::IN_PROGRESS: {
Java_DownloadController_onDownloadUpdated(env, j_item);
if (item->IsPaused())
item->RemoveObserver(this);
break;
}
case DownloadItem::COMPLETE:
......@@ -438,7 +437,6 @@ void DownloadController::OnDownloadUpdated(DownloadItem* item) {
// resume in this case.
Java_DownloadController_onDownloadInterrupted(env, j_item,
IsInterruptedDownloadAutoResumable(item));
item->RemoveObserver(this);
break;
case DownloadItem::MAX_DOWNLOAD_STATE:
NOTREACHED();
......
......@@ -1234,6 +1234,9 @@ void DownloadItemImpl::DestinationUpdate(
TRACE_EVENT_SCOPE_THREAD, "bytes_so_far",
GetReceivedBytes());
if (IsPaused() && destination_info_.received_bytes == bytes_so_far)
return;
UpdateObservers();
}
......
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