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

Side by Side Diff: chrome/browser/sync/glue/autofill_change_processor.cc

Issue 5159001: Rest of the autofill work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch uploaded to debug why try servers have problem applying this patch. Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/sync/glue/autofill_change_processor.h" 5 #include "chrome/browser/sync/glue/autofill_change_processor.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/autofill/personal_data_manager.h"
12 #include "chrome/browser/guid.h" 13 #include "chrome/browser/guid.h"
14 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/autofill/personal_data_manager.h"
15 #include "chrome/browser/sync/glue/autofill_change_processor2.h" 16 #include "chrome/browser/sync/glue/autofill_change_processor2.h"
16 #include "chrome/browser/sync/glue/autofill_model_associator.h" 17 #include "chrome/browser/sync/glue/autofill_model_associator.h"
18 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
19 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
17 #include "chrome/browser/sync/profile_sync_service.h" 20 #include "chrome/browser/sync/profile_sync_service.h"
18 #include "chrome/browser/webdata/autofill_change.h" 21 #include "chrome/browser/webdata/autofill_change.h"
19 #include "chrome/browser/webdata/web_data_service.h" 22 #include "chrome/browser/webdata/web_data_service.h"
20 #include "chrome/browser/webdata/web_database.h" 23 #include "chrome/browser/webdata/web_database.h"
21 #include "chrome/common/notification_service.h" 24 #include "chrome/common/notification_service.h"
25 #include "chrome/common/pref_names.h"
22 26
23 namespace browser_sync { 27 namespace browser_sync {
24 28
25 struct AutofillChangeProcessor::AutofillChangeRecord { 29 struct AutofillChangeProcessor::AutofillChangeRecord {
26 sync_api::SyncManager::ChangeRecord::Action action_; 30 sync_api::SyncManager::ChangeRecord::Action action_;
27 int64 id_; 31 int64 id_;
28 sync_pb::AutofillSpecifics autofill_; 32 sync_pb::AutofillSpecifics autofill_;
29 AutofillChangeRecord(sync_api::SyncManager::ChangeRecord::Action action, 33 AutofillChangeRecord(sync_api::SyncManager::ChangeRecord::Action action,
30 int64 id, const sync_pb::AutofillSpecifics& autofill) 34 int64 id, const sync_pb::AutofillSpecifics& autofill)
31 : action_(action), 35 : action_(action),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 80 }
77 81
78 DCHECK(type.value == NotificationType::AUTOFILL_ENTRIES_CHANGED); 82 DCHECK(type.value == NotificationType::AUTOFILL_ENTRIES_CHANGED);
79 83
80 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); 84 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr();
81 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); 85 ObserveAutofillEntriesChanged(changes, &trans, autofill_root);
82 } 86 }
83 87
84 void AutofillChangeProcessor::PostOptimisticRefreshTask() { 88 void AutofillChangeProcessor::PostOptimisticRefreshTask() {
85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
86 new AutofillModelAssociator::DoOptimisticRefreshTask( 90 new DoOptimisticRefreshForAutofill(
87 personal_data_)); 91 personal_data_));
88 } 92 }
89 93
90 void AutofillChangeProcessor::ObserveAutofillEntriesChanged( 94 void AutofillChangeProcessor::ObserveAutofillEntriesChanged(
91 AutofillChangeList* changes, sync_api::WriteTransaction* trans, 95 AutofillChangeList* changes, sync_api::WriteTransaction* trans,
92 const sync_api::ReadNode& autofill_root) { 96 const sync_api::ReadNode& autofill_root) {
93 for (AutofillChangeList::iterator change = changes->begin(); 97 for (AutofillChangeList::iterator change = changes->begin();
94 change != changes->end(); ++change) { 98 change != changes->end(); ++change) {
95 switch (change->type()) { 99 switch (change->type()) {
96 case AutofillChange::ADD: 100 case AutofillChange::ADD:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 192
189 void AutofillChangeProcessor::ApplyChangesFromSyncModel( 193 void AutofillChangeProcessor::ApplyChangesFromSyncModel(
190 const sync_api::BaseTransaction* trans, 194 const sync_api::BaseTransaction* trans,
191 const sync_api::SyncManager::ChangeRecord* changes, 195 const sync_api::SyncManager::ChangeRecord* changes,
192 int change_count) { 196 int change_count) {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
194 if (!running()) 198 if (!running())
195 return; 199 return;
196 StopObserving(); 200 StopObserving();
197 201
202 bool autofill_profile_not_migrated = HasNotMigratedYet(trans);
203
198 sync_api::ReadNode autofill_root(trans); 204 sync_api::ReadNode autofill_root(trans);
199 if (!autofill_root.InitByTagLookup(kAutofillTag)) { 205 if (!autofill_root.InitByTagLookup(kAutofillTag)) {
200 error_handler()->OnUnrecoverableError(FROM_HERE, 206 error_handler()->OnUnrecoverableError(FROM_HERE,
201 "Autofill root node lookup failed."); 207 "Autofill root node lookup failed.");
202 return; 208 return;
203 } 209 }
204 210
205 for (int i = 0; i < change_count; ++i) { 211 for (int i = 0; i < change_count; ++i) {
206 sync_api::SyncManager::ChangeRecord::Action action(changes[i].action); 212 sync_api::SyncManager::ChangeRecord::Action action(changes[i].action);
207 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == action) { 213 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == action) {
208 DCHECK(changes[i].specifics.HasExtension(sync_pb::autofill)) 214 DCHECK(changes[i].specifics.HasExtension(sync_pb::autofill))
209 << "Autofill specifics data not present on delete!"; 215 << "Autofill specifics data not present on delete!";
210 const sync_pb::AutofillSpecifics& autofill = 216 const sync_pb::AutofillSpecifics& autofill =
211 changes[i].specifics.GetExtension(sync_pb::autofill); 217 changes[i].specifics.GetExtension(sync_pb::autofill);
212 if (autofill.has_value() || 218 if (autofill.has_value() ||
213 (HasNotMigratedYet() && autofill.has_profile())) { 219 (autofill_profile_not_migrated && autofill.has_profile())) {
214 autofill_changes_.push_back(AutofillChangeRecord(changes[i].action, 220 autofill_changes_.push_back(AutofillChangeRecord(changes[i].action,
215 changes[i].id, 221 changes[i].id,
216 autofill)); 222 autofill));
217 } else { 223 } else {
218 NOTREACHED() << "Autofill specifics has no data!"; 224 NOTREACHED() << "Autofill specifics has no data!";
219 } 225 }
220 continue; 226 continue;
221 } 227 }
222 228
223 // Handle an update or add. 229 // Handle an update or add.
224 sync_api::ReadNode sync_node(trans); 230 sync_api::ReadNode sync_node(trans);
225 if (!sync_node.InitByIdLookup(changes[i].id)) { 231 if (!sync_node.InitByIdLookup(changes[i].id)) {
226 error_handler()->OnUnrecoverableError(FROM_HERE, 232 error_handler()->OnUnrecoverableError(FROM_HERE,
227 "Autofill node lookup failed."); 233 "Autofill node lookup failed.");
228 return; 234 return;
229 } 235 }
230 236
231 // Check that the changed node is a child of the autofills folder. 237 // Check that the changed node is a child of the autofills folder.
232 DCHECK(autofill_root.GetId() == sync_node.GetParentId()); 238 DCHECK(autofill_root.GetId() == sync_node.GetParentId());
233 DCHECK(syncable::AUTOFILL == sync_node.GetModelType()); 239 DCHECK(syncable::AUTOFILL == sync_node.GetModelType());
234 240
235 const sync_pb::AutofillSpecifics& autofill( 241 const sync_pb::AutofillSpecifics& autofill(
236 sync_node.GetAutofillSpecifics()); 242 sync_node.GetAutofillSpecifics());
237 int64 sync_id = sync_node.GetId(); 243 int64 sync_id = sync_node.GetId();
238 if (autofill.has_value() || 244 if (autofill.has_value() ||
239 (HasNotMigratedYet() && autofill.has_profile())) { 245 (autofill_profile_not_migrated && autofill.has_profile())) {
240 autofill_changes_.push_back(AutofillChangeRecord(changes[i].action, 246 autofill_changes_.push_back(AutofillChangeRecord(changes[i].action,
241 sync_id, autofill)); 247 sync_id, autofill));
242 } else { 248 } else {
243 NOTREACHED() << "Autofill specifics has no data!"; 249 NOTREACHED() << "Autofill specifics has no data!";
244 } 250 }
245 } 251 }
246 252
247 StartObserving(); 253 StartObserving();
248 } 254 }
249 255
250 void AutofillChangeProcessor::CommitChangesFromSyncModel() { 256 void AutofillChangeProcessor::CommitChangesFromSyncModel() {
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
252 if (!running()) 258 if (!running())
253 return; 259 return;
254 StopObserving(); 260 StopObserving();
255 261
256 std::vector<AutofillEntry> new_entries; 262 std::vector<AutofillEntry> new_entries;
257 for (unsigned int i = 0; i < autofill_changes_.size(); i++) { 263 for (unsigned int i = 0; i < autofill_changes_.size(); i++) {
258 // Handle deletions. 264 // Handle deletions.
259 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == 265 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE ==
260 autofill_changes_[i].action_) { 266 autofill_changes_[i].action_) {
261 if (autofill_changes_[i].autofill_.has_value()) { 267 if (autofill_changes_[i].autofill_.has_value()) {
262 ApplySyncAutofillEntryDelete(autofill_changes_[i].autofill_); 268 ApplySyncAutofillEntryDelete(autofill_changes_[i].autofill_);
263 } else if (autofill_changes_[i].autofill_.has_profile()) { 269 } else if (autofill_changes_[i].autofill_.has_profile()) {
264 DCHECK(HasNotMigratedYet());
265 ApplySyncAutofillProfileDelete(autofill_changes_[i].id_); 270 ApplySyncAutofillProfileDelete(autofill_changes_[i].id_);
266 } else { 271 } else {
267 NOTREACHED() << "Autofill's CommitChanges received change with no" 272 NOTREACHED() << "Autofill's CommitChanges received change with no"
268 " data!"; 273 " data!";
269 } 274 }
270 continue; 275 continue;
271 } 276 }
272 277
273 // Handle update/adds. 278 // Handle update/adds.
274 if (autofill_changes_[i].autofill_.has_value()) { 279 if (autofill_changes_[i].autofill_.has_value()) {
275 ApplySyncAutofillEntryChange(autofill_changes_[i].action_, 280 ApplySyncAutofillEntryChange(autofill_changes_[i].action_,
276 autofill_changes_[i].autofill_, &new_entries, 281 autofill_changes_[i].autofill_, &new_entries,
277 autofill_changes_[i].id_); 282 autofill_changes_[i].id_);
278 } else if (autofill_changes_[i].autofill_.has_profile()) { 283 } else if (autofill_changes_[i].autofill_.has_profile()) {
279 DCHECK(HasNotMigratedYet());
280 ApplySyncAutofillProfileChange(autofill_changes_[i].action_, 284 ApplySyncAutofillProfileChange(autofill_changes_[i].action_,
281 autofill_changes_[i].autofill_.profile(), 285 autofill_changes_[i].autofill_.profile(),
282 autofill_changes_[i].id_); 286 autofill_changes_[i].id_);
283 } else { 287 } else {
284 NOTREACHED() << "Autofill's CommitChanges received change with no data!"; 288 NOTREACHED() << "Autofill's CommitChanges received change with no data!";
285 } 289 }
286 } 290 }
287 autofill_changes_.clear(); 291 autofill_changes_.clear();
288 292
289 // Make changes 293 // Make changes
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 autofill.set_name(UTF16ToUTF8(entry.key().name())); 430 autofill.set_name(UTF16ToUTF8(entry.key().name()));
427 autofill.set_value(UTF16ToUTF8(entry.key().value())); 431 autofill.set_value(UTF16ToUTF8(entry.key().value()));
428 const std::vector<base::Time>& ts(entry.timestamps()); 432 const std::vector<base::Time>& ts(entry.timestamps());
429 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); 433 for (std::vector<base::Time>::const_iterator timestamp = ts.begin();
430 timestamp != ts.end(); ++timestamp) { 434 timestamp != ts.end(); ++timestamp) {
431 autofill.add_usage_timestamp(timestamp->ToInternalValue()); 435 autofill.add_usage_timestamp(timestamp->ToInternalValue());
432 } 436 }
433 node->SetAutofillSpecifics(autofill); 437 node->SetAutofillSpecifics(autofill);
434 } 438 }
435 439
436 // static 440 bool AutofillChangeProcessor::HasNotMigratedYet(
437 void AutofillChangeProcessor::WriteAutofillProfile( 441 const sync_api::BaseTransaction* trans) {
438 const AutoFillProfile& profile, sync_api::WriteNode* node) { 442 return model_associator_->HasNotMigratedYet(trans);
439 sync_pb::AutofillSpecifics autofill;
440 sync_pb::AutofillProfileSpecifics* s(autofill.mutable_profile());
441 s->set_name_first(UTF16ToUTF8(
442 profile.GetFieldText(AutoFillType(NAME_FIRST))));
443 s->set_name_middle(UTF16ToUTF8(
444 profile.GetFieldText(AutoFillType(NAME_MIDDLE))));
445 s->set_name_last(UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_LAST))));
446 s->set_address_home_line1(
447 UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))));
448 s->set_address_home_line2(
449 UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))));
450 s->set_address_home_city(UTF16ToUTF8(profile.GetFieldText(
451 AutoFillType(ADDRESS_HOME_CITY))));
452 s->set_address_home_state(UTF16ToUTF8(profile.GetFieldText(
453 AutoFillType(ADDRESS_HOME_STATE))));
454 s->set_address_home_country(UTF16ToUTF8(profile.GetFieldText(
455 AutoFillType(ADDRESS_HOME_COUNTRY))));
456 s->set_address_home_zip(UTF16ToUTF8(profile.GetFieldText(
457 AutoFillType(ADDRESS_HOME_ZIP))));
458 s->set_email_address(UTF16ToUTF8(profile.GetFieldText(
459 AutoFillType(EMAIL_ADDRESS))));
460 s->set_company_name(UTF16ToUTF8(profile.GetFieldText(
461 AutoFillType(COMPANY_NAME))));
462 s->set_phone_fax_whole_number(UTF16ToUTF8(profile.GetFieldText(
463 AutoFillType(PHONE_FAX_WHOLE_NUMBER))));
464 s->set_phone_home_whole_number(UTF16ToUTF8(profile.GetFieldText(
465 AutoFillType(PHONE_HOME_WHOLE_NUMBER))));
466 node->SetAutofillSpecifics(autofill);
467 }
468 bool AutofillChangeProcessor::HasNotMigratedYet() {
469 return true;
470 } 443 }
471 444
472 } // namespace browser_sync 445 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/autofill_change_processor.h ('k') | chrome/browser/sync/glue/autofill_change_processor2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698