| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 CategoryStatus new_status) { | 221 CategoryStatus new_status) { |
| 222 if (observer_.is_null()) | 222 if (observer_.is_null()) |
| 223 return; | 223 return; |
| 224 | 224 |
| 225 JNIEnv* env = base::android::AttachCurrentThread(); | 225 JNIEnv* env = base::android::AttachCurrentThread(); |
| 226 Java_SnippetsBridge_onCategoryStatusChanged(env, observer_.obj(), | 226 Java_SnippetsBridge_onCategoryStatusChanged(env, observer_.obj(), |
| 227 static_cast<int>(category.id()), | 227 static_cast<int>(category.id()), |
| 228 static_cast<int>(new_status)); | 228 static_cast<int>(new_status)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void NTPSnippetsBridge::OnSuggestionInvalidated( |
| 232 Category category, |
| 233 const std::string& suggestion_id) { |
| 234 if (observer_.is_null()) |
| 235 return; |
| 236 |
| 237 JNIEnv* env = base::android::AttachCurrentThread(); |
| 238 Java_SnippetsBridge_onSuggestionInvalidated( |
| 239 env, observer_.obj(), static_cast<int>(category.id()), |
| 240 ConvertUTF8ToJavaString(env, suggestion_id).obj()); |
| 241 } |
| 242 |
| 231 void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() { | 243 void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() { |
| 232 observer_.Reset(); | 244 observer_.Reset(); |
| 233 content_suggestions_service_observer_.Remove(content_suggestions_service_); | 245 content_suggestions_service_observer_.Remove(content_suggestions_service_); |
| 234 } | 246 } |
| 235 | 247 |
| 236 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, | 248 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, |
| 237 const std::string& snippet_id, | 249 const std::string& snippet_id, |
| 238 const gfx::Image& image) { | 250 const gfx::Image& image) { |
| 239 ScopedJavaLocalRef<jobject> j_bitmap; | 251 ScopedJavaLocalRef<jobject> j_bitmap; |
| 240 if (!image.IsEmpty()) | 252 if (!image.IsEmpty()) |
| 241 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); | 253 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); |
| 242 | 254 |
| 243 base::android::RunCallbackAndroid(callback, j_bitmap); | 255 base::android::RunCallbackAndroid(callback, j_bitmap); |
| 244 } | 256 } |
| 245 | 257 |
| 246 // static | 258 // static |
| 247 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 259 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 248 return RegisterNativesImpl(env); | 260 return RegisterNativesImpl(env); |
| 249 } | 261 } |
| OLD | NEW |