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

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: adressed comments 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 for (size_t i = 0; i < new_synced_entries.size() && !need_to_cull_data; ++i) {
114 if (new_synced_entries[i].IsExpired())
115 need_to_cull_data = true;
116 }
117
111 if (!SaveChangesToWebData(new_synced_entries)) 118 if (!SaveChangesToWebData(new_synced_entries))
112 return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); 119 return SyncError(FROM_HERE, "Failed to update webdata.", model_type());
113 120
114 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 121 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
122 keys_to_ignore_.clear();
115 123
116 SyncChangeList new_changes; 124 SyncChangeList new_changes;
117 for (AutocompleteEntryMap::iterator i = new_db_entries.begin(); 125 for (AutocompleteEntryMap::iterator i = new_db_entries.begin();
118 i != new_db_entries.end(); ++i) { 126 i != new_db_entries.end(); ++i) {
119 new_changes.push_back( 127 // Sync back only the data that appeared after |culling_time|.
Ilya Sherman 2012/03/20 21:25:13 nit: |culling_time| is no longer a variable define
GeorgeY 2012/03/21 20:56:40 Done.
120 SyncChange(i->second.first, CreateSyncData(*(i->second.second)))); 128 if (!i->second.second->IsExpired()) {
129 new_changes.push_back(
130 SyncChange(i->second.first, CreateSyncData(*(i->second.second))));
131 } else {
132 need_to_cull_data = true;
133 // Key is not on the server and is too old, it will not ever be synced -
134 // delete it locally.
135 if (i->second.first == SyncChange::ACTION_ADD)
136 keys_to_ignore_.insert(i->first);
137 }
138 }
139
140 if (need_to_cull_data) {
141 // This will schedule deletion operation later on DB thread and we will
142 // be notified on the results of the deletion and deletes will be synced to
143 // the sync.
144 web_data_service_->RemoveExpiredFormElements();
121 } 145 }
122 146
123 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 147 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
124 148
125 return error; 149 return error;
126 } 150 }
127 151
128 void AutocompleteSyncableService::StopSyncing(syncable::ModelType type) { 152 void AutocompleteSyncableService::StopSyncing(syncable::ModelType type) {
129 DCHECK(CalledOnValidThread()); 153 DCHECK(CalledOnValidThread());
130 DCHECK_EQ(syncable::AUTOFILL, type); 154 DCHECK_EQ(syncable::AUTOFILL, type);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 374 }
351 AutofillEntry entry(change->key(), timestamps); 375 AutofillEntry entry(change->key(), timestamps);
352 SyncChange::SyncChangeType change_type = 376 SyncChange::SyncChangeType change_type =
353 (change->type() == AutofillChange::ADD) ? 377 (change->type() == AutofillChange::ADD) ?
354 SyncChange::ACTION_ADD : SyncChange::ACTION_UPDATE; 378 SyncChange::ACTION_ADD : SyncChange::ACTION_UPDATE;
355 new_changes.push_back(SyncChange(change_type, 379 new_changes.push_back(SyncChange(change_type,
356 CreateSyncData(entry))); 380 CreateSyncData(entry)));
357 break; 381 break;
358 } 382 }
359 case AutofillChange::REMOVE: { 383 case AutofillChange::REMOVE: {
360 std::vector<base::Time> timestamps; 384 if (keys_to_ignore_.find(change->key()) == keys_to_ignore_.end()) {
361 AutofillEntry entry(change->key(), timestamps); 385 std::vector<base::Time> timestamps;
362 new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE, 386 AutofillEntry entry(change->key(), timestamps);
363 CreateSyncData(entry))); 387 new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE,
388 CreateSyncData(entry)));
389 }
364 break; 390 break;
365 } 391 }
366 default: 392 default:
367 NOTREACHED(); 393 NOTREACHED();
368 break; 394 break;
369 } 395 }
370 } 396 }
371 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 397 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
372 if (error.IsSet()) { 398 if (error.IsSet()) {
373 DLOG(WARNING) << "[AUTOCOMPLETE SYNC]" 399 DLOG(WARNING) << "[AUTOCOMPLETE SYNC]"
374 << " Failed processing change:" 400 << " Failed processing change:"
375 << " Error:" << error.message(); 401 << " Error:" << error.message();
376 } 402 }
403 // |keys_to_ignore_| are only needed for the very first notification.
404 keys_to_ignore_.clear();
377 } 405 }
378 406
379 SyncData AutocompleteSyncableService::CreateSyncData( 407 SyncData AutocompleteSyncableService::CreateSyncData(
380 const AutofillEntry& entry) const { 408 const AutofillEntry& entry) const {
381 sync_pb::EntitySpecifics autofill_specifics; 409 sync_pb::EntitySpecifics autofill_specifics;
382 WriteAutofillEntry(entry, &autofill_specifics); 410 WriteAutofillEntry(entry, &autofill_specifics);
383 std::string tag(KeyToTag(UTF16ToUTF8(entry.key().name()), 411 std::string tag(KeyToTag(UTF16ToUTF8(entry.key().name()),
384 UTF16ToUTF8(entry.key().value()))); 412 UTF16ToUTF8(entry.key().value())));
385 return SyncData::CreateLocalData(tag, tag, autofill_specifics); 413 return SyncData::CreateLocalData(tag, tag, autofill_specifics);
386 } 414 }
387 415
388 // static 416 // static
389 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, 417 std::string AutocompleteSyncableService::KeyToTag(const std::string& name,
390 const std::string& value) { 418 const std::string& value) {
391 std::string ns(kAutofillEntryNamespaceTag); 419 std::string ns(kAutofillEntryNamespaceTag);
392 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); 420 return ns + net::EscapePath(name) + "|" + net::EscapePath(value);
393 } 421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698