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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 std::vector<std::string> urls; | 114 std::vector<std::string> urls; |
115 std::vector<std::string> amp_urls; | |
115 std::vector<std::string> thumbnail_urls; | 116 std::vector<std::string> thumbnail_urls; |
116 std::vector<std::string> snippets; | 117 std::vector<std::string> snippets; |
117 std::vector<int64_t> timestamps; | 118 std::vector<int64_t> timestamps; |
119 std::vector<std::string> publishers; | |
118 for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) { | 120 for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) { |
121 // The url from source_info is a url for a site that is one of the | |
122 // HOST_RESTRICT parameters, so this is preferred. If there's an AMP url, | |
123 // prefer that over the plain url | |
124 urls.push_back(snippet.best_source().url.spec()); | |
125 amp_urls.push_back(snippet.best_source().amp_url.is_empty() | |
126 ? snippet.best_source().url.spec() | |
Marc Treib
2016/04/28 08:50:13
Wait, if we don't have an AMP URL, then shouldn't
May
2016/04/28 18:01:52
Ah, yeah it should. Good catch.
| |
127 : snippet.best_source().amp_url.spec()); | |
119 titles.push_back(snippet.title()); | 128 titles.push_back(snippet.title()); |
120 urls.push_back(snippet.url().spec()); | |
121 thumbnail_urls.push_back(snippet.salient_image_url().spec()); | 129 thumbnail_urls.push_back(snippet.salient_image_url().spec()); |
122 snippets.push_back(snippet.snippet()); | 130 snippets.push_back(snippet.snippet()); |
123 timestamps.push_back(snippet.publish_date().ToJavaTime()); | 131 timestamps.push_back(snippet.publish_date().ToJavaTime()); |
132 publishers.push_back(snippet.best_source().publisher_name); | |
124 } | 133 } |
125 | 134 |
126 JNIEnv* env = base::android::AttachCurrentThread(); | 135 JNIEnv* env = base::android::AttachCurrentThread(); |
127 Java_SnippetsBridge_onSnippetsAvailable( | 136 Java_SnippetsBridge_onSnippetsAvailable( |
128 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), | 137 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), |
129 ToJavaArrayOfStrings(env, urls).obj(), | 138 ToJavaArrayOfStrings(env, urls).obj(), |
139 ToJavaArrayOfStrings(env, amp_urls).obj(), | |
130 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), | 140 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), |
131 ToJavaArrayOfStrings(env, snippets).obj(), | 141 ToJavaArrayOfStrings(env, snippets).obj(), |
132 ToJavaLongArray(env, timestamps).obj()); | 142 ToJavaLongArray(env, timestamps).obj(), |
143 ToJavaArrayOfStrings(env, publishers).obj()); | |
133 } | 144 } |
134 | 145 |
135 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { | 146 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { |
136 observer_.Reset(); | 147 observer_.Reset(); |
137 snippet_service_observer_.Remove(ntp_snippets_service_); | 148 snippet_service_observer_.Remove(ntp_snippets_service_); |
138 } | 149 } |
139 | 150 |
140 // static | 151 // static |
141 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 152 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
142 return RegisterNativesImpl(env); | 153 return RegisterNativesImpl(env); |
143 } | 154 } |
OLD | NEW |