Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/history/BrowsingHistoryBridge.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/history/BrowsingHistoryBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/history/BrowsingHistoryBridge.java |
| index f0d1b4ef29d4ebe3eb2048eb128f5b0f6d12162e..c75675ded052f5b6330172397d601ab917f0baf1 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/history/BrowsingHistoryBridge.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/history/BrowsingHistoryBridge.java |
| @@ -4,7 +4,6 @@ |
| package org.chromium.chrome.browser.history; |
| -import org.chromium.base.Callback; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.chrome.browser.profiles.Profile; |
| @@ -14,11 +13,33 @@ import java.util.List; |
| /** The JNI bridge for Android to fetch and manipulate browsing history. */ |
| public class BrowsingHistoryBridge { |
| + /** |
| + * Observer to be notified of browsing history events. |
| + */ |
| + public interface BrowsingHistoryObserver { |
| + /** |
| + * Called after BrowsingHistoryBridge#queryHistory() is complete. |
|
gone
2016/12/08 21:21:56
{@link Browsingetcetc#whatever()}
Theresa
2016/12/08 21:51:15
Done.
|
| + * @param items The items that matched the #queryHistory() parameters. |
| + */ |
| + public void onQueryHistoryComplete(List<HistoryItem> items); |
| + |
| + /** |
| + * Called when history has been deleted through something other than a call to |
| + * BrowsingHistoryBridge#removeItems(). For example, if two instances of the history page |
| + * are open and the user removes items in one instance, the other instance will be notified |
| + * via this method. |
| + */ |
| + public void onHistoryDeleted(); |
| + } |
| + |
| private long mNativeHistoryBridge; |
| - private Callback<List<HistoryItem>> mCallback; |
| + private final BrowsingHistoryObserver mObserver; |
|
gone
2016/12/08 21:21:56
private final above regular private
Theresa
2016/12/08 21:51:15
Done.
|
| + private boolean mRemovingItems; |
| + private boolean mHasPendingRemoveRequest; |
| - public BrowsingHistoryBridge() { |
| + public BrowsingHistoryBridge(BrowsingHistoryObserver observer) { |
| mNativeHistoryBridge = nativeInit(Profile.getLastUsedProfile()); |
| + mObserver = observer; |
| } |
| public void destroy() { |
| @@ -31,30 +52,72 @@ public class BrowsingHistoryBridge { |
| /** |
| * Query browsing history. Only one query may be in-flight at any time. See |
| * BrowsingHistoryService::QueryHistory. |
| - * @param callback The callback that will receive query results. |
| * @param query The query search text. May be empty. |
| * @param endQueryTime The end of the time range to search. A value of 0 indicates that there |
| * is no limit on the end time. See the native QueryOptions. |
| */ |
| - public void queryHistory(Callback<List<HistoryItem>> callback, String query, |
| - long endQueryTime) { |
| - mCallback = callback; |
| + public void queryHistory(String query, long endQueryTime) { |
| nativeQueryHistory(mNativeHistoryBridge, new ArrayList<HistoryItem>(), query, endQueryTime); |
| } |
| + /** |
| + * Adds the HistoryItem to the list of items being removed. The removal will not be committed |
| + * until #removeItems() is called. |
|
gone
2016/12/08 21:21:56
{@link}
Theresa
2016/12/08 21:51:15
Done.
|
| + * @param item The item to mark for removal. |
| + */ |
| + public void markItemForRemoval(HistoryItem item) { |
|
gone
2016/12/08 21:21:56
Should this check for the pointer still being vali
Theresa
2016/12/08 21:51:15
I don't think it needs to -- the pointer only gets
|
| + nativeMarkItemForRemoval(mNativeHistoryBridge, item.getUrl(), item.getTimestamps()); |
| + } |
| + |
| + /** |
| + * Removes all items that have been marked for removal through #markItemForRemoval(). |
| + */ |
| + public void removeItems() { |
| + // Only one remove request may be in-flight at any given time. If items are currently being |
| + // removed, queue the new request and return early. |
| + if (mRemovingItems) { |
| + mHasPendingRemoveRequest = true; |
| + return; |
| + } |
| + mRemovingItems = true; |
| + mHasPendingRemoveRequest = false; |
| + nativeRemoveItems(mNativeHistoryBridge); |
| + } |
| + |
| @CalledByNative |
| public static void createHistoryItemAndAddToList( |
| - List<HistoryItem> items, String url, String domain, String title, long timestamp) { |
| - items.add(new HistoryItem(url, domain, title, timestamp)); |
| + List<HistoryItem> items, String url, String domain, String title, long[] timestamps) { |
| + items.add(new HistoryItem(url, domain, title, timestamps)); |
| } |
| @CalledByNative |
| public void onQueryHistoryComplete(List<HistoryItem> items) { |
| - mCallback.onResult(items); |
| + mObserver.onQueryHistoryComplete(items); |
| + } |
| + |
| + @CalledByNative |
| + public void onRemoveComplete() { |
| + mRemovingItems = false; |
| + if (mHasPendingRemoveRequest) removeItems(); |
| + } |
| + |
| + @CalledByNative |
| + public void onRemoveFailed() { |
| + mRemovingItems = false; |
| + if (mHasPendingRemoveRequest) removeItems(); |
| + // TODO(twellington): handle remove failures. |
| + } |
| + |
| + @CalledByNative |
| + public void onHistoryDeleted() { |
| + mObserver.onHistoryDeleted(); |
| } |
| private native long nativeInit(Profile profile); |
| private native void nativeDestroy(long nativeBrowsingHistoryBridge); |
| private native void nativeQueryHistory(long nativeBrowsingHistoryBridge, |
| List<HistoryItem> historyItems, String query, long queryEndTime); |
| + private native void nativeMarkItemForRemoval(long nativeBrowsingHistoryBridge, |
| + String url, long[] timestamps); |
| + private native void nativeRemoveItems(long nativeBrowsingHistoryBridge); |
| } |