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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsService.java

Issue 1334233003: Add the JNI code in order to let Java use the InterestsFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ntp-interests-retriever
Patch Set: Created 5 years, 3 months 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 unified diff | Download patch
OLDNEW
(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
15 private long mNativeInterestsService;
16
17 /**
18 * POJO representing an interest.
Marc Treib 2015/09/11 14:54:25 POJO?
tache 2015/09/11 15:45:09 Done.
19 */
20 public static class Interest {
21 private String mName;
22 private String mImageUrl;
23 private double mRelevance;
24
25 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.
26 super();
Marc Treib 2015/09/11 14:54:25 Unnecessary
tache 2015/09/11 15:45:09 Done.
27 this.mName = mName;
28 this.mImageUrl = mImageUrl;
29 this.mRelevance = mRelevance;
30 }
31
32 public String getName() {
33 return mName;
34 }
35
36 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.
37 this.mName = mName;
38 }
39
40 public String getImageUrl() {
41 return mImageUrl;
42 }
43
44 public void setImageUrl(String mImageUrl) {
45 this.mImageUrl = mImageUrl;
46 }
47
48 public double getRelevance() {
49 return this.mRelevance;
50 }
51
52 public void setRelevance(double relevance) {
53 this.mRelevance = relevance;
54 }
55 }
56 /**
57 * Interface for receiving the interests of a user.
58 */
59 public interface GetInterestsCallback {
60 /**
61 * Callback method for fetching the interests of a user.
62 * In case of an error an empty array will be returned.
63 *
64 * @param interests The array of interests.
65 */
66 @CalledByNative("GetInterestsCallback")
67 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.
68 }
69
70 /**
71 * InterestsService constructor requires a valid user profile object.
72 *
73 * @param profile The profile for which to fetch the interests
74 */
75 public InterestsService(Profile profile) {
76 mNativeInterestsService = nativeInit(profile);
77 }
78
79 /**
80 * Cleans up the C++ side of this class. This instance must not be used afte r calling destroy().
81 */
82 public void destroy() {
83 assert mNativeInterestsService != 0;
84 nativeDestroy(mNativeInterestsService);
85 mNativeInterestsService = 0;
86 }
87
88
89 public void getInterests(String accessToken, final GetInterestsCallback call back) {
90 GetInterestsCallback wrappedCallback = new GetInterestsCallback() {
91 @Override
92 public void onInterestsCallback(Interest[] interests) {
93 // Don't notify callback if we've already been destroyed.
94 if (mNativeInterestsService != 0) {
95 callback.onInterestsCallback(interests);
96 }
97 }
98 };
99
100 nativeGetInterests(mNativeInterestsService, accessToken, wrappedCallback );
101 }
102
103 /*
104 * Helper method for the native part.
105 */
106 @CalledByNative
107 public static Interest createInterest(String name, String imageUrl, double r elevance) {
108 return new Interest(name, imageUrl, relevance);
109 }
110
111
112 private native long nativeInit(Profile profile);
113 private native void nativeDestroy(long nativeInterestsService);
114 private native void nativeGetInterests(long nativeInterestsService, String t oken,
115 GetInterestsCallback callback);
116
117 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/chrome_jni_registrar.cc » ('j') | chrome/browser/android/interests_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698