| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 PhysicalWebPageSuggestionsProvider::~PhysicalWebPageSuggestionsProvider() = | 41 PhysicalWebPageSuggestionsProvider::~PhysicalWebPageSuggestionsProvider() = |
| 42 default; | 42 default; |
| 43 | 43 |
| 44 void PhysicalWebPageSuggestionsProvider::OnDisplayableUrlsChanged( | 44 void PhysicalWebPageSuggestionsProvider::OnDisplayableUrlsChanged( |
| 45 const std::vector<UrlInfo>& urls) { | 45 const std::vector<UrlInfo>& urls) { |
| 46 NotifyStatusChanged(CategoryStatus::AVAILABLE); | 46 NotifyStatusChanged(CategoryStatus::AVAILABLE); |
| 47 std::vector<ContentSuggestion> suggestions; | 47 std::vector<ContentSuggestion> suggestions; |
| 48 | 48 |
| 49 for (const UrlInfo& url_info : urls) { | 49 for (const UrlInfo& url_info : urls) { |
| 50 if (suggestions.size() >= kMaxSuggestionsCount) break; | 50 if (suggestions.size() >= kMaxSuggestionsCount) { |
| 51 break; |
| 52 } |
| 51 | 53 |
| 52 ContentSuggestion suggestion(provided_category_, url_info.site_url.spec(), | 54 ContentSuggestion suggestion(provided_category_, url_info.site_url.spec(), |
| 53 url_info.site_url); | 55 url_info.site_url); |
| 54 | 56 |
| 55 suggestion.set_title(base::UTF8ToUTF16(url_info.title)); | 57 suggestion.set_title(base::UTF8ToUTF16(url_info.title)); |
| 56 suggestion.set_snippet_text(base::UTF8ToUTF16(url_info.description)); | 58 suggestion.set_snippet_text(base::UTF8ToUTF16(url_info.description)); |
| 57 suggestion.set_publish_date(url_info.scan_time); | 59 suggestion.set_publish_date(url_info.scan_time); |
| 58 suggestion.set_publisher_name(base::UTF8ToUTF16(url_info.site_url.host())); | 60 suggestion.set_publisher_name(base::UTF8ToUTF16(url_info.site_url.host())); |
| 59 suggestions.push_back(std::move(suggestion)); | 61 suggestions.push_back(std::move(suggestion)); |
| 60 } | 62 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 Category category) { | 134 Category category) { |
| 133 // TODO(vitaliii): Implement when dismissed suggestions are supported. | 135 // TODO(vitaliii): Implement when dismissed suggestions are supported. |
| 134 } | 136 } |
| 135 | 137 |
| 136 //////////////////////////////////////////////////////////////////////////////// | 138 //////////////////////////////////////////////////////////////////////////////// |
| 137 // Private methods | 139 // Private methods |
| 138 | 140 |
| 139 // Updates the |category_status_| and notifies the |observer_|, if necessary. | 141 // Updates the |category_status_| and notifies the |observer_|, if necessary. |
| 140 void PhysicalWebPageSuggestionsProvider::NotifyStatusChanged( | 142 void PhysicalWebPageSuggestionsProvider::NotifyStatusChanged( |
| 141 CategoryStatus new_status) { | 143 CategoryStatus new_status) { |
| 142 if (category_status_ == new_status) return; | 144 if (category_status_ == new_status) { |
| 145 return; |
| 146 } |
| 143 category_status_ = new_status; | 147 category_status_ = new_status; |
| 144 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 148 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
| 145 } | 149 } |
| 146 | 150 |
| 147 } // namespace ntp_snippets | 151 } // namespace ntp_snippets |
| OLD | NEW |