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_last_visit_utils.h" | 5 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 const char kBookmarkLastVisitDateOnMobileKey[] = "last_visited"; | 36 const char kBookmarkLastVisitDateOnMobileKey[] = "last_visited"; |
37 const char kBookmarkLastVisitDateOnDesktopKey[] = "last_visited_desktop"; | 37 const char kBookmarkLastVisitDateOnDesktopKey[] = "last_visited_desktop"; |
38 const char kBookmarkDismissedFromNTP[] = "dismissed_from_ntp"; | 38 const char kBookmarkDismissedFromNTP[] = "dismissed_from_ntp"; |
39 | 39 |
40 std::string FormatLastVisitDate(const base::Time& date) { | 40 std::string FormatLastVisitDate(const base::Time& date) { |
41 return base::Int64ToString(date.ToInternalValue()); | 41 return base::Int64ToString(date.ToInternalValue()); |
42 } | 42 } |
43 | 43 |
44 bool ExtractLastVisitDate(const BookmarkNode& node, | 44 bool ExtractLastVisitDate(const BookmarkNode& node, |
45 const std::string& meta_info_key, | 45 const std::string& meta_info_key, |
46 base::Time* out) { | 46 base::Time* out) { |
47 std::string last_visit_date_string; | 47 std::string last_visit_date_string; |
48 if (!node.GetMetaInfo(meta_info_key, &last_visit_date_string)) { | 48 if (!node.GetMetaInfo(meta_info_key, &last_visit_date_string)) { |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 int64_t date = 0; | 52 int64_t date = 0; |
53 if (!base::StringToInt64(last_visit_date_string, &date) || date < 0) { | 53 if (!base::StringToInt64(last_visit_date_string, &date) || date < 0) { |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 | 262 |
263 // Insert into |result|. | 263 // Insert into |result|. |
264 std::vector<const BookmarkNode*> result; | 264 std::vector<const BookmarkNode*> result; |
265 for (const BookmarkModel::URLAndTitle& bookmark : bookmarks) { | 265 for (const BookmarkModel::URLAndTitle& bookmark : bookmarks) { |
266 result.push_back( | 266 result.push_back( |
267 bookmark_model->GetMostRecentlyAddedUserNodeForURL(bookmark.url)); | 267 bookmark_model->GetMostRecentlyAddedUserNodeForURL(bookmark.url)); |
268 } | 268 } |
269 return result; | 269 return result; |
270 } | 270 } |
271 | 271 |
272 void RemoveAllLastVisitDates(bookmarks::BookmarkModel* bookmark_model) { | 272 namespace { |
273 | |
274 void ClearNTPMetadata(bookmarks::BookmarkModel* model, | |
275 const BookmarkNode* node) { | |
276 model->DeleteNodeMetaInfo(node, kBookmarkLastVisitDateOnMobileKey); | |
277 model->DeleteNodeMetaInfo(node, kBookmarkLastVisitDateOnDesktopKey); | |
278 model->DeleteNodeMetaInfo(node, kBookmarkDismissedFromNTP); | |
279 } | |
280 | |
281 } // namespace | |
282 | |
283 void RemoveLastVisitedDatesBetween(const base::Time& begin, | |
284 const base::Time& end, | |
285 base::Callback<bool(const GURL& url)> filter, | |
jkrcal
2017/01/04 12:14:22
Why do you accept |filter| when you not use it? Wh
tschumann
2017/01/04 13:32:32
Good point! Will add this functionality. (Sending
tschumann
2017/01/04 15:08:44
Done.
+Martin: Can you double-check I got the filt
msramek
2017/01/04 15:16:26
Yeah, sorry for that. I guess we really should hav
| |
286 bookmarks::BookmarkModel* bookmark_model) { | |
273 // Get all the bookmark URLs. | 287 // Get all the bookmark URLs. |
274 std::vector<BookmarkModel::URLAndTitle> bookmark_urls; | 288 std::vector<BookmarkModel::URLAndTitle> bookmark_urls; |
275 bookmark_model->GetBookmarks(&bookmark_urls); | 289 bookmark_model->GetBookmarks(&bookmark_urls); |
276 | 290 |
277 for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) { | 291 for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) { |
278 // Get all bookmarks for the given URL. | 292 // Get all bookmarks for the given URL. |
279 std::vector<const BookmarkNode*> bookmarks_for_url; | 293 std::vector<const BookmarkNode*> bookmarks_for_url; |
280 bookmark_model->GetNodesByURL(url_and_title.url, &bookmarks_for_url); | 294 bookmark_model->GetNodesByURL(url_and_title.url, &bookmarks_for_url); |
281 | 295 |
282 for (const BookmarkNode* bookmark : bookmarks_for_url) { | 296 for (const BookmarkNode* bookmark : bookmarks_for_url) { |
283 bookmark_model->DeleteNodeMetaInfo(bookmark, | 297 base::Time last_visit_time; |
284 kBookmarkLastVisitDateOnMobileKey); | 298 if (ExtractLastVisitDate(*bookmark, kBookmarkLastVisitDateOnMobileKey, |
285 bookmark_model->DeleteNodeMetaInfo(bookmark, | 299 &last_visit_time) && |
286 kBookmarkLastVisitDateOnDesktopKey); | 300 begin <= last_visit_time && last_visit_time <= end) { |
301 ClearNTPMetadata(bookmark_model, bookmark); | |
302 } | |
303 if (ExtractLastVisitDate(*bookmark, kBookmarkLastVisitDateOnDesktopKey, | |
304 &last_visit_time) && | |
305 begin <= last_visit_time && last_visit_time <= end) { | |
306 ClearNTPMetadata(bookmark_model, bookmark); | |
307 } | |
287 } | 308 } |
288 } | 309 } |
289 } | 310 } |
290 | 311 |
291 } // namespace ntp_snippets | 312 } // namespace ntp_snippets |
OLD | NEW |