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