| 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" |
| 11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "chrome/browser/history/history_service_factory.h" | 14 #include "chrome/browser/history/history_service_factory.h" |
| 15 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" | 15 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
| 16 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_android.h" | 17 #include "chrome/browser/profiles/profile_android.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
| 21 #include "components/ntp_snippets/content_suggestion.h" | 20 #include "components/ntp_snippets/content_suggestion.h" |
| 22 #include "components/ntp_snippets/ntp_snippets_service.h" | 21 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 23 #include "jni/SnippetsBridge_jni.h" | 22 #include "jni/SnippetsBridge_jni.h" |
| 24 #include "ui/gfx/android/java_bitmap.h" | 23 #include "ui/gfx/android/java_bitmap.h" |
| 25 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 26 | 25 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 53 const JavaParamRef<jobject>& obj, | 52 const JavaParamRef<jobject>& obj, |
| 54 const JavaParamRef<jobject>& j_profile) { | 53 const JavaParamRef<jobject>& j_profile) { |
| 55 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); | 54 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); |
| 56 return reinterpret_cast<intptr_t>(snippets_bridge); | 55 return reinterpret_cast<intptr_t>(snippets_bridge); |
| 57 } | 56 } |
| 58 | 57 |
| 59 static void FetchSnippets(JNIEnv* env, | 58 static void FetchSnippets(JNIEnv* env, |
| 60 const JavaParamRef<jclass>& caller, | 59 const JavaParamRef<jclass>& caller, |
| 61 jboolean j_force_request) { | 60 jboolean j_force_request) { |
| 62 Profile* profile = ProfileManager::GetLastUsedProfile(); | 61 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 63 NTPSnippetsServiceFactory::GetForProfile(profile)->FetchSnippets( | 62 ContentSuggestionsServiceFactory::GetForProfile(profile) |
| 64 j_force_request); | 63 ->ntp_snippets_service() |
| 64 ->FetchSnippets(j_force_request); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Reschedules the fetching of snippets. Used to support different fetching | 67 // Reschedules the fetching of snippets. Used to support different fetching |
| 68 // intervals for different times of day. | 68 // intervals for different times of day. |
| 69 static void RescheduleFetching(JNIEnv* env, | 69 static void RescheduleFetching(JNIEnv* env, |
| 70 const JavaParamRef<jclass>& caller) { | 70 const JavaParamRef<jclass>& caller) { |
| 71 Profile* profile = ProfileManager::GetLastUsedProfile(); | 71 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 72 NTPSnippetsServiceFactory::GetForProfile(profile)->RescheduleFetching(); | 72 ContentSuggestionsServiceFactory::GetForProfile(profile) |
| 73 ->ntp_snippets_service() |
| 74 ->RescheduleFetching(); |
| 73 } | 75 } |
| 74 | 76 |
| 75 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, | 77 NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env, |
| 76 const JavaParamRef<jobject>& j_profile) | 78 const JavaParamRef<jobject>& j_profile) |
| 77 : content_suggestions_service_observer_(this), weak_ptr_factory_(this) { | 79 : content_suggestions_service_observer_(this), weak_ptr_factory_(this) { |
| 78 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 80 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 79 content_suggestions_service_ = | 81 content_suggestions_service_ = |
| 80 ContentSuggestionsServiceFactory::GetForProfile(profile); | 82 ContentSuggestionsServiceFactory::GetForProfile(profile); |
| 81 history_service_ = | 83 history_service_ = |
| 82 HistoryServiceFactory::GetForProfile(profile, | 84 HistoryServiceFactory::GetForProfile(profile, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 if (!image.IsEmpty()) | 212 if (!image.IsEmpty()) |
| 211 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); | 213 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); |
| 212 | 214 |
| 213 base::android::RunCallbackAndroid(callback, j_bitmap); | 215 base::android::RunCallbackAndroid(callback, j_bitmap); |
| 214 } | 216 } |
| 215 | 217 |
| 216 // static | 218 // static |
| 217 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 219 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 218 return RegisterNativesImpl(env); | 220 return RegisterNativesImpl(env); |
| 219 } | 221 } |
| OLD | NEW |