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_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 ClearNTPMetadataIfBetween(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 model->DeleteNodeMetaInfo(&node, kBookmarkDismissedFromNTP); | |
|
jkrcal
2017/01/05 13:28:55
Can you please remove the dismissed bit only if th
tschumann
2017/01/05 19:25:17
let's not remove this here at all -- the content s
jkrcal
2017/01/05 20:01:50
Acknowledged.
| |
| 284 } | |
| 285 } | |
| 286 | |
| 287 } // namespace | |
| 288 | |
| 289 void RemoveLastVisitedDatesBetween(const base::Time& begin, | |
| 290 const base::Time& end, | |
| 291 base::Callback<bool(const GURL& url)> filter, | |
| 292 bookmarks::BookmarkModel* bookmark_model) { | |
| 273 // Get all the bookmark URLs. | 293 // Get all the bookmark URLs. |
| 274 std::vector<BookmarkModel::URLAndTitle> bookmark_urls; | 294 std::vector<BookmarkModel::URLAndTitle> bookmark_urls; |
| 275 bookmark_model->GetBookmarks(&bookmark_urls); | 295 bookmark_model->GetBookmarks(&bookmark_urls); |
| 276 | 296 |
| 277 for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) { | 297 for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) { |
| 298 if (!filter.Run(url_and_title.url)) { | |
| 299 continue; | |
| 300 } | |
| 278 // Get all bookmarks for the given URL. | 301 // Get all bookmarks for the given URL. |
| 279 std::vector<const BookmarkNode*> bookmarks_for_url; | 302 std::vector<const BookmarkNode*> bookmarks_for_url; |
| 280 bookmark_model->GetNodesByURL(url_and_title.url, &bookmarks_for_url); | 303 bookmark_model->GetNodesByURL(url_and_title.url, &bookmarks_for_url); |
| 281 | 304 |
| 282 for (const BookmarkNode* bookmark : bookmarks_for_url) { | 305 for (const BookmarkNode* bookmark : bookmarks_for_url) { |
| 283 bookmark_model->DeleteNodeMetaInfo(bookmark, | 306 ClearNTPMetadataIfBetween(bookmark_model, *bookmark, begin, end, |
| 284 kBookmarkLastVisitDateOnMobileKey); | 307 kBookmarkLastVisitDateOnMobileKey); |
| 285 bookmark_model->DeleteNodeMetaInfo(bookmark, | 308 ClearNTPMetadataIfBetween(bookmark_model, *bookmark, begin, end, |
| 286 kBookmarkLastVisitDateOnDesktopKey); | 309 kBookmarkLastVisitDateOnDesktopKey); |
| 287 } | 310 } |
| 288 } | 311 } |
| 289 } | 312 } |
| 290 | 313 |
| 291 } // namespace ntp_snippets | 314 } // namespace ntp_snippets |
| OLD | NEW |