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

Unified Diff: chrome/browser/webdata/autocomplete_syncable_service.cc

Issue 9585020: Cull autofill entries older than 60 days. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: if (!RemoveFormElementForID(pair_id)) Created 8 years, 9 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/webdata/autocomplete_syncable_service.cc
diff --git a/chrome/browser/webdata/autocomplete_syncable_service.cc b/chrome/browser/webdata/autocomplete_syncable_service.cc
index af1cde14a5b5d40e0d27e42a3d6dcf4f89693d82..fc68ea0d3584c7b07eb89327a8c150f3fbadc657 100644
--- a/chrome/browser/webdata/autocomplete_syncable_service.cc
+++ b/chrome/browser/webdata/autocomplete_syncable_service.cc
@@ -100,24 +100,58 @@ SyncError AutocompleteSyncableService::MergeDataAndStartSyncing(
sync_processor_.reset(sync_processor);
std::vector<AutofillEntry> new_synced_entries;
+ std::vector<AutofillEntry> synced_expired_entries;
// Go through and check for all the entries that sync already knows about.
// CreateOrUpdateEntry() will remove entries that are same with the synced
// ones from |new_db_entries|.
for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin();
sync_iter != initial_sync_data.end(); ++sync_iter) {
- CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries);
+ CreateOrUpdateEntry(*sync_iter, &new_db_entries,
+ &new_synced_entries, &synced_expired_entries);
}
+ // Check if newly received items need culling.
+ bool need_to_cull_data = !synced_expired_entries.empty();
+
if (!SaveChangesToWebData(new_synced_entries))
return SyncError(FROM_HERE, "Failed to update webdata.", model_type());
WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
+ keys_to_ignore_.clear();
SyncChangeList new_changes;
for (AutocompleteEntryMap::iterator i = new_db_entries.begin();
i != new_db_entries.end(); ++i) {
- new_changes.push_back(
- SyncChange(i->second.first, CreateSyncData(*(i->second.second))));
+ // Sync back only the data that appeared after
+ // |AutofillEntry::ExpirationTime()|.
+ if (!i->second.second->IsExpired()) {
+ new_changes.push_back(
+ SyncChange(i->second.first, CreateSyncData(*(i->second.second))));
+ } else {
+ need_to_cull_data = true;
+ // Key is not on the server and is too old, it will not ever be synced -
+ // delete it locally.
+ if (i->second.first == SyncChange::ACTION_ADD)
+ keys_to_ignore_.insert(i->first);
+ }
+ }
+
+ // Delete only the changes never synced to the db as they are too old.
Ilya Sherman 2012/03/23 22:44:45 nit: "synced to" -> "synced to" (extra space)
GeorgeY 2012/03/26 19:59:10 Done.
+ for (size_t i = 0; i < synced_expired_entries.size(); ++i) {
+ // Key is on the server and not local and is too old, we need to notify
+ // sync that it has expired.
+ if (keys_to_ignore_.find(synced_expired_entries[i].key()) ==
+ keys_to_ignore_.end()) {
+ new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE,
+ CreateSyncData(synced_expired_entries[i])));
+ }
+ }
+
+ if (need_to_cull_data) {
+ // This will schedule deletion operation later on DB thread and we will
+ // be notified on the results of the deletion and deletes will be synced to
+ // the sync.
+ web_data_service_->RemoveExpiredFormElements();
}
SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
@@ -168,6 +202,7 @@ SyncError AutocompleteSyncableService::ProcessSyncChanges(
std::vector<AutofillEntry> entries;
scoped_ptr<AutocompleteEntryMap> db_entries;
std::vector<AutofillEntry> new_entries;
+ std::vector<AutofillEntry> ignored_entries;
SyncError list_processing_error;
@@ -191,7 +226,8 @@ SyncError AutocompleteSyncableService::ProcessSyncChanges(
std::make_pair(SyncChange::ACTION_ADD, it);
}
}
- CreateOrUpdateEntry(i->sync_data(), db_entries.get(), &new_entries);
+ CreateOrUpdateEntry(i->sync_data(), db_entries.get(),
+ &new_entries, &ignored_entries);
break;
case SyncChange::ACTION_DELETE: {
DCHECK(i->sync_data().GetSpecifics().has_autofill())
@@ -216,6 +252,18 @@ SyncError AutocompleteSyncableService::ProcessSyncChanges(
if (!SaveChangesToWebData(new_entries))
return SyncError(FROM_HERE, "Failed to update webdata.", model_type());
+ // Remove already expired data.
+ for (size_t i = 0; i < ignored_entries.size(); ++i) {
+ if (db_entries.get() &&
+ db_entries->find(ignored_entries[i].key()) != db_entries->end()) {
+ if (!web_data_service_->GetDatabase()->GetAutofillTable()->
+ RemoveFormElement(ignored_entries[i].key().name(),
+ ignored_entries[i].key().value())) {
+ NOTREACHED();
+ }
Ilya Sherman 2012/03/23 22:44:45 nit: Up to you, but I think this would be a little
GeorgeY 2012/03/26 19:59:10 Done.
+ }
+ }
+
WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
return list_processing_error;
@@ -263,7 +311,8 @@ bool AutocompleteSyncableService::SaveChangesToWebData(
void AutocompleteSyncableService::CreateOrUpdateEntry(
const SyncData& data,
AutocompleteEntryMap* loaded_data,
- std::vector<AutofillEntry>* new_entries) {
+ std::vector<AutofillEntry>* new_entries,
+ std::vector<AutofillEntry>* ignored_entries) {
const sync_pb::EntitySpecifics& specifics = data.GetSpecifics();
const sync_pb::AutofillSpecifics& autofill_specifics(
specifics.autofill());
@@ -286,7 +335,11 @@ void AutocompleteSyncableService::CreateOrUpdateEntry(
timestamps[ts] = base::Time::FromInternalValue(
autofill_specifics.usage_timestamp(ts));
Nicolas Zea 2012/03/26 18:23:55 this should probably only look at the first and la
GeorgeY 2012/03/26 19:59:10 Done.
}
- new_entries->push_back(AutofillEntry(key, timestamps));
+ AutofillEntry new_entry(key, timestamps);
+ if (new_entry.IsExpired())
+ ignored_entries->push_back(new_entry);
+ else
+ new_entries->push_back(new_entry);
} else {
// Entry already present - merge if necessary.
std::vector<base::Time> timestamps;
@@ -294,7 +347,10 @@ void AutocompleteSyncableService::CreateOrUpdateEntry(
autofill_specifics, it->second.second->timestamps(), &timestamps);
if (different) {
AutofillEntry new_entry(it->second.second->key(), timestamps);
- new_entries->push_back(new_entry);
+ if (new_entry.IsExpired())
+ ignored_entries->push_back(new_entry);
+ else
+ new_entries->push_back(new_entry);
// Update the sync db if the list of timestamps have changed.
*(it->second.second) = new_entry;
@@ -357,10 +413,12 @@ void AutocompleteSyncableService::ActOnChanges(
break;
}
case AutofillChange::REMOVE: {
- std::vector<base::Time> timestamps;
- AutofillEntry entry(change->key(), timestamps);
- new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE,
- CreateSyncData(entry)));
+ if (keys_to_ignore_.find(change->key()) == keys_to_ignore_.end()) {
+ std::vector<base::Time> timestamps;
+ AutofillEntry entry(change->key(), timestamps);
+ new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE,
+ CreateSyncData(entry)));
+ }
break;
}
default:
@@ -374,6 +432,8 @@ void AutocompleteSyncableService::ActOnChanges(
<< " Failed processing change:"
<< " Error:" << error.message();
}
+ // |keys_to_ignore_| are only needed for the very first notification.
+ keys_to_ignore_.clear();
}
SyncData AutocompleteSyncableService::CreateSyncData(

Powered by Google App Engine
This is Rietveld 408576698