Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3556)

Unified Diff: chrome/browser/android/ntp/ntp_snippets_bridge.cc

Issue 2781583002: [Content suggestions] Add a function to the service API to fetch favicons (Closed)
Patch Set: Fix compilation #2 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8780ce17bf3e28519f63be87d16d7e4db5ad1583..f8e0913e5fd757be504e06fa37e21eb95d8704b5 100644
--- a/chrome/browser/android/ntp/ntp_snippets_bridge.cc
+++ b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
@@ -175,7 +175,7 @@ void NTPSnippetsBridge::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
ScopedJavaLocalRef<jintArray> NTPSnippetsBridge::GetCategories(
JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj) {
+ const JavaParamRef<jobject>& obj) {
std::vector<int> category_ids;
for (Category category : content_suggestions_service_->GetCategories()) {
category_ids.push_back(category.id());
@@ -190,15 +190,15 @@ int NTPSnippetsBridge::GetCategoryStatus(JNIEnv* env,
Category::FromIDValue(j_category_id)));
}
-base::android::ScopedJavaLocalRef<jobject> NTPSnippetsBridge::GetCategoryInfo(
+ScopedJavaLocalRef<jobject> NTPSnippetsBridge::GetCategoryInfo(
JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj,
+ const JavaParamRef<jobject>& obj,
jint j_category_id) {
base::Optional<CategoryInfo> info =
content_suggestions_service_->GetCategoryInfo(
Category::FromIDValue(j_category_id));
if (!info) {
- return base::android::ScopedJavaLocalRef<jobject>(env, nullptr);
+ return ScopedJavaLocalRef<jobject>(env, nullptr);
}
return Java_SnippetsBridge_createSuggestionsCategoryInfo(
env, j_category_id, ConvertUTF16ToJavaString(env, info->title()),
@@ -209,7 +209,7 @@ base::android::ScopedJavaLocalRef<jobject> NTPSnippetsBridge::GetCategoryInfo(
ScopedJavaLocalRef<jobject> NTPSnippetsBridge::GetSuggestionsForCategory(
JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj,
+ const JavaParamRef<jobject>& obj,
jint j_category_id) {
Category category = Category::FromIDValue(j_category_id);
return ToJavaSuggestionList(
@@ -223,7 +223,7 @@ void NTPSnippetsBridge::FetchSuggestionImage(
jint j_category_id,
const JavaParamRef<jstring>& id_within_category,
const JavaParamRef<jobject>& j_callback) {
- base::android::ScopedJavaGlobalRef<jobject> callback(j_callback);
+ ScopedJavaGlobalRef<jobject> callback(j_callback);
content_suggestions_service_->FetchSuggestionImage(
ContentSuggestion::ID(Category::FromIDValue(j_category_id),
ConvertJavaStringToUTF8(env, id_within_category)),
@@ -231,6 +231,23 @@ void NTPSnippetsBridge::FetchSuggestionImage(
weak_ptr_factory_.GetWeakPtr(), callback));
}
+void NTPSnippetsBridge::FetchSuggestionFavicon(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ jint j_category_id,
+ const JavaParamRef<jstring>& id_within_category,
+ jint j_minimum_size_px,
+ jint j_desired_size_px,
+ const JavaParamRef<jobject>& j_callback) {
+ ScopedJavaGlobalRef<jobject> callback(j_callback);
+ content_suggestions_service_->FetchSuggestionFavicon(
+ ContentSuggestion::ID(Category::FromIDValue(j_category_id),
+ ConvertJavaStringToUTF8(env, id_within_category)),
+ j_minimum_size_px, j_desired_size_px,
+ base::Bind(&NTPSnippetsBridge::OnImageFetched,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+}
+
void NTPSnippetsBridge::Fetch(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
@@ -249,9 +266,8 @@ void NTPSnippetsBridge::Fetch(
weak_ptr_factory_.GetWeakPtr(), category));
}
-void NTPSnippetsBridge::ReloadSuggestions(
- JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj) {
+void NTPSnippetsBridge::ReloadSuggestions(JNIEnv* env,
+ const JavaParamRef<jobject>& obj) {
content_suggestions_service_->ReloadSuggestions();
}
@@ -391,9 +407,8 @@ void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env,
ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED);
}
-void NTPSnippetsBridge::OnNTPInitialized(
- JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj) {
+void NTPSnippetsBridge::OnNTPInitialized(JNIEnv* env,
+ const JavaParamRef<jobject>& obj) {
ntp_snippets::RemoteSuggestionsScheduler* scheduler =
GetRemoteSuggestionsScheduler();
// Can be null if the feature has been disabled but the scheduler has not been
@@ -405,9 +420,8 @@ void NTPSnippetsBridge::OnNTPInitialized(
scheduler->OnNTPOpened();
}
-void NTPSnippetsBridge::OnColdStart(
- JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj) {
+void NTPSnippetsBridge::OnColdStart(JNIEnv* env,
+ const JavaParamRef<jobject>& obj) {
ntp_snippets::RemoteSuggestionsScheduler* scheduler =
GetRemoteSuggestionsScheduler();
// TODO(fhorschig): Remove guard when https://crbug.com/678556 is resolved.
@@ -419,7 +433,7 @@ void NTPSnippetsBridge::OnColdStart(
void NTPSnippetsBridge::OnActivityWarmResumed(
JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj) {
+ const JavaParamRef<jobject>& obj) {
ntp_snippets::RemoteSuggestionsScheduler* scheduler =
GetRemoteSuggestionsScheduler();
// TODO(fhorschig): Remove guard when https://crbug.com/678556 is resolved.
@@ -432,14 +446,14 @@ void NTPSnippetsBridge::OnActivityWarmResumed(
NTPSnippetsBridge::~NTPSnippetsBridge() {}
void NTPSnippetsBridge::OnNewSuggestions(Category category) {
- JNIEnv* env = base::android::AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
Java_SnippetsBridge_onNewSuggestions(env, bridge_,
static_cast<int>(category.id()));
}
void NTPSnippetsBridge::OnCategoryStatusChanged(Category category,
CategoryStatus new_status) {
- JNIEnv* env = base::android::AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
Java_SnippetsBridge_onCategoryStatusChanged(env, bridge_,
static_cast<int>(category.id()),
static_cast<int>(new_status));
@@ -447,14 +461,14 @@ void NTPSnippetsBridge::OnCategoryStatusChanged(Category category,
void NTPSnippetsBridge::OnSuggestionInvalidated(
const ContentSuggestion::ID& suggestion_id) {
- JNIEnv* env = base::android::AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
Java_SnippetsBridge_onSuggestionInvalidated(
env, bridge_.obj(), static_cast<int>(suggestion_id.category().id()),
ConvertUTF8ToJavaString(env, suggestion_id.id_within_category()).obj());
}
void NTPSnippetsBridge::OnFullRefreshRequired() {
- JNIEnv* env = base::android::AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
Java_SnippetsBridge_onFullRefreshRequired(env, bridge_.obj());
}
@@ -469,7 +483,7 @@ void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback,
if (!image.IsEmpty()) {
j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap());
}
- base::android::RunCallbackAndroid(callback, j_bitmap);
+ RunCallbackAndroid(callback, j_bitmap);
}
void NTPSnippetsBridge::OnSuggestionsFetched(

Powered by Google App Engine
This is Rietveld 408576698