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..1d36f25056f1375675a3be9a438c6035f8fa9885 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,37 @@ 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. |
+ else |
+ ClearOldOnDemandFavicons(GetCurrentExpirationTime()); |
ScheduleExpire(); |
} |
+void ExpireHistoryBackend::ClearOldOnDemandFavicons( |
+ base::Time expiration_threshold) { |
+ if (!base::FeatureList::IsEnabled(internal::kClearOldOnDemandFavicons)) |
+ return; |
+ |
+ std::map<favicon_base::FaviconID, IconMappingsForExpiry> favicons = |
+ thumb_db_->GetOldOnDemandFavicons(expiration_threshold); |
+ DeleteEffects effects; |
+ |
+ for (auto id_and_urls_pair : favicons) { |
+ favicon_base::FaviconID icon_id = id_and_urls_pair.first; |
+ const IconMappingsForExpiry& urls = id_and_urls_pair.second; |
+ |
+ if (backend_client_ && IsAnyURLBookmarked(backend_client_, urls.page_urls)) |
+ continue; |
+ |
+ thumb_db_->DeleteFavicon(icon_id); |
+ thumb_db_->DeleteIconMappingsForFaviconId(icon_id); |
+ effects.deleted_favicons.insert(urls.icon_url); |
+ } |
+ |
+ BroadcastNotifications(&effects, DELETION_EXPIRED); |
+} |
+ |
bool ExpireHistoryBackend::ExpireSomeOldHistory( |
base::Time end_time, |
const ExpiringVisitsReader* reader, |