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 #include "chrome/browser/interests/android/interests_service.h" | 5 #include "chrome/browser/interests/android/interests_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
12 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
13 #include "chrome/browser/interests/interests_fetcher.h" | 14 #include "chrome/browser/interests/interests_fetcher.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_android.h" | 16 #include "chrome/browser/profiles/profile_android.h" |
16 #include "jni/InterestsService_jni.h" | 17 #include "jni/InterestsService_jni.h" |
17 | 18 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 JNIEnv* env, | 62 JNIEnv* env, |
62 const JavaParamRef<jobject>& obj, | 63 const JavaParamRef<jobject>& obj, |
63 const JavaParamRef<jobject>& j_callback_obj) { | 64 const JavaParamRef<jobject>& j_callback_obj) { |
64 ScopedJavaGlobalRef<jobject> j_callback(env, j_callback_obj); | 65 ScopedJavaGlobalRef<jobject> j_callback(env, j_callback_obj); |
65 | 66 |
66 scoped_ptr<InterestsFetcher> fetcher = | 67 scoped_ptr<InterestsFetcher> fetcher = |
67 InterestsFetcher::CreateFromProfile(profile_); | 68 InterestsFetcher::CreateFromProfile(profile_); |
68 InterestsFetcher* fetcher_raw_ptr = fetcher.get(); | 69 InterestsFetcher* fetcher_raw_ptr = fetcher.get(); |
69 | 70 |
70 InterestsFetcher::InterestsCallback callback = base::Bind( | 71 InterestsFetcher::InterestsCallback callback = base::Bind( |
71 &InterestsService::OnObtainedInterests, | 72 &InterestsService::OnObtainedInterests, weak_ptr_factory_.GetWeakPtr(), |
72 weak_ptr_factory_.GetWeakPtr(), | 73 base::Passed(std::move(fetcher)), j_callback); |
73 base::Passed(fetcher.Pass()), | |
74 j_callback); | |
75 | 74 |
76 fetcher_raw_ptr->FetchInterests(callback); | 75 fetcher_raw_ptr->FetchInterests(callback); |
77 } | 76 } |
78 | 77 |
79 // static | 78 // static |
80 bool InterestsService::Register(JNIEnv* env) { | 79 bool InterestsService::Register(JNIEnv* env) { |
81 return RegisterNativesImpl(env); | 80 return RegisterNativesImpl(env); |
82 } | 81 } |
83 | 82 |
84 void InterestsService::OnObtainedInterests( | 83 void InterestsService::OnObtainedInterests( |
85 scoped_ptr<InterestsFetcher> fetcher, | 84 scoped_ptr<InterestsFetcher> fetcher, |
86 const ScopedJavaGlobalRef<jobject>& j_callback, | 85 const ScopedJavaGlobalRef<jobject>& j_callback, |
87 scoped_ptr<std::vector<InterestsFetcher::Interest>> interests) { | 86 scoped_ptr<std::vector<InterestsFetcher::Interest>> interests) { |
88 JNIEnv* env = AttachCurrentThread(); | 87 JNIEnv* env = AttachCurrentThread(); |
89 ScopedJavaLocalRef<jobjectArray> j_interests = | 88 ScopedJavaLocalRef<jobjectArray> j_interests = |
90 ConvertInterestsToJava(env, interests.Pass()); | 89 ConvertInterestsToJava(env, std::move(interests)); |
91 Java_GetInterestsCallback_onInterestsAvailable(env, | 90 Java_GetInterestsCallback_onInterestsAvailable(env, |
92 j_callback.obj(), | 91 j_callback.obj(), |
93 j_interests.obj()); | 92 j_interests.obj()); |
94 } | 93 } |
95 | 94 |
96 static jlong Init(JNIEnv* env, | 95 static jlong Init(JNIEnv* env, |
97 const JavaParamRef<jobject>& jobj, | 96 const JavaParamRef<jobject>& jobj, |
98 const JavaParamRef<jobject>& jprofile) { | 97 const JavaParamRef<jobject>& jprofile) { |
99 InterestsService* interests_service = | 98 InterestsService* interests_service = |
100 new InterestsService(ProfileAndroid::FromProfileAndroid(jprofile)); | 99 new InterestsService(ProfileAndroid::FromProfileAndroid(jprofile)); |
101 return reinterpret_cast<intptr_t>(interests_service); | 100 return reinterpret_cast<intptr_t>(interests_service); |
102 } | 101 } |
OLD | NEW |