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

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

Issue 2879103003: android: move ResourcePrefetchPredictor usage to LoadingPredictor. (Closed)
Patch Set: Created 3 years, 7 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/LoadingPredictor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/LoadingPredictor.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/LoadingPredictor.java
new file mode 100644
index 0000000000000000000000000000000000000000..24406dfb35636c6cf3c03b868909592d314a1042
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/LoadingPredictor.java
@@ -0,0 +1,66 @@
+// Copyright 2017 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;
+
+/**
+ * Interface to the loading predictor.
+ *
+ * Allows chrome to hint at a likely future navigation.
+ */
+@JNINamespace("predictors")
+class LoadingPredictor {
+ private static boolean sInitializationStarted;
+
+ private final Profile mProfile;
+
+ /**
+ * @param profile The profile used to get the loading predictor.
+ */
+ public LoadingPredictor(Profile profile) {
+ mProfile = profile;
+ }
+
+ /**
+ * Starts the asynchronous initialization of the loading predictor.
+ */
+ public boolean startInitialization() {
+ ThreadUtils.assertOnUiThread();
+ sInitializationStarted = true;
+ return nativeStartInitialization(mProfile);
+ }
+
+ /**
+ * Hints at a future navigation to a URL.
+ *
+ * @param url The URL to start the prefetch for.
alexilin 2017/05/15 13:05:50 nit: Update url parameter description?
Benoit L 2017/05/15 13:33:23 Done.
+ * @return false in case the LoadingPredictor is not usable.
+ */
+ public boolean prepareForPageLoad(String url) {
+ ThreadUtils.assertOnUiThread();
+ if (!sInitializationStarted) {
+ throw new RuntimeException("startInitialization() not called.");
+ }
+ return nativePrepareForPageLoad(mProfile, url);
+ }
+
+ /**
+ * Indicates that a page load hint is no longer active.
+ *
+ * @param url The hinted URL.
+ * @return false in case the LoadingPredictor is not usable.
+ */
+ public boolean cancelPageLoadHint(String url) {
+ ThreadUtils.assertOnUiThread();
+ return nativeCancelPageLoadHint(mProfile, url);
+ }
+
+ private static native boolean nativeStartInitialization(Profile profile);
+ private static native boolean nativePrepareForPageLoad(Profile profile, String url);
+ private static native boolean nativeCancelPageLoadHint(Profile profile, String url);
+}

Powered by Google App Engine
This is Rietveld 408576698