Commit 7b88754c authored by qinmin's avatar qinmin Committed by Commit bot

Fix the issue while clicking on offline page donwload notification

When OfflinePageDownloadBridge is created, it will load all the
offline page items.
However, openItem() can get called before all page items are loaded.
This causes the native side unable to find the downloaded item.
As a result, nothing happens when user clicks offline page download
success notification.
This CL waits for all the page items to get loaded before calling
openItem().

BUG=640467

Review-Url: https://codereview.chromium.org/2272883004
Cr-Commit-Position: refs/heads/master@{#414317}
parent 81a0c399
...@@ -506,6 +506,7 @@ public class DownloadNotificationService extends Service { ...@@ -506,6 +506,7 @@ public class DownloadNotificationService extends Service {
? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE
: DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD); : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD);
DownloadServiceDelegate downloadServiceDelegate = getServiceDelegate(itemType); DownloadServiceDelegate downloadServiceDelegate = getServiceDelegate(itemType);
boolean destroyImmediately = true;
switch (intent.getAction()) { switch (intent.getAction()) {
case ACTION_DOWNLOAD_CANCEL: case ACTION_DOWNLOAD_CANCEL:
// TODO(qinmin): Alternatively, we can delete the downloaded content on // TODO(qinmin): Alternatively, we can delete the downloaded content on
...@@ -531,15 +532,27 @@ public class DownloadNotificationService extends Service { ...@@ -531,15 +532,27 @@ public class DownloadNotificationService extends Service {
resumeAllPendingDownloads(); resumeAllPendingDownloads();
break; break;
case ACTION_DOWNLOAD_OPEN: case ACTION_DOWNLOAD_OPEN:
assert entry == null; final OfflinePageDownloadBridge bridge =
String guid = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNLOAD_GUID); (OfflinePageDownloadBridge) downloadServiceDelegate;
downloadServiceDelegate.openItem(guid); destroyImmediately = false;
bridge.addObserver(
new OfflinePageDownloadBridge.Observer() {
@Override
public void onItemsLoaded() {
String guid = IntentUtils.safeGetStringExtra(
intent, EXTRA_DOWNLOAD_GUID);
bridge.openItem(guid);
bridge.destroyServiceDelegate();
}
});
break; break;
default: default:
Log.e(TAG, "Unrecognized intent action.", intent); Log.e(TAG, "Unrecognized intent action.", intent);
break; break;
} }
downloadServiceDelegate.destroyServiceDelegate(); if (destroyImmediately) {
downloadServiceDelegate.destroyServiceDelegate();
}
} }
}; };
try { try {
......
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