diff options
-rwxr-xr-x | build/get_landmines.py | 1 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/OWNERS | 1 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksBridge.java (renamed from chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java) | 2 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksModel.java | 391 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/OWNERS | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | components/enhanced_bookmarks/BUILD.gn | 2 | ||||
-rw-r--r-- | components/enhanced_bookmarks/enhanced_bookmark_utils.h | 2 |
8 files changed, 397 insertions, 5 deletions
diff --git a/build/get_landmines.py b/build/get_landmines.py index ac3d7d6..7a918c8 100755 --- a/build/get_landmines.py +++ b/build/get_landmines.py @@ -29,6 +29,7 @@ def print_landmines(): print 'Need to clobber winja goma due to backend cwd cache fix.' if platform() == 'android': print 'Clobber: to handle new way of suppressing findbugs failures.' + print 'Clobber to fix gyp not rename package name (crbug.com/457038)' if platform() == 'win' and builder() == 'ninja': print 'Compile on cc_unittests fails due to symbols removed in r185063.' if platform() == 'linux' and builder() == 'ninja': diff --git a/chrome/android/java/src/org/chromium/chrome/browser/OWNERS b/chrome/android/java/src/org/chromium/chrome/browser/OWNERS deleted file mode 100644 index 1982eec..0000000 --- a/chrome/android/java/src/org/chromium/chrome/browser/OWNERS +++ /dev/null @@ -1 +0,0 @@ -per-file EnhancedBookmarksBridge.java=kkimlabs@chromium.org diff --git a/chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksBridge.java index 14a0c0d..b4940a3 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksBridge.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package org.chromium.chrome.browser; +package org.chromium.chrome.browser.enhanced_bookmarks; import android.graphics.Bitmap; import android.util.LruCache; diff --git a/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksModel.java b/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksModel.java new file mode 100644 index 0000000..3ccea00 --- /dev/null +++ b/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksModel.java @@ -0,0 +1,391 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.chrome.browser.enhanced_bookmarks; + +import org.chromium.base.ObserverList; +import org.chromium.chrome.browser.BookmarksBridge; +import org.chromium.chrome.browser.BookmarksBridge.BookmarkItem; +import org.chromium.chrome.browser.BookmarksBridge.BookmarkModelObserver; +import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksBridge.FiltersObserver; +import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksBridge.SalientImageCallback; +import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksBridge.SearchServiceObserver; +import org.chromium.chrome.browser.profiles.Profile; +import org.chromium.components.bookmarks.BookmarkId; +import org.chromium.components.bookmarks.BookmarkMatch; +import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; +import org.chromium.content_public.browser.WebContents; + +import java.util.Collections; +import java.util.List; + +/** + * A class that encapsulates all the (enhanced) bookmark model related logic. Essentially, this is a + * collection of all the bookmark bridges with helper functions. It is recommended to create a new + * instance of this class, instead of passing it around. However, be sure to call + * {@link EnhancedBookmarksModel#destroy()} once you are done with it. + */ +public class EnhancedBookmarksModel { + + /** + * Observer that listens to delete event. This interface is used by undo controllers to know + * which bookmarks were deleted. Note this observer only listens to events that go through + * enhanced bookmark model. + */ + public interface EnhancedBookmarkDeleteObserver { + + /** + * Callback being triggered immediately before bookmarks are deleted. + * @param titles All titles of the bookmarks to be deleted. + */ + void onDeleteBookmarks(String[] titles); + } + + private final BookmarksBridge mBookmarksBridge; + private final EnhancedBookmarksBridge mEnhancedBookmarksBridge; + private ObserverList<EnhancedBookmarkDeleteObserver> mDeleteObservers = new ObserverList<>(); + + /** + * Initialize enhanced bookmark model for last used non-incognito profile with a java-side image + * cache that has the given size. + * @param salientImageCacheSize Maximum cache size in bytes. + */ + public EnhancedBookmarksModel(int salientImageCacheSize) { + Profile originalProfile = Profile.getLastUsedProfile().getOriginalProfile(); + mBookmarksBridge = new BookmarksBridge(originalProfile); + mEnhancedBookmarksBridge = new EnhancedBookmarksBridge(originalProfile, + salientImageCacheSize); + } + + /** + * Initialize enhanced bookmark model with no cache for salient images. This constructor uses + * the last non-incognito profile. + */ + public EnhancedBookmarksModel() { + this(0); + } + + /** + * Clean up all the bridges. This must be called after done using this class. + */ + public void destroy() { + mBookmarksBridge.destroy(); + mEnhancedBookmarksBridge.destroy(); + } + + /** + * @see BookmarksBridge#addObserver(BookmarkModelObserver) + */ + public void addModelObserver(BookmarkModelObserver observer) { + mBookmarksBridge.addObserver(observer); + } + + /** + * @see BookmarksBridge#removeObserver(BookmarkModelObserver) + */ + public void removeModelObserver(BookmarkModelObserver observer) { + mBookmarksBridge.removeObserver(observer); + } + + /** + * @see BookmarksBridge#isBookmarkModelLoaded() + */ + public boolean isBookmarkModelLoaded() { + return mBookmarksBridge.isBookmarkModelLoaded(); + } + + /** + * @see BookmarksBridge#getBookmarkById(BookmarkId) + */ + public BookmarkItem getBookmarkById(BookmarkId id) { + return mBookmarksBridge.getBookmarkById(id); + } + + /** + * Add an observer that listens to delete events that go through enhanced bookmark model. + * @param observer The observer to add. + */ + public void addDeleteObserver(EnhancedBookmarkDeleteObserver observer) { + mDeleteObservers.addObserver(observer); + } + + /** + * Remove the observer from listening to bookmark deleting events. + * @param observer The observer to remove. + */ + public void removeDeleteObserver(EnhancedBookmarkDeleteObserver observer) { + mDeleteObservers.removeObserver(observer); + } + + /** + * Delete one or multiple bookmarks from model. If more than one bookmarks are passed here, this + * method will group these delete operations into one undo bundle so that later if the user + * clicks undo, all bookmarks deleted here will be restored. + * @param bookmarks Bookmarks to delete. Note this array should not contain a folder and its + * children, because deleting folder will also remove all its children, and + * deleting children once more will cause errors. + */ + public void deleteBookmarks(BookmarkId... bookmarks) { + assert bookmarks != null && bookmarks.length > 0; + // Store all titles of bookmarks. + String[] titles = new String[bookmarks.length]; + for (int i = 0; i < bookmarks.length; i++) { + titles[i] = getBookmarkTitle(bookmarks[i]); + } + + if (bookmarks.length == 1) { + mBookmarksBridge.deleteBookmark(bookmarks[0]); + } else { + mBookmarksBridge.startGroupingUndos(); + for (BookmarkId bookmark : bookmarks) { + mBookmarksBridge.deleteBookmark(bookmark); + } + mBookmarksBridge.endGroupingUndos(); + } + + for (EnhancedBookmarkDeleteObserver observer : mDeleteObservers) { + observer.onDeleteBookmarks(titles); + } + } + + /** + * @see BookmarksBridge#getTopLevelFolderParentIDs() + */ + public List<BookmarkId> getTopLevelFolderParentIDs() { + return mBookmarksBridge.getTopLevelFolderParentIDs(); + } + + /** + * @see BookmarksBridge#getTopLevelFolderIDs(boolean, boolean) + */ + public List<BookmarkId> getTopLevelFolderIDs(boolean getSpecial, boolean getNormal) { + return mBookmarksBridge.getTopLevelFolderIDs(getSpecial, getNormal); + } + + /** + * @see BookmarksBridge#getUncategorizedBookmarkIDs() + */ + public List<BookmarkId> getUncategorizedBookmarkIDs() { + return Collections.emptyList(); + } + + /** + * @see BookmarksBridge#getAllFoldersWithDepths(List, List) + */ + public void getAllFoldersWithDepths(List<BookmarkId> bookmarkList, List<Integer> depthList) { + mBookmarksBridge.getAllFoldersWithDepths(bookmarkList, depthList); + } + + /** + * @see BookmarksBridge#getMoveDestinations(List, List, List) + */ + public void getMoveDestinations(List<BookmarkId> bookmarkList, List<Integer> depthList, + List<BookmarkId> bookmarksToMove) { + mBookmarksBridge.getMoveDestinations(bookmarkList, depthList, bookmarksToMove); + } + + /** + * @see BookmarksBridge#getOtherFolderId() + */ + public BookmarkId getOtherFolderId() { + return mBookmarksBridge.getOtherFolderId(); + } + + /** + * @see BookmarksBridge#getMobileFolderId() + */ + public BookmarkId getMobileFolderId() { + return mBookmarksBridge.getMobileFolderId(); + } + + /** + * @see BookmarksBridge#getDesktopFolderId() + */ + public BookmarkId getDesktopFolderId() { + return mBookmarksBridge.getDesktopFolderId(); + } + + /** + * @return The id of the default folder to add bookmarks/folders to. + */ + public BookmarkId getDefaultFolder() { + return mBookmarksBridge.getMobileFolderId(); + } + + /** + * @see BookmarksBridge#getChildIDs(BookmarkId, boolean, boolean) + */ + public List<BookmarkId> getChildIDs(BookmarkId id, boolean getFolders, boolean getBookmarks) { + return mBookmarksBridge.getChildIDs(id, getFolders, getBookmarks); + } + + public BookmarkId getChildAt(BookmarkId folderId, int index) { + return mBookmarksBridge.getChildAt(folderId, index); + } + + /** + * @see BookmarksBridge#getAllBookmarkIDsOrderedByCreationDate() + */ + public List<BookmarkId> getAllBookmarkIDsOrderedByCreationDate() { + return mBookmarksBridge.getAllBookmarkIDsOrderedByCreationDate(); + } + + /** + * @see BookmarksBridge#doesBookmarkExist(BookmarkId) + */ + public boolean doesBookmarkExist(BookmarkId id) { + return mBookmarksBridge.doesBookmarkExist(id); + } + + /** + * @see BookmarksBridge#setBookmarkTitle(BookmarkId, String) + */ + public void setBookmarkTitle(BookmarkId bookmark, String title) { + mBookmarksBridge.setBookmarkTitle(bookmark, title); + } + + /** + * @see BookmarksBridge#setBookmarkUrl(BookmarkId, String) + */ + public void setBookmarkUrl(BookmarkId bookmark, String url) { + mBookmarksBridge.setBookmarkUrl(bookmark, url); + } + + /** + * + * @see EnhancedBookmarksBridge#addFolder(BookmarkId, int, String) + */ + public BookmarkId addFolder(BookmarkId parent, int index, String title) { + return mEnhancedBookmarksBridge.addFolder(parent, index, title); + } + + /** + * @see EnhancedBookmarksBridge#addBookmark(BookmarkId, int, String, String) + */ + public BookmarkId addBookmark(BookmarkId parent, int index, String title, String url) { + url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); + return mEnhancedBookmarksBridge.addBookmark(parent, index, title, url); + } + + /** + * @see EnhancedBookmarksBridge#moveBookmark(BookmarkId, BookmarkId) + */ + public void moveBookmarks(List<BookmarkId> bookmarkIds, BookmarkId newParentId) { + for (int i = bookmarkIds.size() - 1; i >= 0; i--) { + mEnhancedBookmarksBridge.moveBookmark(bookmarkIds.get(i), newParentId); + } + } + + /** + * @see BookmarkItem#getTitle() + */ + public String getBookmarkTitle(BookmarkId bookmarkId) { + return mBookmarksBridge.getBookmarkById(bookmarkId).getTitle(); + } + + /** + * @see EnhancedBookmarksBridge#getBookmarkDescription(BookmarkId) + */ + public String getBookmarkDescription(BookmarkId id) { + return mEnhancedBookmarksBridge.getBookmarkDescription(id); + } + + /** + * @see EnhancedBookmarksBridge#setBookmarkDescription(BookmarkId, String) + */ + public void setBookmarkDescription(BookmarkId id, String description) { + mEnhancedBookmarksBridge.setBookmarkDescription(id, description); + } + + /** + * @see EnhancedBookmarksBridge#salientImageForUrl(String, SalientImageCallback) + */ + public boolean salientImageForUrl(String url, SalientImageCallback callback) { + return mEnhancedBookmarksBridge.salientImageForUrl(url, callback); + } + + /** + * @see EnhancedBookmarksBridge#fetchImageForTab(WebContents) + */ + public void fetchImageForTab(WebContents webContents) { + mEnhancedBookmarksBridge.fetchImageForTab(webContents); + } + + /** + * @see BookmarksBridge#undo() + */ + public void undo() { + mBookmarksBridge.undo(); + } + + /** + * @see EnhancedBookmarksBridge#getFiltersForBookmark(BookmarkId) + */ + public String[] getFiltersForBookmark(BookmarkId bookmark) { + return mEnhancedBookmarksBridge.getFiltersForBookmark(bookmark); + } + + /** + * @see EnhancedBookmarksBridge#getFilters() + */ + public List<String> getFilters() { + return mEnhancedBookmarksBridge.getFilters(); + } + + /** + * @see EnhancedBookmarksBridge#getBookmarksForFilter(String) + */ + public List<BookmarkId> getBookmarksForFilter(String filter) { + return mEnhancedBookmarksBridge.getBookmarksForFilter(filter); + } + + /** + * @see EnhancedBookmarksBridge#addFiltersObserver(FiltersObserver) + */ + public void addFiltersObserver(FiltersObserver observer) { + mEnhancedBookmarksBridge.addFiltersObserver(observer); + } + + /** + * @see EnhancedBookmarksBridge#removeFiltersObserver(FiltersObserver) + */ + public void removeFiltersObserver(FiltersObserver observer) { + mEnhancedBookmarksBridge.removeFiltersObserver(observer); + } + + /** + * @see EnhancedBookmarksBridge#sendSearchRequest(String) + */ + public void sendSearchRequest(String query) { + mEnhancedBookmarksBridge.sendSearchRequest(query); + } + + /** + * @see EnhancedBookmarksBridge#sendSearchRequest(String) + */ + public List<BookmarkId> getSearchResultsForQuery(String query) { + return mEnhancedBookmarksBridge.getSearchResultsForQuery(query); + } + + /** + * @see BookmarksBridge#searchBookmarks(String, int) + */ + public List<BookmarkMatch> getLocalSearchForQuery(String query, int maxNumberOfQuery) { + return mBookmarksBridge.searchBookmarks(query, maxNumberOfQuery); + } + + /** + * @see EnhancedBookmarksBridge#addSearchObserver(SearchServiceObserver) + */ + public void addSearchObserver(SearchServiceObserver observer) { + mEnhancedBookmarksBridge.addSearchObserver(observer); + } + + /** + * @see EnhancedBookmarksBridge#removeSearchObserver(SearchServiceObserver) + */ + public void removeSearchObserver(SearchServiceObserver observer) { + mEnhancedBookmarksBridge.removeSearchObserver(observer); + } +} diff --git a/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/OWNERS b/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/OWNERS new file mode 100644 index 0000000..6f497bd --- /dev/null +++ b/chrome/android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/OWNERS @@ -0,0 +1 @@ +kkimlabs@chromium.org
\ No newline at end of file diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 83a49a8..e46c54a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1582,7 +1582,7 @@ 'android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerServiceFactory.java', 'android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerTabUtils.java', 'android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java', - 'android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java', + 'android/java/src/org/chromium/chrome/browser/enhanced_bookmarks/EnhancedBookmarksBridge.java', 'android/java/src/org/chromium/chrome/browser/favicon/FaviconHelper.java', 'android/java/src/org/chromium/chrome/browser/findinpage/FindInPageBridge.java', 'android/java/src/org/chromium/chrome/browser/ForeignSessionHelper.java', diff --git a/components/enhanced_bookmarks/BUILD.gn b/components/enhanced_bookmarks/BUILD.gn index 11462c4..924b570 100644 --- a/components/enhanced_bookmarks/BUILD.gn +++ b/components/enhanced_bookmarks/BUILD.gn @@ -61,7 +61,7 @@ if (is_android) { "enhanced_bookmark_utils.h", ] outputs = [ - "org/chromium/chrome/browser/enhancedbookmark/LaunchLocation.java", + "org/chromium/chrome/browser/enhanced_bookmarks/LaunchLocation.java", ] } } diff --git a/components/enhanced_bookmarks/enhanced_bookmark_utils.h b/components/enhanced_bookmarks/enhanced_bookmark_utils.h index f2ce4dc..97a9b27 100644 --- a/components/enhanced_bookmarks/enhanced_bookmark_utils.h +++ b/components/enhanced_bookmarks/enhanced_bookmark_utils.h @@ -22,7 +22,7 @@ static const char kLaunchLocationUMA[] = "Stars.LaunchLocation"; // Please sync with the corresponding histograms.xml. // // A Java counterpart will be generated for this enum. -// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.enhancedbookmark +// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.enhanced_bookmarks enum LaunchLocation { ALL_ITEMS = 0, UNCATEGORIZED = 1, // Deprecated. |