| 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/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "chrome/browser/history/history_service_factory.h" | 13 #include "chrome/browser/history/history_service_factory.h" |
| 14 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" | 14 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_android.h" | 16 #include "chrome/browser/profiles/profile_android.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "components/history/core/browser/history_service.h" | 18 #include "components/history/core/browser/history_service.h" |
| 19 #include "components/ntp_snippets/ntp_snippet.h" | 19 #include "components/ntp_snippets/ntp_snippet.h" |
| 20 #include "components/ntp_snippets/ntp_snippets_service.h" | 20 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 21 #include "jni/SnippetsBridge_jni.h" | 21 #include "jni/SnippetsBridge_jni.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | |
| 23 #include "ui/gfx/android/java_bitmap.h" | 22 #include "ui/gfx/android/java_bitmap.h" |
| 23 #include "ui/gfx/image/image.h" |
| 24 | 24 |
| 25 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
| 26 using base::android::ConvertJavaStringToUTF8; | 26 using base::android::ConvertJavaStringToUTF8; |
| 27 using base::android::JavaParamRef; | 27 using base::android::JavaParamRef; |
| 28 using base::android::ToJavaArrayOfStrings; | 28 using base::android::ToJavaArrayOfStrings; |
| 29 using base::android::ToJavaLongArray; | 29 using base::android::ToJavaLongArray; |
| 30 using base::android::ScopedJavaGlobalRef; | 30 using base::android::ScopedJavaGlobalRef; |
| 31 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 void NTPSnippetsBridge::NTPSnippetsServiceCleared() { | 171 void NTPSnippetsBridge::NTPSnippetsServiceCleared() { |
| 172 // The user signed out or disabled sync. Since snippets rely on those, we | 172 // The user signed out or disabled sync. Since snippets rely on those, we |
| 173 // clear them to be consistent with the initially signed out state. | 173 // clear them to be consistent with the initially signed out state. |
| 174 JNIEnv* env = base::android::AttachCurrentThread(); | 174 JNIEnv* env = base::android::AttachCurrentThread(); |
| 175 Java_SnippetsBridge_onSnippetsCleared(env, observer_.obj()); | 175 Java_SnippetsBridge_onSnippetsCleared(env, observer_.obj()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, | 178 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, |
| 179 const std::string& snippet_id, | 179 const std::string& snippet_id, |
| 180 const SkBitmap* bitmap) { | 180 const gfx::Image& image) { |
| 181 JNIEnv* env = AttachCurrentThread(); | 181 JNIEnv* env = AttachCurrentThread(); |
| 182 | 182 |
| 183 ScopedJavaLocalRef<jobject> j_bitmap; | 183 ScopedJavaLocalRef<jobject> j_bitmap; |
| 184 if (bitmap && !bitmap->isNull()) | 184 if (!image.IsEmpty()) |
| 185 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); | 185 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); |
| 186 | 186 |
| 187 Java_FetchSnippetImageCallback_onSnippetImageAvailable(env, callback.obj(), | 187 Java_FetchSnippetImageCallback_onSnippetImageAvailable(env, callback.obj(), |
| 188 j_bitmap.obj()); | 188 j_bitmap.obj()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // static | 191 // static |
| 192 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 192 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 193 return RegisterNativesImpl(env); | 193 return RegisterNativesImpl(env); |
| 194 } | 194 } |
| OLD | NEW |