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 CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
6 #define CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ | 6 #define CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.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 "chrome/browser/history/history_types.h" | 17 #include "chrome/browser/history/history_types.h" |
18 | 18 |
19 class BookmarkService; | |
20 class GURL; | 19 class GURL; |
21 class TestingProfile; | 20 class TestingProfile; |
22 | 21 |
23 namespace history { | 22 namespace history { |
24 | 23 |
25 class ArchivedDatabase; | 24 class ArchivedDatabase; |
| 25 class HistoryClient; |
26 class HistoryDatabase; | 26 class HistoryDatabase; |
27 struct HistoryDetails; | 27 struct HistoryDetails; |
28 class ThumbnailDatabase; | 28 class ThumbnailDatabase; |
29 | 29 |
30 // Delegate used to broadcast notifications to the main thread. | 30 // Delegate used to broadcast notifications to the main thread. |
31 class BroadcastNotificationDelegate { | 31 class BroadcastNotificationDelegate { |
32 public: | 32 public: |
33 // Schedules a broadcast of the given notification on the application main | 33 // Schedules a broadcast of the given notification on the application main |
34 // thread. | 34 // thread. |
35 virtual void BroadcastNotifications(int type, | 35 virtual void BroadcastNotifications(int type, |
(...skipping 23 matching lines...) Expand all Loading... |
59 | 59 |
60 // Helper component to HistoryBackend that manages expiration and deleting of | 60 // Helper component to HistoryBackend that manages expiration and deleting of |
61 // history, as well as moving data from the main database to the archived | 61 // history, as well as moving data from the main database to the archived |
62 // database as it gets old. | 62 // database as it gets old. |
63 // | 63 // |
64 // It will automatically start periodically archiving old history once you call | 64 // It will automatically start periodically archiving old history once you call |
65 // StartArchivingOldStuff(). | 65 // StartArchivingOldStuff(). |
66 class ExpireHistoryBackend { | 66 class ExpireHistoryBackend { |
67 public: | 67 public: |
68 // The delegate pointer must be non-NULL. We will NOT take ownership of it. | 68 // The delegate pointer must be non-NULL. We will NOT take ownership of it. |
69 // BookmarkService may be NULL. The BookmarkService is used when expiring | 69 // HistoryClient may be NULL. The HistoryClient is used when expiring URLS so |
70 // URLs so that we don't remove any URLs or favicons that are bookmarked | 70 // that we don't remove any URLs or favicons that are bookmarked (visits are |
71 // (visits are removed though). | 71 // removed though). |
72 ExpireHistoryBackend(BroadcastNotificationDelegate* delegate, | 72 ExpireHistoryBackend(BroadcastNotificationDelegate* delegate, |
73 BookmarkService* bookmark_service); | 73 HistoryClient* history_client); |
74 ~ExpireHistoryBackend(); | 74 ~ExpireHistoryBackend(); |
75 | 75 |
76 // Completes initialization by setting the databases that this class will use. | 76 // Completes initialization by setting the databases that this class will use. |
77 void SetDatabases(HistoryDatabase* main_db, | 77 void SetDatabases(HistoryDatabase* main_db, |
78 ArchivedDatabase* archived_db, | 78 ArchivedDatabase* archived_db, |
79 ThumbnailDatabase* thumb_db); | 79 ThumbnailDatabase* thumb_db); |
80 | 80 |
81 // Begins periodic expiration of history older than the given threshold. This | 81 // Begins periodic expiration of history older than the given threshold. This |
82 // will continue until the object is deleted. | 82 // will continue until the object is deleted. |
83 void StartArchivingOldStuff(base::TimeDelta expiration_threshold); | 83 void StartArchivingOldStuff(base::TimeDelta expiration_threshold); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // be more history to expire with the current time threshold (it does not | 244 // be more history to expire with the current time threshold (it does not |
245 // indicate success or failure). | 245 // indicate success or failure). |
246 bool ArchiveSomeOldHistory(base::Time end_time, | 246 bool ArchiveSomeOldHistory(base::Time end_time, |
247 const ExpiringVisitsReader* reader, | 247 const ExpiringVisitsReader* reader, |
248 int max_visits); | 248 int max_visits); |
249 | 249 |
250 // Tries to detect possible bad history or inconsistencies in the database | 250 // Tries to detect possible bad history or inconsistencies in the database |
251 // and deletes items. For example, URLs with no visits. | 251 // and deletes items. For example, URLs with no visits. |
252 void ParanoidExpireHistory(); | 252 void ParanoidExpireHistory(); |
253 | 253 |
254 // Returns the BookmarkService, blocking until it is loaded. This may return | 254 // Returns the HistoryClient, blocking until the bookmarks are loaded. This |
255 // NULL. | 255 // may return NULL during testing. |
256 BookmarkService* GetBookmarkService(); | 256 HistoryClient* GetHistoryClient(); |
257 | 257 |
258 // Initializes periodic expiration work queue by populating it with with tasks | 258 // Initializes periodic expiration work queue by populating it with with tasks |
259 // for all known readers. | 259 // for all known readers. |
260 void InitWorkQueue(); | 260 void InitWorkQueue(); |
261 | 261 |
262 // Returns the reader for all visits. This method is only used by the unit | 262 // Returns the reader for all visits. This method is only used by the unit |
263 // tests. | 263 // tests. |
264 const ExpiringVisitsReader* GetAllVisitsReader(); | 264 const ExpiringVisitsReader* GetAllVisitsReader(); |
265 | 265 |
266 // Returns the reader for AUTO_SUBFRAME visits. This method is only used by | 266 // Returns the reader for AUTO_SUBFRAME visits. This method is only used by |
(...skipping 24 matching lines...) Expand all Loading... |
291 // determine what to do at an iteration, as well as populate it for future | 291 // determine what to do at an iteration, as well as populate it for future |
292 // iterations. | 292 // iterations. |
293 std::queue<const ExpiringVisitsReader*> work_queue_; | 293 std::queue<const ExpiringVisitsReader*> work_queue_; |
294 | 294 |
295 // Readers for various types of visits. | 295 // Readers for various types of visits. |
296 // TODO(dglazkov): If you are adding another one, please consider reorganizing | 296 // TODO(dglazkov): If you are adding another one, please consider reorganizing |
297 // into a map. | 297 // into a map. |
298 scoped_ptr<ExpiringVisitsReader> all_visits_reader_; | 298 scoped_ptr<ExpiringVisitsReader> all_visits_reader_; |
299 scoped_ptr<ExpiringVisitsReader> auto_subframe_visits_reader_; | 299 scoped_ptr<ExpiringVisitsReader> auto_subframe_visits_reader_; |
300 | 300 |
301 // The BookmarkService; may be null. This is owned by the Profile. | 301 // The HistoryClient; may be NULL. |
302 // | 302 // |
303 // Use GetBookmarkService to access this, which makes sure the service is | 303 // Use GetHistoryClient to access this, which makes sure the bookmarks are |
304 // loaded. | 304 // loaded before returning. |
305 BookmarkService* bookmark_service_; | 305 HistoryClient* history_client_; |
306 | 306 |
307 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); | 307 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); |
308 }; | 308 }; |
309 | 309 |
310 } // namespace history | 310 } // namespace history |
311 | 311 |
312 #endif // CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ | 312 #endif // CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
OLD | NEW |