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

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

Powered by Google App Engine
This is Rietveld 408576698