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

Unified Diff: chrome/browser/sync/sessions2/sessions_sync_manager.cc

Issue 81923003: sync: add garbage collection to SessionsSyncManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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/sync/sessions2/sessions_sync_manager.cc
diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager.cc b/chrome/browser/sync/sessions2/sessions_sync_manager.cc
index 93e5128c5276b49bf26d1351343cb229e206b797..382644d470d221b7bda90d872029d93a1437cb8a 100644
--- a/chrome/browser/sync/sessions2/sessions_sync_manager.cc
+++ b/chrome/browser/sync/sessions2/sessions_sync_manager.cc
@@ -41,6 +41,10 @@ static const int kMaxSyncNavigationCount = 6;
// from all other URL's as accessing it triggers a sync refresh of Sessions.
static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs";
+// Default number of days without activity after which a session is considered
+// stale and becomes a candidate for garbage collection.
+static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks.
+
SessionsSyncManager::SessionsSyncManager(
Profile* profile,
SyncInternalApiDelegate* delegate,
@@ -50,6 +54,7 @@ SessionsSyncManager::SessionsSyncManager(
profile_(profile),
delegate_(delegate),
local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID),
+ stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
local_event_router_(router.Pass()) {
}
@@ -915,4 +920,31 @@ FaviconCache* SessionsSyncManager::GetFaviconCache() {
return &favicon_cache_;
}
+void SessionsSyncManager::DoGarbageCollection() {
+ std::vector<const SyncedSession*> sessions;
+ if (!GetAllForeignSessions(&sessions))
+ return; // No foreign sessions.
+
+ // Iterate through all the sessions and delete any with age older than
+ // |stale_session_threshold_days_|.
+ syncer::SyncChangeList changes;
+ for (std::vector<const SyncedSession*>::const_iterator iter =
+ sessions.begin(); iter != sessions.end(); ++iter) {
+ const SyncedSession* session = *iter;
+ int session_age_in_days =
+ (base::Time::Now() - session->modified_time).InDays();
+ std::string session_tag = session->session_tag;
+ if (session_age_in_days > 0 && // If false, local clock is not trustworty.
+ static_cast<size_t>(session_age_in_days) >
+ stale_session_threshold_days_) {
+ DVLOG(1) << "Found stale session " << session_tag
+ << " with age " << session_age_in_days << ", deleting.";
+ DeleteForeignSessionInternal(session_tag, &changes);
+ }
+ }
+
+ if (!changes.empty())
+ sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
+}
+
}; // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698