| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 382 |
| 383 if (!fetch_date_.is_null()) { | 383 if (!fetch_date_.is_null()) { |
| 384 result.set_fetch_date(fetch_date_.ToInternalValue()); | 384 result.set_fetch_date(fetch_date_.ToInternalValue()); |
| 385 } | 385 } |
| 386 return result; | 386 return result; |
| 387 } | 387 } |
| 388 | 388 |
| 389 ContentSuggestion RemoteSuggestion::ToContentSuggestion( | 389 ContentSuggestion RemoteSuggestion::ToContentSuggestion( |
| 390 Category category) const { | 390 Category category) const { |
| 391 GURL url = url_; | 391 GURL url = url_; |
| 392 if (base::FeatureList::IsEnabled(kPreferAmpUrlsFeature) && | 392 bool use_amp = base::FeatureList::IsEnabled(kPreferAmpUrlsFeature) && |
| 393 !amp_url_.is_empty()) { | 393 !amp_url_.is_empty(); |
| 394 if (use_amp) { |
| 394 url = amp_url_; | 395 url = amp_url_; |
| 395 } | 396 } |
| 396 ContentSuggestion suggestion(category, id(), url); | 397 ContentSuggestion suggestion(category, id(), url); |
| 398 // Set url for fetching favicons if it differs from the main url (domains of |
| 399 // AMP URLs sometimes failed to provide favicons). |
| 400 if (use_amp) { |
| 401 suggestion.set_url_with_favicon(url_); |
| 402 } |
| 397 suggestion.set_title(base::UTF8ToUTF16(title_)); | 403 suggestion.set_title(base::UTF8ToUTF16(title_)); |
| 398 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet_)); | 404 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet_)); |
| 399 suggestion.set_publish_date(publish_date_); | 405 suggestion.set_publish_date(publish_date_); |
| 400 suggestion.set_publisher_name(base::UTF8ToUTF16(publisher_name_)); | 406 suggestion.set_publisher_name(base::UTF8ToUTF16(publisher_name_)); |
| 401 suggestion.set_score(score_); | 407 suggestion.set_score(score_); |
| 402 if (should_notify_) { | 408 if (should_notify_) { |
| 403 NotificationExtra extra; | 409 NotificationExtra extra; |
| 404 extra.deadline = notification_deadline_; | 410 extra.deadline = notification_deadline_; |
| 405 suggestion.set_notification_extra( | 411 suggestion.set_notification_extra( |
| 406 base::MakeUnique<NotificationExtra>(extra)); | 412 base::MakeUnique<NotificationExtra>(extra)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 428 } | 434 } |
| 429 | 435 |
| 430 // static | 436 // static |
| 431 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( | 437 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( |
| 432 const std::vector<std::string>& ids, | 438 const std::vector<std::string>& ids, |
| 433 int remote_category_id) { | 439 int remote_category_id) { |
| 434 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); | 440 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); |
| 435 } | 441 } |
| 436 | 442 |
| 437 } // namespace ntp_snippets | 443 } // namespace ntp_snippets |
| OLD | NEW |