From 2f936d9b8a1d2ab13d8b1a558d294b795e944e5a Mon Sep 17 00:00:00 2001 From: Filip Gorski Date: Tue, 1 Dec 2015 14:39:31 -0800 Subject: [PATCH] [Offline pages] Filter out offline pages without matching bookmarks in UI Making sure that when offline page filter is applied, all of the bookmark IDs are checked against the bookmark model, before being used by UI. BUG=537806 Review URL: https://codereview.chromium.org/1470403002 Cr-Commit-Position: refs/heads/master@{#362185} (cherry picked from commit f2d8e24f06b57fa0edc5dcd999516e3343d8a769) Review URL: https://codereview.chromium.org/1486753005 . Cr-Commit-Position: refs/branch-heads/2564@{#186} Cr-Branched-From: 1283eca15bd9f772387f75241576cde7bdec7f54-refs/heads/master@{#359700} --- .../enhancedbookmarks/EnhancedBookmarksModel.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarksModel.java b/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarksModel.java index 5ec67615c9b2a..c0eea27e8c4fb 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarksModel.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarksModel.java @@ -27,6 +27,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.List; import java.util.concurrent.TimeUnit; @@ -327,9 +328,17 @@ public List getBookmarkIDsByFilter(EnhancedBookmarkFilter filter) { List offlinePages = mOfflinePageBridge.getAllPages(); Collections.sort(offlinePages, sOfflinePageComparator); + + // We are going to filter out all of the offline pages without a matching bookmark. + // http://crbug.com/537806 + HashSet existingBookmarks = + new HashSet(getAllBookmarkIDsOrderedByCreationDate()); + List bookmarkIds = new ArrayList(); for (OfflinePageItem offlinePage : offlinePages) { - bookmarkIds.add(offlinePage.getBookmarkId()); + if (existingBookmarks.contains(offlinePage.getBookmarkId())) { + bookmarkIds.add(offlinePage.getBookmarkId()); + } } return bookmarkIds; }