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

Side by Side Diff: chrome/browser/android/ntp/ntp_snippets_bridge.cc

Issue 2184683002: Show content suggestions from all categories on the NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge the two loops into one Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // URL for the article. This will also be used to find the favicon for the 140 // URL for the article. This will also be used to find the favicon for the
141 // article. 141 // article.
142 std::vector<std::string> urls; 142 std::vector<std::string> urls;
143 // URL for the AMP version of the article if it exists. This will be used as 143 // URL for the AMP version of the article if it exists. This will be used as
144 // the URL to direct the user to on tap. 144 // the URL to direct the user to on tap.
145 std::vector<std::string> amp_urls; 145 std::vector<std::string> amp_urls;
146 std::vector<std::string> snippets; 146 std::vector<std::string> snippets;
147 std::vector<int64_t> timestamps; 147 std::vector<int64_t> timestamps;
148 std::vector<std::string> publishers; 148 std::vector<std::string> publishers;
149 std::vector<float> scores; 149 std::vector<float> scores;
150 for (const ntp_snippets::ContentSuggestion& suggestion : 150
151 content_suggestions_service_->GetSuggestionsForCategory( 151 // Show all suggestions from all categories, even though we currently display
152 ContentSuggestionsCategory::ARTICLES)) { 152 // them in a single section on the UI.
153 ids.push_back(suggestion.id()); 153 // TODO(pke): This is only for debugging new sections and will be replaced
154 titles.push_back(suggestion.title()); 154 // with proper multi-section UI support.
155 // The url from source_info is a url for a site that is one of the 155 for (ContentSuggestionsCategory category :
156 // HOST_RESTRICT parameters, so this is preferred. 156 content_suggestions_service_->GetCategories()) {
157 urls.push_back(suggestion.url().spec()); 157 if (content_suggestions_service_->GetCategoryStatus(category) !=
158 amp_urls.push_back(suggestion.amp_url().spec()); 158 ContentSuggestionsCategoryStatus::AVAILABLE) {
159 snippets.push_back(suggestion.snippet_text()); 159 continue;
160 timestamps.push_back(suggestion.publish_date().ToJavaTime()); 160 }
161 publishers.push_back(suggestion.publisher_name()); 161 for (const ntp_snippets::ContentSuggestion& suggestion :
162 scores.push_back(suggestion.score()); 162 content_suggestions_service_->GetSuggestionsForCategory(category)) {
163 ids.push_back(suggestion.id());
164 titles.push_back(suggestion.title());
165 // The url from source_info is a url for a site that is one of the
166 // HOST_RESTRICT parameters, so this is preferred.
167 urls.push_back(suggestion.url().spec());
168 amp_urls.push_back(suggestion.amp_url().spec());
169 snippets.push_back(suggestion.snippet_text());
170 timestamps.push_back(suggestion.publish_date().ToJavaTime());
171 publishers.push_back(suggestion.publisher_name());
172 scores.push_back(suggestion.score());
173 }
163 } 174 }
164 175
165 JNIEnv* env = base::android::AttachCurrentThread(); 176 JNIEnv* env = base::android::AttachCurrentThread();
166 Java_SnippetsBridge_onSnippetsAvailable( 177 Java_SnippetsBridge_onSnippetsAvailable(
167 env, observer_.obj(), ToJavaArrayOfStrings(env, ids).obj(), 178 env, observer_.obj(), ToJavaArrayOfStrings(env, ids).obj(),
168 ToJavaArrayOfStrings(env, titles).obj(), 179 ToJavaArrayOfStrings(env, titles).obj(),
169 ToJavaArrayOfStrings(env, urls).obj(), 180 ToJavaArrayOfStrings(env, urls).obj(),
170 ToJavaArrayOfStrings(env, amp_urls).obj(), 181 ToJavaArrayOfStrings(env, amp_urls).obj(),
171 ToJavaArrayOfStrings(env, snippets).obj(), 182 ToJavaArrayOfStrings(env, snippets).obj(),
172 ToJavaLongArray(env, timestamps).obj(), 183 ToJavaLongArray(env, timestamps).obj(),
(...skipping 24 matching lines...) Expand all
197 if (!image.IsEmpty()) 208 if (!image.IsEmpty())
198 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); 209 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap());
199 210
200 base::android::RunCallbackAndroid(callback, j_bitmap); 211 base::android::RunCallbackAndroid(callback, j_bitmap);
201 } 212 }
202 213
203 // static 214 // static
204 bool NTPSnippetsBridge::Register(JNIEnv* env) { 215 bool NTPSnippetsBridge::Register(JNIEnv* env) {
205 return RegisterNativesImpl(env); 216 return RegisterNativesImpl(env);
206 } 217 }
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698