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

Side by Side Diff: components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc

Issue 2377663002: [NTP Snippets] Introduce ContentSuggestion::ID (Closed)
Patch Set: . 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/bookmarks/bookmark_suggestions_provider.h" 5 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return CategoryInfo( 147 return CategoryInfo(
148 l10n_util::GetStringUTF16(IDS_NTP_BOOKMARK_SUGGESTIONS_SECTION_HEADER), 148 l10n_util::GetStringUTF16(IDS_NTP_BOOKMARK_SUGGESTIONS_SECTION_HEADER),
149 ContentSuggestionsCardLayout::MINIMAL_CARD, 149 ContentSuggestionsCardLayout::MINIMAL_CARD,
150 /*has_more_button=*/true, 150 /*has_more_button=*/true,
151 /*show_if_empty=*/ShouldShowIfEmpty() && bookmark_model_->HasBookmarks()); 151 /*show_if_empty=*/ShouldShowIfEmpty() && bookmark_model_->HasBookmarks());
152 // TODO(treib): Setting show_if_empty to true is a temporary hack, see 152 // TODO(treib): Setting show_if_empty to true is a temporary hack, see
153 // crbug.com/640568. 153 // crbug.com/640568.
154 } 154 }
155 155
156 void BookmarkSuggestionsProvider::DismissSuggestion( 156 void BookmarkSuggestionsProvider::DismissSuggestion(
157 const std::string& suggestion_id) { 157 const ContentSuggestion::ID& suggestion_id) {
158 DCHECK(bookmark_model_->loaded()); 158 DCHECK(bookmark_model_->loaded());
159 GURL url(GetWithinCategoryIDFromUniqueID(suggestion_id)); 159 GURL url(suggestion_id.within_category_id());
160 MarkBookmarksDismissed(bookmark_model_, url); 160 MarkBookmarksDismissed(bookmark_model_, url);
161 } 161 }
162 162
163 void BookmarkSuggestionsProvider::FetchSuggestionImage( 163 void BookmarkSuggestionsProvider::FetchSuggestionImage(
164 const std::string& suggestion_id, 164 const ContentSuggestion::ID& suggestion_id,
165 const ImageFetchedCallback& callback) { 165 const ImageFetchedCallback& callback) {
166 base::ThreadTaskRunnerHandle::Get()->PostTask( 166 base::ThreadTaskRunnerHandle::Get()->PostTask(
167 FROM_HERE, base::Bind(callback, gfx::Image())); 167 FROM_HERE, base::Bind(callback, gfx::Image()));
168 } 168 }
169 169
170 void BookmarkSuggestionsProvider::ClearHistory( 170 void BookmarkSuggestionsProvider::ClearHistory(
171 base::Time begin, 171 base::Time begin,
172 base::Time end, 172 base::Time end,
173 const base::Callback<bool(const GURL& url)>& filter) { 173 const base::Callback<bool(const GURL& url)>& filter) {
174 // TODO(vitaliii): Do not remove all dates, but only the ones matched by the 174 // TODO(vitaliii): Do not remove all dates, but only the ones matched by the
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 end_of_list_last_visit_date_) { 253 end_of_list_last_visit_date_) {
254 return; 254 return;
255 } 255 }
256 256
257 // Some node from our list got deleted, we should update the suggestions. 257 // Some node from our list got deleted, we should update the suggestions.
258 FetchBookmarks(); 258 FetchBookmarks();
259 } 259 }
260 260
261 ContentSuggestion BookmarkSuggestionsProvider::ConvertBookmark( 261 ContentSuggestion BookmarkSuggestionsProvider::ConvertBookmark(
262 const BookmarkNode* bookmark) { 262 const BookmarkNode* bookmark) {
263 ContentSuggestion suggestion( 263 ContentSuggestion suggestion(provided_category_, bookmark->url().spec(),
264 MakeUniqueID(provided_category_, bookmark->url().spec()), 264 bookmark->url());
265 bookmark->url());
266 265
267 suggestion.set_title(bookmark->GetTitle()); 266 suggestion.set_title(bookmark->GetTitle());
268 suggestion.set_snippet_text(base::string16()); 267 suggestion.set_snippet_text(base::string16());
269 suggestion.set_publish_date( 268 suggestion.set_publish_date(
270 GetLastVisitDateForBookmark(bookmark, creation_date_fallback_)); 269 GetLastVisitDateForBookmark(bookmark, creation_date_fallback_));
271 suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host())); 270 suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host()));
272 return suggestion; 271 return suggestion;
273 } 272 }
274 273
275 void BookmarkSuggestionsProvider::FetchBookmarksInternal() { 274 void BookmarkSuggestionsProvider::FetchBookmarksInternal() {
(...skipping 28 matching lines...) Expand all
304 303
305 void BookmarkSuggestionsProvider::NotifyStatusChanged( 304 void BookmarkSuggestionsProvider::NotifyStatusChanged(
306 CategoryStatus new_status) { 305 CategoryStatus new_status) {
307 if (category_status_ == new_status) 306 if (category_status_ == new_status)
308 return; 307 return;
309 category_status_ = new_status; 308 category_status_ = new_status;
310 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 309 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
311 } 310 }
312 311
313 } // namespace ntp_snippets 312 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698