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 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ |
6 #define COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
18 | 18 |
19 class GURL; | 19 class GURL; |
20 class TestingProfile; | 20 class TestingProfile; |
21 | 21 |
22 namespace base { | 22 namespace base { |
| 23 struct Feature; |
23 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
24 } | 25 } |
25 | 26 |
26 namespace history { | 27 namespace history { |
27 | 28 |
28 class HistoryBackendClient; | 29 class HistoryBackendClient; |
29 class HistoryBackendNotifier; | 30 class HistoryBackendNotifier; |
30 class HistoryDatabase; | 31 class HistoryDatabase; |
31 class ThumbnailDatabase; | 32 class ThumbnailDatabase; |
32 | 33 |
33 // Encapsulates visit expiration criteria and type of visits to expire. | 34 // Encapsulates visit expiration criteria and type of visits to expire. |
34 class ExpiringVisitsReader { | 35 class ExpiringVisitsReader { |
35 public: | 36 public: |
36 virtual ~ExpiringVisitsReader() {} | 37 virtual ~ExpiringVisitsReader() {} |
37 // Populates |visits| from |db|, using provided |end_time| and |max_visits| | 38 // Populates |visits| from |db|, using provided |end_time| and |max_visits| |
38 // cap. | 39 // cap. |
39 virtual bool Read(base::Time end_time, HistoryDatabase* db, | 40 virtual bool Read(base::Time end_time, HistoryDatabase* db, |
40 VisitVector* visits, int max_visits) const = 0; | 41 VisitVector* visits, int max_visits) const = 0; |
41 }; | 42 }; |
42 | 43 |
43 typedef std::vector<const ExpiringVisitsReader*> ExpiringVisitsReaders; | 44 typedef std::vector<const ExpiringVisitsReader*> ExpiringVisitsReaders; |
44 | 45 |
| 46 namespace internal { |
| 47 // Feature that enables clearing old on-demand favicons. |
| 48 extern const base::Feature kClearOldOnDemandFavicons; |
| 49 } // namespace internal |
| 50 |
45 // Helper component to HistoryBackend that manages expiration and deleting of | 51 // Helper component to HistoryBackend that manages expiration and deleting of |
46 // history. | 52 // history. |
47 // | 53 // |
48 // It will automatically start periodically expiring old history once you call | 54 // It will automatically start periodically expiring old history once you call |
49 // StartExpiringOldStuff(). | 55 // StartExpiringOldStuff(). |
50 class ExpireHistoryBackend { | 56 class ExpireHistoryBackend { |
51 public: | 57 public: |
52 // The delegate pointer must be non-null. We will NOT take ownership of it. | 58 // The delegate pointer must be non-null. We will NOT take ownership of it. |
53 // HistoryBackendClient may be null. The HistoryBackendClient is used when | 59 // HistoryBackendClient may be null. The HistoryBackendClient is used when |
54 // expiring URLS so that we don't remove any URLs or favicons that are | 60 // expiring URLS so that we don't remove any URLs or favicons that are |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // should not save it. | 101 // should not save it. |
96 base::Time GetCurrentExpirationTime() const { | 102 base::Time GetCurrentExpirationTime() const { |
97 return base::Time::Now() - expiration_threshold_; | 103 return base::Time::Now() - expiration_threshold_; |
98 } | 104 } |
99 | 105 |
100 private: | 106 private: |
101 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, DeleteFaviconsIfPossible); | 107 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, DeleteFaviconsIfPossible); |
102 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpireSomeOldHistory); | 108 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpireSomeOldHistory); |
103 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpiringVisitsReader); | 109 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpiringVisitsReader); |
104 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpireSomeOldHistoryWithSource); | 110 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpireSomeOldHistoryWithSource); |
| 111 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, |
| 112 ClearOldOnDemandFaviconsDoesNotDeleteStarred); |
| 113 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, |
| 114 ClearOldOnDemandFaviconsDoesDeleteUnstarred); |
105 friend class ::TestingProfile; | 115 friend class ::TestingProfile; |
106 | 116 |
107 struct DeleteEffects { | 117 struct DeleteEffects { |
108 DeleteEffects(); | 118 DeleteEffects(); |
109 ~DeleteEffects(); | 119 ~DeleteEffects(); |
110 | 120 |
111 // The time range affected. These can be is_null() to be unbounded in one | 121 // The time range affected. These can be is_null() to be unbounded in one |
112 // or both directions. | 122 // or both directions. |
113 base::Time begin_time, end_time; | 123 base::Time begin_time, end_time; |
114 | 124 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 void BroadcastNotifications(DeleteEffects* effects, DeletionType type); | 209 void BroadcastNotifications(DeleteEffects* effects, DeletionType type); |
200 | 210 |
201 // Schedules a call to DoExpireIteration. | 211 // Schedules a call to DoExpireIteration. |
202 void ScheduleExpire(); | 212 void ScheduleExpire(); |
203 | 213 |
204 // Calls ExpireSomeOldHistory to expire some amount of old history, according | 214 // Calls ExpireSomeOldHistory to expire some amount of old history, according |
205 // to the items in work queue, and schedules another call to happen in the | 215 // to the items in work queue, and schedules another call to happen in the |
206 // future. | 216 // future. |
207 void DoExpireIteration(); | 217 void DoExpireIteration(); |
208 | 218 |
| 219 // Clears all old on-demand favicons from thumbnail database. |
| 220 void ClearOldOnDemandFavicons(base::Time expiration_threshold); |
| 221 |
209 // Tries to expire the oldest |max_visits| visits from history that are older | 222 // Tries to expire the oldest |max_visits| visits from history that are older |
210 // than |time_threshold|. The return value indicates if we think there might | 223 // than |time_threshold|. The return value indicates if we think there might |
211 // be more history to expire with the current time threshold (it does not | 224 // be more history to expire with the current time threshold (it does not |
212 // indicate success or failure). | 225 // indicate success or failure). |
213 bool ExpireSomeOldHistory(base::Time end_time, | 226 bool ExpireSomeOldHistory(base::Time end_time, |
214 const ExpiringVisitsReader* reader, | 227 const ExpiringVisitsReader* reader, |
215 int max_visits); | 228 int max_visits); |
216 | 229 |
217 // Tries to detect possible bad history or inconsistencies in the database | 230 // Tries to detect possible bad history or inconsistencies in the database |
218 // and deletes items. For example, URLs with no visits. | 231 // and deletes items. For example, URLs with no visits. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Used to generate runnable methods to do timers on this class. They will be | 276 // Used to generate runnable methods to do timers on this class. They will be |
264 // automatically canceled when this class is deleted. | 277 // automatically canceled when this class is deleted. |
265 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; | 278 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; |
266 | 279 |
267 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); | 280 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); |
268 }; | 281 }; |
269 | 282 |
270 } // namespace history | 283 } // namespace history |
271 | 284 |
272 #endif // COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ | 285 #endif // COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ |
OLD | NEW |