| Index: chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| index ddfd91624d3ffd1eb5bca40314bc2ac01e8d468e..2fa54167fffdcad3fb500e0b0b28b59c2e27c772 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| @@ -59,30 +59,39 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| private static final int INVALID_INDEX = -1;
|
|
|
| private final List<DownloadItemWrapper> mDownloadItems = new ArrayList<>();
|
| + private final List<DownloadItemWrapper> mDownloadOffTheRecordItems = new ArrayList<>();
|
| private final List<OfflinePageItemWrapper> mOfflinePageItems = new ArrayList<>();
|
| private final List<DownloadHistoryItemWrapper> mFilteredItems = new ArrayList<>();
|
| + private final boolean mShowOffTheRecord;
|
|
|
| private int mFilter = DownloadFilter.FILTER_ALL;
|
| private DownloadManagerUi mManager;
|
| private OfflinePageDownloadBridge mOfflinePageBridge;
|
|
|
| + DownloadHistoryAdapter(boolean showOffTheRecord) {
|
| + mShowOffTheRecord = showOffTheRecord;
|
| + }
|
| +
|
| @Override
|
| public void initialize(DownloadManagerUi manager) {
|
| manager.addObserver(this);
|
| mManager = manager;
|
|
|
| + // Get all regular and (if necessary) off the record downloads.
|
| getDownloadManagerService().addDownloadHistoryAdapter(this);
|
| - getDownloadManagerService().getAllDownloads();
|
| + getDownloadManagerService().getAllDownloads(false);
|
| + if (mShowOffTheRecord) getDownloadManagerService().getAllDownloads(true);
|
|
|
| initializeOfflinePageBridge();
|
| }
|
|
|
| /** Called when the user's download history has been gathered. */
|
| - public void onAllDownloadsRetrieved(List<DownloadItem> result) {
|
| - mDownloadItems.clear();
|
| - for (DownloadItem item : result) {
|
| - mDownloadItems.add(new DownloadItemWrapper(item));
|
| - }
|
| + public void onAllDownloadsRetrieved(List<DownloadItem> result, boolean isOffTheRecord) {
|
| + if (isOffTheRecord && !mShowOffTheRecord) return;
|
| +
|
| + List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord);
|
| + list.clear();
|
| + for (DownloadItem item : result) list.add(new DownloadItemWrapper(item, isOffTheRecord));
|
| filter(DownloadFilter.FILTER_ALL);
|
| }
|
|
|
| @@ -103,6 +112,9 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| for (DownloadHistoryItemWrapper wrapper : mDownloadItems) {
|
| totalSize += wrapper.getFileSize();
|
| }
|
| + for (DownloadHistoryItemWrapper wrapper : mDownloadOffTheRecordItems) {
|
| + totalSize += wrapper.getFileSize();
|
| + }
|
| for (DownloadHistoryItemWrapper wrapper : mOfflinePageItems) {
|
| totalSize += wrapper.getFileSize();
|
| }
|
| @@ -163,14 +175,17 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| /**
|
| * Updates the list when new information about a download comes in.
|
| */
|
| - public void onDownloadItemUpdated(DownloadItem item) {
|
| - int index = findItemIndex(mDownloadItems, item.getId());
|
| + public void onDownloadItemUpdated(DownloadItem item, boolean isOffTheRecord) {
|
| + if (isOffTheRecord && !mShowOffTheRecord) return;
|
| +
|
| + List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord);
|
| + int index = findItemIndex(list, item.getId());
|
| if (index == INVALID_INDEX) {
|
| // Add a new entry.
|
| - mDownloadItems.add(new DownloadItemWrapper(item));
|
| + list.add(new DownloadItemWrapper(item, isOffTheRecord));
|
| } else {
|
| // Update the old one.
|
| - mDownloadItems.set(index, new DownloadItemWrapper(item));
|
| + list.set(index, new DownloadItemWrapper(item, isOffTheRecord));
|
| }
|
|
|
| filter(mFilter);
|
| @@ -178,12 +193,16 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
|
|
| /**
|
| * Removes the DownloadItem with the given ID.
|
| - * @param guid ID of the DownloadItem that has been removed.
|
| + * @param guid ID of the DownloadItem that has been removed.
|
| + * @param isOffTheRecord True if off the record, false otherwise.
|
| */
|
| - public void onDownloadItemRemoved(String guid) {
|
| - int index = findItemIndex(mDownloadItems, guid);
|
| + public void onDownloadItemRemoved(String guid, boolean isOffTheRecord) {
|
| + if (isOffTheRecord && !mShowOffTheRecord) return;
|
| +
|
| + List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord);
|
| + int index = findItemIndex(list, guid);
|
| if (index != INVALID_INDEX) {
|
| - DownloadItemWrapper wrapper = mDownloadItems.remove(index);
|
| + DownloadItemWrapper wrapper = list.remove(index);
|
| if (mManager.getSelectionDelegate().isItemSelected(wrapper)) {
|
| mManager.getSelectionDelegate().toggleSelectionForItem(wrapper);
|
| }
|
| @@ -214,12 +233,17 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| mFilteredItems.clear();
|
| if (filterType == DownloadFilter.FILTER_ALL) {
|
| mFilteredItems.addAll(mDownloadItems);
|
| + mFilteredItems.addAll(mDownloadOffTheRecordItems);
|
| mFilteredItems.addAll(mOfflinePageItems);
|
| } else {
|
| for (DownloadHistoryItemWrapper item : mDownloadItems) {
|
| if (item.getFilterType() == filterType) mFilteredItems.add(item);
|
| }
|
|
|
| + for (DownloadHistoryItemWrapper item : mDownloadOffTheRecordItems) {
|
| + if (item.getFilterType() == filterType) mFilteredItems.add(item);
|
| + }
|
| +
|
| if (filterType == DownloadFilter.FILTER_PAGE) {
|
| for (DownloadHistoryItemWrapper item : mOfflinePageItems) mFilteredItems.add(item);
|
| }
|
| @@ -272,6 +296,10 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| });
|
| }
|
|
|
| + private List<DownloadItemWrapper> getDownloadItemList(boolean isOffTheRecord) {
|
| + return isOffTheRecord ? mDownloadOffTheRecordItems : mDownloadItems;
|
| + }
|
| +
|
| /**
|
| * Search for an existing entry for the {@link DownloadHistoryItemWrapper} with the given ID.
|
| * @param list List to search through.
|
|
|