Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java |
| index 20b930a6a5da660478b1ee618c7efe7bdb5e3c68..2336f3a67ed3e3efb92c891b60a396a6bd618036 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/EnhancedBookmarksBridge.java |
| @@ -20,8 +20,10 @@ import java.util.List; |
| @JNINamespace("enhanced_bookmarks::android") |
| public final class EnhancedBookmarksBridge { |
| private long mNativeEnhancedBookmarksBridge; |
| - private final ObserverList<FiltersObserver> mObservers = |
| + private final ObserverList<FiltersObserver> mFilterObservers = |
| new ObserverList<FiltersObserver>(); |
| + private final ObserverList<SearchServiceObserver> mSearchObservers = |
| + new ObserverList<SearchServiceObserver>(); |
| /** |
| * Interface to provide consumers notifications to changes in clusters |
| @@ -34,6 +36,16 @@ public final class EnhancedBookmarksBridge { |
| void onFiltersChanged(); |
| } |
| + /** |
| + * Interface to provide consumers notifications to changes in search service results. |
| + */ |
| + public interface SearchServiceObserver { |
| + /** |
| + * Invoked when client detects that search results have been updated. |
|
Ted C
2014/10/23 00:31:42
I think it is worth noting that this might not cor
Ian Wen
2014/10/29 00:11:39
This will always be triggered for the most recent
|
| + */ |
| + void onSearchResultReturned(); |
| + } |
| + |
| public EnhancedBookmarksBridge(Profile profile) { |
| mNativeEnhancedBookmarksBridge = nativeInit(profile); |
| } |
| @@ -59,7 +71,7 @@ public final class EnhancedBookmarksBridge { |
| * @param observer Observer to add |
| */ |
| public void addFiltersObserver(FiltersObserver observer) { |
| - mObservers.addObserver(observer); |
| + mFilterObservers.addObserver(observer); |
| } |
| /** |
| @@ -67,7 +79,7 @@ public final class EnhancedBookmarksBridge { |
| * @param observer Observer to remove |
| */ |
| public void removeFiltersObserver(FiltersObserver observer) { |
| - mObservers.removeObserver(observer); |
| + mFilterObservers.removeObserver(observer); |
| } |
| /** |
| @@ -82,6 +94,43 @@ public final class EnhancedBookmarksBridge { |
| } |
| /** |
| + * Send request to search server for querying related bookmarks. |
| + * @param query Keyword used to find related bookmarks. |
| + */ |
| + public void sendSearchRequest(String query) { |
| + nativeSendSearchRequest(mNativeEnhancedBookmarksBridge, query); |
| + } |
| + |
| + /** |
| + * Get list of bookmarks as result of a search request that was sent before in |
| + * {@link EnhancedBookmarksBridge#sendSearchRequest(String)}. Normally this function should be |
| + * called after {@link SearchServiceObserver#onSearchResultReturned()} |
|
Kibeom Kim (inactive)
2014/10/22 18:42:01
Let's add a cautious comment that the search resul
Ian Wen
2014/10/29 00:11:39
This will only happen in a race condition when syn
|
| + * @param query Keyword used to find related bookmarks. |
| + * @return List of BookmarkIds that are related to query. |
| + */ |
| + public List<BookmarkId> getSearchResultsForQuery(String query) { |
| + List<BookmarkId> list = new ArrayList<BookmarkId>(); |
| + nativeGetSearchResults(mNativeEnhancedBookmarksBridge, list, query); |
| + return list; |
| + } |
| + |
| + /** |
| + * Registers a FiltersObserver to listen for filter change notifications. |
|
Ted C
2014/10/23 00:31:42
copy/paste incorrectness
Ian Wen
2014/10/29 00:11:39
Done.
|
| + * @param observer Observer to add |
| + */ |
| + public void addSearchObserver(SearchServiceObserver observer) { |
| + mSearchObservers.addObserver(observer); |
| + } |
| + |
| + /** |
| + * Unregisters a FiltersObserver from listening to filter change notifications. |
| + * @param observer Observer to remove |
| + */ |
| + public void removeSearchObserver(SearchServiceObserver observer) { |
| + mSearchObservers.removeObserver(observer); |
| + } |
| + |
| + /** |
| * @return Current set of known auto-filters for bookmarks. |
| */ |
| public List<String> getFilters() { |
| @@ -92,12 +141,19 @@ public final class EnhancedBookmarksBridge { |
| @CalledByNative |
| private void onFiltersChanged() { |
| - for (FiltersObserver observer : mObservers) { |
| + for (FiltersObserver observer : mFilterObservers) { |
| observer.onFiltersChanged(); |
| } |
| } |
| @CalledByNative |
| + private void onSearchResultReturned() { |
| + for (SearchServiceObserver observer : mSearchObservers) { |
| + observer.onSearchResultReturned(); |
| + } |
| + } |
| + |
| + @CalledByNative |
| private static void addToBookmarkIdList(List<BookmarkId> bookmarkIdList, long id, int type) { |
| bookmarkIdList.add(new BookmarkId(id, type)); |
| } |
| @@ -111,4 +167,7 @@ public final class EnhancedBookmarksBridge { |
| private native void nativeGetBookmarksForFilter(long nativeEnhancedBookmarksBridge, |
| String filter, List<BookmarkId> list); |
| private native String[] nativeGetFilters(long nativeEnhancedBookmarksBridge); |
| + private native void nativeGetSearchResults(long nativeEnhancedBookmarksBridge, |
| + List<BookmarkId> list, String query); |
| + private native void nativeSendSearchRequest(long nativeEnhancedBookmarksBridge, String query); |
| } |