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

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

Issue 2865183003: Use the same design for all suggestions (Closed)
Patch Set: Address comments Created 3 years, 7 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/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/time/time.h"
14 #include "components/ntp_snippets/category.h" 15 #include "components/ntp_snippets/category.h"
15 #include "components/ntp_snippets/reading_list/reading_list_distillation_state_u til.h"
16 #include "components/reading_list/core/reading_list_entry.h" 16 #include "components/reading_list/core/reading_list_entry.h"
17 #include "components/reading_list/core/reading_list_model.h" 17 #include "components/reading_list/core/reading_list_model.h"
18 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
19 #include "components/url_formatter/url_formatter.h" 19 #include "components/url_formatter/url_formatter.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
22 22
23 namespace ntp_snippets { 23 namespace ntp_snippets {
24 24
25 namespace { 25 namespace {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ContentSuggestion suggestion(provided_category_, entry->URL().spec(), 211 ContentSuggestion suggestion(provided_category_, entry->URL().spec(),
212 entry->URL()); 212 entry->URL());
213 213
214 if (!entry->Title().empty()) { 214 if (!entry->Title().empty()) {
215 suggestion.set_title(base::UTF8ToUTF16(entry->Title())); 215 suggestion.set_title(base::UTF8ToUTF16(entry->Title()));
216 } else { 216 } else {
217 suggestion.set_title(url_formatter::FormatUrl(entry->URL())); 217 suggestion.set_title(url_formatter::FormatUrl(entry->URL()));
218 } 218 }
219 suggestion.set_publisher_name( 219 suggestion.set_publisher_name(
220 url_formatter::FormatUrl(entry->URL().GetOrigin())); 220 url_formatter::FormatUrl(entry->URL().GetOrigin()));
221 int64_t entry_time =
222 entry->DistillationTime() / base::Time::kMicrosecondsPerSecond;
Marc Treib 2017/05/11 09:05:05 Any reason DistillationTime is an int64 rather tha
gambard 2017/05/11 11:13:37 I am not sure. The comment says "to avoid conversi
223 if (entry_time == 0) {
Marc Treib 2017/05/11 09:05:05 Check DistillationTime() == 0 directly, before doi
gambard 2017/05/11 11:13:37 Done.
224 entry_time = entry->CreationTime() / base::Time::kMicrosecondsPerSecond;
225 }
226
227 suggestion.set_publish_date(base::Time::FromDoubleT(entry_time));
221 228
222 auto extra = base::MakeUnique<ReadingListSuggestionExtra>(); 229 auto extra = base::MakeUnique<ReadingListSuggestionExtra>();
223 extra->distilled_state = 230 extra->distilled = entry->DistilledState() == ReadingListEntry::PROCESSED;
224 SuggestionStateFromReadingListState(entry->DistilledState());
225 extra->favicon_page_url = 231 extra->favicon_page_url =
226 entry->DistilledURL().is_valid() ? entry->DistilledURL() : entry->URL(); 232 entry->DistilledURL().is_valid() ? entry->DistilledURL() : entry->URL();
227 suggestion.set_reading_list_suggestion_extra(std::move(extra)); 233 suggestion.set_reading_list_suggestion_extra(std::move(extra));
228 234
229 return suggestion; 235 return suggestion;
230 } 236 }
231 237
232 void ReadingListSuggestionsProvider::NotifyStatusChanged( 238 void ReadingListSuggestionsProvider::NotifyStatusChanged(
233 CategoryStatus new_status) { 239 CategoryStatus new_status) {
234 if (category_status_ == new_status) { 240 if (category_status_ == new_status) {
235 return; 241 return;
236 } 242 }
237 category_status_ = new_status; 243 category_status_ = new_status;
238 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 244 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
239 } 245 }
240 246
241 void ReadingListSuggestionsProvider::SetDismissedState(const GURL& url, 247 void ReadingListSuggestionsProvider::SetDismissedState(const GURL& url,
242 bool dismissed) { 248 bool dismissed) {
243 reading_list::ContentSuggestionsExtra extra; 249 reading_list::ContentSuggestionsExtra extra;
244 extra.dismissed = dismissed; 250 extra.dismissed = dismissed;
245 reading_list_model_->SetContentSuggestionsExtra(url, extra); 251 reading_list_model_->SetContentSuggestionsExtra(url, extra);
246 } 252 }
247 253
248 } // namespace ntp_snippets 254 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698