Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Unified Diff: trunk/src/chrome/browser/history/expire_history_backend.cc

Issue 19637009: Revert 212459 "Remove TextDatabase from the history service." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: trunk/src/chrome/browser/history/expire_history_backend.cc
===================================================================
--- trunk/src/chrome/browser/history/expire_history_backend.cc (revision 212472)
+++ trunk/src/chrome/browser/history/expire_history_backend.cc (working copy)
@@ -19,6 +19,8 @@
#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"
using base::Time;
@@ -170,6 +172,10 @@
// The list of all favicon urls that were actually deleted from the thumbnail
// db.
std::set<GURL> expired_favicons;
+
+ // Tracks the set of databases that have changed so we can optimize when
+ // when we're done.
+ TextDatabaseManager::ChangeSet text_db_changes;
};
ExpireHistoryBackend::ExpireHistoryBackend(
@@ -179,6 +185,7 @@
main_db_(NULL),
archived_db_(NULL),
thumb_db_(NULL),
+ text_db_(NULL),
weak_factory_(this),
bookmark_service_(bookmark_service) {
}
@@ -188,10 +195,12 @@
void ExpireHistoryBackend::SetDatabases(HistoryDatabase* main_db,
ArchivedDatabase* archived_db,
- ThumbnailDatabase* thumb_db) {
+ ThumbnailDatabase* thumb_db,
+ TextDatabaseManager* text_db) {
main_db_ = main_db;
archived_db_ = archived_db;
thumb_db_ = thumb_db;
+ text_db_ = text_db;
}
void ExpireHistoryBackend::DeleteURL(const GURL& url) {
@@ -233,6 +242,9 @@
DeleteFaviconsIfPossible(dependencies.affected_favicons,
&dependencies.expired_favicons);
+ if (text_db_)
+ text_db_->OptimizeChangedDatabases(dependencies.text_db_changes);
+
BroadcastDeleteNotifications(&dependencies, DELETION_USER_INITIATED);
}
@@ -241,6 +253,10 @@
if (!main_db_)
return;
+ // There may be stuff in the text database manager's temporary cache.
+ if (text_db_)
+ text_db_->DeleteFromUncommitted(restrict_urls, begin_time, end_time);
+
// Find the affected visits and delete them.
// TODO(brettw): bug 1171164: We should query the archived database here, too.
VisitVector visits;
@@ -274,6 +290,10 @@
if (!main_db_)
return;
+ // There may be stuff in the text database manager's temporary cache.
+ if (text_db_)
+ text_db_->DeleteFromUncommittedForTimes(times);
+
// Find the affected visits and delete them.
// TODO(brettw): bug 1171164: We should query the archived database here, too.
VisitVector visits;
@@ -348,6 +368,7 @@
// Initialize the queue with all tasks for the first set of iterations.
InitWorkQueue();
ScheduleArchive();
+ ScheduleExpireHistoryIndexFiles();
}
void ExpireHistoryBackend::DeleteFaviconsIfPossible(
@@ -401,12 +422,22 @@
// Add the URL row to the affected URL list.
std::map<URLID, URLRow>::const_iterator found =
dependencies->affected_urls.find(visits[i].url_id);
+ const URLRow* cur_row = NULL;
if (found == dependencies->affected_urls.end()) {
URLRow row;
if (!main_db_->GetURLRow(visits[i].url_id, &row))
continue;
dependencies->affected_urls[visits[i].url_id] = row;
+ cur_row = &dependencies->affected_urls[visits[i].url_id];
+ } else {
+ cur_row = &found->second;
}
+
+ // Delete any associated full-text indexed data.
+ if (visits[i].is_indexed && text_db_) {
+ text_db_->DeletePageData(visits[i].visit_time, cur_row->url(),
+ &dependencies->text_db_changes);
+ }
}
}
@@ -416,6 +447,13 @@
DeleteDependencies* dependencies) {
main_db_->DeleteSegmentForURL(url_row.id());
+ // The URL may be in the text database manager's temporary cache.
+ if (text_db_) {
+ std::set<GURL> restrict_urls;
+ restrict_urls.insert(url_row.url());
+ text_db_->DeleteFromUncommitted(restrict_urls, base::Time(), base::Time());
+ }
+
if (!is_bookmarked) {
dependencies->deleted_urls.push_back(url_row);
@@ -684,6 +722,48 @@
// TODO(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);
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ExpireHistoryBackend::DoExpireHistoryIndexFiles,
+ weak_factory_.GetWeakPtr()),
+ delay);
+}
+
+void ExpireHistoryBackend::DoExpireHistoryIndexFiles() {
+ if (!text_db_) {
+ // The text database may have been closed since the task was scheduled.
+ return;
+ }
+
+ 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);
+
+ base::FilePath::StringType history_index_files_pattern =
+ TextDatabase::file_base();
+ history_index_files_pattern.append(FILE_PATH_LITERAL("*"));
+ base::FileEnumerator file_enumerator(
+ text_db_->GetDir(), false, base::FileEnumerator::FILES,
+ history_index_files_pattern);
+ for (base::FilePath file = file_enumerator.Next(); !file.empty();
+ file = file_enumerator.Next()) {
+ TextDatabase::DBIdent file_id = TextDatabase::FileNameToID(file);
+ if (file_id < cutoff_id)
+ sql::Connection::Delete(file);
+ }
+}
+
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

Powered by Google App Engine
This is Rietveld 408576698