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

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

Issue 2903573002: [Thumbnails DB] Add functionality to clear unused on-demand favicons. (Closed)
Patch Set: Brett's comments 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 #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
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);
115 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest,
116 ClearOldOnDemandFaviconsDoesDeleteAfterLongDelay);
117 FRIEND_TEST_ALL_PREFIXES(
118 ExpireHistoryTest,
119 ClearOldOnDemandFaviconsDoesNotDeleteAfterShortDelay);
120
105 friend class ::TestingProfile; 121 friend class ::TestingProfile;
106 122
107 struct DeleteEffects { 123 struct DeleteEffects {
108 DeleteEffects(); 124 DeleteEffects();
109 ~DeleteEffects(); 125 ~DeleteEffects();
110 126
111 // The time range affected. These can be is_null() to be unbounded in one 127 // The time range affected. These can be is_null() to be unbounded in one
112 // or both directions. 128 // or both directions.
113 base::Time begin_time, end_time; 129 base::Time begin_time, end_time;
114 130
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void BroadcastNotifications(DeleteEffects* effects, DeletionType type); 215 void BroadcastNotifications(DeleteEffects* effects, DeletionType type);
200 216
201 // Schedules a call to DoExpireIteration. 217 // Schedules a call to DoExpireIteration.
202 void ScheduleExpire(); 218 void ScheduleExpire();
203 219
204 // Calls ExpireSomeOldHistory to expire some amount of old history, according 220 // 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 221 // to the items in work queue, and schedules another call to happen in the
206 // future. 222 // future.
207 void DoExpireIteration(); 223 void DoExpireIteration();
208 224
225 // Clears all old on-demand favicons from thumbnail database.
226 void ClearOldOnDemandFavicons(base::Time expiration_threshold);
227
209 // Tries to expire the oldest |max_visits| visits from history that are older 228 // 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 229 // 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 230 // be more history to expire with the current time threshold (it does not
212 // indicate success or failure). 231 // indicate success or failure).
213 bool ExpireSomeOldHistory(base::Time end_time, 232 bool ExpireSomeOldHistory(base::Time end_time,
214 const ExpiringVisitsReader* reader, 233 const ExpiringVisitsReader* reader,
215 int max_visits); 234 int max_visits);
216 235
217 // Tries to detect possible bad history or inconsistencies in the database 236 // Tries to detect possible bad history or inconsistencies in the database
218 // and deletes items. For example, URLs with no visits. 237 // and deletes items. For example, URLs with no visits.
(...skipping 14 matching lines...) Expand all
233 // Non-owning pointer to the notification delegate (guaranteed non-NULL). 252 // Non-owning pointer to the notification delegate (guaranteed non-NULL).
234 HistoryBackendNotifier* notifier_; 253 HistoryBackendNotifier* notifier_;
235 254
236 // Non-owning pointers to the databases we deal with (MAY BE NULL). 255 // Non-owning pointers to the databases we deal with (MAY BE NULL).
237 HistoryDatabase* main_db_; // Main history database. 256 HistoryDatabase* main_db_; // Main history database.
238 ThumbnailDatabase* thumb_db_; // Thumbnails and favicons. 257 ThumbnailDatabase* thumb_db_; // Thumbnails and favicons.
239 258
240 // The threshold for "old" history where we will automatically delete it. 259 // The threshold for "old" history where we will automatically delete it.
241 base::TimeDelta expiration_threshold_; 260 base::TimeDelta expiration_threshold_;
242 261
262 // The lastly used threshold for "old" on-demand favicons.
263 base::Time last_on_demand_expiration_threshold_;
264
243 // List of all distinct types of readers. This list is used to populate the 265 // List of all distinct types of readers. This list is used to populate the
244 // work queue. 266 // work queue.
245 ExpiringVisitsReaders readers_; 267 ExpiringVisitsReaders readers_;
246 268
247 // Work queue for periodic expiration tasks, used by DoExpireIteration() to 269 // Work queue for periodic expiration tasks, used by DoExpireIteration() to
248 // determine what to do at an iteration, as well as populate it for future 270 // determine what to do at an iteration, as well as populate it for future
249 // iterations. 271 // iterations.
250 std::queue<const ExpiringVisitsReader*> work_queue_; 272 std::queue<const ExpiringVisitsReader*> work_queue_;
251 273
252 // Readers for various types of visits. 274 // Readers for various types of visits.
(...skipping 10 matching lines...) Expand all
263 // Used to generate runnable methods to do timers on this class. They will be 285 // Used to generate runnable methods to do timers on this class. They will be
264 // automatically canceled when this class is deleted. 286 // automatically canceled when this class is deleted.
265 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; 287 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_;
266 288
267 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); 289 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend);
268 }; 290 };
269 291
270 } // namespace history 292 } // namespace history
271 293
272 #endif // COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_ 294 #endif // COMPONENTS_HISTORY_CORE_BROWSER_EXPIRE_HISTORY_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698