| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.ntp; | |
| 6 | |
| 7 import org.chromium.base.annotations.CalledByNative; | |
| 8 import org.chromium.chrome.browser.profiles.Profile; | |
| 9 | |
| 10 /** | |
| 11 * Retrieve the user's interests. | |
| 12 */ | |
| 13 public class InterestsService { | |
| 14 private long mNativeInterestsService; | |
| 15 | |
| 16 /** | |
| 17 * A user's interest. | |
| 18 */ | |
| 19 public static class Interest { | |
| 20 private final String mName; | |
| 21 private final String mImageUrl; | |
| 22 private final double mRelevance; | |
| 23 | |
| 24 public Interest(String name, String imageUrl, double relevance) { | |
| 25 mName = name; | |
| 26 mImageUrl = imageUrl; | |
| 27 mRelevance = relevance; | |
| 28 } | |
| 29 | |
| 30 public String getName() { | |
| 31 return mName; | |
| 32 } | |
| 33 | |
| 34 public String getImageUrl() { | |
| 35 return mImageUrl; | |
| 36 } | |
| 37 | |
| 38 public double getRelevance() { | |
| 39 return mRelevance; | |
| 40 } | |
| 41 } | |
| 42 /** | |
| 43 * Interface for receiving the interests of a user. | |
| 44 */ | |
| 45 public interface GetInterestsCallback { | |
| 46 /** | |
| 47 * Callback method for fetching the interests of a user. | |
| 48 * | |
| 49 * @param interests The array of interests. Null if error. | |
| 50 */ | |
| 51 @CalledByNative("GetInterestsCallback") | |
| 52 public void onInterestsAvailableCallback(Interest[] interests); | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * InterestsService constructor requires a valid user profile object. | |
| 57 * | |
| 58 * @param profile The profile for which to fetch the interests | |
| 59 */ | |
| 60 public InterestsService(Profile profile) { | |
| 61 mNativeInterestsService = nativeInit(profile); | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * Cleans up the C++ side of this class. This instance must not be used afte
r calling destroy(). | |
| 66 */ | |
| 67 public void destroy() { | |
| 68 assert mNativeInterestsService != 0; | |
| 69 nativeDestroy(mNativeInterestsService); | |
| 70 mNativeInterestsService = 0; | |
| 71 } | |
| 72 | |
| 73 public void getInterests(final GetInterestsCallback callback) { | |
| 74 GetInterestsCallback wrappedCallback = new GetInterestsCallback() { | |
| 75 @Override | |
| 76 public void onInterestsAvailableCallback(Interest[] interests) { | |
| 77 callback.onInterestsAvailableCallback(interests); | |
| 78 } | |
| 79 }; | |
| 80 | |
| 81 nativeGetInterests(mNativeInterestsService, wrappedCallback); | |
| 82 } | |
| 83 | |
| 84 /* | |
| 85 * Helper methods for the native part. | |
| 86 */ | |
| 87 @CalledByNative | |
| 88 private static Interest createInterest(String name, String imageUrl, double
relevance) { | |
| 89 return new Interest(name, imageUrl, relevance); | |
| 90 } | |
| 91 | |
| 92 @CalledByNative | |
| 93 private static Interest[] createInterestsArray(int size) { | |
| 94 return new Interest[size]; | |
| 95 } | |
| 96 | |
| 97 private native long nativeInit(Profile profile); | |
| 98 private native void nativeDestroy(long nativeInterestsService); | |
| 99 private native void nativeGetInterests( | |
| 100 long nativeInterestsService, GetInterestsCallback callback); | |
| 101 } | |
| OLD | NEW |