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

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

Issue 2815623002: ReadingListProvider handles dismissal (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"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_HEADER), 63 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_HEADER),
64 ContentSuggestionsCardLayout::FULL_CARD, 64 ContentSuggestionsCardLayout::FULL_CARD,
65 ContentSuggestionsAdditionalAction::VIEW_ALL, 65 ContentSuggestionsAdditionalAction::VIEW_ALL,
66 /*show_if_empty=*/false, 66 /*show_if_empty=*/false,
67 l10n_util::GetStringUTF16( 67 l10n_util::GetStringUTF16(
68 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_EMPTY)); 68 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_EMPTY));
69 } 69 }
70 70
71 void ReadingListSuggestionsProvider::DismissSuggestion( 71 void ReadingListSuggestionsProvider::DismissSuggestion(
72 const ContentSuggestion::ID& suggestion_id) { 72 const ContentSuggestion::ID& suggestion_id) {
73 // TODO(crbug.com/702241): Implement this method. 73 DCHECK(reading_list_model_->loaded());
74 GURL url(suggestion_id.id_within_category());
75 SetDismissedState(url, true);
74 } 76 }
75 77
76 void ReadingListSuggestionsProvider::FetchSuggestionImage( 78 void ReadingListSuggestionsProvider::FetchSuggestionImage(
77 const ContentSuggestion::ID& suggestion_id, 79 const ContentSuggestion::ID& suggestion_id,
78 const ImageFetchedCallback& callback) { 80 const ImageFetchedCallback& callback) {
79 base::ThreadTaskRunnerHandle::Get()->PostTask( 81 base::ThreadTaskRunnerHandle::Get()->PostTask(
80 FROM_HERE, base::Bind(callback, gfx::Image())); 82 FROM_HERE, base::Bind(callback, gfx::Image()));
81 } 83 }
82 84
83 void ReadingListSuggestionsProvider::Fetch( 85 void ReadingListSuggestionsProvider::Fetch(
84 const Category& category, 86 const Category& category,
85 const std::set<std::string>& known_suggestion_ids, 87 const std::set<std::string>& known_suggestion_ids,
86 const FetchDoneCallback& callback) { 88 const FetchDoneCallback& callback) {
87 LOG(DFATAL) << "ReadingListSuggestionsProvider has no |Fetch| functionality!"; 89 LOG(DFATAL) << "ReadingListSuggestionsProvider has no |Fetch| functionality!";
88 base::ThreadTaskRunnerHandle::Get()->PostTask( 90 base::ThreadTaskRunnerHandle::Get()->PostTask(
89 FROM_HERE, 91 FROM_HERE,
90 base::Bind(callback, 92 base::Bind(callback,
91 Status(StatusCode::PERMANENT_ERROR, 93 Status(StatusCode::PERMANENT_ERROR,
92 "ReadingListSuggestionsProvider has no |Fetch| " 94 "ReadingListSuggestionsProvider has no |Fetch| "
93 "functionality!"), 95 "functionality!"),
94 base::Passed(std::vector<ContentSuggestion>()))); 96 base::Passed(std::vector<ContentSuggestion>())));
95 } 97 }
96 98
97 void ReadingListSuggestionsProvider::ClearHistory( 99 void ReadingListSuggestionsProvider::ClearHistory(
98 base::Time begin, 100 base::Time begin,
99 base::Time end, 101 base::Time end,
100 const base::Callback<bool(const GURL& url)>& filter) { 102 const base::Callback<bool(const GURL& url)>& filter) {
101 // TODO(crbug.com/702241): Implement this method. 103 // Ignored, Reading List does not depend on history.
102 } 104 }
103 105
104 void ReadingListSuggestionsProvider::ClearCachedSuggestions(Category category) { 106 void ReadingListSuggestionsProvider::ClearCachedSuggestions(Category category) {
105 DCHECK_EQ(category, provided_category_); 107 DCHECK_EQ(category, provided_category_);
106 // Ignored. 108 // Ignored.
107 } 109 }
108 110
109 void ReadingListSuggestionsProvider::GetDismissedSuggestionsForDebugging( 111 void ReadingListSuggestionsProvider::GetDismissedSuggestionsForDebugging(
110 Category category, 112 Category category,
111 const DismissedSuggestionsCallback& callback) { 113 const DismissedSuggestionsCallback& callback) {
112 // TODO(crbug.com/702241): Implement this method. 114 if (!reading_list_model_ || reading_list_model_->IsPerformingBatchUpdates()) {
Marc Treib 2017/04/11 13:41:09 Can reading_list_model_ be null?
gambard 2017/04/11 15:01:18 Yes. Looks at ReadingListSuggestionsProvider::Read
115 return;
Marc Treib 2017/04/11 13:41:09 Should probably still call the callback with an em
gambard 2017/04/11 15:01:18 Done.
116 }
117
118 DCHECK(reading_list_model_->loaded());
119 std::vector<const ReadingListEntry*> entries;
120 for (const GURL& url : reading_list_model_->Keys()) {
121 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
122 if (entry->ContentSuggestionsExtra()->dismissed) {
123 entries.emplace_back(entry);
124 }
125 }
126
127 std::sort(entries.begin(), entries.end(), CompareEntries);
128
129 std::vector<ContentSuggestion> suggestions;
130 for (const ReadingListEntry* entry : entries) {
131 suggestions.emplace_back(ConvertEntry(entry));
132 }
133
134 callback.Run(std::vector<ContentSuggestion>());
113 } 135 }
136
114 void ReadingListSuggestionsProvider::ClearDismissedSuggestionsForDebugging( 137 void ReadingListSuggestionsProvider::ClearDismissedSuggestionsForDebugging(
115 Category category) { 138 Category category) {
116 // TODO(crbug.com/702241): Implement this method. 139 for (const auto& url : reading_list_model_->Keys()) {
140 SetDismissedState(url, false);
141 }
117 } 142 }
118 143
119 void ReadingListSuggestionsProvider::ReadingListModelLoaded( 144 void ReadingListSuggestionsProvider::ReadingListModelLoaded(
120 const ReadingListModel* model) { 145 const ReadingListModel* model) {
121 DCHECK(model == reading_list_model_); 146 DCHECK(model == reading_list_model_);
122 FetchReadingListInternal(); 147 FetchReadingListInternal();
123 } 148 }
124 149
125 void ReadingListSuggestionsProvider::ReadingListModelBeingDeleted( 150 void ReadingListSuggestionsProvider::ReadingListModelBeingDeleted(
126 const ReadingListModel* model) { 151 const ReadingListModel* model) {
(...skipping 18 matching lines...) Expand all
145 170
146 void ReadingListSuggestionsProvider::FetchReadingListInternal() { 171 void ReadingListSuggestionsProvider::FetchReadingListInternal() {
147 if (!reading_list_model_ || reading_list_model_->IsPerformingBatchUpdates()) { 172 if (!reading_list_model_ || reading_list_model_->IsPerformingBatchUpdates()) {
148 return; 173 return;
149 } 174 }
150 175
151 DCHECK(reading_list_model_->loaded()); 176 DCHECK(reading_list_model_->loaded());
152 std::vector<const ReadingListEntry*> entries; 177 std::vector<const ReadingListEntry*> entries;
153 for (const GURL& url : reading_list_model_->Keys()) { 178 for (const GURL& url : reading_list_model_->Keys()) {
154 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); 179 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
155 if (!entry->IsRead()) { 180 if (!entry->IsRead() && !entry->ContentSuggestionsExtra()->dismissed) {
156 entries.emplace_back(entry); 181 entries.emplace_back(entry);
157 } 182 }
158 } 183 }
159 184
160 if (entries.size() > kMaxEntries) { 185 if (entries.size() > kMaxEntries) {
161 // Get the |kMaxEntries| most recent entries. 186 // Get the |kMaxEntries| most recent entries.
162 std::partial_sort(entries.begin(), entries.begin() + kMaxEntries, 187 std::partial_sort(entries.begin(), entries.begin() + kMaxEntries,
163 entries.end(), CompareEntries); 188 entries.end(), CompareEntries);
164 entries.resize(kMaxEntries); 189 entries.resize(kMaxEntries);
165 } else { 190 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 226
202 void ReadingListSuggestionsProvider::NotifyStatusChanged( 227 void ReadingListSuggestionsProvider::NotifyStatusChanged(
203 CategoryStatus new_status) { 228 CategoryStatus new_status) {
204 if (category_status_ == new_status) { 229 if (category_status_ == new_status) {
205 return; 230 return;
206 } 231 }
207 category_status_ = new_status; 232 category_status_ = new_status;
208 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 233 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
209 } 234 }
210 235
236 void ReadingListSuggestionsProvider::SetDismissedState(const GURL& url,
237 bool dismissed) {
238 reading_list::ContentSuggestionsExtra extra;
239 extra.dismissed = dismissed;
240 reading_list_model_->SetContentSuggestionsExtra(url, extra);
241 }
242
211 } // namespace ntp_snippets 243 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698