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

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

Issue 235863023: Eliminate the archived history database and clean up related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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: chrome/browser/history/expire_history_backend.cc
diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc
index cf77fe48b6adad9cfdcb4c9f1db2567784181864..160e40db30cbbfa95016fe8b052d61d389343d43 100644
--- a/chrome/browser/history/expire_history_backend.cc
+++ b/chrome/browser/history/expire_history_backend.cc
@@ -16,7 +16,6 @@
#include "base/message_loop/message_loop.h"
#include "chrome/browser/bookmarks/bookmark_service.h"
#include "chrome/browser/chrome_notification_types.h"
-#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/thumbnail_database.h"
@@ -94,32 +93,6 @@ class AutoSubframeVisitsReader : public ExpiringVisitsReader {
}
};
-// Returns true if this visit is worth archiving. Otherwise, this visit is not
-// worth saving (for example, subframe navigations and redirects) and we can
-// just delete it when it gets old.
-bool ShouldArchiveVisit(const VisitRow& visit) {
- int no_qualifier = content::PageTransitionStripQualifier(visit.transition);
-
- // These types of transitions are always "important" and the user will want
- // to see them.
- if (no_qualifier == content::PAGE_TRANSITION_TYPED ||
- no_qualifier == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
- no_qualifier == content::PAGE_TRANSITION_AUTO_TOPLEVEL)
- return true;
-
- // Only archive these "less important" transitions when they were the final
- // navigation and not part of a redirect chain.
- if ((no_qualifier == content::PAGE_TRANSITION_LINK ||
- no_qualifier == content::PAGE_TRANSITION_FORM_SUBMIT ||
- no_qualifier == content::PAGE_TRANSITION_KEYWORD ||
- no_qualifier == content::PAGE_TRANSITION_GENERATED) &&
- visit.transition & content::PAGE_TRANSITION_CHAIN_END)
- return true;
-
- // The transition types we ignore are AUTO_SUBFRAME and MANUAL_SUBFRAME.
- return false;
-}
-
// The number of visits we will expire very time we check for old items. This
// Prevents us from doing too much work any given time.
const int kNumExpirePerIteration = 32;
@@ -169,7 +142,6 @@ ExpireHistoryBackend::ExpireHistoryBackend(
BookmarkService* bookmark_service)
: delegate_(delegate),
main_db_(NULL),
- archived_db_(NULL),
thumb_db_(NULL),
weak_factory_(this),
bookmark_service_(bookmark_service) {
@@ -179,10 +151,8 @@ ExpireHistoryBackend::~ExpireHistoryBackend() {
}
void ExpireHistoryBackend::SetDatabases(HistoryDatabase* main_db,
- ArchivedDatabase* archived_db,
ThumbnailDatabase* thumb_db) {
main_db_ = main_db;
- archived_db_ = archived_db;
thumb_db_ = thumb_db;
}
@@ -203,8 +173,7 @@ void ExpireHistoryBackend::DeleteURLs(const std::vector<GURL>& urls) {
// Collect all the visits and delete them. Note that we don't give
// up if there are no visits, since the URL could still have an
- // entry that we should delete. TODO(brettw): bug 1171148: We
- // should also delete from the archived DB.
+ // entry that we should delete.
VisitVector visits;
main_db_->GetVisitsForURL(url_row.id(), &visits);
@@ -234,7 +203,6 @@ void ExpireHistoryBackend::ExpireHistoryBetween(
return;
// Find the affected visits and delete them.
- // TODO(brettw): bug 1171164: We should query the archived database here, too.
VisitVector visits;
main_db_->GetAllVisitsInRange(begin_time, end_time, 0, &visits);
if (!restrict_urls.empty()) {
@@ -267,7 +235,6 @@ void ExpireHistoryBackend::ExpireHistoryForTimes(
return;
// Find the affected visits and delete them.
- // TODO(brettw): bug 1171164: We should query the archived database here, too.
VisitVector visits;
main_db_->GetVisitsForTimes(times, &visits);
ExpireVisits(visits);
@@ -294,12 +261,12 @@ void ExpireHistoryBackend::ExpireVisits(const VisitVector& visits) {
ParanoidExpireHistory();
}
-void ExpireHistoryBackend::ArchiveHistoryBefore(Time end_time) {
+void ExpireHistoryBackend::ExpireHistoryBefore(Time end_time) {
if (!main_db_)
return;
- // Archive as much history as possible before the given date.
- ArchiveSomeOldHistory(end_time, GetAllVisitsReader(),
+ // Expire all history before the given date.
+ ExpireSomeOldHistory(end_time, GetAllVisitsReader(),
std::numeric_limits<int>::max());
ParanoidExpireHistory();
}
@@ -324,7 +291,7 @@ const ExpiringVisitsReader*
return auto_subframe_visits_reader_.get();
}
-void ExpireHistoryBackend::StartArchivingOldStuff(
+void ExpireHistoryBackend::StartExpiringOldStuff(
TimeDelta expiration_threshold) {
expiration_threshold_ = expiration_threshold;
@@ -339,7 +306,7 @@ void ExpireHistoryBackend::StartArchivingOldStuff(
// Initialize the queue with all tasks for the first set of iterations.
InitWorkQueue();
- ScheduleArchive();
+ ScheduleExpire();
}
void ExpireHistoryBackend::DeleteFaviconsIfPossible(
@@ -372,10 +339,10 @@ void ExpireHistoryBackend::BroadcastDeleteNotifications(
// determine if they care whether anything was deleted).
scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails);
details->all_history = false;
- details->archived = (type == DELETION_ARCHIVED);
+ details->expired = (type == DELETION_EXPIRED);
details->rows = dependencies->deleted_urls;
details->favicon_urls = dependencies->expired_favicons;
- delegate_->NotifySyncURLsDeleted(false, details->archived, &details->rows);
+ delegate_->NotifySyncURLsDeleted(false, details->expired, &details->rows);
delegate_->BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
details.PassAs<HistoryDetails>());
}
@@ -427,27 +394,6 @@ void ExpireHistoryBackend::DeleteOneURL(
}
}
-URLID ExpireHistoryBackend::ArchiveOneURL(const URLRow& url_row) {
- if (!archived_db_)
- return 0;
-
- // See if this URL is present in the archived database already. Note that
- // we must look up by ID since the URL ID will be different.
- URLRow archived_row;
- if (archived_db_->GetRowForURL(url_row.url(), &archived_row)) {
- // TODO(sky): bug 1168470, need to archive past search terms.
- // TODO(brettw): should be copy the visit counts over? This will mean that
- // the main DB's visit counts are only for the last 3 months rather than
- // accumulative.
- archived_row.set_last_visit(url_row.last_visit());
- archived_db_->UpdateURLRow(archived_row.id(), archived_row);
- return archived_row.id();
- }
-
- // This row is not in the archived DB, add it.
- return archived_db_->AddURL(url_row);
-}
-
namespace {
struct ChangedURL {
@@ -518,62 +464,7 @@ void ExpireHistoryBackend::ExpireURLsForVisits(
}
}
-void ExpireHistoryBackend::ArchiveURLsAndVisits(
- const VisitVector& visits,
- DeleteDependencies* dependencies) {
- if (!archived_db_ || !main_db_)
- return;
-
- // Make sure all unique URL rows are added to the dependency list and the
- // archived database. We will also keep the mapping between the main DB URLID
- // and the archived one.
- std::map<URLID, URLID> main_id_to_archived_id;
- for (size_t i = 0; i < visits.size(); i++) {
- std::map<URLID, URLRow>::const_iterator found =
- dependencies->affected_urls.find(visits[i].url_id);
- if (found == dependencies->affected_urls.end()) {
- // Unique URL encountered, archive it.
- URLRow row; // Row in the main DB.
- URLID archived_id; // ID in the archived DB.
- if (!main_db_->GetURLRow(visits[i].url_id, &row) ||
- !(archived_id = ArchiveOneURL(row))) {
- // Failure archiving, skip this one.
- continue;
- }
-
- // Only add URL to the dependency list once we know we successfully
- // archived it.
- main_id_to_archived_id[row.id()] = archived_id;
- dependencies->affected_urls[row.id()] = row;
- }
- }
-
- // Retrieve the sources for all the archived visits before archiving.
- // The returned visit_sources vector should contain the source for each visit
- // from visits at the same index.
- VisitSourceMap visit_sources;
- main_db_->GetVisitsSource(visits, &visit_sources);
-
- // Now archive the visits since we know the URL ID to make them reference.
- // The source visit list should still reference the visits in the main DB, but
- // we will update it to reflect only the visits that were successfully
- // archived.
- for (size_t i = 0; i < visits.size(); i++) {
- // Construct the visit that we will add to the archived database. We do
- // not store referring visits since we delete many of the visits when
- // archiving.
- VisitRow cur_visit(visits[i]);
- cur_visit.url_id = main_id_to_archived_id[cur_visit.url_id];
- cur_visit.referring_visit = 0;
- VisitSourceMap::iterator iter = visit_sources.find(visits[i].visit_id);
- archived_db_->AddVisit(
- &cur_visit,
- iter == visit_sources.end() ? SOURCE_BROWSED : iter->second);
- // Ignore failures, we will delete it from the main DB no matter what.
- }
-}
-
-void ExpireHistoryBackend::ScheduleArchive() {
+void ExpireHistoryBackend::ScheduleExpire() {
TimeDelta delay;
if (work_queue_.empty()) {
// If work queue is empty, reset the work queue to contain all tasks and
@@ -586,16 +477,16 @@ void ExpireHistoryBackend::ScheduleArchive() {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::Bind(&ExpireHistoryBackend::DoArchiveIteration,
+ base::Bind(&ExpireHistoryBackend::DoExpireIteration,
weak_factory_.GetWeakPtr()),
delay);
}
-void ExpireHistoryBackend::DoArchiveIteration() {
+void ExpireHistoryBackend::DoExpireIteration() {
DCHECK(!work_queue_.empty()) << "queue has to be non-empty";
const ExpiringVisitsReader* reader = work_queue_.front();
- bool more_to_expire = ArchiveSomeOldHistory(GetCurrentArchiveTime(), reader,
+ bool more_to_expire = ExpireSomeOldHistory(GetCurrentExpirationTime(), reader,
kNumExpirePerIteration);
work_queue_.pop();
@@ -604,10 +495,10 @@ void ExpireHistoryBackend::DoArchiveIteration() {
if (more_to_expire)
work_queue_.push(reader);
- ScheduleArchive();
+ ScheduleExpire();
}
-bool ExpireHistoryBackend::ArchiveSomeOldHistory(
+bool ExpireHistoryBackend::ExpireSomeOldHistory(
base::Time end_time,
const ExpiringVisitsReader* reader,
int max_visits) {
@@ -619,51 +510,17 @@ bool ExpireHistoryBackend::ArchiveSomeOldHistory(
Time effective_end_time =
Time::FromInternalValue(end_time.ToInternalValue() + 1);
- VisitVector affected_visits;
+ VisitVector visits_to_delete;
bool more_to_expire = reader->Read(effective_end_time, main_db_,
- &affected_visits, max_visits);
+ &visits_to_delete, max_visits);
- // Some visits we'll delete while others we'll archive.
- VisitVector deleted_visits, archived_visits;
- for (size_t i = 0; i < affected_visits.size(); i++) {
- if (ShouldArchiveVisit(affected_visits[i]))
- archived_visits.push_back(affected_visits[i]);
- else
- deleted_visits.push_back(affected_visits[i]);
- }
+ DeleteDependencies dependencies;
+ DeleteVisitRelatedInfo(visits_to_delete, &dependencies);
+ ExpireURLsForVisits(visits_to_delete, &dependencies);
+ DeleteFaviconsIfPossible(dependencies.affected_favicons,
+ &dependencies.expired_favicons);
- // Do the actual archiving.
- DeleteDependencies archived_dependencies;
- ArchiveURLsAndVisits(archived_visits, &archived_dependencies);
- DeleteVisitRelatedInfo(archived_visits, &archived_dependencies);
-
- DeleteDependencies deleted_dependencies;
- DeleteVisitRelatedInfo(deleted_visits, &deleted_dependencies);
-
- // This will remove or archive all the affected URLs. Must do the deleting
- // cleanup before archiving so the delete dependencies structure references
- // only those URLs that were actually deleted instead of having some visits
- // archived and then the rest deleted.
- ExpireURLsForVisits(deleted_visits, &deleted_dependencies);
- ExpireURLsForVisits(archived_visits, &archived_dependencies);
-
- // Create a union of all affected favicons (we don't store favicons for
- // archived URLs) and delete them.
- std::set<chrome::FaviconID> affected_favicons(
- archived_dependencies.affected_favicons);
- for (std::set<chrome::FaviconID>::const_iterator i =
- deleted_dependencies.affected_favicons.begin();
- i != deleted_dependencies.affected_favicons.end(); ++i) {
- affected_favicons.insert(*i);
- }
- DeleteFaviconsIfPossible(affected_favicons,
- &deleted_dependencies.expired_favicons);
-
- // Send notifications for the stuff that was deleted. These won't normally be
- // in history views since they were subframes, but they will be in the visited
- // link system, which needs to be updated now. This function is smart enough
- // to not do anything if nothing was deleted.
- BroadcastDeleteNotifications(&deleted_dependencies, DELETION_ARCHIVED);
+ BroadcastDeleteNotifications(&dependencies, DELETION_EXPIRED);
return more_to_expire;
}

Powered by Google App Engine
This is Rietveld 408576698