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 "components/ntp_snippets/physical_web_pages/physical_web_page_suggestio
ns_provider.h" | 5 #include "components/ntp_snippets/physical_web_pages/physical_web_page_suggestio
ns_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 UrlInfo::UrlInfo() {} | 21 UrlInfo::UrlInfo() {} |
22 UrlInfo::~UrlInfo() {} | 22 UrlInfo::~UrlInfo() {} |
23 UrlInfo::UrlInfo(const UrlInfo& other) = default; | 23 UrlInfo::UrlInfo(const UrlInfo& other) = default; |
24 | 24 |
25 PhysicalWebPageSuggestionsProvider::PhysicalWebPageSuggestionsProvider( | 25 PhysicalWebPageSuggestionsProvider::PhysicalWebPageSuggestionsProvider( |
26 ContentSuggestionsProvider::Observer* observer, | 26 ContentSuggestionsProvider::Observer* observer, |
27 CategoryFactory* category_factory) | 27 CategoryFactory* category_factory) |
28 : ContentSuggestionsProvider(observer, category_factory), | 28 : ContentSuggestionsProvider(observer, category_factory), |
29 category_status_(CategoryStatus::AVAILABLE_LOADING), | 29 category_status_(CategoryStatus::AVAILABLE_LOADING), |
30 provided_category_(category_factory->FromKnownCategory( | 30 provided_category_(category_factory->FromKnownCategory( |
31 KnownCategories::PHYSICAL_WEB_PAGES)) {} | 31 KnownCategories::PHYSICAL_WEB_PAGES)) { |
| 32 observer->OnCategoryStatusChanged(this, provided_category_, category_status_); |
| 33 } |
32 | 34 |
33 PhysicalWebPageSuggestionsProvider::~PhysicalWebPageSuggestionsProvider() {} | 35 PhysicalWebPageSuggestionsProvider::~PhysicalWebPageSuggestionsProvider() {} |
34 | 36 |
35 void PhysicalWebPageSuggestionsProvider::OnDisplayableUrlsChanged( | 37 void PhysicalWebPageSuggestionsProvider::OnDisplayableUrlsChanged( |
36 const std::vector<UrlInfo>& urls) { | 38 const std::vector<UrlInfo>& urls) { |
37 NotifyStatusChanged(CategoryStatus::AVAILABLE); | 39 NotifyStatusChanged(CategoryStatus::AVAILABLE); |
38 std::vector<ContentSuggestion> suggestions; | 40 std::vector<ContentSuggestion> suggestions; |
39 | 41 |
40 for (const UrlInfo& url_info : urls) { | 42 for (const UrlInfo& url_info : urls) { |
41 if (suggestions.size() >= kMaxSuggestionsCount) break; | 43 if (suggestions.size() >= kMaxSuggestionsCount) break; |
42 | 44 |
43 ContentSuggestion suggestion( | 45 ContentSuggestion suggestion( |
44 MakeUniqueID(provided_category_, url_info.site_url.spec()), | 46 MakeUniqueID(provided_category_, url_info.site_url.spec()), |
45 url_info.site_url); | 47 url_info.site_url); |
46 | 48 |
47 suggestion.set_title(base::UTF8ToUTF16(url_info.title)); | 49 suggestion.set_title(base::UTF8ToUTF16(url_info.title)); |
48 suggestion.set_snippet_text(base::UTF8ToUTF16(url_info.description)); | 50 suggestion.set_snippet_text(base::UTF8ToUTF16(url_info.description)); |
49 suggestion.set_publish_date(url_info.scan_time); | 51 suggestion.set_publish_date(url_info.scan_time); |
50 suggestion.set_publisher_name(base::UTF8ToUTF16(url_info.site_url.host())); | 52 suggestion.set_publisher_name(base::UTF8ToUTF16(url_info.site_url.host())); |
51 suggestions.push_back(std::move(suggestion)); | 53 suggestions.push_back(std::move(suggestion)); |
52 } | 54 } |
53 | 55 |
54 observer()->OnNewSuggestions(this, provided_category_, | 56 observer()->OnNewSuggestions(this, provided_category_, |
55 std::move(suggestions)); | 57 std::move(suggestions)); |
56 } | 58 } |
57 | 59 |
58 std::vector<Category> | |
59 PhysicalWebPageSuggestionsProvider::GetProvidedCategories() { | |
60 return std::vector<Category>({provided_category_}); | |
61 } | |
62 | |
63 CategoryStatus PhysicalWebPageSuggestionsProvider::GetCategoryStatus( | 60 CategoryStatus PhysicalWebPageSuggestionsProvider::GetCategoryStatus( |
64 Category category) { | 61 Category category) { |
65 return category_status_; | 62 return category_status_; |
66 } | 63 } |
67 | 64 |
68 CategoryInfo PhysicalWebPageSuggestionsProvider::GetCategoryInfo( | 65 CategoryInfo PhysicalWebPageSuggestionsProvider::GetCategoryInfo( |
69 Category category) { | 66 Category category) { |
70 // TODO(vitaliii): Use a proper string once it's been agreed on. | 67 // TODO(vitaliii): Use a proper string once it's been agreed on. |
71 return CategoryInfo(base::ASCIIToUTF16("Physical web pages"), | 68 return CategoryInfo(base::ASCIIToUTF16("Physical web pages"), |
72 ContentSuggestionsCardLayout::MINIMAL_CARD, | 69 ContentSuggestionsCardLayout::MINIMAL_CARD, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 104 |
108 // Updates the |category_status_| and notifies the |observer_|, if necessary. | 105 // Updates the |category_status_| and notifies the |observer_|, if necessary. |
109 void PhysicalWebPageSuggestionsProvider::NotifyStatusChanged( | 106 void PhysicalWebPageSuggestionsProvider::NotifyStatusChanged( |
110 CategoryStatus new_status) { | 107 CategoryStatus new_status) { |
111 if (category_status_ == new_status) return; | 108 if (category_status_ == new_status) return; |
112 category_status_ = new_status; | 109 category_status_ = new_status; |
113 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 110 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
114 } | 111 } |
115 | 112 |
116 } // namespace ntp_snippets | 113 } // namespace ntp_snippets |
OLD | NEW |