| Index: chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| diff --git a/chrome/browser/android/ntp/ntp_snippets_bridge.cc b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| index 373de14c8c375514d5a2045b5272095207e5892c..23b378344ca03031387585a674ca5bf53cbf833c 100644
|
| --- a/chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| +++ b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| @@ -12,12 +12,13 @@
|
| #include "base/android/jni_string.h"
|
| #include "base/callback.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| +#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
|
| #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/profiles/profile_android.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "components/history/core/browser/history_service.h"
|
| -#include "components/ntp_snippets/ntp_snippet.h"
|
| +#include "components/ntp_snippets/content_suggestion.h"
|
| #include "components/ntp_snippets/ntp_snippets_service.h"
|
| #include "jni/SnippetsBridge_jni.h"
|
| #include "ui/gfx/android/java_bitmap.h"
|
| @@ -31,6 +32,8 @@ using base::android::ToJavaLongArray;
|
| using base::android::ToJavaFloatArray;
|
| using base::android::ScopedJavaGlobalRef;
|
| using base::android::ScopedJavaLocalRef;
|
| +using ntp_snippets::ContentSuggestionsCategory;
|
| +using ntp_snippets::ContentSuggestionsCategoryStatus;
|
|
|
| namespace {
|
|
|
| @@ -68,13 +71,14 @@ static void RescheduleFetching(JNIEnv* env,
|
|
|
| NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env,
|
| const JavaParamRef<jobject>& j_profile)
|
| - : snippet_service_observer_(this), weak_ptr_factory_(this) {
|
| + : content_suggestions_service_observer_(this), weak_ptr_factory_(this) {
|
| Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
|
| - ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile);
|
| + content_suggestions_service_ =
|
| + ContentSuggestionsServiceFactory::GetForProfile(profile);
|
| history_service_ =
|
| HistoryServiceFactory::GetForProfile(profile,
|
| ServiceAccessType::EXPLICIT_ACCESS);
|
| - snippet_service_observer_.Add(ntp_snippets_service_);
|
| + content_suggestions_service_observer_.Add(content_suggestions_service_);
|
| }
|
|
|
| void NTPSnippetsBridge::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| @@ -85,7 +89,7 @@ void NTPSnippetsBridge::SetObserver(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj,
|
| const JavaParamRef<jobject>& j_observer) {
|
| observer_.Reset(env, j_observer);
|
| - NTPSnippetsServiceLoaded();
|
| + OnNewSuggestions();
|
| }
|
|
|
| void NTPSnippetsBridge::FetchImage(JNIEnv* env,
|
| @@ -93,7 +97,7 @@ void NTPSnippetsBridge::FetchImage(JNIEnv* env,
|
| const JavaParamRef<jstring>& snippet_id,
|
| const JavaParamRef<jobject>& j_callback) {
|
| base::android::ScopedJavaGlobalRef<jobject> callback(j_callback);
|
| - ntp_snippets_service_->FetchSuggestionImage(
|
| + content_suggestions_service_->FetchSuggestionImage(
|
| ConvertJavaStringToUTF8(env, snippet_id),
|
| base::Bind(&NTPSnippetsBridge::OnImageFetched,
|
| weak_ptr_factory_.GetWeakPtr(), callback));
|
| @@ -102,7 +106,8 @@ void NTPSnippetsBridge::FetchImage(JNIEnv* env,
|
| void NTPSnippetsBridge::DiscardSnippet(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj,
|
| const JavaParamRef<jstring>& id) {
|
| - ntp_snippets_service_->DiscardSuggestion(ConvertJavaStringToUTF8(env, id));
|
| + content_suggestions_service_->DiscardSuggestion(
|
| + ConvertJavaStringToUTF8(env, id));
|
| }
|
|
|
| void NTPSnippetsBridge::SnippetVisited(JNIEnv* env,
|
| @@ -118,14 +123,15 @@ void NTPSnippetsBridge::SnippetVisited(JNIEnv* env,
|
| &tracker_);
|
| }
|
|
|
| -int NTPSnippetsBridge::GetDisabledReason(JNIEnv* env,
|
| +int NTPSnippetsBridge::GetCategoryStatus(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj) {
|
| - return static_cast<int>(ntp_snippets_service_->disabled_reason());
|
| + return static_cast<int>(content_suggestions_service_->GetCategoryStatus(
|
| + ContentSuggestionsCategory::ARTICLES));
|
| }
|
|
|
| NTPSnippetsBridge::~NTPSnippetsBridge() {}
|
|
|
| -void NTPSnippetsBridge::NTPSnippetsServiceLoaded() {
|
| +void NTPSnippetsBridge::OnNewSuggestions() {
|
| if (observer_.is_null())
|
| return;
|
|
|
| @@ -137,24 +143,23 @@ void NTPSnippetsBridge::NTPSnippetsServiceLoaded() {
|
| // URL for the AMP version of the article if it exists. This will be used as
|
| // the URL to direct the user to on tap.
|
| std::vector<std::string> amp_urls;
|
| - std::vector<std::string> thumbnail_urls;
|
| std::vector<std::string> snippets;
|
| std::vector<int64_t> timestamps;
|
| std::vector<std::string> publishers;
|
| std::vector<float> scores;
|
| - for (const std::unique_ptr<ntp_snippets::NTPSnippet>& snippet :
|
| - ntp_snippets_service_->snippets()) {
|
| - ids.push_back(snippet->id());
|
| - titles.push_back(snippet->title());
|
| + for (const ntp_snippets::ContentSuggestion& suggestion :
|
| + content_suggestions_service_->GetSuggestionsForCategory(
|
| + ContentSuggestionsCategory::ARTICLES)) {
|
| + ids.push_back(suggestion.id());
|
| + titles.push_back(suggestion.title());
|
| // The url from source_info is a url for a site that is one of the
|
| // HOST_RESTRICT parameters, so this is preferred.
|
| - urls.push_back(snippet->best_source().url.spec());
|
| - amp_urls.push_back(snippet->best_source().amp_url.spec());
|
| - thumbnail_urls.push_back(snippet->salient_image_url().spec());
|
| - snippets.push_back(snippet->snippet());
|
| - timestamps.push_back(snippet->publish_date().ToJavaTime());
|
| - publishers.push_back(snippet->best_source().publisher_name);
|
| - scores.push_back(snippet->score());
|
| + urls.push_back(suggestion.url().spec());
|
| + amp_urls.push_back(suggestion.amp_url().spec());
|
| + snippets.push_back(suggestion.snippet_text());
|
| + timestamps.push_back(suggestion.publish_date().ToJavaTime());
|
| + publishers.push_back(suggestion.publisher_name());
|
| + scores.push_back(suggestion.score());
|
| }
|
|
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
| @@ -163,25 +168,26 @@ void NTPSnippetsBridge::NTPSnippetsServiceLoaded() {
|
| ToJavaArrayOfStrings(env, titles).obj(),
|
| ToJavaArrayOfStrings(env, urls).obj(),
|
| ToJavaArrayOfStrings(env, amp_urls).obj(),
|
| - ToJavaArrayOfStrings(env, thumbnail_urls).obj(),
|
| ToJavaArrayOfStrings(env, snippets).obj(),
|
| ToJavaLongArray(env, timestamps).obj(),
|
| ToJavaArrayOfStrings(env, publishers).obj(),
|
| ToJavaFloatArray(env, scores).obj());
|
| }
|
|
|
| -void NTPSnippetsBridge::NTPSnippetsServiceShutdown() {
|
| - observer_.Reset();
|
| - snippet_service_observer_.Remove(ntp_snippets_service_);
|
| -}
|
| +void NTPSnippetsBridge::OnCategoryStatusChanged(
|
| + ContentSuggestionsCategory category,
|
| + ContentSuggestionsCategoryStatus new_status) {
|
| + if (category != ContentSuggestionsCategory::ARTICLES)
|
| + return;
|
|
|
| -void NTPSnippetsBridge::NTPSnippetsServiceDisabledReasonChanged(
|
| - ntp_snippets::DisabledReason disabled_reason) {
|
| - // The user signed out or disabled sync. Since snippets rely on those, we
|
| - // clear them to be consistent with the initially signed out state.
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
| - Java_SnippetsBridge_onDisabledReasonChanged(
|
| - env, observer_.obj(), static_cast<int>(disabled_reason));
|
| + Java_SnippetsBridge_onCategoryStatusChanged(env, observer_.obj(),
|
| + static_cast<int>(new_status));
|
| +}
|
| +
|
| +void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() {
|
| + observer_.Reset();
|
| + content_suggestions_service_observer_.Remove(content_suggestions_service_);
|
| }
|
|
|
| void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback,
|
|
|