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