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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 // | 182 // |
173 // The visits in the given vector should have already been deleted from the | 183 // The visits in the given vector should have already been deleted from the |
174 // database, and the list of affected URLs already be filled into | 184 // database, and the list of affected URLs already be filled into |
175 // |depenencies->affected_urls|. | 185 // |depenencies->affected_urls|. |
176 // | 186 // |
177 // Starred URLs will not be deleted. The information in the dependencies that | 187 // Starred URLs will not be deleted. The information in the dependencies that |
178 // DeleteOneURL fills in will be updated, and this function will also delete | 188 // DeleteOneURL fills in will be updated, and this function will also delete |
179 // any now-unused favicons. | 189 // any now-unused favicons. |
180 void ExpireURLsForVisits(const VisitVector& visits, DeleteEffects* effects); | 190 void ExpireURLsForVisits(const VisitVector& visits, DeleteEffects* effects); |
181 | 191 |
192 // Clears all old on-demand favicons from thumbnail database. | |
193 void ClearOldOnDemandFavicons(base::Time expiration_threshold); | |
pkotwicz
2017/07/07 00:42:38
Nit: Match the function order in the .cc and the .
jkrcal
2017/07/07 08:45:16
Done.
| |
194 | |
182 // Deletes the favicons listed in |effects->affected_favicons| if they are | 195 // Deletes the favicons listed in |effects->affected_favicons| if they are |
183 // unsued. Fails silently (we don't care about favicons so much, so don't want | 196 // unsued. Fails silently (we don't care about favicons so much, so don't want |
184 // to stop everything if it fails). Fills |expired_favicons| with the set of | 197 // to stop everything if it fails). Fills |expired_favicons| with the set of |
185 // favicon urls that no longer have associated visits and were therefore | 198 // favicon urls that no longer have associated visits and were therefore |
186 // expired. | 199 // expired. |
187 void DeleteFaviconsIfPossible(DeleteEffects* effects); | 200 void DeleteFaviconsIfPossible(DeleteEffects* effects); |
188 | 201 |
189 // Enum representing what type of action resulted in the history DB deletion. | 202 // Enum representing what type of action resulted in the history DB deletion. |
190 enum DeletionType { | 203 enum DeletionType { |
191 // User initiated the deletion from the History UI. | 204 // User initiated the deletion from the History UI. |
(...skipping 71 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 |