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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Feature that enables clearing old on-demand favicons. | |
119 const base::Feature kClearOldOnDemandFavicons{ | |
120 "ClearOldOnDemandFavicons", base::FEATURE_DISABLED_BY_DEFAULT}; | |
121 | |
117 } // namespace | 122 } // namespace |
118 | 123 |
119 | 124 |
120 // ExpireHistoryBackend::DeleteEffects ---------------------------------------- | 125 // ExpireHistoryBackend::DeleteEffects ---------------------------------------- |
121 | 126 |
122 ExpireHistoryBackend::DeleteEffects::DeleteEffects() { | 127 ExpireHistoryBackend::DeleteEffects::DeleteEffects() { |
123 } | 128 } |
124 | 129 |
125 ExpireHistoryBackend::DeleteEffects::~DeleteEffects() { | 130 ExpireHistoryBackend::DeleteEffects::~DeleteEffects() { |
126 } | 131 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 // For now, we explicitly add all known readers. If we come up with more | 298 // For now, we explicitly add all known readers. If we come up with more |
294 // reader types (in case we want to expire different types of visits in | 299 // reader types (in case we want to expire different types of visits in |
295 // different ways), we can make it be populated by creator/owner of | 300 // different ways), we can make it be populated by creator/owner of |
296 // ExpireHistoryBackend. | 301 // ExpireHistoryBackend. |
297 readers_.push_back(GetAllVisitsReader()); | 302 readers_.push_back(GetAllVisitsReader()); |
298 readers_.push_back(GetAutoSubframeVisitsReader()); | 303 readers_.push_back(GetAutoSubframeVisitsReader()); |
299 | 304 |
300 // Initialize the queue with all tasks for the first set of iterations. | 305 // Initialize the queue with all tasks for the first set of iterations. |
301 InitWorkQueue(); | 306 InitWorkQueue(); |
302 ScheduleExpire(); | 307 ScheduleExpire(); |
308 | |
309 // Remove favicons that are not bound to visits. | |
310 if (!base::FeatureList::IsEnabled(kClearOldOnDemandFavicons)) | |
311 return; | |
312 task_runner_->PostDelayedTask( | |
313 FROM_HERE, | |
314 base::Bind(&ExpireHistoryBackend::ClearOldOnDemandFavicons, | |
315 weak_factory_.GetWeakPtr()), | |
316 base::TimeDelta::FromSeconds(kExpirationDelaySec)); | |
317 } | |
318 | |
319 void ExpireHistoryBackend::ClearOldOnDemandFavicons() { | |
320 thumb_db_->ClearOldOnDemandFavicons(GetCurrentExpirationTime()); | |
303 } | 321 } |
304 | 322 |
305 void ExpireHistoryBackend::DeleteFaviconsIfPossible(DeleteEffects* effects) { | 323 void ExpireHistoryBackend::DeleteFaviconsIfPossible(DeleteEffects* effects) { |
306 if (!thumb_db_) | 324 if (!thumb_db_) |
307 return; | 325 return; |
308 | 326 |
309 for (std::set<favicon_base::FaviconID>::const_iterator i = | 327 for (std::set<favicon_base::FaviconID>::const_iterator i = |
310 effects->affected_favicons.begin(); | 328 effects->affected_favicons.begin(); |
311 i != effects->affected_favicons.end(); ++i) { | 329 i != effects->affected_favicons.end(); ++i) { |
312 if (!thumb_db_->HasMappingFor(*i)) { | 330 if (!thumb_db_->HasMappingFor(*i)) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 base::Bind(&ExpireHistoryBackend::DoExpireIteration, | 481 base::Bind(&ExpireHistoryBackend::DoExpireIteration, |
464 weak_factory_.GetWeakPtr()), | 482 weak_factory_.GetWeakPtr()), |
465 delay); | 483 delay); |
466 } | 484 } |
467 | 485 |
468 void ExpireHistoryBackend::DoExpireIteration() { | 486 void ExpireHistoryBackend::DoExpireIteration() { |
469 DCHECK(!work_queue_.empty()) << "queue has to be non-empty"; | 487 DCHECK(!work_queue_.empty()) << "queue has to be non-empty"; |
470 | 488 |
471 const ExpiringVisitsReader* reader = work_queue_.front(); | 489 const ExpiringVisitsReader* reader = work_queue_.front(); |
472 bool more_to_expire = ExpireSomeOldHistory( | 490 bool more_to_expire = ExpireSomeOldHistory( |
473 GetCurrentExpirationTime(), reader, kNumExpirePerIteration); | 491 GetCurrentExpirationTime(), reader, kNumExpirePerIteration); |
pkotwicz
2017/06/22 20:32:22
Can we call ClearOldOnDemandFavicons() here if |mo
jkrcal
2017/07/06 17:01:48
Done.
| |
474 | 492 |
475 work_queue_.pop(); | 493 work_queue_.pop(); |
476 // If there are more items to expire, add the reader back to the queue, thus | 494 // If there are more items to expire, add the reader back to the queue, thus |
477 // creating a new task for future iterations. | 495 // creating a new task for future iterations. |
478 if (more_to_expire) | 496 if (more_to_expire) |
479 work_queue_.push(reader); | 497 work_queue_.push(reader); |
480 | 498 |
481 ScheduleExpire(); | 499 ScheduleExpire(); |
482 } | 500 } |
483 | 501 |
(...skipping 21 matching lines...) Expand all Loading... | |
505 BroadcastNotifications(&deleted_effects, DELETION_EXPIRED); | 523 BroadcastNotifications(&deleted_effects, DELETION_EXPIRED); |
506 | 524 |
507 return more_to_expire; | 525 return more_to_expire; |
508 } | 526 } |
509 | 527 |
510 void ExpireHistoryBackend::ParanoidExpireHistory() { | 528 void ExpireHistoryBackend::ParanoidExpireHistory() { |
511 // TODO(brettw): Bug 1067331: write this to clean up any errors. | 529 // TODO(brettw): Bug 1067331: write this to clean up any errors. |
512 } | 530 } |
513 | 531 |
514 } // namespace history | 532 } // namespace history |
OLD | NEW |