Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4413)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/ResourcePrefetchPredictor.java

Issue 2377643002: predictors: Make the resource_prefetch_predictor accessible from Java. (Closed)
Patch Set: Address comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/ResourcePrefetchPredictor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ResourcePrefetchPredictor.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ResourcePrefetchPredictor.java
new file mode 100644
index 0000000000000000000000000000000000000000..9673f4933c0a8a61dbce008c56e46e7fc6d707e8
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ResourcePrefetchPredictor.java
@@ -0,0 +1,71 @@
+// Copyright 2016 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.customtabs;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.chrome.browser.profiles.Profile;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Interface to the resource prefetch predictor.
+ *
+ * This allows to initiate and abort prefetches of likely subresources, based on
+ * the local browsing history.
+ */
+@JNINamespace("predictors")
+class ResourcePrefetchPredictor {
+ private ResourcePrefetchPredictor(long nativePointer) {
+ mNativePtr = nativePointer;
+ }
+
+ private static Map<Profile, ResourcePrefetchPredictor> sServiceMap;
+
+ /**
+ * @return a ResourcePrefetchPredictor for a given profile.
+ *
+ * If the predictor is not enabled, the object returned will not actually trigger any prefetch.
+ */
+ public static ResourcePrefetchPredictor getForProfile(Profile profile) {
+ ThreadUtils.assertOnUiThread();
+ if (sServiceMap == null) sServiceMap = new HashMap<Profile, ResourcePrefetchPredictor>();
gone 2016/09/28 18:18:15 new HashMap<>():
Benoit L 2016/10/03 09:42:05 Done.
+
+ ResourcePrefetchPredictor result = sServiceMap.get(profile);
+ if (result == null) {
+ long nativePtr = nativeGetResourcePrefetchPredictorForProfile(profile);
+ result = new ResourcePrefetchPredictor(nativePtr);
+ sServiceMap.put(profile, result);
+ }
+ return result;
+ }
+
+ /**
+ * Starts a prefetch for a URL.
+ *
+ * @param url The URL to start the prefetch for.
+ */
+ public void startPrefetching(String url) {
+ nativeStartPrefetching(mNativePtr, url);
+ }
+
+ /**
+ * Stops a prefetch for a URL, if one is in progress.
+ *
+ * @param url The URL to stop the prefetch of.
+ */
+ public void stopPrefetching(String url) {
+ nativeStopPrefetching(mNativePtr, url);
+ }
+
+ private long mNativePtr;
+
+ private static native long nativeGetResourcePrefetchPredictorForProfile(Profile profile);
+ private native void nativeStartPrefetching(
+ long nativeResourcePrefetchPredictorAndroid, String url);
+ private native void nativeStopPrefetching(
+ long nativeResourcePrefetchPredictorAndroid, String url);
+}
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | chrome/browser/predictors/resource_prefetch_predictor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698