OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/ntp/ntp_snippets_bridge.h" | 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, | 158 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, |
159 const JavaParamRef<jobject>& j_bridge, | 159 const JavaParamRef<jobject>& j_bridge, |
160 const JavaParamRef<jobject>& j_profile) | 160 const JavaParamRef<jobject>& j_profile) |
161 : content_suggestions_service_observer_(this), | 161 : content_suggestions_service_observer_(this), |
162 bridge_(env, j_bridge), | 162 bridge_(env, j_bridge), |
163 weak_ptr_factory_(this) { | 163 weak_ptr_factory_(this) { |
164 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 164 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
165 content_suggestions_service_ = | 165 content_suggestions_service_ = |
166 ContentSuggestionsServiceFactory::GetForProfile(profile); | 166 ContentSuggestionsServiceFactory::GetForProfile(profile); |
167 history_service_ = | 167 history_service_ = HistoryServiceFactory::GetForProfile( |
168 HistoryServiceFactory::GetForProfile(profile, | 168 profile, ServiceAccessType::EXPLICIT_ACCESS); |
169 ServiceAccessType::EXPLICIT_ACCESS); | |
170 content_suggestions_service_observer_.Add(content_suggestions_service_); | 169 content_suggestions_service_observer_.Add(content_suggestions_service_); |
171 } | 170 } |
172 | 171 |
173 void NTPSnippetsBridge::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 172 void NTPSnippetsBridge::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
174 delete this; | 173 delete this; |
175 } | 174 } |
176 | 175 |
177 ScopedJavaLocalRef<jintArray> NTPSnippetsBridge::GetCategories( | 176 ScopedJavaLocalRef<jintArray> NTPSnippetsBridge::GetCategories( |
178 JNIEnv* env, | 177 JNIEnv* env, |
179 const base::android::JavaParamRef<jobject>& obj) { | 178 const base::android::JavaParamRef<jobject>& obj) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 JNIEnv* env, | 235 JNIEnv* env, |
237 const JavaParamRef<jobject>& obj, | 236 const JavaParamRef<jobject>& obj, |
238 jint j_category_id, | 237 jint j_category_id, |
239 const JavaParamRef<jobjectArray>& j_displayed_suggestions) { | 238 const JavaParamRef<jobjectArray>& j_displayed_suggestions) { |
240 std::vector<std::string> known_suggestion_ids; | 239 std::vector<std::string> known_suggestion_ids; |
241 AppendJavaStringArrayToStringVector(env, j_displayed_suggestions, | 240 AppendJavaStringArrayToStringVector(env, j_displayed_suggestions, |
242 &known_suggestion_ids); | 241 &known_suggestion_ids); |
243 | 242 |
244 Category category = Category::FromIDValue(j_category_id); | 243 Category category = Category::FromIDValue(j_category_id); |
245 content_suggestions_service_->Fetch( | 244 content_suggestions_service_->Fetch( |
246 category, std::set<std::string>(known_suggestion_ids.begin(), | 245 category, |
247 known_suggestion_ids.end()), | 246 std::set<std::string>(known_suggestion_ids.begin(), |
| 247 known_suggestion_ids.end()), |
248 base::Bind(&NTPSnippetsBridge::OnSuggestionsFetched, | 248 base::Bind(&NTPSnippetsBridge::OnSuggestionsFetched, |
249 weak_ptr_factory_.GetWeakPtr(), category)); | 249 weak_ptr_factory_.GetWeakPtr(), category)); |
250 } | 250 } |
251 | 251 |
252 void NTPSnippetsBridge::ReloadSuggestions( | 252 void NTPSnippetsBridge::ReloadSuggestions( |
253 JNIEnv* env, | 253 JNIEnv* env, |
254 const base::android::JavaParamRef<jobject>& obj) { | 254 const base::android::JavaParamRef<jobject>& obj) { |
255 content_suggestions_service_->ReloadSuggestions(); | 255 content_suggestions_service_->ReloadSuggestions(); |
256 } | 256 } |
257 | 257 |
258 void NTPSnippetsBridge::DismissSuggestion( | 258 void NTPSnippetsBridge::DismissSuggestion( |
259 JNIEnv* env, | 259 JNIEnv* env, |
260 const JavaParamRef<jobject>& obj, | 260 const JavaParamRef<jobject>& obj, |
261 const JavaParamRef<jstring>& jurl, | 261 const JavaParamRef<jstring>& jurl, |
262 jint global_position, | 262 jint global_position, |
263 jint j_category_id, | 263 jint j_category_id, |
264 jint position_in_category, | 264 jint position_in_category, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 JNIEnv* env = AttachCurrentThread(); | 480 JNIEnv* env = AttachCurrentThread(); |
481 Java_SnippetsBridge_onMoreSuggestions( | 481 Java_SnippetsBridge_onMoreSuggestions( |
482 env, bridge_, category.id(), | 482 env, bridge_, category.id(), |
483 ToJavaSuggestionList(env, category, suggestions)); | 483 ToJavaSuggestionList(env, category, suggestions)); |
484 } | 484 } |
485 | 485 |
486 // static | 486 // static |
487 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 487 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
488 return RegisterNativesImpl(env); | 488 return RegisterNativesImpl(env); |
489 } | 489 } |
OLD | NEW |