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

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

Issue 1958163002: [NTP Snippets] Refactor home-grown container API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated client code. Created 4 years, 7 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
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/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // URL for the article. This will also be used to find the favicon for the 130 // URL for the article. This will also be used to find the favicon for the
131 // article. 131 // article.
132 std::vector<std::string> urls; 132 std::vector<std::string> urls;
133 // URL for the AMP version of the article if it exists. This will be used as 133 // URL for the AMP version of the article if it exists. This will be used as
134 // the URL to direct the user to on tap. 134 // the URL to direct the user to on tap.
135 std::vector<std::string> amp_urls; 135 std::vector<std::string> amp_urls;
136 std::vector<std::string> thumbnail_urls; 136 std::vector<std::string> thumbnail_urls;
137 std::vector<std::string> snippets; 137 std::vector<std::string> snippets;
138 std::vector<int64_t> timestamps; 138 std::vector<int64_t> timestamps;
139 std::vector<std::string> publishers; 139 std::vector<std::string> publishers;
140 for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) { 140 for (const auto& snippet : ntp_snippets_service_->snippets()) {
Bernhard Bauer 2016/05/10 14:48:56 Could you keep the original type? I find it's much
mastiz 2016/05/10 15:59:52 Done.
141 // The url from source_info is a url for a site that is one of the 141 // The url from source_info is a url for a site that is one of the
142 // HOST_RESTRICT parameters, so this is preferred. 142 // HOST_RESTRICT parameters, so this is preferred.
143 urls.push_back(snippet.best_source().url.spec()); 143 urls.push_back(snippet->best_source().url.spec());
144 amp_urls.push_back(snippet.best_source().amp_url.spec()); 144 amp_urls.push_back(snippet->best_source().amp_url.spec());
145 titles.push_back(snippet.title()); 145 titles.push_back(snippet->title());
146 thumbnail_urls.push_back(snippet.salient_image_url().spec()); 146 thumbnail_urls.push_back(snippet->salient_image_url().spec());
147 snippets.push_back(snippet.snippet()); 147 snippets.push_back(snippet->snippet());
148 timestamps.push_back(snippet.publish_date().ToJavaTime()); 148 timestamps.push_back(snippet->publish_date().ToJavaTime());
149 publishers.push_back(snippet.best_source().publisher_name); 149 publishers.push_back(snippet->best_source().publisher_name);
150 } 150 }
151 151
152 JNIEnv* env = base::android::AttachCurrentThread(); 152 JNIEnv* env = base::android::AttachCurrentThread();
153 Java_SnippetsBridge_onSnippetsAvailable( 153 Java_SnippetsBridge_onSnippetsAvailable(
154 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), 154 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(),
155 ToJavaArrayOfStrings(env, urls).obj(), 155 ToJavaArrayOfStrings(env, urls).obj(),
156 ToJavaArrayOfStrings(env, amp_urls).obj(), 156 ToJavaArrayOfStrings(env, amp_urls).obj(),
157 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), 157 ToJavaArrayOfStrings(env, thumbnail_urls).obj(),
158 ToJavaArrayOfStrings(env, snippets).obj(), 158 ToJavaArrayOfStrings(env, snippets).obj(),
159 ToJavaLongArray(env, timestamps).obj(), 159 ToJavaLongArray(env, timestamps).obj(),
(...skipping 15 matching lines...) Expand all
175 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); 175 j_bitmap = gfx::ConvertToJavaBitmap(bitmap);
176 176
177 Java_FetchSnippetImageCallback_onSnippetImageAvailable(env, callback.obj(), 177 Java_FetchSnippetImageCallback_onSnippetImageAvailable(env, callback.obj(),
178 j_bitmap.obj()); 178 j_bitmap.obj());
179 } 179 }
180 180
181 // static 181 // static
182 bool NTPSnippetsBridge::Register(JNIEnv* env) { 182 bool NTPSnippetsBridge::Register(JNIEnv* env) {
183 return RegisterNativesImpl(env); 183 return RegisterNativesImpl(env);
184 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698