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

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

Issue 2616633002: Respect time range in browsing data removal for last-visited data. (Closed)
Patch Set: rebase Created 3 years, 11 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_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
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
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 ClearLastVisitedMetadataIfBetween(bookmarks::BookmarkModel* model,
275 const BookmarkNode& node,
276 const base::Time& begin,
277 const base::Time& end,
278 const std::string& meta_key) {
279 base::Time last_visit_time;
280 if (ExtractLastVisitDate(node, meta_key, &last_visit_time) &&
281 begin <= last_visit_time && last_visit_time <= end) {
282 model->DeleteNodeMetaInfo(&node, meta_key);
283 }
284 }
285
286 } // namespace
287
288 void RemoveLastVisitedDatesBetween(const base::Time& begin,
289 const base::Time& end,
290 base::Callback<bool(const GURL& url)> filter,
291 bookmarks::BookmarkModel* bookmark_model) {
273 // Get all the bookmark URLs. 292 // Get all the bookmark URLs.
274 std::vector<BookmarkModel::URLAndTitle> bookmark_urls; 293 std::vector<BookmarkModel::URLAndTitle> bookmark_urls;
275 bookmark_model->GetBookmarks(&bookmark_urls); 294 bookmark_model->GetBookmarks(&bookmark_urls);
276 295
277 for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) { 296 for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) {
297 if (!filter.Run(url_and_title.url)) {
298 continue;
299 }
278 // Get all bookmarks for the given URL. 300 // Get all bookmarks for the given URL.
279 std::vector<const BookmarkNode*> bookmarks_for_url; 301 std::vector<const BookmarkNode*> bookmarks_for_url;
280 bookmark_model->GetNodesByURL(url_and_title.url, &bookmarks_for_url); 302 bookmark_model->GetNodesByURL(url_and_title.url, &bookmarks_for_url);
281 303
282 for (const BookmarkNode* bookmark : bookmarks_for_url) { 304 for (const BookmarkNode* bookmark : bookmarks_for_url) {
283 bookmark_model->DeleteNodeMetaInfo(bookmark, 305 // The dismissal metadata is managed by the BookmarkSuggestionsProvider.
284 kBookmarkLastVisitDateOnMobileKey); 306 ClearLastVisitedMetadataIfBetween(bookmark_model, *bookmark, begin, end,
285 bookmark_model->DeleteNodeMetaInfo(bookmark, 307 kBookmarkLastVisitDateOnMobileKey);
286 kBookmarkLastVisitDateOnDesktopKey); 308 ClearLastVisitedMetadataIfBetween(bookmark_model, *bookmark, begin, end,
309 kBookmarkLastVisitDateOnDesktopKey);
287 } 310 }
288 } 311 }
289 } 312 }
290 313
291 } // namespace ntp_snippets 314 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698