| Index: chrome/browser/history/expire_history_backend.h
|
| ===================================================================
|
| --- chrome/browser/history/expire_history_backend.h (revision 19822)
|
| +++ chrome/browser/history/expire_history_backend.h (working copy)
|
| @@ -5,12 +5,14 @@
|
| #ifndef CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H__
|
| #define CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H__
|
|
|
| +#include <queue>
|
| #include <set>
|
| #include <vector>
|
|
|
| #include "base/basictypes.h"
|
| #include "base/task.h"
|
| #include "base/time.h"
|
| +#include "base/scoped_ptr.h"
|
| #include "chrome/browser/history/history_types.h"
|
| #include "chrome/browser/history/text_database_manager.h"
|
| #include "testing/gtest/include/gtest/gtest_prod.h"
|
| @@ -36,6 +38,18 @@
|
| HistoryDetails* details_deleted) = 0;
|
| };
|
|
|
| +// Encapsulates visit expiration criteria and type of visits to expire.
|
| +class ExpiringVisitsReader {
|
| + public:
|
| + virtual ~ExpiringVisitsReader() {}
|
| + // Populates |visits| from |db|, using provided |end_time| and |max_visits|
|
| + // cap.
|
| + virtual bool Read(base::Time end_time, HistoryDatabase* db,
|
| + VisitVector* visits, int max_visits) const = 0;
|
| +};
|
| +
|
| +typedef std::vector<const ExpiringVisitsReader*> ExpiringVisitsReaders;
|
| +
|
| // Helper component to HistoryBackend that manages expiration and deleting of
|
| // history, as well as moving data from the main database to the archived
|
| // database as it gets old.
|
| @@ -86,6 +100,7 @@
|
| FRIEND_TEST(ExpireHistoryTest, DeleteTextIndexForURL);
|
| FRIEND_TEST(ExpireHistoryTest, DeleteFaviconsIfPossible);
|
| FRIEND_TEST(ExpireHistoryTest, ArchiveSomeOldHistory);
|
| + FRIEND_TEST(ExpireHistoryTest, ExpiringVisitsReader);
|
| friend class ::TestingProfile;
|
|
|
| struct DeleteDependencies {
|
| @@ -207,19 +222,21 @@
|
| // Broadcast the URL deleted notification.
|
| void BroadcastDeleteNotifications(DeleteDependencies* dependencies);
|
|
|
| - // Schedules a call to DoArchiveIteration at the given time in the
|
| + // Schedules a call to DoArchiveIteration.
|
| + void ScheduleArchive();
|
| +
|
| + // Calls ArchiveSomeOldHistory to expire some amount of old history, according
|
| + // to the items in work queue, and schedules another call to happen in the
|
| // future.
|
| - void ScheduleArchive(base::TimeDelta delay);
|
| -
|
| - // Calls ArchiveSomeOldHistory to expire some amount of old history, and
|
| - // schedules another call to happen in the future.
|
| void DoArchiveIteration();
|
|
|
| // Tries to expire the oldest |max_visits| visits from history that are older
|
| // than |time_threshold|. The return value indicates if we think there might
|
| // be more history to expire with the current time threshold (it does not
|
| // indicate success or failure).
|
| - bool ArchiveSomeOldHistory(base::Time time_threshold, int max_visits);
|
| + bool ArchiveSomeOldHistory(base::Time end_time,
|
| + const ExpiringVisitsReader* reader,
|
| + int max_visits);
|
|
|
| // Tries to detect possible bad history or inconsistencies in the database
|
| // and deletes items. For example, URLs with no visits.
|
| @@ -229,6 +246,18 @@
|
| // NULL.
|
| BookmarkService* GetBookmarkService();
|
|
|
| + // Initializes periodic expiration work queue by populating it with with tasks
|
| + // for all known readers.
|
| + void InitWorkQueue();
|
| +
|
| + // Returns the reader for all visits. This method is only used by the unit
|
| + // tests.
|
| + const ExpiringVisitsReader* GetAllVisitsReader();
|
| +
|
| + // Returns the reader for AUTO_SUBFRAME visits. This method is only used by
|
| + // the unit tests.
|
| + const ExpiringVisitsReader* GetAutoSubframeVisitsReader();
|
| +
|
| // Non-owning pointer to the notification delegate (guaranteed non-NULL).
|
| BroadcastNotificationDelegate* delegate_;
|
|
|
| @@ -246,6 +275,21 @@
|
| // the archived database.
|
| base::TimeDelta expiration_threshold_;
|
|
|
| + // List of all distinct types of readers. This list is used to populate the
|
| + // work queue.
|
| + ExpiringVisitsReaders readers_;
|
| +
|
| + // Work queue for periodic expiration tasks, used by DoArchiveIteration() to
|
| + // determine what to do at an iteration, as well as populate it for future
|
| + // iterations.
|
| + std::queue<const ExpiringVisitsReader*> work_queue_;
|
| +
|
| + // Readers for various types of visits.
|
| + // TODO(dglazkov): If you are adding another one, please consider reorganizing
|
| + // into a map.
|
| + scoped_ptr<ExpiringVisitsReader> all_visits_reader_;
|
| + scoped_ptr<ExpiringVisitsReader> auto_subframe_visits_reader_;
|
| +
|
| // The BookmarkService; may be null. This is owned by the Profile.
|
| //
|
| // Use GetBookmarkService to access this, which makes sure the service is
|
|
|