Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider.cc

Issue 2377663002: [NTP Snippets] Introduce ContentSuggestion::ID (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
38 default; 38 default;
39 39
40 void PhysicalWebPageSuggestionsProvider::OnDisplayableUrlsChanged( 40 void PhysicalWebPageSuggestionsProvider::OnDisplayableUrlsChanged(
41 const std::vector<UrlInfo>& urls) { 41 const std::vector<UrlInfo>& urls) {
42 NotifyStatusChanged(CategoryStatus::AVAILABLE); 42 NotifyStatusChanged(CategoryStatus::AVAILABLE);
43 std::vector<ContentSuggestion> suggestions; 43 std::vector<ContentSuggestion> suggestions;
44 44
45 for (const UrlInfo& url_info : urls) { 45 for (const UrlInfo& url_info : urls) {
46 if (suggestions.size() >= kMaxSuggestionsCount) break; 46 if (suggestions.size() >= kMaxSuggestionsCount) break;
47 47
48 ContentSuggestion suggestion( 48 ContentSuggestion suggestion(provided_category_, url_info.site_url.spec(),
49 MakeUniqueID(provided_category_, url_info.site_url.spec()), 49 url_info.site_url);
50 url_info.site_url);
51 50
52 suggestion.set_title(base::UTF8ToUTF16(url_info.title)); 51 suggestion.set_title(base::UTF8ToUTF16(url_info.title));
53 suggestion.set_snippet_text(base::UTF8ToUTF16(url_info.description)); 52 suggestion.set_snippet_text(base::UTF8ToUTF16(url_info.description));
54 suggestion.set_publish_date(url_info.scan_time); 53 suggestion.set_publish_date(url_info.scan_time);
55 suggestion.set_publisher_name(base::UTF8ToUTF16(url_info.site_url.host())); 54 suggestion.set_publisher_name(base::UTF8ToUTF16(url_info.site_url.host()));
56 suggestions.push_back(std::move(suggestion)); 55 suggestions.push_back(std::move(suggestion));
57 } 56 }
58 57
59 observer()->OnNewSuggestions(this, provided_category_, 58 observer()->OnNewSuggestions(this, provided_category_,
60 std::move(suggestions)); 59 std::move(suggestions));
61 } 60 }
62 61
63 CategoryStatus PhysicalWebPageSuggestionsProvider::GetCategoryStatus( 62 CategoryStatus PhysicalWebPageSuggestionsProvider::GetCategoryStatus(
64 Category category) { 63 Category category) {
65 return category_status_; 64 return category_status_;
66 } 65 }
67 66
68 CategoryInfo PhysicalWebPageSuggestionsProvider::GetCategoryInfo( 67 CategoryInfo PhysicalWebPageSuggestionsProvider::GetCategoryInfo(
69 Category category) { 68 Category category) {
70 // TODO(vitaliii): Use a proper string once it's been agreed on. 69 // TODO(vitaliii): Use a proper string once it's been agreed on.
71 return CategoryInfo(base::ASCIIToUTF16("Physical web pages"), 70 return CategoryInfo(base::ASCIIToUTF16("Physical web pages"),
72 ContentSuggestionsCardLayout::MINIMAL_CARD, 71 ContentSuggestionsCardLayout::MINIMAL_CARD,
73 /* has_more_button */ true, 72 /* has_more_button */ true,
74 /* show_if_empty */ false); 73 /* show_if_empty */ false);
75 } 74 }
76 75
77 void PhysicalWebPageSuggestionsProvider::DismissSuggestion( 76 void PhysicalWebPageSuggestionsProvider::DismissSuggestion(
78 const std::string& suggestion_id) { 77 const ContentSuggestion::ID& suggestion_id) {
79 // TODO(vitaliii): Implement this and then 78 // TODO(vitaliii): Implement this and then
80 // ClearDismissedSuggestionsForDebugging. 79 // ClearDismissedSuggestionsForDebugging.
81 } 80 }
82 81
83 void PhysicalWebPageSuggestionsProvider::FetchSuggestionImage( 82 void PhysicalWebPageSuggestionsProvider::FetchSuggestionImage(
84 const std::string& suggestion_id, const ImageFetchedCallback& callback) { 83 const ContentSuggestion::ID& suggestion_id,
84 const ImageFetchedCallback& callback) {
85 // TODO(vitaliii): Implement. 85 // TODO(vitaliii): Implement.
86 base::ThreadTaskRunnerHandle::Get()->PostTask( 86 base::ThreadTaskRunnerHandle::Get()->PostTask(
87 FROM_HERE, base::Bind(callback, gfx::Image())); 87 FROM_HERE, base::Bind(callback, gfx::Image()));
88 } 88 }
89 89
90 void PhysicalWebPageSuggestionsProvider::ClearHistory( 90 void PhysicalWebPageSuggestionsProvider::ClearHistory(
91 base::Time begin, 91 base::Time begin,
92 base::Time end, 92 base::Time end,
93 const base::Callback<bool(const GURL& url)>& filter) { 93 const base::Callback<bool(const GURL& url)>& filter) {
94 ClearDismissedSuggestionsForDebugging(provided_category_); 94 ClearDismissedSuggestionsForDebugging(provided_category_);
(...skipping 21 matching lines...) Expand all
116 116
117 // Updates the |category_status_| and notifies the |observer_|, if necessary. 117 // Updates the |category_status_| and notifies the |observer_|, if necessary.
118 void PhysicalWebPageSuggestionsProvider::NotifyStatusChanged( 118 void PhysicalWebPageSuggestionsProvider::NotifyStatusChanged(
119 CategoryStatus new_status) { 119 CategoryStatus new_status) {
120 if (category_status_ == new_status) return; 120 if (category_status_ == new_status) return;
121 category_status_ = new_status; 121 category_status_ = new_status;
122 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 122 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
123 } 123 }
124 124
125 } // namespace ntp_snippets 125 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698