OLD | NEW |
---|---|
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_model_associator.h" | 5 #include "chrome/browser/sync/glue/autofill_model_associator.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 std::vector<AutofillEntry> entries; | 144 std::vector<AutofillEntry> entries; |
145 ScopedVector<AutoFillProfile> profiles; | 145 ScopedVector<AutoFillProfile> profiles; |
146 | 146 |
147 if (!LoadAutofillData(&entries, &profiles.get())) { | 147 if (!LoadAutofillData(&entries, &profiles.get())) { |
148 LOG(ERROR) << "Could not get the autofill data from WebDatabase."; | 148 LOG(ERROR) << "Could not get the autofill data from WebDatabase."; |
149 return false; | 149 return false; |
150 } | 150 } |
151 | 151 |
152 DataBundle bundle; | 152 DataBundle bundle; |
153 { | 153 { |
154 sync_api::WriteTransaction trans( | 154 sync_api::WriteTransaction trans(sync_service_->GetUserShareHandle()); |
tim (not reviewing)
2011/01/21 18:17:00
Maybe what I was thinking before, since the handle
akalin
2011/01/21 21:21:09
Yeah, I agree. I actually tried going down that p
| |
155 sync_service_->backend()->GetUserShareHandle()); | |
156 | 155 |
157 sync_api::ReadNode autofill_root(&trans); | 156 sync_api::ReadNode autofill_root(&trans); |
158 if (!autofill_root.InitByTagLookup(kAutofillTag)) { | 157 if (!autofill_root.InitByTagLookup(kAutofillTag)) { |
159 LOG(ERROR) << "Server did not create the top-level autofill node. We " | 158 LOG(ERROR) << "Server did not create the top-level autofill node. We " |
160 << "might be running against an out-of-date server."; | 159 << "might be running against an out-of-date server."; |
161 return false; | 160 return false; |
162 } | 161 } |
163 | 162 |
164 if (!TraverseAndAssociateChromeAutofillEntries(&trans, autofill_root, | 163 if (!TraverseAndAssociateChromeAutofillEntries(&trans, autofill_root, |
165 entries, &bundle.current_entries, &bundle.new_entries)) { | 164 entries, &bundle.current_entries, &bundle.new_entries)) { |
(...skipping 12 matching lines...) Expand all Loading... | |
178 // Since we're on the DB thread, we don't have to worry about updating | 177 // Since we're on the DB thread, we don't have to worry about updating |
179 // the autofill database after closing the write transaction, since | 178 // the autofill database after closing the write transaction, since |
180 // this is the only thread that writes to the database. We also don't have | 179 // this is the only thread that writes to the database. We also don't have |
181 // to worry about the sync model getting out of sync, because changes are | 180 // to worry about the sync model getting out of sync, because changes are |
182 // propogated to the ChangeProcessor on this thread. | 181 // propogated to the ChangeProcessor on this thread. |
183 if (!SaveChangesToWebData(bundle)) { | 182 if (!SaveChangesToWebData(bundle)) { |
184 LOG(ERROR) << "Failed to update autofill entries."; | 183 LOG(ERROR) << "Failed to update autofill entries."; |
185 return false; | 184 return false; |
186 } | 185 } |
187 | 186 |
188 if (sync_service_->backend()->GetAutofillMigrationState() != | 187 if (sync_service_->GetAutofillMigrationState() != |
189 syncable::MIGRATED) { | 188 syncable::MIGRATED) { |
190 syncable::AutofillMigrationDebugInfo debug_info; | 189 syncable::AutofillMigrationDebugInfo debug_info; |
191 debug_info.autofill_entries_added_during_migration = | 190 debug_info.autofill_entries_added_during_migration = |
192 number_of_entries_created_; | 191 number_of_entries_created_; |
193 sync_service_->backend()->SetAutofillMigrationDebugInfo( | 192 sync_service_->SetAutofillMigrationDebugInfo( |
194 syncable::AutofillMigrationDebugInfo::ENTRIES_ADDED, | 193 syncable::AutofillMigrationDebugInfo::ENTRIES_ADDED, |
195 debug_info); | 194 debug_info); |
196 } | 195 } |
197 | 196 |
198 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 197 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
199 new DoOptimisticRefreshForAutofill(personal_data_)); | 198 new DoOptimisticRefreshForAutofill(personal_data_)); |
200 return true; | 199 return true; |
201 } | 200 } |
202 | 201 |
203 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) { | 202 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 375 |
377 bool AutofillModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 376 bool AutofillModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
378 DCHECK(has_nodes); | 377 DCHECK(has_nodes); |
379 *has_nodes = false; | 378 *has_nodes = false; |
380 int64 autofill_sync_id; | 379 int64 autofill_sync_id; |
381 if (!GetSyncIdForTaggedNode(kAutofillTag, &autofill_sync_id)) { | 380 if (!GetSyncIdForTaggedNode(kAutofillTag, &autofill_sync_id)) { |
382 LOG(ERROR) << "Server did not create the top-level autofill node. We " | 381 LOG(ERROR) << "Server did not create the top-level autofill node. We " |
383 << "might be running against an out-of-date server."; | 382 << "might be running against an out-of-date server."; |
384 return false; | 383 return false; |
385 } | 384 } |
386 sync_api::ReadTransaction trans( | 385 sync_api::ReadTransaction trans(sync_service_->GetUserShareHandle()); |
387 sync_service_->backend()->GetUserShareHandle()); | |
388 | 386 |
389 sync_api::ReadNode autofill_node(&trans); | 387 sync_api::ReadNode autofill_node(&trans); |
390 if (!autofill_node.InitByIdLookup(autofill_sync_id)) { | 388 if (!autofill_node.InitByIdLookup(autofill_sync_id)) { |
391 LOG(ERROR) << "Server did not create the top-level autofill node. We " | 389 LOG(ERROR) << "Server did not create the top-level autofill node. We " |
392 << "might be running against an out-of-date server."; | 390 << "might be running against an out-of-date server."; |
393 return false; | 391 return false; |
394 } | 392 } |
395 | 393 |
396 // The sync model has user created nodes if the autofill folder has any | 394 // The sync model has user created nodes if the autofill folder has any |
397 // children. | 395 // children. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
438 SyncIdToAutofillMap::iterator iter = id_map_inverse_.find(sync_id); | 436 SyncIdToAutofillMap::iterator iter = id_map_inverse_.find(sync_id); |
439 if (iter == id_map_inverse_.end()) | 437 if (iter == id_map_inverse_.end()) |
440 return; | 438 return; |
441 CHECK(id_map_.erase(iter->second)); | 439 CHECK(id_map_.erase(iter->second)); |
442 id_map_inverse_.erase(iter); | 440 id_map_inverse_.erase(iter); |
443 } | 441 } |
444 | 442 |
445 bool AutofillModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, | 443 bool AutofillModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, |
446 int64* sync_id) { | 444 int64* sync_id) { |
447 sync_api::ReadTransaction trans( | 445 sync_api::ReadTransaction trans(sync_service_->GetUserShareHandle()); |
448 sync_service_->backend()->GetUserShareHandle()); | |
449 sync_api::ReadNode sync_node(&trans); | 446 sync_api::ReadNode sync_node(&trans); |
450 if (!sync_node.InitByTagLookup(tag.c_str())) | 447 if (!sync_node.InitByTagLookup(tag.c_str())) |
451 return false; | 448 return false; |
452 *sync_id = sync_node.GetId(); | 449 *sync_id = sync_node.GetId(); |
453 return true; | 450 return true; |
454 } | 451 } |
455 | 452 |
456 bool AutofillModelAssociator::IsAbortPending() { | 453 bool AutofillModelAssociator::IsAbortPending() { |
457 base::AutoLock lock(abort_association_pending_lock_); | 454 base::AutoLock lock(abort_association_pending_lock_); |
458 return abort_association_pending_; | 455 return abort_association_pending_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 diff = MergeField(p, PHONE_HOME_WHOLE_NUMBER, s.phone_home_whole_number()) | 523 diff = MergeField(p, PHONE_HOME_WHOLE_NUMBER, s.phone_home_whole_number()) |
527 || diff; | 524 || diff; |
528 return diff; | 525 return diff; |
529 } | 526 } |
530 | 527 |
531 bool AutofillModelAssociator::HasNotMigratedYet( | 528 bool AutofillModelAssociator::HasNotMigratedYet( |
532 const sync_api::BaseTransaction* trans) { | 529 const sync_api::BaseTransaction* trans) { |
533 | 530 |
534 // Now read the current value from the directory. | 531 // Now read the current value from the directory. |
535 syncable::AutofillMigrationState autofill_migration_state = | 532 syncable::AutofillMigrationState autofill_migration_state = |
536 sync_service()->backend()->GetAutofillMigrationState(); | 533 sync_service_->GetAutofillMigrationState(); |
537 | 534 |
538 DCHECK_NE(autofill_migration_state, syncable::NOT_DETERMINED); | 535 DCHECK_NE(autofill_migration_state, syncable::NOT_DETERMINED); |
539 | 536 |
540 if (autofill_migration_state== syncable::NOT_DETERMINED) { | 537 if (autofill_migration_state== syncable::NOT_DETERMINED) { |
541 VLOG(1) << "Autofill migration state is not determined inside " | 538 VLOG(1) << "Autofill migration state is not determined inside " |
542 << " model associator"; | 539 << " model associator"; |
543 } | 540 } |
544 | 541 |
545 if (autofill_migration_state == syncable::NOT_MIGRATED) { | 542 if (autofill_migration_state == syncable::NOT_MIGRATED) { |
546 return true; | 543 return true; |
547 } | 544 } |
548 | 545 |
549 if (autofill_migration_state == syncable::INSUFFICIENT_INFO_TO_DETERMINE) { | 546 if (autofill_migration_state == syncable::INSUFFICIENT_INFO_TO_DETERMINE) { |
550 VLOG(1) << "[AUTOFILL MIGRATION]" | 547 VLOG(1) << "[AUTOFILL MIGRATION]" |
551 << "current autofill migration state is insufficient info to" | 548 << "current autofill migration state is insufficient info to" |
552 << "determine."; | 549 << "determine."; |
553 sync_api::ReadNode autofill_profile_root_node(trans); | 550 sync_api::ReadNode autofill_profile_root_node(trans); |
554 if (!autofill_profile_root_node.InitByTagLookup( | 551 if (!autofill_profile_root_node.InitByTagLookup( |
555 browser_sync::kAutofillProfileTag) || | 552 browser_sync::kAutofillProfileTag) || |
556 autofill_profile_root_node.GetFirstChildId()== | 553 autofill_profile_root_node.GetFirstChildId()== |
557 static_cast<int64>(0)) { | 554 static_cast<int64>(0)) { |
558 sync_service()->backend()->SetAutofillMigrationState( | 555 sync_service_->SetAutofillMigrationState( |
559 syncable::NOT_MIGRATED); | 556 syncable::NOT_MIGRATED); |
560 | 557 |
561 VLOG(1) << "[AUTOFILL MIGRATION]" | 558 VLOG(1) << "[AUTOFILL MIGRATION]" |
562 << "Current autofill migration state is NOT Migrated because" | 559 << "Current autofill migration state is NOT Migrated because" |
563 << "legacy autofill root node is present whereas new " | 560 << "legacy autofill root node is present whereas new " |
564 << "Autofill profile root node is absent."; | 561 << "Autofill profile root node is absent."; |
565 return true; | 562 return true; |
566 } | 563 } |
567 | 564 |
568 sync_service()->backend()->SetAutofillMigrationState(syncable::MIGRATED); | 565 sync_service_->SetAutofillMigrationState(syncable::MIGRATED); |
569 | 566 |
570 VLOG(1) << "[AUTOFILL MIGRATION]" | 567 VLOG(1) << "[AUTOFILL MIGRATION]" |
571 << "Current autofill migration state is migrated."; | 568 << "Current autofill migration state is migrated."; |
572 } | 569 } |
573 | 570 |
574 return false; | 571 return false; |
575 } | 572 } |
576 | 573 |
577 } // namespace browser_sync | 574 } // namespace browser_sync |
OLD | NEW |