Chromium Code Reviews| Index: components/history/core/browser/expire_history_backend.cc |
| diff --git a/components/history/core/browser/expire_history_backend.cc b/components/history/core/browser/expire_history_backend.cc |
| index d57a60432afb85c3f74790c13d50d8e7865dd7b9..027728d8d9bac5c72ad656f0f7b9662b9c3c1315 100644 |
| --- a/components/history/core/browser/expire_history_backend.cc |
| +++ b/components/history/core/browser/expire_history_backend.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/bind.h" |
| #include "base/compiler_specific.h" |
| +#include "base/feature_list.h" |
| #include "base/files/file_enumerator.h" |
| #include "base/files/file_util.h" |
| #include "base/location.h" |
| @@ -114,8 +115,23 @@ const int kExpirationDelaySec = 30; |
| // iteration, so we want to wait longer before checking to avoid wasting CPU. |
| const int kExpirationEmptyDelayMin = 5; |
| +bool IsAnyURLBookmarked(HistoryBackendClient* backend_client, |
| + const std::vector<GURL>& urls) { |
| + for (const GURL& url : urls) { |
| + if (backend_client->IsBookmarked(url)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| } // namespace |
| +namespace internal { |
| + |
| +const base::Feature kClearOldOnDemandFavicons{ |
| + "ClearOldOnDemandFavicons", base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| +} // namespace internal |
| // ExpireHistoryBackend::DeleteEffects ---------------------------------------- |
| @@ -477,10 +493,39 @@ void ExpireHistoryBackend::DoExpireIteration() { |
| // creating a new task for future iterations. |
| if (more_to_expire) |
| work_queue_.push(reader); |
| + // Otherwise do a final clean-up - remove old favicons not bound to visits. |
|
brettw
2017/07/11 19:26:43
Style nit: I find this comment before the else wit
jkrcal
2017/07/13 20:26:10
Done.
|
| + else |
| + ClearOldOnDemandFavicons(GetCurrentExpirationTime()); |
| ScheduleExpire(); |
| } |
| +void ExpireHistoryBackend::ClearOldOnDemandFavicons( |
| + base::Time expiration_threshold) { |
| + if (!base::FeatureList::IsEnabled(internal::kClearOldOnDemandFavicons)) |
| + return; |
| + |
| + std::map<favicon_base::FaviconID, IconMappingsForExpiry> icon_mappings = |
| + thumb_db_->GetOldOnDemandFavicons(expiration_threshold); |
| + DeleteEffects effects; |
| + |
| + for (auto id_and_mappings_pair : icon_mappings) { |
| + favicon_base::FaviconID icon_id = id_and_mappings_pair.first; |
| + const IconMappingsForExpiry& mappings = id_and_mappings_pair.second; |
| + |
| + if (backend_client_ && |
| + IsAnyURLBookmarked(backend_client_, mappings.page_urls)) { |
| + continue; |
| + } |
| + |
| + thumb_db_->DeleteFavicon(icon_id); |
| + thumb_db_->DeleteIconMappingsForFaviconId(icon_id); |
| + effects.deleted_favicons.insert(mappings.icon_url); |
| + } |
| + |
| + BroadcastNotifications(&effects, DELETION_EXPIRED); |
| +} |
| + |
| bool ExpireHistoryBackend::ExpireSomeOldHistory( |
| base::Time end_time, |
| const ExpiringVisitsReader* reader, |