| 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/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" | 13 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_android.h" | 15 #include "chrome/browser/profiles/profile_android.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "components/ntp_snippets/ntp_snippet.h" | 17 #include "components/ntp_snippets/ntp_snippet.h" |
| 17 #include "components/ntp_snippets/ntp_snippets_service.h" | 18 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 18 #include "jni/SnippetsBridge_jni.h" | 19 #include "jni/SnippetsBridge_jni.h" |
| 19 | 20 |
| 20 using base::android::ConvertJavaStringToUTF8; | 21 using base::android::ConvertJavaStringToUTF8; |
| 21 using base::android::JavaParamRef; | 22 using base::android::JavaParamRef; |
| 22 using base::android::ToJavaArrayOfStrings; | 23 using base::android::ToJavaArrayOfStrings; |
| 23 using base::android::ToJavaLongArray; | 24 using base::android::ToJavaLongArray; |
| 24 | 25 |
| 25 static jlong Init(JNIEnv* env, | 26 static jlong Init(JNIEnv* env, |
| 26 const JavaParamRef<jobject>& obj, | 27 const JavaParamRef<jobject>& obj, |
| 27 const JavaParamRef<jobject>& j_profile) { | 28 const JavaParamRef<jobject>& j_profile) { |
| 28 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); | 29 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); |
| 29 return reinterpret_cast<intptr_t>(snippets_bridge); | 30 return reinterpret_cast<intptr_t>(snippets_bridge); |
| 30 } | 31 } |
| 31 | 32 |
| 33 static void FetchSnippets(JNIEnv* env, |
| 34 const JavaParamRef<jclass>& caller) { |
| 35 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 36 NTPSnippetsServiceFactory::GetForProfile(profile)->FetchSnippets(); |
| 37 } |
| 38 |
| 32 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, | 39 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, |
| 33 const JavaParamRef<jobject>& j_profile) | 40 const JavaParamRef<jobject>& j_profile) |
| 34 : snippet_service_observer_(this) { | 41 : snippet_service_observer_(this) { |
| 35 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 42 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 36 ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile); | 43 ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile); |
| 37 } | 44 } |
| 38 | 45 |
| 39 void NTPSnippetsBridge::SetObserver(JNIEnv* env, | 46 void NTPSnippetsBridge::SetObserver(JNIEnv* env, |
| 40 const JavaParamRef<jobject>& obj, | 47 const JavaParamRef<jobject>& obj, |
| 41 const JavaParamRef<jobject>& j_observer) { | 48 const JavaParamRef<jobject>& j_observer) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 91 |
| 85 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { | 92 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { |
| 86 observer_.Reset(); | 93 observer_.Reset(); |
| 87 snippet_service_observer_.Remove(ntp_snippets_service_); | 94 snippet_service_observer_.Remove(ntp_snippets_service_); |
| 88 } | 95 } |
| 89 | 96 |
| 90 // static | 97 // static |
| 91 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 98 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 92 return RegisterNativesImpl(env); | 99 return RegisterNativesImpl(env); |
| 93 } | 100 } |
| OLD | NEW |