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

Side by Side 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: Addressed comments and added culling when the sync is off. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 5 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 std::vector<AutofillEntry> new_synced_entries; 102 std::vector<AutofillEntry> new_synced_entries;
103 // Go through and check for all the entries that sync already knows about. 103 // Go through and check for all the entries that sync already knows about.
104 // CreateOrUpdateEntry() will remove entries that are same with the synced 104 // CreateOrUpdateEntry() will remove entries that are same with the synced
105 // ones from |new_db_entries|. 105 // ones from |new_db_entries|.
106 for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin(); 106 for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin();
107 sync_iter != initial_sync_data.end(); ++sync_iter) { 107 sync_iter != initial_sync_data.end(); ++sync_iter) {
108 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); 108 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries);
109 } 109 }
110 110
111 // Check if newly received items need culling.
112 bool need_to_cull_data = false;
113 base::Time culling_time = base::Time::Now() -
114 base::TimeDelta::FromDays(AutofillEntry::kExpirationPeriodInDays);
115 for (size_t i = 0; i < new_synced_entries.size() && !need_to_cull_data; ++i) {
116 if (new_synced_entries[i].HasTimestampsOlder(culling_time))
117 need_to_cull_data = true;
118 }
119
111 if (!SaveChangesToWebData(new_synced_entries)) 120 if (!SaveChangesToWebData(new_synced_entries))
112 return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); 121 return SyncError(FROM_HERE, "Failed to update webdata.", model_type());
113 122
114 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 123 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
124 keys_to_ignore_.clear();
115 125
116 SyncChangeList new_changes; 126 SyncChangeList new_changes;
117 for (AutocompleteEntryMap::iterator i = new_db_entries.begin(); 127 for (AutocompleteEntryMap::iterator i = new_db_entries.begin();
118 i != new_db_entries.end(); ++i) { 128 i != new_db_entries.end(); ++i) {
119 new_changes.push_back( 129 if (i->second.second->CullExpiredTimeStamps(culling_time))
120 SyncChange(i->second.first, CreateSyncData(*(i->second.second)))); 130 need_to_cull_data = true;
131 // Sync back only the data that appeared after |culling_time|.
132 if (!i->second.second->timestamps().empty()) {
133 new_changes.push_back(
134 SyncChange(i->second.first, CreateSyncData(*(i->second.second))));
135 } else {
136 // Key is not on the server and is too old, it will not ever be synced -
137 // delete it locally.
138 if (SyncChange::ACTION_ADD == i->second.first)
139 keys_to_ignore_.insert(i->first);
140 }
141 }
142
143 if (need_to_cull_data) {
144 // This will schedule deletion operation later on DB thread and we will
145 // be notified on the results of the deletion and deletes will be synced to
146 // the sync.
147 web_data_service_->RemoveFormElementsAddedBetween(base::Time(),
148 culling_time);
121 } 149 }
122 150
123 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 151 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
124 152
125 return error; 153 return error;
126 } 154 }
127 155
128 void AutocompleteSyncableService::StopSyncing(syncable::ModelType type) { 156 void AutocompleteSyncableService::StopSyncing(syncable::ModelType type) {
129 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
130 DCHECK_EQ(syncable::AUTOFILL, type); 158 DCHECK_EQ(syncable::AUTOFILL, type);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 378 }
351 AutofillEntry entry(change->key(), timestamps); 379 AutofillEntry entry(change->key(), timestamps);
352 SyncChange::SyncChangeType change_type = 380 SyncChange::SyncChangeType change_type =
353 (change->type() == AutofillChange::ADD) ? 381 (change->type() == AutofillChange::ADD) ?
354 SyncChange::ACTION_ADD : SyncChange::ACTION_UPDATE; 382 SyncChange::ACTION_ADD : SyncChange::ACTION_UPDATE;
355 new_changes.push_back(SyncChange(change_type, 383 new_changes.push_back(SyncChange(change_type,
356 CreateSyncData(entry))); 384 CreateSyncData(entry)));
357 break; 385 break;
358 } 386 }
359 case AutofillChange::REMOVE: { 387 case AutofillChange::REMOVE: {
360 std::vector<base::Time> timestamps; 388 if (keys_to_ignore_.find(change->key()) == keys_to_ignore_.end()) {
361 AutofillEntry entry(change->key(), timestamps); 389 std::vector<base::Time> timestamps;
362 new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE, 390 AutofillEntry entry(change->key(), timestamps);
363 CreateSyncData(entry))); 391 new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE,
392 CreateSyncData(entry)));
393 }
364 break; 394 break;
365 } 395 }
366 default: 396 default:
367 NOTREACHED(); 397 NOTREACHED();
368 break; 398 break;
369 } 399 }
370 } 400 }
371 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 401 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
372 if (error.IsSet()) { 402 if (error.IsSet()) {
373 DLOG(WARNING) << "[AUTOCOMPLETE SYNC]" 403 DLOG(WARNING) << "[AUTOCOMPLETE SYNC]"
374 << " Failed processing change:" 404 << " Failed processing change:"
375 << " Error:" << error.message(); 405 << " Error:" << error.message();
376 } 406 }
407 // |keys_to_ignore_| are only needed for the very first notification.
408 keys_to_ignore_.clear();
377 } 409 }
378 410
379 SyncData AutocompleteSyncableService::CreateSyncData( 411 SyncData AutocompleteSyncableService::CreateSyncData(
380 const AutofillEntry& entry) const { 412 const AutofillEntry& entry) const {
381 sync_pb::EntitySpecifics autofill_specifics; 413 sync_pb::EntitySpecifics autofill_specifics;
382 WriteAutofillEntry(entry, &autofill_specifics); 414 WriteAutofillEntry(entry, &autofill_specifics);
383 std::string tag(KeyToTag(UTF16ToUTF8(entry.key().name()), 415 std::string tag(KeyToTag(UTF16ToUTF8(entry.key().name()),
384 UTF16ToUTF8(entry.key().value()))); 416 UTF16ToUTF8(entry.key().value())));
385 return SyncData::CreateLocalData(tag, tag, autofill_specifics); 417 return SyncData::CreateLocalData(tag, tag, autofill_specifics);
386 } 418 }
387 419
388 // static 420 // static
389 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, 421 std::string AutocompleteSyncableService::KeyToTag(const std::string& name,
390 const std::string& value) { 422 const std::string& value) {
391 std::string ns(kAutofillEntryNamespaceTag); 423 std::string ns(kAutofillEntryNamespaceTag);
392 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); 424 return ns + net::EscapePath(name) + "|" + net::EscapePath(value);
393 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698