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

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: The access_token is obtained in the native code. Created 5 years, 2 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 private long mNativeInterestsService;
15
16 /**
17 * A user's interest.
18 */
19 public static class Interest {
20 private String mName;
21 private String mImageUrl;
22 private double mRelevance;
Bernhard Bauer 2015/09/29 14:04:04 Make these final?
PEConn 2015/10/07 13:55:21 Done.
23
24 public Interest(String name, String imageUrl, double relevance) {
25 this.mName = name;
26 this.mImageUrl = imageUrl;
27 this.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 this.mRelevance;
Bernhard Bauer 2015/09/29 14:04:04 You can remove the `this.`.
PEConn 2015/10/07 13:55:21 Done.
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 * In case of an error an empty array will be returned.
Bernhard Bauer 2015/09/29 14:04:04 Generally, it's useful to be able to distinguish b
PEConn 2015/10/07 13:55:21 Done.
49 *
50 * @param interests The array of interests.
51 */
52 @CalledByNative("GetInterestsCallback")
53 public void onInterestsAvailableCallback(Interest[] interests);
54 }
55
56 /**
57 * InterestsService constructor requires a valid user profile object.
58 *
59 * @param profile The profile for which to fetch the interests
60 */
61 public InterestsService(Profile profile) {
62 mNativeInterestsService = nativeInit(profile);
63 }
64
65 /**
66 * Cleans up the C++ side of this class. This instance must not be used afte r calling destroy().
67 */
68 public void destroy() {
69 assert mNativeInterestsService != 0;
70 nativeDestroy(mNativeInterestsService);
71 mNativeInterestsService = 0;
72 }
73
74 public void getInterests(final GetInterestsCallback callback) {
75 GetInterestsCallback wrappedCallback = new GetInterestsCallback() {
76 @Override
77 public void onInterestsAvailableCallback(Interest[] interests) {
78 // Don't notify callback if we've already been destroyed.
Bernhard Bauer 2015/09/29 14:04:04 Is this actually going to be necessary? The native
PEConn 2015/10/07 13:55:21 Done.
79 if (mNativeInterestsService != 0) {
80 callback.onInterestsAvailableCallback(interests);
81 }
82 }
83 };
84
85 nativeGetInterests(mNativeInterestsService, wrappedCallback);
86 }
87
88 /*
89 * Helper method for the native part.
90 */
91 @CalledByNative
92 public static Interest createInterest(String name, String imageUrl, double r elevance) {
Bernhard Bauer 2015/09/29 14:04:04 If this method is only meant to be called from nat
PEConn 2015/10/07 13:55:21 Done.
93 return new Interest(name, imageUrl, relevance);
94 }
95
96 private native long nativeInit(Profile profile);
97 private native void nativeDestroy(long nativeInterestsService);
98 private native void nativeGetInterests(
99 long nativeInterestsService, GetInterestsCallback callback);
100 }
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