OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history/core/browser/expire_history_backend.h" | 5 #include "components/history/core/browser/expire_history_backend.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
11 #include <limits> | 11 #include <limits> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/feature_list.h" | |
15 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
16 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
17 #include "base/location.h" | 18 #include "base/location.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
20 #include "components/history/core/browser/history_backend_client.h" | 21 #include "components/history/core/browser/history_backend_client.h" |
21 #include "components/history/core/browser/history_backend_notifier.h" | 22 #include "components/history/core/browser/history_backend_notifier.h" |
22 #include "components/history/core/browser/history_database.h" | 23 #include "components/history/core/browser/history_database.h" |
23 #include "components/history/core/browser/thumbnail_database.h" | 24 #include "components/history/core/browser/thumbnail_database.h" |
24 | 25 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 const int kExpirationDelaySec = 30; | 110 const int kExpirationDelaySec = 30; |
110 | 111 |
111 // The number of minutes between checking, as with kExpirationDelaySec, but | 112 // The number of minutes between checking, as with kExpirationDelaySec, but |
112 // when we didn't find enough things to expire last time. If there was no | 113 // when we didn't find enough things to expire last time. If there was no |
113 // history to expire last iteration, it's likely there is nothing next | 114 // history to expire last iteration, it's likely there is nothing next |
114 // iteration, so we want to wait longer before checking to avoid wasting CPU. | 115 // iteration, so we want to wait longer before checking to avoid wasting CPU. |
115 const int kExpirationEmptyDelayMin = 5; | 116 const int kExpirationEmptyDelayMin = 5; |
116 | 117 |
117 } // namespace | 118 } // namespace |
118 | 119 |
120 namespace internal { | |
121 | |
122 const base::Feature kClearOldOnDemandFavicons{ | |
123 "ClearOldOnDemandFavicons", base::FEATURE_DISABLED_BY_DEFAULT}; | |
124 | |
125 } // namespace internal | |
119 | 126 |
120 // ExpireHistoryBackend::DeleteEffects ---------------------------------------- | 127 // ExpireHistoryBackend::DeleteEffects ---------------------------------------- |
121 | 128 |
122 ExpireHistoryBackend::DeleteEffects::DeleteEffects() { | 129 ExpireHistoryBackend::DeleteEffects::DeleteEffects() { |
123 } | 130 } |
124 | 131 |
125 ExpireHistoryBackend::DeleteEffects::~DeleteEffects() { | 132 ExpireHistoryBackend::DeleteEffects::~DeleteEffects() { |
126 } | 133 } |
127 | 134 |
128 | 135 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 | 477 |
471 const ExpiringVisitsReader* reader = work_queue_.front(); | 478 const ExpiringVisitsReader* reader = work_queue_.front(); |
472 bool more_to_expire = ExpireSomeOldHistory( | 479 bool more_to_expire = ExpireSomeOldHistory( |
473 GetCurrentExpirationTime(), reader, kNumExpirePerIteration); | 480 GetCurrentExpirationTime(), reader, kNumExpirePerIteration); |
474 | 481 |
475 work_queue_.pop(); | 482 work_queue_.pop(); |
476 // If there are more items to expire, add the reader back to the queue, thus | 483 // If there are more items to expire, add the reader back to the queue, thus |
477 // creating a new task for future iterations. | 484 // creating a new task for future iterations. |
478 if (more_to_expire) | 485 if (more_to_expire) |
479 work_queue_.push(reader); | 486 work_queue_.push(reader); |
487 // Otherwise do a final clean-up - remove old favicons not bound to visits. | |
488 else | |
489 ClearOldOnDemandFavicons(GetCurrentExpirationTime()); | |
480 | 490 |
481 ScheduleExpire(); | 491 ScheduleExpire(); |
482 } | 492 } |
483 | 493 |
494 void ExpireHistoryBackend::ClearOldOnDemandFavicons( | |
495 base::Time expiration_threshold) { | |
496 if (!base::FeatureList::IsEnabled(internal::kClearOldOnDemandFavicons)) | |
497 return; | |
498 | |
499 std::vector<std::pair<favicon_base::FaviconID, GURL>> favicons = | |
500 thumb_db_->GetOldOnDemandFavicons(expiration_threshold); | |
501 | |
502 // Multiple page URLs may map to the same favicon. We omit the favicon from | |
503 // cleaning if at least one of its associated page URLs is bookmarked. | |
504 std::set<favicon_base::FaviconID> ids_of_icons_with_some_bookmarked_page; | |
505 std::set<favicon_base::FaviconID> ids_of_icons_with_no_bookmarked_page; | |
506 for (auto id_and_url_pair : favicons) { | |
507 favicon_base::FaviconID icon_id = id_and_url_pair.first; | |
508 if (ids_of_icons_with_some_bookmarked_page.count(icon_id)) | |
509 continue; | |
510 | |
511 const GURL& page_url = id_and_url_pair.second; | |
512 if (backend_client_ && backend_client_->IsBookmarked(page_url)) { | |
513 ids_of_icons_with_some_bookmarked_page.insert(icon_id); | |
514 ids_of_icons_with_no_bookmarked_page.erase(icon_id); | |
515 continue; | |
516 } | |
517 | |
518 ids_of_icons_with_no_bookmarked_page.insert(icon_id); | |
519 } | |
520 | |
521 for (favicon_base::FaviconID icon_id : ids_of_icons_with_no_bookmarked_page) { | |
522 if (!thumb_db_->DeleteFavicon(icon_id) || | |
523 !thumb_db_->DeleteIconMappingsForFaviconId(icon_id)) | |
pkotwicz
2017/07/07 00:42:38
Don't you need to update DeleteEffects::deleted_fa
jkrcal
2017/07/07 08:45:16
Done.
This meant pulling also the icon_url. This
| |
524 return; | |
pkotwicz
2017/07/07 00:42:38
For the sake of consistency with DeleteFaviconsIfP
jkrcal
2017/07/07 08:45:16
Done.
| |
525 } | |
526 } | |
527 | |
484 bool ExpireHistoryBackend::ExpireSomeOldHistory( | 528 bool ExpireHistoryBackend::ExpireSomeOldHistory( |
485 base::Time end_time, | 529 base::Time end_time, |
486 const ExpiringVisitsReader* reader, | 530 const ExpiringVisitsReader* reader, |
487 int max_visits) { | 531 int max_visits) { |
488 if (!main_db_) | 532 if (!main_db_) |
489 return false; | 533 return false; |
490 | 534 |
491 // Add an extra time unit to given end time, because | 535 // Add an extra time unit to given end time, because |
492 // GetAllVisitsInRange, et al. queries' end value is non-inclusive. | 536 // GetAllVisitsInRange, et al. queries' end value is non-inclusive. |
493 base::Time effective_end_time = | 537 base::Time effective_end_time = |
(...skipping 11 matching lines...) Expand all Loading... | |
505 BroadcastNotifications(&deleted_effects, DELETION_EXPIRED); | 549 BroadcastNotifications(&deleted_effects, DELETION_EXPIRED); |
506 | 550 |
507 return more_to_expire; | 551 return more_to_expire; |
508 } | 552 } |
509 | 553 |
510 void ExpireHistoryBackend::ParanoidExpireHistory() { | 554 void ExpireHistoryBackend::ParanoidExpireHistory() { |
511 // TODO(brettw): Bug 1067331: write this to clean up any errors. | 555 // TODO(brettw): Bug 1067331: write this to clean up any errors. |
512 } | 556 } |
513 | 557 |
514 } // namespace history | 558 } // namespace history |
OLD | NEW |