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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/engagement/SiteEngagementService.java

Issue 2553013002: Expose the Site Engagement Service to Java. (Closed)
Patch Set: Clean up. Fix desktop compile Created 4 years 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/engagement/SiteEngagementService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/engagement/SiteEngagementService.java b/chrome/android/java/src/org/chromium/chrome/browser/engagement/SiteEngagementService.java
new file mode 100644
index 0000000000000000000000000000000000000000..63486583c553bb5ef9c6e41c3f80758dee724c44
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/engagement/SiteEngagementService.java
@@ -0,0 +1,65 @@
+// 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.engagement;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.annotations.CalledByNative;
+
+import org.chromium.chrome.browser.profiles.Profile;
+
+/**
+ * Provides access to the Site Engagement Service for a profile.
+ *
+ * Site engagement measures the level of engagement that a user has with an origin. This class
+ * allows Java to retrieve and modify engagement scores for URLs.
+ */
+public class SiteEngagementService {
+
+ /** Pointer to the native side SiteEngagementServiceAndroid shim. */
+ private long mNativePointer;
+
+ /**
+ * Returns a SiteEngagementService for the provided profile.
+ * Must be called on the UI thread.
+ */
+ public static SiteEngagementService getForProfile(Profile profile) {
gone 2016/12/07 21:50:25 Does this always create a new SiteEngagementServic
dominickn 2016/12/08 01:03:53 Hmm, there's an issue here with multiple ones on t
+ assert ThreadUtils.runningOnUiThread();
+ return new SiteEngagementService(profile);
+ }
+
+ /**
+ * Returns the engagement score for the provided URL.
+ * Must be called on the UI thread.
+ */
+ public double getScore(String url) {
+ assert mNativePointer != 0;
gone 2016/12/07 21:50:25 Not sure how useful this assert is; if the pointer
dominickn 2016/12/08 01:03:53 Done.
+ assert ThreadUtils.runningOnUiThread();
+ return nativeGetScore(mNativePointer, url);
+ }
+
+ /**
+ * Sets the provided URL to have the provided engagement score.
+ * Must be called on the UI thread.
+ */
+ public void resetScoreForUrl(String url, double score) {
+ assert mNativePointer != 0;
gone 2016/12/07 21:50:25 Ditto.
dominickn 2016/12/08 01:03:54 Done.
+ assert ThreadUtils.runningOnUiThread();
+ nativeResetScoreForURL(mNativePointer, url, score);
+ }
+
+ private SiteEngagementService(Profile profile) {
+ mNativePointer = nativeGetForProfile(profile);
+ }
+
+ @CalledByNative
+ private void onNativeDestroyed() {
+ mNativePointer = 0;
+ }
+
+ private native long nativeGetForProfile(Profile profile);
+ private native double nativeGetScore(long nativeSiteEngagementServiceAndroid, String url);
+ private native void nativeResetScoreForURL(
+ long nativeSiteEngagementServiceAndroid, String url, double score);
+}

Powered by Google App Engine
This is Rietveld 408576698