Commit 7581dd15 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Fixed redundant download completed observer updates

We should be careful to not let the same download completion update
surface twice to the UI layer. Otherwise it might inadvertently
introduce duplicate notification bugs.

Bug : 949941

Change-Id: I161066f81fd6d12afb57236847d9d6c47fb2984a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1555653
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649340}
parent b0b81be1
...@@ -254,7 +254,7 @@ public class DownloadNotificationService { ...@@ -254,7 +254,7 @@ public class DownloadNotificationService {
startTrackingInProgressDownload(id); startTrackingInProgressDownload(id);
} }
public void cancelNotification(int notificationId) { private void cancelNotification(int notificationId) {
// TODO(b/65052774): Add back NOTIFICATION_NAMESPACE when able to. // TODO(b/65052774): Add back NOTIFICATION_NAMESPACE when able to.
mNotificationManager.cancel(notificationId); mNotificationManager.cancel(notificationId);
} }
......
...@@ -264,6 +264,13 @@ void DownloadOfflineContentProvider::OnDownloadUpdated(DownloadItem* item) { ...@@ -264,6 +264,13 @@ void DownloadOfflineContentProvider::OnDownloadUpdated(DownloadItem* item) {
if (item->GetState() == DownloadItem::COMPLETE) { if (item->GetState() == DownloadItem::COMPLETE) {
// TODO(crbug.com/938152): May be move this to DownloadItem. // TODO(crbug.com/938152): May be move this to DownloadItem.
if (completed_downloads_.find(item->GetGuid()) !=
completed_downloads_.end()) {
return;
}
completed_downloads_.insert(item->GetGuid());
AddCompletedDownload(item); AddCompletedDownload(item);
} }
...@@ -283,12 +290,12 @@ void DownloadOfflineContentProvider::OnDownloadRemoved(DownloadItem* item) { ...@@ -283,12 +290,12 @@ void DownloadOfflineContentProvider::OnDownloadRemoved(DownloadItem* item) {
observer.OnItemRemoved(contentId); observer.OnItemRemoved(contentId);
} }
void DownloadOfflineContentProvider::OnDownloadDestroyed(DownloadItem* item) {
completed_downloads_.erase(item->GetGuid());
}
void DownloadOfflineContentProvider::AddCompletedDownload(DownloadItem* item) { void DownloadOfflineContentProvider::AddCompletedDownload(DownloadItem* item) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (completed_downloads_.find(item->GetGuid()) != completed_downloads_.end())
return;
completed_downloads_.insert(item->GetGuid());
DownloadManagerBridge::AddCompletedDownload( DownloadManagerBridge::AddCompletedDownload(
item, item,
base::BindOnce(&DownloadOfflineContentProvider::AddCompletedDownloadDone, base::BindOnce(&DownloadOfflineContentProvider::AddCompletedDownloadDone,
......
...@@ -70,6 +70,7 @@ class DownloadOfflineContentProvider : public OfflineContentProvider, ...@@ -70,6 +70,7 @@ class DownloadOfflineContentProvider : public OfflineContentProvider,
// DownloadItem::Observer overrides // DownloadItem::Observer overrides
void OnDownloadUpdated(DownloadItem* item) override; void OnDownloadUpdated(DownloadItem* item) override;
void OnDownloadRemoved(DownloadItem* item) override; void OnDownloadRemoved(DownloadItem* item) override;
void OnDownloadDestroyed(DownloadItem* download) override;
// DownloadManager::Observer overrides // DownloadManager::Observer overrides
void ManagerGoingDown(DownloadManager* manager) override; void ManagerGoingDown(DownloadManager* manager) override;
......
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