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

Side by Side Diff: components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc

Issue 2780793002: Add extra information for ReadingList ContentSuggestion (Closed)
Patch Set: Address comments Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/reading_list/reading_list_suggestions_provider .h" 5 #include "components/ntp_snippets/reading_list/reading_list_suggestions_provider .h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/ntp_snippets/category.h" 14 #include "components/ntp_snippets/category.h"
15 #include "components/ntp_snippets/reading_list/reading_list_distillation_state_u til.h"
14 #include "components/reading_list/core/reading_list_entry.h" 16 #include "components/reading_list/core/reading_list_entry.h"
15 #include "components/reading_list/core/reading_list_model.h" 17 #include "components/reading_list/core/reading_list_model.h"
16 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
17 #include "components/url_formatter/url_formatter.h" 19 #include "components/url_formatter/url_formatter.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 21
20 namespace ntp_snippets { 22 namespace ntp_snippets {
21 23
22 namespace { 24 namespace {
23 // Max number of entries to return. 25 // Max number of entries to return.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Get the |kMaxEntries| most recent entries. 144 // Get the |kMaxEntries| most recent entries.
143 std::partial_sort(entries.begin(), entries.begin() + kMaxEntries, 145 std::partial_sort(entries.begin(), entries.begin() + kMaxEntries,
144 entries.end(), CompareEntries); 146 entries.end(), CompareEntries);
145 entries.resize(kMaxEntries); 147 entries.resize(kMaxEntries);
146 } else { 148 } else {
147 std::sort(entries.begin(), entries.end(), CompareEntries); 149 std::sort(entries.begin(), entries.end(), CompareEntries);
148 } 150 }
149 151
150 std::vector<ContentSuggestion> suggestions; 152 std::vector<ContentSuggestion> suggestions;
151 for (const ReadingListEntry* entry : entries) { 153 for (const ReadingListEntry* entry : entries) {
152 ContentSuggestion suggestion(provided_category_, entry->URL().spec(), 154 suggestions.emplace_back(ConvertEntry(entry));
153 entry->URL());
154
155 suggestion.set_title(base::UTF8ToUTF16(entry->Title()));
156 suggestion.set_snippet_text(
157 url_formatter::FormatUrl(entry->URL().GetOrigin()));
158 suggestions.emplace_back(std::move(suggestion));
159 } 155 }
160 156
161 NotifyStatusChanged(CategoryStatus::AVAILABLE); 157 NotifyStatusChanged(CategoryStatus::AVAILABLE);
162 observer()->OnNewSuggestions(this, provided_category_, 158 observer()->OnNewSuggestions(this, provided_category_,
163 std::move(suggestions)); 159 std::move(suggestions));
164 } 160 }
165 161
162 ContentSuggestion ReadingListSuggestionsProvider::ConvertEntry(
163 const ReadingListEntry* entry) {
164 ContentSuggestion suggestion(provided_category_, entry->URL().spec(),
165 entry->URL());
166 suggestion.set_title(base::UTF8ToUTF16(entry->Title()));
167 suggestion.set_snippet_text(
Marc Treib 2017/03/29 08:24:58 As per the comment on the other CL, I think this s
gambard 2017/03/29 09:54:07 Wasn't rebased yet. Done.
168 url_formatter::FormatUrl(entry->URL().GetOrigin()));
169
170 auto extra = base::MakeUnique<ReadingListSuggestionExtra>();
171 extra->distilled_state =
172 SuggestionStateFromReadingListState(entry->DistilledState());
173 extra->favicon_page_url =
174 entry->DistilledURL().is_valid() ? entry->DistilledURL() : entry->URL();
175 suggestion.set_reading_list_suggestion_extra(std::move(extra));
176
177 return suggestion;
178 }
179
166 void ReadingListSuggestionsProvider::NotifyStatusChanged( 180 void ReadingListSuggestionsProvider::NotifyStatusChanged(
167 CategoryStatus new_status) { 181 CategoryStatus new_status) {
168 if (category_status_ == new_status) { 182 if (category_status_ == new_status) {
169 return; 183 return;
170 } 184 }
171 category_status_ = new_status; 185 category_status_ = new_status;
172 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 186 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
173 } 187 }
174 188
175 } // namespace ntp_snippets 189 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698