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

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

Issue 2222933002: Make bookmark suggestions dismissable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix CL dependency Created 4 years, 4 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 CategoryStatus BookmarkSuggestionsProvider::GetCategoryStatus( 62 CategoryStatus BookmarkSuggestionsProvider::GetCategoryStatus(
63 Category category) { 63 Category category) {
64 DCHECK_EQ(category, provided_category_); 64 DCHECK_EQ(category, provided_category_);
65 return category_status_; 65 return category_status_;
66 } 66 }
67 67
68 void BookmarkSuggestionsProvider::DismissSuggestion( 68 void BookmarkSuggestionsProvider::DismissSuggestion(
69 const std::string& suggestion_id) { 69 const std::string& suggestion_id) {
70 // TODO(jkrcal): Implement blacklisting bookmarks until they are next visited. 70 DCHECK(bookmark_model_->loaded());
71 // Then also implement ClearDismissedSuggestionsForDebugging. 71 GURL url(GetWithinCategoryIDFromUniqueID(suggestion_id));
72 MarkBookmarksDismissed(bookmark_model_, url);
72 } 73 }
73 74
74 void BookmarkSuggestionsProvider::FetchSuggestionImage( 75 void BookmarkSuggestionsProvider::FetchSuggestionImage(
75 const std::string& suggestion_id, 76 const std::string& suggestion_id,
76 const ImageFetchedCallback& callback) { 77 const ImageFetchedCallback& callback) {
77 base::ThreadTaskRunnerHandle::Get()->PostTask( 78 base::ThreadTaskRunnerHandle::Get()->PostTask(
78 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image())); 79 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
79 } 80 }
80 81
81 void BookmarkSuggestionsProvider::ClearCachedSuggestionsForDebugging( 82 void BookmarkSuggestionsProvider::ClearCachedSuggestionsForDebugging(
82 Category category) { 83 Category category) {
83 DCHECK_EQ(category, provided_category_); 84 DCHECK_EQ(category, provided_category_);
84 // Ignored. 85 // Ignored.
85 } 86 }
86 87
87 std::vector<ContentSuggestion> 88 std::vector<ContentSuggestion>
88 BookmarkSuggestionsProvider::GetDismissedSuggestionsForDebugging( 89 BookmarkSuggestionsProvider::GetDismissedSuggestionsForDebugging(
89 Category category) { 90 Category category) {
90 DCHECK_EQ(category, provided_category_); 91 DCHECK_EQ(category, provided_category_);
91 // TODO(pke): Implement when discarded suggestions are supported. 92 std::vector<const BookmarkNode*> bookmarks =
92 return std::vector<ContentSuggestion>(); 93 GetDismissedBookmarksForDebugging(bookmark_model_);
94
95 std::vector<ContentSuggestion> suggestions;
96 for (const BookmarkNode* bookmark : bookmarks) {
Marc Treib 2016/08/08 14:03:59 nit: braces not required
Philipp Keck 2016/08/08 14:20:11 Done.
97 suggestions.emplace_back(ConvertBookmark(bookmark));
98 }
99 return suggestions;
93 } 100 }
94 101
95 void BookmarkSuggestionsProvider::ClearDismissedSuggestionsForDebugging( 102 void BookmarkSuggestionsProvider::ClearDismissedSuggestionsForDebugging(
96 Category category) { 103 Category category) {
97 DCHECK_EQ(category, provided_category_); 104 DCHECK_EQ(category, provided_category_);
98 // TODO(pke): Implement when discarded suggestions are supported. 105 if (!bookmark_model_->loaded())
106 return;
107 MarkAllBookmarksUndismissed(bookmark_model_);
99 } 108 }
100 109
101 void BookmarkSuggestionsProvider::BookmarkModelLoaded( 110 void BookmarkSuggestionsProvider::BookmarkModelLoaded(
102 bookmarks::BookmarkModel* model, 111 bookmarks::BookmarkModel* model,
103 bool ids_reassigned) { 112 bool ids_reassigned) {
104 DCHECK_EQ(bookmark_model_, model); 113 DCHECK_EQ(bookmark_model_, model);
105 if (fetch_requested_) { 114 if (fetch_requested_) {
106 fetch_requested_ = false; 115 fetch_requested_ = false;
107 FetchBookmarksInternal(); 116 FetchBookmarksInternal();
108 } 117 }
(...skipping 12 matching lines...) Expand all
121 base::Time time = GetLastVisitDateForBookmark(node); 130 base::Time time = GetLastVisitDateForBookmark(node);
122 if (time == node_to_change_last_visit_date_ || 131 if (time == node_to_change_last_visit_date_ ||
123 time < end_of_list_last_visit_date_) 132 time < end_of_list_last_visit_date_)
124 return; 133 return;
125 134
126 // Last visit date of a node has changed (and is relevant for the list), we 135 // Last visit date of a node has changed (and is relevant for the list), we
127 // should update the suggestions. 136 // should update the suggestions.
128 FetchBookmarks(); 137 FetchBookmarks();
129 } 138 }
130 139
140 ContentSuggestion BookmarkSuggestionsProvider::ConvertBookmark(
141 const BookmarkNode* bookmark) {
142 ContentSuggestion suggestion(
143 MakeUniqueID(provided_category_, bookmark->url().spec()),
144 bookmark->url());
145
146 suggestion.set_title(bookmark->GetTitle());
147 suggestion.set_snippet_text(base::string16());
148 suggestion.set_publish_date(GetLastVisitDateForBookmark(bookmark));
149 suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host()));
150 return suggestion;
151 }
152
131 void BookmarkSuggestionsProvider::FetchBookmarksInternal() { 153 void BookmarkSuggestionsProvider::FetchBookmarksInternal() {
132 DCHECK(bookmark_model_->loaded()); 154 DCHECK(bookmark_model_->loaded());
133 155
134 NotifyStatusChanged(CategoryStatus::AVAILABLE); 156 NotifyStatusChanged(CategoryStatus::AVAILABLE);
135 157
136 std::vector<const BookmarkNode*> bookmarks = GetRecentlyVisitedBookmarks( 158 std::vector<const BookmarkNode*> bookmarks = GetRecentlyVisitedBookmarks(
137 bookmark_model_, kMaxBookmarks, GetThresholdTime()); 159 bookmark_model_, kMaxBookmarks, GetThresholdTime());
138 160
139 std::vector<ContentSuggestion> suggestions; 161 std::vector<ContentSuggestion> suggestions;
140 for (const BookmarkNode* bookmark : bookmarks) { 162 for (const BookmarkNode* bookmark : bookmarks) {
141 ContentSuggestion suggestion( 163 suggestions.emplace_back(ConvertBookmark(bookmark));
142 MakeUniqueID(provided_category_, bookmark->url().spec()),
143 bookmark->url());
144
145 suggestion.set_title(bookmark->GetTitle());
146 suggestion.set_snippet_text(base::string16());
147 suggestion.set_publish_date(GetLastVisitDateForBookmark(bookmark));
148 suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host()));
149 suggestions.emplace_back(std::move(suggestion));
150 } 164 }
151 165
152 if (suggestions.empty()) 166 if (suggestions.empty())
153 end_of_list_last_visit_date_ = GetThresholdTime(); 167 end_of_list_last_visit_date_ = GetThresholdTime();
154 else 168 else
155 end_of_list_last_visit_date_ = suggestions.back().publish_date(); 169 end_of_list_last_visit_date_ = suggestions.back().publish_date();
156 170
157 observer()->OnNewSuggestions(this, provided_category_, 171 observer()->OnNewSuggestions(this, provided_category_,
158 std::move(suggestions)); 172 std::move(suggestions));
159 } 173 }
160 174
161 void BookmarkSuggestionsProvider::FetchBookmarks() { 175 void BookmarkSuggestionsProvider::FetchBookmarks() {
162 if (bookmark_model_->loaded()) 176 if (bookmark_model_->loaded())
163 FetchBookmarksInternal(); 177 FetchBookmarksInternal();
164 else 178 else
165 fetch_requested_ = true; 179 fetch_requested_ = true;
166 } 180 }
167 181
168 void BookmarkSuggestionsProvider::NotifyStatusChanged( 182 void BookmarkSuggestionsProvider::NotifyStatusChanged(
169 CategoryStatus new_status) { 183 CategoryStatus new_status) {
170 if (category_status_ == new_status) 184 if (category_status_ == new_status)
171 return; 185 return;
172 category_status_ = new_status; 186 category_status_ = new_status;
173 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 187 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
174 } 188 }
175 189
176 } // namespace ntp_snippets 190 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698