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/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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 false, | 104 false, |
105 base::Bind(&SnippetVisitedHistoryRequestCallback, callback), | 105 base::Bind(&SnippetVisitedHistoryRequestCallback, callback), |
106 &tracker_); | 106 &tracker_); |
107 } | 107 } |
108 | 108 |
109 void NTPSnippetsBridge::NTPSnippetsServiceLoaded() { | 109 void NTPSnippetsBridge::NTPSnippetsServiceLoaded() { |
110 if (observer_.is_null()) | 110 if (observer_.is_null()) |
111 return; | 111 return; |
112 | 112 |
113 std::vector<std::string> titles; | 113 std::vector<std::string> titles; |
114 // url for the article. This will also be used to find the favicon for the | |
Marc Treib
2016/04/29 09:19:29
nitty nit: I'd use "URL" in comments. Also comment
Bernhard Bauer
2016/04/29 09:26:34
Nit: "URL"
May
2016/04/29 11:54:21
Done.
| |
115 // article | |
Bernhard Bauer
2016/04/29 09:26:34
Nit: period at the end please.
May
2016/04/29 11:54:21
Done.
| |
114 std::vector<std::string> urls; | 116 std::vector<std::string> urls; |
117 // url for the amp version of the article if it exists. This will be used as | |
Bernhard Bauer
2016/04/29 09:26:34
Nit: "AMP"
May
2016/04/29 11:54:21
Done.
| |
118 // the url to direct the user to on tap. | |
119 std::vector<std::string> amp_urls; | |
115 std::vector<std::string> thumbnail_urls; | 120 std::vector<std::string> thumbnail_urls; |
116 std::vector<std::string> snippets; | 121 std::vector<std::string> snippets; |
117 std::vector<int64_t> timestamps; | 122 std::vector<int64_t> timestamps; |
123 std::vector<std::string> publishers; | |
118 for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) { | 124 for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) { |
125 // The url from source_info is a url for a site that is one of the | |
126 // HOST_RESTRICT parameters, so this is preferred. | |
127 urls.push_back(snippet.best_source().url.spec()); | |
Marc Treib
2016/04/29 09:19:29
Hm, I think this is problematic. We currently use
May
2016/04/29 11:54:20
Hmm, good point. Changed DiscardSnippet to use the
| |
128 amp_urls.push_back(snippet.best_source().amp_url.spec()); | |
119 titles.push_back(snippet.title()); | 129 titles.push_back(snippet.title()); |
120 urls.push_back(snippet.url().spec()); | |
121 thumbnail_urls.push_back(snippet.salient_image_url().spec()); | 130 thumbnail_urls.push_back(snippet.salient_image_url().spec()); |
122 snippets.push_back(snippet.snippet()); | 131 snippets.push_back(snippet.snippet()); |
123 timestamps.push_back(snippet.publish_date().ToJavaTime()); | 132 timestamps.push_back(snippet.publish_date().ToJavaTime()); |
133 publishers.push_back(snippet.best_source().publisher_name); | |
124 } | 134 } |
125 | 135 |
126 JNIEnv* env = base::android::AttachCurrentThread(); | 136 JNIEnv* env = base::android::AttachCurrentThread(); |
127 Java_SnippetsBridge_onSnippetsAvailable( | 137 Java_SnippetsBridge_onSnippetsAvailable( |
128 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), | 138 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), |
129 ToJavaArrayOfStrings(env, urls).obj(), | 139 ToJavaArrayOfStrings(env, urls).obj(), |
140 ToJavaArrayOfStrings(env, amp_urls).obj(), | |
130 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), | 141 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), |
131 ToJavaArrayOfStrings(env, snippets).obj(), | 142 ToJavaArrayOfStrings(env, snippets).obj(), |
132 ToJavaLongArray(env, timestamps).obj()); | 143 ToJavaLongArray(env, timestamps).obj(), |
144 ToJavaArrayOfStrings(env, publishers).obj()); | |
133 } | 145 } |
134 | 146 |
135 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { | 147 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { |
136 observer_.Reset(); | 148 observer_.Reset(); |
137 snippet_service_observer_.Remove(ntp_snippets_service_); | 149 snippet_service_observer_.Remove(ntp_snippets_service_); |
138 } | 150 } |
139 | 151 |
140 // static | 152 // static |
141 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 153 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
142 return RegisterNativesImpl(env); | 154 return RegisterNativesImpl(env); |
143 } | 155 } |
OLD | NEW |