summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-14 20:54:59 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-14 20:54:59 +0000
commit14593524ba43e80db1c842df87026d0194ff823d (patch)
treecefc35eb8a1bdef0ca4789b9cf9bdf1a2f43e7fc /chrome/browser
parentd8f977430b5e85b8489f7c39afc0afad06892672 (diff)
downloadchromium_src-14593524ba43e80db1c842df87026d0194ff823d.zip
chromium_src-14593524ba43e80db1c842df87026d0194ff823d.tar.gz
chromium_src-14593524ba43e80db1c842df87026d0194ff823d.tar.bz2
Remove old history index files.
BUG=none TEST=none Review URL: http://codereview.chromium.org/2762012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/history/expire_history_backend.cc46
-rw-r--r--chrome/browser/history/expire_history_backend.h6
-rw-r--r--chrome/browser/history/text_database_manager.h3
3 files changed, 54 insertions, 1 deletions
diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc
index 2a01212..bd471ad 100644
--- a/chrome/browser/history/expire_history_backend.cc
+++ b/chrome/browser/history/expire_history_backend.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/history/archived_database.h"
#include "chrome/browser/history/history_database.h"
#include "chrome/browser/history/history_notifications.h"
+#include "chrome/browser/history/text_database.h"
#include "chrome/browser/history/text_database_manager.h"
#include "chrome/browser/history/thumbnail_database.h"
#include "chrome/common/notification_type.h"
@@ -123,6 +124,14 @@ const int kExpirationDelaySec = 30;
// iteration, so we want to wait longer before checking to avoid wasting CPU.
const int kExpirationEmptyDelayMin = 5;
+// The number of minutes that we wait for before scheduling a task to
+// delete old history index files.
+const int kIndexExpirationDelayMin = 2;
+
+// The number of the most recent months for which we do not want to delete
+// the history index files.
+const int kStoreHistoryIndexesForMonths = 12;
+
} // namespace
struct ExpireHistoryBackend::DeleteDependencies {
@@ -303,6 +312,7 @@ void ExpireHistoryBackend::StartArchivingOldStuff(
// Initialize the queue with all tasks for the first set of iterations.
InitWorkQueue();
ScheduleArchive();
+ ScheduleExpireHistoryIndexFiles();
}
void ExpireHistoryBackend::DeleteFaviconsIfPossible(
@@ -556,7 +566,6 @@ void ExpireHistoryBackend::ScheduleArchive() {
delay = TimeDelta::FromSeconds(kExpirationDelaySec);
}
- factory_.RevokeAll();
MessageLoop::current()->PostDelayedTask(FROM_HERE, factory_.NewRunnableMethod(
&ExpireHistoryBackend::DoArchiveIteration), delay.InMilliseconds());
}
@@ -641,6 +650,41 @@ void ExpireHistoryBackend::ParanoidExpireHistory() {
// FIXME(brettw): Bug 1067331: write this to clean up any errors.
}
+void ExpireHistoryBackend::ScheduleExpireHistoryIndexFiles() {
+ if (!text_db_) {
+ // Can't expire old history index files because we
+ // don't know where they're located.
+ return;
+ }
+
+ TimeDelta delay = TimeDelta::FromMinutes(kIndexExpirationDelayMin);
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, factory_.NewRunnableMethod(
+ &ExpireHistoryBackend::DoExpireHistoryIndexFiles),
+ delay.InMilliseconds());
+}
+
+void ExpireHistoryBackend::DoExpireHistoryIndexFiles() {
+ Time::Exploded exploded;
+ Time::Now().LocalExplode(&exploded);
+ int cutoff_month =
+ exploded.year * 12 + exploded.month - kStoreHistoryIndexesForMonths;
+ TextDatabase::DBIdent cutoff_id =
+ (cutoff_month / 12) * 100 + (cutoff_month % 12);
+
+ FilePath::StringType history_index_files_pattern = TextDatabase::file_base();
+ history_index_files_pattern.append(FILE_PATH_LITERAL("*"));
+ file_util::FileEnumerator file_enumerator(
+ text_db_->GetDir(), false, file_util::FileEnumerator::FILES,
+ history_index_files_pattern);
+ for (FilePath file = file_enumerator.Next(); !file.empty();
+ file = file_enumerator.Next()) {
+ TextDatabase::DBIdent file_id = TextDatabase::FileNameToID(file);
+ if (file_id < cutoff_id)
+ file_util::Delete(file, false);
+ }
+}
+
BookmarkService* ExpireHistoryBackend::GetBookmarkService() {
// We use the bookmark service to determine if a URL is bookmarked. The
// bookmark service is loaded on a separate thread and may not be done by the
diff --git a/chrome/browser/history/expire_history_backend.h b/chrome/browser/history/expire_history_backend.h
index 0435561..9f060ed 100644
--- a/chrome/browser/history/expire_history_backend.h
+++ b/chrome/browser/history/expire_history_backend.h
@@ -222,6 +222,12 @@ class ExpireHistoryBackend {
// and deletes items. For example, URLs with no visits.
void ParanoidExpireHistory();
+ // Schedules a call to DoExpireHistoryIndexFiles.
+ void ScheduleExpireHistoryIndexFiles();
+
+ // Deletes old history index files.
+ void DoExpireHistoryIndexFiles();
+
// Returns the BookmarkService, blocking until it is loaded. This may return
// NULL.
BookmarkService* GetBookmarkService();
diff --git a/chrome/browser/history/text_database_manager.h b/chrome/browser/history/text_database_manager.h
index b4179a5..c84d423 100644
--- a/chrome/browser/history/text_database_manager.h
+++ b/chrome/browser/history/text_database_manager.h
@@ -82,6 +82,9 @@ class TextDatabaseManager {
// functions should be called.
bool Init(const HistoryPublisher* history_publisher);
+ // Returns the directory that holds the full text database files.
+ const FilePath& GetDir() { return dir_; }
+
// Allows scoping updates. This also allows things to go faster since every
// page add doesn't need to be committed to disk (slow). Note that files will
// still get created during a transaction.