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; | 19 class BookmarkService; |
20 class GURL; | 20 class GURL; |
21 class TestingProfile; | 21 class TestingProfile; |
22 | 22 |
23 namespace history { | 23 namespace history { |
24 | 24 |
25 class ArchivedDatabase; | 25 class ArchivedDatabase; |
26 class HistoryDatabase; | 26 class HistoryDatabase; |
27 struct HistoryDetails; | 27 struct HistoryDetails; |
| 28 class TextDatabaseManager; |
28 class ThumbnailDatabase; | 29 class ThumbnailDatabase; |
29 | 30 |
30 // Delegate used to broadcast notifications to the main thread. | 31 // Delegate used to broadcast notifications to the main thread. |
31 class BroadcastNotificationDelegate { | 32 class BroadcastNotificationDelegate { |
32 public: | 33 public: |
33 // Schedules a broadcast of the given notification on the application main | 34 // Schedules a broadcast of the given notification on the application main |
34 // thread. The details argument will have ownership taken by this function. | 35 // thread. The details argument will have ownership taken by this function. |
35 virtual void BroadcastNotifications(int type, | 36 virtual void BroadcastNotifications(int type, |
36 HistoryDetails* details_deleted) = 0; | 37 HistoryDetails* details_deleted) = 0; |
37 | 38 |
(...skipping 30 matching lines...) Expand all Loading... |
68 // BookmarkService may be NULL. The BookmarkService is used when expiring | 69 // BookmarkService may be NULL. The BookmarkService is used when expiring |
69 // URLs so that we don't remove any URLs or favicons that are bookmarked | 70 // URLs so that we don't remove any URLs or favicons that are bookmarked |
70 // (visits are removed though). | 71 // (visits are removed though). |
71 ExpireHistoryBackend(BroadcastNotificationDelegate* delegate, | 72 ExpireHistoryBackend(BroadcastNotificationDelegate* delegate, |
72 BookmarkService* bookmark_service); | 73 BookmarkService* bookmark_service); |
73 ~ExpireHistoryBackend(); | 74 ~ExpireHistoryBackend(); |
74 | 75 |
75 // Completes initialization by setting the databases that this class will use. | 76 // Completes initialization by setting the databases that this class will use. |
76 void SetDatabases(HistoryDatabase* main_db, | 77 void SetDatabases(HistoryDatabase* main_db, |
77 ArchivedDatabase* archived_db, | 78 ArchivedDatabase* archived_db, |
78 ThumbnailDatabase* thumb_db); | 79 ThumbnailDatabase* thumb_db, |
| 80 TextDatabaseManager* text_db); |
79 | 81 |
80 // Begins periodic expiration of history older than the given threshold. This | 82 // Begins periodic expiration of history older than the given threshold. This |
81 // will continue until the object is deleted. | 83 // will continue until the object is deleted. |
82 void StartArchivingOldStuff(base::TimeDelta expiration_threshold); | 84 void StartArchivingOldStuff(base::TimeDelta expiration_threshold); |
83 | 85 |
84 // Deletes everything associated with a URL. | 86 // Deletes everything associated with a URL. |
85 void DeleteURL(const GURL& url); | 87 void DeleteURL(const GURL& url); |
86 | 88 |
87 // Deletes everything associated with each URL in the list. | 89 // Deletes everything associated with each URL in the list. |
88 void DeleteURLs(const std::vector<GURL>& url); | 90 void DeleteURLs(const std::vector<GURL>& url); |
(...skipping 30 matching lines...) Expand all Loading... |
119 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ArchiveSomeOldHistory); | 121 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ArchiveSomeOldHistory); |
120 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpiringVisitsReader); | 122 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ExpiringVisitsReader); |
121 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ArchiveSomeOldHistoryWithSource); | 123 FRIEND_TEST_ALL_PREFIXES(ExpireHistoryTest, ArchiveSomeOldHistoryWithSource); |
122 friend class ::TestingProfile; | 124 friend class ::TestingProfile; |
123 | 125 |
124 struct DeleteDependencies; | 126 struct DeleteDependencies; |
125 | 127 |
126 // Deletes the visit-related stuff for all the visits in the given list, and | 128 // Deletes the visit-related stuff for all the visits in the given list, and |
127 // adds the rows for unique URLs affected to the affected_urls list in | 129 // adds the rows for unique URLs affected to the affected_urls list in |
128 // the dependencies structure. | 130 // the dependencies structure. |
| 131 // |
| 132 // Deleted information is the visits themselves and the full-text index |
| 133 // entries corresponding to them. |
129 void DeleteVisitRelatedInfo(const VisitVector& visits, | 134 void DeleteVisitRelatedInfo(const VisitVector& visits, |
130 DeleteDependencies* dependencies); | 135 DeleteDependencies* dependencies); |
131 | 136 |
132 // Moves the given visits from the main database to the archived one. | 137 // Moves the given visits from the main database to the archived one. |
133 void ArchiveVisits(const VisitVector& visits); | 138 void ArchiveVisits(const VisitVector& visits); |
134 | 139 |
135 // Finds or deletes dependency information for the given URL. Information that | 140 // Finds or deletes dependency information for the given URL. Information that |
136 // is specific to this URL (URL row, thumbnails, etc.) is deleted. | 141 // is specific to this URL (URL row, thumbnails, full text indexed stuff, |
| 142 // etc.) is deleted. |
137 // | 143 // |
138 // This does not affect the visits! This is used for expiration as well as | 144 // This does not affect the visits! This is used for expiration as well as |
139 // deleting from the UI, and they handle visits differently. | 145 // deleting from the UI, and they handle visits differently. |
140 // | 146 // |
141 // Other information will be collected and returned in the output containers. | 147 // Other information will be collected and returned in the output containers. |
142 // This includes some of the things deleted that are needed elsewhere, plus | 148 // This includes some of the things deleted that are needed elsewhere, plus |
143 // some things like favicons that could be shared by many URLs, and need to | 149 // some things like favicons that could be shared by many URLs, and need to |
144 // be checked for deletion (this allows us to delete many URLs with only one | 150 // be checked for deletion (this allows us to delete many URLs with only one |
145 // check for shared information at the end). | 151 // check for shared information at the end). |
146 // | 152 // |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // be more history to expire with the current time threshold (it does not | 233 // be more history to expire with the current time threshold (it does not |
228 // indicate success or failure). | 234 // indicate success or failure). |
229 bool ArchiveSomeOldHistory(base::Time end_time, | 235 bool ArchiveSomeOldHistory(base::Time end_time, |
230 const ExpiringVisitsReader* reader, | 236 const ExpiringVisitsReader* reader, |
231 int max_visits); | 237 int max_visits); |
232 | 238 |
233 // Tries to detect possible bad history or inconsistencies in the database | 239 // Tries to detect possible bad history or inconsistencies in the database |
234 // and deletes items. For example, URLs with no visits. | 240 // and deletes items. For example, URLs with no visits. |
235 void ParanoidExpireHistory(); | 241 void ParanoidExpireHistory(); |
236 | 242 |
| 243 // Schedules a call to DoExpireHistoryIndexFiles. |
| 244 void ScheduleExpireHistoryIndexFiles(); |
| 245 |
| 246 // Deletes old history index files. |
| 247 void DoExpireHistoryIndexFiles(); |
| 248 |
237 // Returns the BookmarkService, blocking until it is loaded. This may return | 249 // Returns the BookmarkService, blocking until it is loaded. This may return |
238 // NULL. | 250 // NULL. |
239 BookmarkService* GetBookmarkService(); | 251 BookmarkService* GetBookmarkService(); |
240 | 252 |
241 // Initializes periodic expiration work queue by populating it with with tasks | 253 // Initializes periodic expiration work queue by populating it with with tasks |
242 // for all known readers. | 254 // for all known readers. |
243 void InitWorkQueue(); | 255 void InitWorkQueue(); |
244 | 256 |
245 // Returns the reader for all visits. This method is only used by the unit | 257 // Returns the reader for all visits. This method is only used by the unit |
246 // tests. | 258 // tests. |
247 const ExpiringVisitsReader* GetAllVisitsReader(); | 259 const ExpiringVisitsReader* GetAllVisitsReader(); |
248 | 260 |
249 // Returns the reader for AUTO_SUBFRAME visits. This method is only used by | 261 // Returns the reader for AUTO_SUBFRAME visits. This method is only used by |
250 // the unit tests. | 262 // the unit tests. |
251 const ExpiringVisitsReader* GetAutoSubframeVisitsReader(); | 263 const ExpiringVisitsReader* GetAutoSubframeVisitsReader(); |
252 | 264 |
253 // Non-owning pointer to the notification delegate (guaranteed non-NULL). | 265 // Non-owning pointer to the notification delegate (guaranteed non-NULL). |
254 BroadcastNotificationDelegate* delegate_; | 266 BroadcastNotificationDelegate* delegate_; |
255 | 267 |
256 // Non-owning pointers to the databases we deal with (MAY BE NULL). | 268 // Non-owning pointers to the databases we deal with (MAY BE NULL). |
257 HistoryDatabase* main_db_; // Main history database. | 269 HistoryDatabase* main_db_; // Main history database. |
258 ArchivedDatabase* archived_db_; // Old history. | 270 ArchivedDatabase* archived_db_; // Old history. |
259 ThumbnailDatabase* thumb_db_; // Thumbnails and favicons. | 271 ThumbnailDatabase* thumb_db_; // Thumbnails and favicons. |
| 272 TextDatabaseManager* text_db_; // Full text index. |
260 | 273 |
261 // Used to generate runnable methods to do timers on this class. They will be | 274 // Used to generate runnable methods to do timers on this class. They will be |
262 // automatically canceled when this class is deleted. | 275 // automatically canceled when this class is deleted. |
263 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; | 276 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; |
264 | 277 |
265 // The threshold for "old" history where we will automatically expire it to | 278 // The threshold for "old" history where we will automatically expire it to |
266 // the archived database. | 279 // the archived database. |
267 base::TimeDelta expiration_threshold_; | 280 base::TimeDelta expiration_threshold_; |
268 | 281 |
269 // List of all distinct types of readers. This list is used to populate the | 282 // List of all distinct types of readers. This list is used to populate the |
(...skipping 16 matching lines...) Expand all Loading... |
286 // Use GetBookmarkService to access this, which makes sure the service is | 299 // Use GetBookmarkService to access this, which makes sure the service is |
287 // loaded. | 300 // loaded. |
288 BookmarkService* bookmark_service_; | 301 BookmarkService* bookmark_service_; |
289 | 302 |
290 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); | 303 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); |
291 }; | 304 }; |
292 | 305 |
293 } // namespace history | 306 } // namespace history |
294 | 307 |
295 #endif // CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ | 308 #endif // CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
OLD | NEW |