| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/ntp_snippets/remote/remote_suggestion.h" | 5 #include "components/ntp_snippets/remote/remote_suggestion.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 } else { | 145 } else { |
| 146 DLOG(WARNING) << "No publisher data for article " << corpus_id_str; | 146 DLOG(WARNING) << "No publisher data for article " << corpus_id_str; |
| 147 } | 147 } |
| 148 | 148 |
| 149 std::string amp_url_str; | 149 std::string amp_url_str; |
| 150 GURL amp_url; | 150 GURL amp_url; |
| 151 // Expected to not have AMP url sometimes. | 151 // Expected to not have AMP url sometimes. |
| 152 if (dict_value->GetString("ampUrl", &_url_str)) { | 152 if (dict_value->GetString("ampUrl", &_url_str)) { |
| 153 amp_url = GURL(amp_url_str); | 153 amp_url = GURL(amp_url_str); |
| 154 DLOG_IF(WARNING, !amp_url.is_valid()) << "Invalid AMP url " | 154 DLOG_IF(WARNING, !amp_url.is_valid()) |
| 155 << amp_url_str; | 155 << "Invalid AMP url " << amp_url_str; |
| 156 } | 156 } |
| 157 sources.emplace_back(corpus_id, site_title, | 157 sources.emplace_back(corpus_id, site_title, |
| 158 amp_url.is_valid() ? amp_url : GURL()); | 158 amp_url.is_valid() ? amp_url : GURL()); |
| 159 // We use the raw string so that we can compare it against other primary | 159 // We use the raw string so that we can compare it against other primary |
| 160 // IDs. Parsing the ID as a URL might add a trailing slash (and we don't do | 160 // IDs. Parsing the ID as a URL might add a trailing slash (and we don't do |
| 161 // this for the primary ID). | 161 // this for the primary ID). |
| 162 ids.push_back(corpus_id_str); | 162 ids.push_back(corpus_id_str); |
| 163 } | 163 } |
| 164 if (sources.empty()) { | 164 if (sources.empty()) { |
| 165 DLOG(WARNING) << "No sources found for article " << primary_id; | 165 DLOG(WARNING) << "No sources found for article " << primary_id; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 const SnippetSourceProto& source_proto = proto.sources(i); | 301 const SnippetSourceProto& source_proto = proto.sources(i); |
| 302 GURL url(source_proto.url()); | 302 GURL url(source_proto.url()); |
| 303 if (!url.is_valid()) { | 303 if (!url.is_valid()) { |
| 304 // We must at least have a valid source URL. | 304 // We must at least have a valid source URL. |
| 305 DLOG(WARNING) << "Invalid article url " << source_proto.url(); | 305 DLOG(WARNING) << "Invalid article url " << source_proto.url(); |
| 306 continue; | 306 continue; |
| 307 } | 307 } |
| 308 GURL amp_url; | 308 GURL amp_url; |
| 309 if (source_proto.has_amp_url()) { | 309 if (source_proto.has_amp_url()) { |
| 310 amp_url = GURL(source_proto.amp_url()); | 310 amp_url = GURL(source_proto.amp_url()); |
| 311 DLOG_IF(WARNING, !amp_url.is_valid()) << "Invalid AMP URL " | 311 DLOG_IF(WARNING, !amp_url.is_valid()) |
| 312 << source_proto.amp_url(); | 312 << "Invalid AMP URL " << source_proto.amp_url(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 sources.emplace_back(url, source_proto.publisher_name(), amp_url); | 315 sources.emplace_back(url, source_proto.publisher_name(), amp_url); |
| 316 } | 316 } |
| 317 | 317 |
| 318 if (sources.empty()) { | 318 if (sources.empty()) { |
| 319 DLOG(WARNING) << "No sources found for article " << snippet->id(); | 319 DLOG(WARNING) << "No sources found for article " << snippet->id(); |
| 320 return nullptr; | 320 return nullptr; |
| 321 } | 321 } |
| 322 const SnippetSource& source = FindBestSource(sources); | 322 const SnippetSource& source = FindBestSource(sources); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 428 } |
| 429 | 429 |
| 430 // static | 430 // static |
| 431 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( | 431 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( |
| 432 const std::vector<std::string>& ids, | 432 const std::vector<std::string>& ids, |
| 433 int remote_category_id) { | 433 int remote_category_id) { |
| 434 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); | 434 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); |
| 435 } | 435 } |
| 436 | 436 |
| 437 } // namespace ntp_snippets | 437 } // namespace ntp_snippets |
| OLD | NEW |