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

Side by Side Diff: components/history/core/browser/expire_history_backend.cc

Issue 2903573002: [Thumbnails DB] Add functionality to clear unused on-demand favicons. (Closed)
Patch Set: Peter's comments #4 Created 3 years, 5 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 (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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // last expiration found at least kNumExpirePerIteration and we want to check 108 // last expiration found at least kNumExpirePerIteration and we want to check
108 // again "soon." 109 // again "soon."
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
118 bool IsAnyURLBookmarked(HistoryBackendClient* backend_client,
119 const std::vector<GURL>& urls) {
120 for (const GURL& url : urls) {
121 if (backend_client->IsBookmarked(url))
122 return true;
123 }
124 return false;
125 }
126
117 } // namespace 127 } // namespace
118 128
129 namespace internal {
130
131 const base::Feature kClearOldOnDemandFavicons{
132 "ClearOldOnDemandFavicons", base::FEATURE_DISABLED_BY_DEFAULT};
133
134 } // namespace internal
119 135
120 // ExpireHistoryBackend::DeleteEffects ---------------------------------------- 136 // ExpireHistoryBackend::DeleteEffects ----------------------------------------
121 137
122 ExpireHistoryBackend::DeleteEffects::DeleteEffects() { 138 ExpireHistoryBackend::DeleteEffects::DeleteEffects() {
123 } 139 }
124 140
125 ExpireHistoryBackend::DeleteEffects::~DeleteEffects() { 141 ExpireHistoryBackend::DeleteEffects::~DeleteEffects() {
126 } 142 }
127 143
128 144
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 486
471 const ExpiringVisitsReader* reader = work_queue_.front(); 487 const ExpiringVisitsReader* reader = work_queue_.front();
472 bool more_to_expire = ExpireSomeOldHistory( 488 bool more_to_expire = ExpireSomeOldHistory(
473 GetCurrentExpirationTime(), reader, kNumExpirePerIteration); 489 GetCurrentExpirationTime(), reader, kNumExpirePerIteration);
474 490
475 work_queue_.pop(); 491 work_queue_.pop();
476 // If there are more items to expire, add the reader back to the queue, thus 492 // If there are more items to expire, add the reader back to the queue, thus
477 // creating a new task for future iterations. 493 // creating a new task for future iterations.
478 if (more_to_expire) 494 if (more_to_expire)
479 work_queue_.push(reader); 495 work_queue_.push(reader);
496 // Otherwise do a final clean-up - remove old favicons not bound to visits.
497 else
498 ClearOldOnDemandFavicons(GetCurrentExpirationTime());
480 499
481 ScheduleExpire(); 500 ScheduleExpire();
482 } 501 }
483 502
503 void ExpireHistoryBackend::ClearOldOnDemandFavicons(
504 base::Time expiration_threshold) {
505 if (!base::FeatureList::IsEnabled(internal::kClearOldOnDemandFavicons))
506 return;
507
508 std::map<favicon_base::FaviconID, IconMappingsForExpiry> favicons =
509 thumb_db_->GetOldOnDemandFavicons(expiration_threshold);
510 DeleteEffects effects;
511
512 for (auto id_and_urls_pair : favicons) {
513 favicon_base::FaviconID icon_id = id_and_urls_pair.first;
514 const IconMappingsForExpiry& urls = id_and_urls_pair.second;
515
516 if (backend_client_ && IsAnyURLBookmarked(backend_client_, urls.page_urls))
517 continue;
518
519 thumb_db_->DeleteFavicon(icon_id);
520 thumb_db_->DeleteIconMappingsForFaviconId(icon_id);
521 effects.deleted_favicons.insert(urls.icon_url);
522 }
523
524 BroadcastNotifications(&effects, DELETION_EXPIRED);
525 }
526
484 bool ExpireHistoryBackend::ExpireSomeOldHistory( 527 bool ExpireHistoryBackend::ExpireSomeOldHistory(
485 base::Time end_time, 528 base::Time end_time,
486 const ExpiringVisitsReader* reader, 529 const ExpiringVisitsReader* reader,
487 int max_visits) { 530 int max_visits) {
488 if (!main_db_) 531 if (!main_db_)
489 return false; 532 return false;
490 533
491 // Add an extra time unit to given end time, because 534 // Add an extra time unit to given end time, because
492 // GetAllVisitsInRange, et al. queries' end value is non-inclusive. 535 // GetAllVisitsInRange, et al. queries' end value is non-inclusive.
493 base::Time effective_end_time = 536 base::Time effective_end_time =
(...skipping 11 matching lines...) Expand all
505 BroadcastNotifications(&deleted_effects, DELETION_EXPIRED); 548 BroadcastNotifications(&deleted_effects, DELETION_EXPIRED);
506 549
507 return more_to_expire; 550 return more_to_expire;
508 } 551 }
509 552
510 void ExpireHistoryBackend::ParanoidExpireHistory() { 553 void ExpireHistoryBackend::ParanoidExpireHistory() {
511 // TODO(brettw): Bug 1067331: write this to clean up any errors. 554 // TODO(brettw): Bug 1067331: write this to clean up any errors.
512 } 555 }
513 556
514 } // namespace history 557 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698