Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 if (fetch_requested_) { | 143 if (fetch_requested_) { |
| 144 fetch_requested_ = false; | 144 fetch_requested_ = false; |
| 145 FetchBookmarksInternal(); | 145 FetchBookmarksInternal(); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void BookmarkSuggestionsProvider::OnWillChangeBookmarkMetaInfo( | 149 void BookmarkSuggestionsProvider::OnWillChangeBookmarkMetaInfo( |
| 150 BookmarkModel* model, | 150 BookmarkModel* model, |
| 151 const BookmarkNode* node) { | 151 const BookmarkNode* node) { |
| 152 // Store the last visit date of the node that is about to change. | 152 // Store the last visit date of the node that is about to change. |
| 153 node_to_change_last_visit_date_ = GetLastVisitDateForBookmark(node); | 153 node_to_change_last_visit_date_ = |
| 154 GetLastVisitDateForNotDismissedBookmark(node); | |
| 154 } | 155 } |
| 155 | 156 |
| 156 void BookmarkSuggestionsProvider::BookmarkMetaInfoChanged( | 157 void BookmarkSuggestionsProvider::BookmarkMetaInfoChanged( |
| 157 BookmarkModel* model, | 158 BookmarkModel* model, |
| 158 const BookmarkNode* node) { | 159 const BookmarkNode* node) { |
| 159 base::Time time = GetLastVisitDateForBookmark(node); | 160 base::Time time = GetLastVisitDateForNotDismissedBookmark(node); |
| 160 if (time == node_to_change_last_visit_date_ || | 161 if (time == node_to_change_last_visit_date_ || |
| 161 time < end_of_list_last_visit_date_) | 162 time < end_of_list_last_visit_date_) |
| 162 return; | 163 return; |
| 163 | 164 |
| 164 // Last visit date of a node has changed (and is relevant for the list), we | 165 // Last visit date of a node has changed (and is relevant for the list), we |
| 165 // should update the suggestions. | 166 // should update the suggestions. |
| 166 FetchBookmarks(); | 167 FetchBookmarks(); |
| 167 } | 168 } |
| 168 | 169 |
| 170 void BookmarkSuggestionsProvider::BookmarkNodeRemoved( | |
| 171 bookmarks::BookmarkModel* model, | |
| 172 const bookmarks::BookmarkNode* parent, | |
| 173 int old_index, | |
| 174 const bookmarks::BookmarkNode* node, | |
| 175 const std::set<GURL>& no_longer_bookmarked) { | |
| 176 if (GetLastVisitDateForNotDismissedBookmark(node) < | |
| 177 end_of_list_last_visit_date_) | |
| 178 return; | |
| 179 | |
| 180 // Some node from our list got deleted, we should update the suggestions. | |
| 181 FetchBookmarks(); | |
|
Marc Treib
2016/08/11 15:24:54
The bookmark might have been dismissed, but I gues
jkrcal
2016/08/11 15:41:35
The node it still valid at this point. Thus, GetLa
| |
| 182 } | |
| 183 | |
| 169 ContentSuggestion BookmarkSuggestionsProvider::ConvertBookmark( | 184 ContentSuggestion BookmarkSuggestionsProvider::ConvertBookmark( |
| 170 const BookmarkNode* bookmark) { | 185 const BookmarkNode* bookmark) { |
| 171 ContentSuggestion suggestion( | 186 ContentSuggestion suggestion( |
| 172 MakeUniqueID(provided_category_, bookmark->url().spec()), | 187 MakeUniqueID(provided_category_, bookmark->url().spec()), |
| 173 bookmark->url()); | 188 bookmark->url()); |
| 174 | 189 |
| 175 suggestion.set_title(bookmark->GetTitle()); | 190 suggestion.set_title(bookmark->GetTitle()); |
| 176 suggestion.set_snippet_text(base::string16()); | 191 suggestion.set_snippet_text(base::string16()); |
| 177 suggestion.set_publish_date(GetLastVisitDateForBookmark(bookmark)); | 192 suggestion.set_publish_date(GetLastVisitDateForBookmark(bookmark)); |
| 178 suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host())); | 193 suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host())); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 | 225 |
| 211 void BookmarkSuggestionsProvider::NotifyStatusChanged( | 226 void BookmarkSuggestionsProvider::NotifyStatusChanged( |
| 212 CategoryStatus new_status) { | 227 CategoryStatus new_status) { |
| 213 if (category_status_ == new_status) | 228 if (category_status_ == new_status) |
| 214 return; | 229 return; |
| 215 category_status_ = new_status; | 230 category_status_ = new_status; |
| 216 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 231 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
| 217 } | 232 } |
| 218 | 233 |
| 219 } // namespace ntp_snippets | 234 } // namespace ntp_snippets |
| OLD | NEW |