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 | 8 |
9 #include "base/android/callback_android.h" | 9 #include "base/android/callback_android.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 env, observer_.obj(), static_cast<int>(category.id()), | 317 env, observer_.obj(), static_cast<int>(category.id()), |
318 ConvertUTF8ToJavaString(env, suggestion_id).obj()); | 318 ConvertUTF8ToJavaString(env, suggestion_id).obj()); |
319 } | 319 } |
320 | 320 |
321 void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() { | 321 void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() { |
322 observer_.Reset(); | 322 observer_.Reset(); |
323 content_suggestions_service_observer_.Remove(content_suggestions_service_); | 323 content_suggestions_service_observer_.Remove(content_suggestions_service_); |
324 } | 324 } |
325 | 325 |
326 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, | 326 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, |
327 const std::string& snippet_id, | |
328 const gfx::Image& image) { | 327 const gfx::Image& image) { |
329 ScopedJavaLocalRef<jobject> j_bitmap; | 328 ScopedJavaLocalRef<jobject> j_bitmap; |
330 if (!image.IsEmpty()) | 329 if (!image.IsEmpty()) |
331 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); | 330 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); |
332 | 331 |
333 base::android::RunCallbackAndroid(callback, j_bitmap); | 332 base::android::RunCallbackAndroid(callback, j_bitmap); |
334 } | 333 } |
335 | 334 |
336 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { | 335 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { |
337 return content_suggestions_service_->category_factory()->FromIDValue(id); | 336 return content_suggestions_service_->category_factory()->FromIDValue(id); |
338 } | 337 } |
339 | 338 |
340 // static | 339 // static |
341 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 340 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
342 return RegisterNativesImpl(env); | 341 return RegisterNativesImpl(env); |
343 } | 342 } |
OLD | NEW |