Skip to content

Commit

Permalink
Fix open paths for download ContentId work
Browse files Browse the repository at this point in the history
Add two new ways to open an OfflineItem in the new API path:
- From the snackbar.
- From the notification.

BUG=691805

Review-Url: https://codereview.chromium.org/2798093003
Cr-Commit-Position: refs/heads/master@{#464080}
  • Loading branch information
dtrainor authored and Commit bot committed Apr 12, 2017
1 parent 0ecaeb8 commit a2d733f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,8 @@ public void finishNativeInitialization() {
ContentId id = getContentIdFromIntent(intent);
if (LegacyHelpers.isLegacyOfflinePage(id)) {
OfflinePageDownloadBridge.openDownloadedPage(id);
} else if (id != null) {
OfflineContentAggregatorNotificationBridgeUiFactory.instance().openItem(id);
}
} else {
Log.e(TAG, "Unrecognized intent action.", intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.chromium.base.BuildInfo;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.download.items.OfflineContentAggregatorNotificationBridgeUiFactory;
import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBridge;
import org.chromium.chrome.browser.snackbar.Snackbar;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.components.offline_items_collection.LegacyHelpers;

/**
* Class for displaying a snackbar when a download completes.
Expand Down Expand Up @@ -50,18 +52,23 @@ public void onAction(Object actionData) {
DownloadManagerService.openDownloadsPage(mContext);
return;
}

DownloadManagerService manager = DownloadManagerService.getDownloadManagerService();
final ActionDataInfo download = (ActionDataInfo) actionData;
if (download.downloadInfo.isOfflinePage()) {
if (LegacyHelpers.isLegacyOfflinePage(download.downloadInfo.getContentId())) {
OfflinePageDownloadBridge.openDownloadedPage(download.downloadInfo.getContentId());
return;
}
if (download.usesAndroidDownloadManager) {
mContext.startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS).addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK));
return;
} else if (LegacyHelpers.isLegacyDownload(download.downloadInfo.getContentId())) {
if (download.usesAndroidDownloadManager) {
mContext.startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} else {
manager.openDownloadedContent(download.downloadInfo, download.systemDownloadId);
}
} else {
OfflineContentAggregatorNotificationBridgeUiFactory.instance().openItem(
download.downloadInfo.getContentId());
}
DownloadManagerService manager = DownloadManagerService.getDownloadManagerService();
manager.openDownloadedContent(download.downloadInfo, download.systemDownloadId);

if (download.notificationId != INVALID_NOTIFICATION_ID) {
manager.getDownloadNotifier().removeDownloadNotification(
download.notificationId, download.downloadInfo);
Expand Down Expand Up @@ -99,7 +106,8 @@ public void onDownloadSucceeded(
// TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(false);
ActionDataInfo info = null;
if (canBeResolved || downloadInfo.isOfflinePage() || usesAndroidDownloadManager) {
if (canBeResolved || !LegacyHelpers.isLegacyDownload(downloadInfo.getContentId())
|| usesAndroidDownloadManager) {
info = new ActionDataInfo(downloadInfo, notificationId, downloadId,
usesAndroidDownloadManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void destroy() {
destroyServiceDelegate();
}

/** @see OfflineContentProvider#openItem(ContentId) */
public void openItem(ContentId id) {
mProvider.openItem(id);
}

// OfflineContentProvider.Observer implementation.
@Override
public void onItemsAvailable() {}
Expand Down

0 comments on commit a2d733f

Please sign in to comment.