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

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: LocalRef to GlobalRef 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..316aa147e7f95db1617439e2ab57cfa3a1a66bca
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/engagement/SiteEngagementService.java
@@ -0,0 +1,72 @@
+// 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) {
+ assert ThreadUtils.runningOnUiThread();
+ return nativeSiteEngagementServiceForProfile(profile);
+ }
+
+ /**
+ * Returns the engagement score for the provided URL.
+ * Must be called on the UI thread.
+ */
+ public double getScore(String url) {
+ assert ThreadUtils.runningOnUiThread();
+ if (mNativePointer == 0) return 0.0;
+ 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) {
benwells 2016/12/09 04:31:32 Nit: can you put ..ForTest on this, and on the cor
dominickn 2016/12/09 04:44:17 No, this native method is used by the chrome://sit
benwells 2016/12/09 04:57:36 Acknowledged.
+ assert ThreadUtils.runningOnUiThread();
+ if (mNativePointer == 0) return;
+ nativeResetScoreForURL(mNativePointer, url, score);
+ }
+
+ @CalledByNative
+ private static SiteEngagementService create(long nativePointer) {
+ return new SiteEngagementService(nativePointer);
+ }
+
+ /** This object may only be created via the static getForProfile method. */
benwells 2016/12/09 04:31:32 Is this used? getForProfile doesn't call this.
dominickn 2016/12/09 04:44:17 This method is called by create(), which is called
benwells 2016/12/09 04:57:36 Acknowledged.
+ private SiteEngagementService(long nativePointer) {
+ mNativePointer = nativePointer;
+ }
+
+ @CalledByNative
+ private void onNativeDestroyed() {
+ mNativePointer = 0;
+ }
+
+ private static native SiteEngagementService nativeSiteEngagementServiceForProfile(
+ Profile profile);
+ private native double nativeGetScore(long nativeSiteEngagementServiceAndroid, String url);
+ private native void nativeResetScoreForURL(
+ long nativeSiteEngagementServiceAndroid, String url, double score);
+}
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | chrome/browser/engagement/site_engagement_service_android.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698