OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.history; |
| 6 |
| 7 import org.chromium.base.Callback; |
| 8 import org.chromium.base.annotations.CalledByNative; |
| 9 import org.chromium.chrome.browser.profiles.Profile; |
| 10 |
| 11 import java.util.ArrayList; |
| 12 import java.util.List; |
| 13 |
| 14 /** The JNI bridge for Android to fetch and manipulate browsing history. */ |
| 15 public class BrowsingHistoryBridge { |
| 16 |
| 17 private long mNativeHistoryBridge; |
| 18 private Callback<List<HistoryItem>> mCallback; |
| 19 |
| 20 public BrowsingHistoryBridge() { |
| 21 mNativeHistoryBridge = nativeInit(Profile.getLastUsedProfile()); |
| 22 } |
| 23 |
| 24 public void destroy() { |
| 25 if (mNativeHistoryBridge != 0) { |
| 26 nativeDestroy(mNativeHistoryBridge); |
| 27 mNativeHistoryBridge = 0; |
| 28 } |
| 29 } |
| 30 |
| 31 /** |
| 32 * Query browsing history. Only one query may be in-flight at any time. See |
| 33 * BrowsingHistoryService::QueryHistory. |
| 34 * @param callback The callback that will receive query results. |
| 35 * @param query The query search text. May be empty. |
| 36 * @param endQueryTime The end of the time range to search. A value of 0 ind
icates that there |
| 37 * is no limit on the end time. See the native QueryOpti
ons. |
| 38 */ |
| 39 public void queryHistory(Callback<List<HistoryItem>> callback, String query, |
| 40 long endQueryTime) { |
| 41 mCallback = callback; |
| 42 nativeQueryHistory(mNativeHistoryBridge, new ArrayList<HistoryItem>(), q
uery, endQueryTime); |
| 43 } |
| 44 |
| 45 @CalledByNative |
| 46 public static void createHistoryItemAndAddToList( |
| 47 List<HistoryItem> items, String url, String domain, String title, lo
ng timestamp) { |
| 48 items.add(new HistoryItem(url, domain, title, timestamp)); |
| 49 } |
| 50 |
| 51 @CalledByNative |
| 52 public void onQueryHistoryComplete(List<HistoryItem> items) { |
| 53 mCallback.onResult(items); |
| 54 } |
| 55 |
| 56 private native long nativeInit(Profile profile); |
| 57 private native void nativeDestroy(long nativeBrowsingHistoryBridge); |
| 58 private native void nativeQueryHistory(long nativeBrowsingHistoryBridge, |
| 59 List<HistoryItem> historyItems, String query, long queryEndTime); |
| 60 } |
OLD | NEW |