Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsService.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsService.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsService.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e6a26589f79d5defcb022e7021565524e5cd016a |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsService.java |
@@ -0,0 +1,117 @@ |
+// Copyright 2015 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.ntp; |
+ |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.chrome.browser.profiles.Profile; |
+ |
+/** |
+ * Retrieve the user's interests. |
+ */ |
+public class InterestsService { |
+ |
+ private long mNativeInterestsService; |
+ |
+ /** |
+ * POJO representing an interest. |
Marc Treib
2015/09/11 14:54:25
POJO?
tache
2015/09/11 15:45:09
Done.
|
+ */ |
+ public static class Interest { |
+ private String mName; |
+ private String mImageUrl; |
+ private double mRelevance; |
+ |
+ public Interest(String mName, String mImageUrl, double mRelevance) { |
Marc Treib
2015/09/11 14:54:25
Params shouldn't have the leading "m".
tache
2015/09/11 15:45:09
Done.
|
+ super(); |
Marc Treib
2015/09/11 14:54:25
Unnecessary
tache
2015/09/11 15:45:09
Done.
|
+ this.mName = mName; |
+ this.mImageUrl = mImageUrl; |
+ this.mRelevance = mRelevance; |
+ } |
+ |
+ public String getName() { |
+ return mName; |
+ } |
+ |
+ public void setName(String mName) { |
Marc Treib
2015/09/11 14:54:25
Are the setters needed?
tache
2015/09/11 15:45:09
Done.
|
+ this.mName = mName; |
+ } |
+ |
+ public String getImageUrl() { |
+ return mImageUrl; |
+ } |
+ |
+ public void setImageUrl(String mImageUrl) { |
+ this.mImageUrl = mImageUrl; |
+ } |
+ |
+ public double getRelevance() { |
+ return this.mRelevance; |
+ } |
+ |
+ public void setRelevance(double relevance) { |
+ this.mRelevance = relevance; |
+ } |
+ } |
+ /** |
+ * Interface for receiving the interests of a user. |
+ */ |
+ public interface GetInterestsCallback { |
+ /** |
+ * Callback method for fetching the interests of a user. |
+ * In case of an error an empty array will be returned. |
+ * |
+ * @param interests The array of interests. |
+ */ |
+ @CalledByNative("GetInterestsCallback") |
+ public void onInterestsCallback(Interest[] interests); |
Marc Treib
2015/09/11 14:54:25
onInterests what?
Maybe "onInterestsAvailable"?
tache
2015/09/11 15:45:09
Done.
|
+ } |
+ |
+ /** |
+ * InterestsService constructor requires a valid user profile object. |
+ * |
+ * @param profile The profile for which to fetch the interests |
+ */ |
+ public InterestsService(Profile profile) { |
+ mNativeInterestsService = nativeInit(profile); |
+ } |
+ |
+ /** |
+ * Cleans up the C++ side of this class. This instance must not be used after calling destroy(). |
+ */ |
+ public void destroy() { |
+ assert mNativeInterestsService != 0; |
+ nativeDestroy(mNativeInterestsService); |
+ mNativeInterestsService = 0; |
+ } |
+ |
+ |
+ public void getInterests(String accessToken, final GetInterestsCallback callback) { |
+ GetInterestsCallback wrappedCallback = new GetInterestsCallback() { |
+ @Override |
+ public void onInterestsCallback(Interest[] interests) { |
+ // Don't notify callback if we've already been destroyed. |
+ if (mNativeInterestsService != 0) { |
+ callback.onInterestsCallback(interests); |
+ } |
+ } |
+ }; |
+ |
+ nativeGetInterests(mNativeInterestsService, accessToken, wrappedCallback); |
+ } |
+ |
+ /* |
+ * Helper method for the native part. |
+ */ |
+ @CalledByNative |
+ public static Interest createInterest(String name, String imageUrl, double relevance) { |
+ return new Interest(name, imageUrl, relevance); |
+ } |
+ |
+ |
+ private native long nativeInit(Profile profile); |
+ private native void nativeDestroy(long nativeInterestsService); |
+ private native void nativeGetInterests(long nativeInterestsService, String token, |
+ GetInterestsCallback callback); |
+ |
+} |