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" | |
8 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 11 #include "base/values.h" |
13 #include "components/ntp_snippets/category.h" | 12 #include "components/ntp_snippets/category.h" |
14 #include "components/ntp_snippets/features.h" | |
15 #include "components/ntp_snippets/remote/proto/ntp_snippets.pb.h" | 13 #include "components/ntp_snippets/remote/proto/ntp_snippets.pb.h" |
16 | 14 |
17 namespace { | 15 namespace { |
18 | 16 |
19 struct SnippetSource { | 17 struct SnippetSource { |
20 SnippetSource(const GURL& url, | 18 SnippetSource(const GURL& url, |
21 const std::string& publisher_name, | 19 const std::string& publisher_name, |
22 const GURL& amp_url) | 20 const GURL& amp_url) |
23 : url(url), publisher_name(publisher_name), amp_url(amp_url) {} | 21 : url(url), publisher_name(publisher_name), amp_url(amp_url) {} |
24 GURL url; | 22 GURL url; |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 380 |
383 if (!fetch_date_.is_null()) { | 381 if (!fetch_date_.is_null()) { |
384 result.set_fetch_date(fetch_date_.ToInternalValue()); | 382 result.set_fetch_date(fetch_date_.ToInternalValue()); |
385 } | 383 } |
386 return result; | 384 return result; |
387 } | 385 } |
388 | 386 |
389 ContentSuggestion RemoteSuggestion::ToContentSuggestion( | 387 ContentSuggestion RemoteSuggestion::ToContentSuggestion( |
390 Category category) const { | 388 Category category) const { |
391 GURL url = url_; | 389 GURL url = url_; |
392 bool use_amp = base::FeatureList::IsEnabled(kPreferAmpUrlsFeature) && | 390 bool use_amp = !amp_url_.is_empty(); |
393 !amp_url_.is_empty(); | |
394 if (use_amp) { | 391 if (use_amp) { |
395 url = amp_url_; | 392 url = amp_url_; |
396 } | 393 } |
397 ContentSuggestion suggestion(category, id(), url); | 394 ContentSuggestion suggestion(category, id(), url); |
398 // Set url for fetching favicons if it differs from the main url (domains of | 395 // Set url for fetching favicons if it differs from the main url (domains of |
399 // AMP URLs sometimes failed to provide favicons). | 396 // AMP URLs sometimes failed to provide favicons). |
400 if (use_amp) { | 397 if (use_amp) { |
401 suggestion.set_url_with_favicon(url_); | 398 suggestion.set_url_with_favicon(url_); |
402 } | 399 } |
403 suggestion.set_title(base::UTF8ToUTF16(title_)); | 400 suggestion.set_title(base::UTF8ToUTF16(title_)); |
(...skipping 30 matching lines...) Expand all Loading... |
434 } | 431 } |
435 | 432 |
436 // static | 433 // static |
437 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( | 434 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( |
438 const std::vector<std::string>& ids, | 435 const std::vector<std::string>& ids, |
439 int remote_category_id) { | 436 int remote_category_id) { |
440 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); | 437 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); |
441 } | 438 } |
442 | 439 |
443 } // namespace ntp_snippets | 440 } // namespace ntp_snippets |
OLD | NEW |