| 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_profile_model_associator.h" | 5 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | 
| 6 | 6 | 
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" | 
|  | 8 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" | 
|  | 9 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | 
| 8 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" | 
|  | 11 #include "chrome/browser/sync/syncable/syncable.h" | 
| 9 #include "chrome/browser/webdata/web_database.h" | 12 #include "chrome/browser/webdata/web_database.h" | 
| 10 | 13 | 
| 11 using sync_api::ReadNode; | 14 using sync_api::ReadNode; | 
| 12 namespace browser_sync { | 15 namespace browser_sync { | 
| 13 | 16 | 
| 14 const char kAutofillProfileTag[] = "google_chrome_autofill_profile"; | 17 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; | 
| 15 | 18 | 
| 16 AutofillProfileModelAssociator::AutofillProfileModelAssociator( | 19 AutofillProfileModelAssociator::AutofillProfileModelAssociator( | 
| 17     ProfileSyncService* sync_service, | 20     ProfileSyncService* sync_service, | 
| 18     WebDatabase* web_database, | 21     WebDatabase* web_database, | 
| 19     PersonalDataManager* personal_data) | 22     PersonalDataManager* personal_data) | 
| 20     : sync_service_(sync_service), | 23     : sync_service_(sync_service), | 
| 21       web_database_(web_database), | 24       web_database_(web_database), | 
| 22       personal_data_(personal_data), | 25       personal_data_(personal_data), | 
| 23       autofill_node_id_(sync_api::kInvalidId), | 26       autofill_node_id_(sync_api::kInvalidId), | 
| 24       abort_association_pending_(false) { | 27       abort_association_pending_(false), | 
|  | 28       number_of_profiles_created_(0) { | 
| 25   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 29   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
| 26   DCHECK(sync_service_); | 30   DCHECK(sync_service_); | 
| 27   DCHECK(web_database_); | 31   DCHECK(web_database_); | 
| 28   DCHECK(personal_data_); | 32   DCHECK(personal_data_); | 
| 29 } | 33 } | 
| 30 | 34 | 
| 31 AutofillProfileModelAssociator::~AutofillProfileModelAssociator() { | 35 AutofillProfileModelAssociator::~AutofillProfileModelAssociator() { | 
| 32   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 36   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
| 33 } | 37 } | 
| 34 | 38 | 
| 35 bool AutofillProfileModelAssociator::TraverseAndAssociateChromeAutoFillProfiles( | 39 bool AutofillProfileModelAssociator::TraverseAndAssociateChromeAutoFillProfiles( | 
| 36     sync_api::WriteTransaction* write_trans, | 40     sync_api::WriteTransaction* write_trans, | 
| 37     const sync_api::ReadNode& autofill_root, | 41     const sync_api::ReadNode& autofill_root, | 
| 38     const std::vector<AutoFillProfile*>& all_profiles_from_db, | 42     const std::vector<AutoFillProfile*>& all_profiles_from_db, | 
| 39     std::set<std::string>* current_profiles, | 43     std::set<std::string>* current_profiles, | 
| 40     std::vector<AutoFillProfile*>* updated_profiles, | 44     std::vector<AutoFillProfile*>* updated_profiles, | 
| 41     std::vector<AutoFillProfile*>* new_profiles, | 45     std::vector<AutoFillProfile*>* new_profiles, | 
| 42     std::vector<std::string>* profiles_to_delete) { | 46     std::vector<std::string>* profiles_to_delete) { | 
| 43 | 47 | 
|  | 48   if (MigrationLoggingEnabled()) { | 
|  | 49     VLOG(1) << "[AUTOFILL MIGRATION]" | 
|  | 50             << "Printing profiles from web db"; | 
|  | 51 | 
|  | 52     for (std::vector<AutoFillProfile*>::const_iterator ix = | 
|  | 53         all_profiles_from_db.begin(); ix != all_profiles_from_db.end(); ++ix) { | 
|  | 54       AutoFillProfile* p = *ix; | 
|  | 55       VLOG(1) << "[AUTOFILL MIGRATION]  " | 
|  | 56               << UTF16ToUTF8(p->GetFieldText(AutoFillType(NAME_FIRST))) | 
|  | 57               << UTF16ToUTF8(p->GetFieldText(AutoFillType(NAME_LAST))) | 
|  | 58               << p->guid(); | 
|  | 59     } | 
|  | 60   } | 
|  | 61 | 
|  | 62   if (MigrationLoggingEnabled()) { | 
|  | 63     VLOG(1) << "[AUTOFILL MIGRATION]" | 
|  | 64             << "Looking for the above data in sync db.."; | 
|  | 65   } | 
| 44   // Alias the all_profiles_from_db so we fit in 80 characters | 66   // Alias the all_profiles_from_db so we fit in 80 characters | 
| 45   const std::vector<AutoFillProfile*>& profiles(all_profiles_from_db); | 67   const std::vector<AutoFillProfile*>& profiles(all_profiles_from_db); | 
| 46   for (std::vector<AutoFillProfile*>::const_iterator ix = profiles.begin(); | 68   for (std::vector<AutoFillProfile*>::const_iterator ix = profiles.begin(); | 
| 47       ix != profiles.end(); | 69       ix != profiles.end(); | 
| 48       ++ix) { | 70       ++ix) { | 
| 49     std::string guid((*ix)->guid()); | 71     std::string guid((*ix)->guid()); | 
| 50 | 72 | 
| 51     ReadNode node(write_trans); | 73     ReadNode node(write_trans); | 
| 52     if (node.InitByClientTagLookup(syncable::AUTOFILL_PROFILE, guid)) { | 74     if (node.InitByClientTagLookup(syncable::AUTOFILL_PROFILE, guid)) { | 
|  | 75       if (MigrationLoggingEnabled()) { | 
|  | 76         VLOG(1) << "[AUTOFILL MIGRATION]" | 
|  | 77                 << " Found in sync db: " | 
|  | 78                 << UTF16ToUTF8((*ix)->GetFieldText(AutoFillType(NAME_FIRST))) | 
|  | 79                 << UTF16ToUTF8((*ix)->GetFieldText(AutoFillType(NAME_LAST))) | 
|  | 80                 << (*ix)->guid() | 
|  | 81                 << " so associating"; | 
|  | 82       } | 
| 53       const sync_pb::AutofillProfileSpecifics& autofill( | 83       const sync_pb::AutofillProfileSpecifics& autofill( | 
| 54           node.GetAutofillProfileSpecifics()); | 84           node.GetAutofillProfileSpecifics()); | 
| 55       if (OverwriteProfileWithServerData(*ix, autofill)) { | 85       if (OverwriteProfileWithServerData(*ix, autofill)) { | 
| 56         updated_profiles->push_back(*ix); | 86         updated_profiles->push_back(*ix); | 
| 57       } | 87       } | 
| 58       Associate(&guid, node.GetId()); | 88       Associate(&guid, node.GetId()); | 
| 59       current_profiles->insert(guid); | 89       current_profiles->insert(guid); | 
| 60     } else { | 90     } else { | 
| 61       MakeNewAutofillProfileSyncNodeIfNeeded(write_trans, | 91       MakeNewAutofillProfileSyncNodeIfNeeded(write_trans, | 
| 62           autofill_root, | 92           autofill_root, | 
| 63           (**ix), | 93           (**ix), | 
| 64           new_profiles, | 94           new_profiles, | 
| 65           current_profiles, | 95           current_profiles, | 
| 66           profiles_to_delete); | 96           profiles_to_delete); | 
| 67     } | 97     } | 
| 68   } | 98   } | 
| 69 |  | 
| 70   return true; | 99   return true; | 
| 71 } | 100 } | 
| 72 | 101 | 
|  | 102 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode( | 
|  | 103     const std::string& tag, | 
|  | 104     int64* sync_id) { | 
|  | 105   sync_api::ReadTransaction trans( | 
|  | 106       sync_service_->backend()->GetUserShareHandle()); | 
|  | 107   sync_api::ReadNode sync_node(&trans); | 
|  | 108   if (!sync_node.InitByTagLookup(tag.c_str())) | 
|  | 109     return false; | 
|  | 110   *sync_id = sync_node.GetId(); | 
|  | 111   return true; | 
|  | 112 } | 
|  | 113 | 
| 73 bool AutofillProfileModelAssociator::LoadAutofillData( | 114 bool AutofillProfileModelAssociator::LoadAutofillData( | 
| 74     std::vector<AutoFillProfile*>* profiles) { | 115     std::vector<AutoFillProfile*>* profiles) { | 
| 75   if (IsAbortPending()) | 116   if (IsAbortPending()) | 
| 76     return false; | 117     return false; | 
| 77 | 118 | 
| 78   if (!web_database_->GetAutoFillProfiles(profiles)) | 119   if (!web_database_->GetAutoFillProfiles(profiles)) | 
| 79     return false; | 120     return false; | 
| 80 | 121 | 
| 81   return true; | 122   return true; | 
| 82 } | 123 } | 
| 83 | 124 | 
| 84 bool AutofillProfileModelAssociator::AssociateModels() { | 125 bool AutofillProfileModelAssociator::AssociateModels() { | 
| 85   VLOG(1) << "Associating Autofill Models"; | 126   VLOG(1) << "Associating Autofill Models"; | 
| 86   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 127   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
| 87   { | 128   { | 
| 88     AutoLock lock(abort_association_pending_lock_); | 129     AutoLock lock(abort_association_pending_lock_); | 
| 89     abort_association_pending_ = false; | 130     abort_association_pending_ = false; | 
| 90   } | 131   } | 
| 91 | 132 | 
| 92   ScopedVector<AutoFillProfile> profiles; | 133   ScopedVector<AutoFillProfile> profiles; | 
| 93 | 134 | 
| 94   if (!LoadAutofillData(&profiles.get())) { | 135   if (!LoadAutofillData(&profiles.get())) { | 
| 95     LOG(ERROR) << "Could not get the autofill data from WebDatabase."; | 136     LOG(ERROR) << "Could not get the autofill data from WebDatabase."; | 
| 96     return false; | 137     return false; | 
| 97   } | 138   } | 
| 98 | 139 | 
|  | 140   if (MigrationLoggingEnabled()) { | 
|  | 141     VLOG(1) << "[AUTOFILL MIGRATION]" | 
|  | 142             << " Now associating to the new autofill profile model associator" | 
|  | 143             << "root node"; | 
|  | 144   } | 
| 99   DataBundle bundle; | 145   DataBundle bundle; | 
| 100   { | 146   { | 
| 101     // The write transaction lock is held inside this block. | 147     // The write transaction lock is held inside this block. | 
| 102     // We do all the web db operations outside this block. | 148     // We do all the web db operations outside this block. | 
| 103     sync_api::WriteTransaction trans( | 149     sync_api::WriteTransaction trans( | 
| 104         sync_service_->backend()->GetUserShareHandle()); | 150         sync_service_->backend()->GetUserShareHandle()); | 
| 105 | 151 | 
| 106     sync_api::ReadNode autofill_root(&trans); | 152     sync_api::ReadNode autofill_root(&trans); | 
| 107     if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { | 153     if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { | 
| 108       LOG(ERROR) << "Server did not create the top-level autofill node. We " | 154       LOG(ERROR) << "Server did not create the top-level autofill node. We " | 
| 109                  << "might be running against an out-of-date server."; | 155                  << "might be running against an out-of-date server."; | 
| 110       return false; | 156       return false; | 
| 111     } | 157     } | 
| 112 | 158 | 
| 113     if (!TraverseAndAssociateChromeAutoFillProfiles(&trans, autofill_root, | 159     if (!TraverseAndAssociateChromeAutoFillProfiles(&trans, autofill_root, | 
| 114             profiles.get(), &bundle.current_profiles, | 160             profiles.get(), &bundle.current_profiles, | 
| 115             &bundle.updated_profiles, | 161             &bundle.updated_profiles, | 
| 116             &bundle.new_profiles, | 162             &bundle.new_profiles, | 
| 117             &bundle.profiles_to_delete) || | 163             &bundle.profiles_to_delete) || | 
| 118         !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { | 164         !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { | 
| 119       return false; | 165       return false; | 
| 120     } | 166     } | 
| 121   } | 167   } | 
| 122 | 168 | 
| 123   if (!SaveChangesToWebData(bundle)) { | 169   if (!SaveChangesToWebData(bundle)) { | 
| 124     LOG(ERROR) << "Failed to update autofill entries."; | 170     LOG(ERROR) << "Failed to update autofill entries."; | 
| 125     return false; | 171     return false; | 
| 126   } | 172   } | 
| 127 | 173 | 
| 128   // TODO(lipalani) Bug 64111- split out the OptimisticRefreshTask | 174   if (sync_service_->backend()->GetAutofillMigrationState() != | 
| 129   // into its own class | 175      syncable::MIGRATED) { | 
| 130   // from autofill_model_associator | 176     syncable::AutofillMigrationDebugInfo debug_info; | 
| 131   // Will be done as part of the autofill_model_associator work. | 177     debug_info.autofill_profile_added_during_migration = | 
| 132   // BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 178       number_of_profiles_created_; | 
| 133   // new DoOptimisticRefreshTask(personal_data_)); | 179     sync_service_->backend()->SetAutofillMigrationDebugInfo( | 
|  | 180       syncable::AutofillMigrationDebugInfo::PROFILES_ADDED, | 
|  | 181       debug_info); | 
|  | 182     sync_service()->backend()->SetAutofillMigrationState( | 
|  | 183       syncable::MIGRATED); | 
|  | 184   } | 
|  | 185 | 
|  | 186   BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 
|  | 187       new DoOptimisticRefreshForAutofill(personal_data_)); | 
| 134   return true; | 188   return true; | 
| 135 } | 189 } | 
| 136 | 190 | 
| 137 bool AutofillProfileModelAssociator::DisassociateModels() { | 191 bool AutofillProfileModelAssociator::DisassociateModels() { | 
| 138   id_map_.clear(); | 192   id_map_.clear(); | 
| 139   id_map_inverse_.clear(); | 193   id_map_inverse_.clear(); | 
| 140   return true; | 194   return true; | 
| 141 } | 195 } | 
| 142 | 196 | 
| 143 // Helper to compare the local value and cloud value of a field, merge into | 197 // Helper to compare the local value and cloud value of a field, merge into | 
| 144 // the local value if they differ, and return whether the merge happened. | 198 // the local value if they differ, and return whether the merge happened. | 
| 145 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, | 199 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, | 
| 146     AutoFillFieldType t, | 200     AutoFillFieldType t, | 
| 147     const std::string& specifics_field) { | 201     const std::string& specifics_field) { | 
| 148   if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field) | 202   if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field) | 
| 149     return false; | 203     return false; | 
| 150   f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field)); | 204   f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field)); | 
| 151   return true; | 205   return true; | 
| 152 } | 206 } | 
| 153 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( | 207 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( | 
| 154     bool *has_nodes) { | 208     bool *has_nodes) { | 
| 155   CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); | 209   CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); | 
| 156   sync_api::ReadTransaction trans( | 210   sync_api::ReadTransaction trans( | 
| 157       sync_service_->backend()->GetUserShareHandle()); | 211       sync_service_->backend()->GetUserShareHandle()); | 
| 158 | 212 | 
| 159   sync_api::ReadNode node(&trans); | 213   sync_api::ReadNode node(&trans); | 
| 160 | 214 | 
| 161   if (!node.InitByClientTagLookup( | 215   if (!node.InitByTagLookup(kAutofillProfileTag)) { | 
| 162         syncable::AUTOFILL_PROFILE, |  | 
| 163         kAutofillProfileTag)) { |  | 
| 164     LOG(ERROR) << "Sever did not create a top level node" | 216     LOG(ERROR) << "Sever did not create a top level node" | 
| 165                << "Out of data server or autofill type not enabled"; | 217                << "Out of data server or autofill type not enabled"; | 
| 166     return false; | 218     return false; | 
| 167   } | 219   } | 
| 168 | 220 | 
| 169   *has_nodes = sync_api::kInvalidId != node.GetFirstChildId(); | 221   *has_nodes = sync_api::kInvalidId != node.GetFirstChildId(); | 
| 170   return true; | 222   return true; | 
| 171 } | 223 } | 
| 172 // static | 224 // static | 
| 173 bool AutofillProfileModelAssociator::OverwriteProfileWithServerData( | 225 bool AutofillProfileModelAssociator::OverwriteProfileWithServerData( | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 196 | 248 | 
| 197 | 249 | 
| 198 int64 AutofillProfileModelAssociator::FindSyncNodeWithProfile( | 250 int64 AutofillProfileModelAssociator::FindSyncNodeWithProfile( | 
| 199     sync_api::WriteTransaction* trans, | 251     sync_api::WriteTransaction* trans, | 
| 200     const sync_api::BaseNode& autofill_root, | 252     const sync_api::BaseNode& autofill_root, | 
| 201     const AutoFillProfile& profile_from_db) { | 253     const AutoFillProfile& profile_from_db) { | 
| 202   int64 sync_child_id = autofill_root.GetFirstChildId(); | 254   int64 sync_child_id = autofill_root.GetFirstChildId(); | 
| 203   while (sync_child_id != sync_api::kInvalidId) { | 255   while (sync_child_id != sync_api::kInvalidId) { | 
| 204     ReadNode read_node(trans); | 256     ReadNode read_node(trans); | 
| 205     AutoFillProfile p; | 257     AutoFillProfile p; | 
| 206     if (read_node.InitByIdLookup(sync_child_id)) { | 258     if (!read_node.InitByIdLookup(sync_child_id)) { | 
| 207       LOG(ERROR) << "unable to find the id given by getfirst child " << | 259       LOG(ERROR) << "unable to find the id given by getfirst child " << | 
| 208         sync_child_id; | 260         sync_child_id; | 
| 209       return sync_api::kInvalidId; | 261       return sync_api::kInvalidId; | 
| 210     } | 262     } | 
| 211     const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 263     const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 
| 212         read_node.GetAutofillProfileSpecifics()); | 264         read_node.GetAutofillProfileSpecifics()); | 
| 213     OverwriteProfileWithServerData(&p, autofill_specifics); | 265     OverwriteProfileWithServerData(&p, autofill_specifics); | 
| 214     if (p.Compare(profile_from_db) == 0) { | 266     if (p.Compare(profile_from_db) == 0) { | 
| 215       return sync_child_id; | 267       return sync_child_id; | 
| 216     } | 268     } | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 238       return false; | 290       return false; | 
| 239     } | 291     } | 
| 240     const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 292     const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 
| 241         read_node.GetAutofillProfileSpecifics()); | 293         read_node.GetAutofillProfileSpecifics()); | 
| 242     AutoFillProfile* p = new AutoFillProfile(autofill_specifics.guid()); | 294     AutoFillProfile* p = new AutoFillProfile(autofill_specifics.guid()); | 
| 243     OverwriteProfileWithServerData(p, autofill_specifics); | 295     OverwriteProfileWithServerData(p, autofill_specifics); | 
| 244     new_profiles->push_back(p); | 296     new_profiles->push_back(p); | 
| 245     std::string guid = autofill_specifics.guid(); | 297     std::string guid = autofill_specifics.guid(); | 
| 246     Associate(&guid, sync_node_id); | 298     Associate(&guid, sync_node_id); | 
| 247     current_profiles->insert(autofill_specifics.guid()); | 299     current_profiles->insert(autofill_specifics.guid()); | 
|  | 300     if (MigrationLoggingEnabled()) { | 
|  | 301       VLOG(1) << "[AUTOFILL MIGRATION]" | 
|  | 302               << "Found in sync db but with a different guid: " | 
|  | 303               << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_FIRST))) | 
|  | 304               << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_LAST))) | 
|  | 305               << "New guid " << autofill_specifics.guid() | 
|  | 306               << " so associating"; | 
|  | 307     } | 
| 248   } else { | 308   } else { | 
| 249     sync_api::WriteNode node(trans); | 309     sync_api::WriteNode node(trans); | 
| 250     if (!node.InitUniqueByCreation( | 310     if (!node.InitUniqueByCreation( | 
| 251              syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { | 311              syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { | 
| 252       LOG(ERROR) << "Failed to create autofill sync node."; | 312       LOG(ERROR) << "Failed to create autofill sync node."; | 
| 253       return false; | 313       return false; | 
| 254     } | 314     } | 
| 255     node.SetTitle(UTF8ToWide(profile.guid())); | 315     node.SetTitle(UTF8ToWide(profile.guid())); | 
|  | 316     if (MigrationLoggingEnabled()) { | 
|  | 317       VLOG(1) << "[AUTOFILL MIGRATION]" | 
|  | 318               << "NOT Found in sync db  " | 
|  | 319               << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_FIRST))) | 
|  | 320               << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_LAST))) | 
|  | 321               << profile.guid() | 
|  | 322               << " so creating a new sync node."; | 
|  | 323     } | 
|  | 324     AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); | 
|  | 325     current_profiles->insert(profile.guid()); | 
|  | 326     number_of_profiles_created_++; | 
| 256 | 327 | 
| 257     // TODO(lipalani) -Bug 64111 This needs rewriting. This will be tackled |  | 
| 258     // when rewriting autofill change processor. |  | 
| 259     // AutofillChangeProcessor::WriteAutofillProfile(profile, &node); |  | 
| 260   } | 328   } | 
| 261   return true; | 329   return true; | 
| 262 } | 330 } | 
| 263 | 331 | 
| 264 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( | 332 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( | 
| 265     sync_api::WriteTransaction* write_trans, | 333     sync_api::WriteTransaction* write_trans, | 
| 266     const sync_api::ReadNode& autofill_root, | 334     const sync_api::ReadNode& autofill_root, | 
| 267     DataBundle* bundle) { | 335     DataBundle* bundle) { | 
| 268   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 336   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
| 269 | 337 | 
|  | 338   if (MigrationLoggingEnabled()) { | 
|  | 339     VLOG(1) << "[AUTOFILL MIGRATION] " | 
|  | 340             << " Iterating over sync nodes of autofill profile root node"; | 
|  | 341   } | 
| 270   int64 sync_child_id = autofill_root.GetFirstChildId(); | 342   int64 sync_child_id = autofill_root.GetFirstChildId(); | 
| 271   while (sync_child_id != sync_api::kInvalidId) { | 343   while (sync_child_id != sync_api::kInvalidId) { | 
| 272     ReadNode sync_child(write_trans); | 344     ReadNode sync_child(write_trans); | 
| 273     if (!sync_child.InitByIdLookup(sync_child_id)) { | 345     if (!sync_child.InitByIdLookup(sync_child_id)) { | 
| 274       LOG(ERROR) << "Failed to fetch child node."; | 346       LOG(ERROR) << "Failed to fetch child node."; | 
| 275       return false; | 347       return false; | 
| 276     } | 348     } | 
| 277     const sync_pb::AutofillProfileSpecifics& autofill( | 349     const sync_pb::AutofillProfileSpecifics& autofill( | 
| 278         sync_child.GetAutofillProfileSpecifics()); | 350         sync_child.GetAutofillProfileSpecifics()); | 
| 279 | 351 | 
| 280     AddNativeProfileIfNeeded(autofill, bundle, sync_child); | 352     AddNativeProfileIfNeeded(autofill, bundle, sync_child); | 
| 281 | 353 | 
| 282     sync_child_id = sync_child.GetSuccessorId(); | 354     sync_child_id = sync_child.GetSuccessorId(); | 
| 283   } | 355   } | 
| 284   return true; | 356   return true; | 
| 285 } | 357 } | 
| 286 | 358 | 
| 287 void AutofillProfileModelAssociator::AddNativeProfileIfNeeded( | 359 void AutofillProfileModelAssociator::AddNativeProfileIfNeeded( | 
| 288     const sync_pb::AutofillProfileSpecifics& profile, | 360     const sync_pb::AutofillProfileSpecifics& profile, | 
| 289     DataBundle* bundle, | 361     DataBundle* bundle, | 
| 290     const sync_api::ReadNode& node) { | 362     const sync_api::ReadNode& node) { | 
| 291   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 363   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
| 292 | 364 | 
|  | 365   if (MigrationLoggingEnabled()) { | 
|  | 366     VLOG(1) << "[AUTOFILL MIGRATION] " | 
|  | 367             << "Trying to lookup " | 
|  | 368             << profile.name_first() | 
|  | 369             << " " | 
|  | 370             << profile.name_last() | 
|  | 371             << " in the web db"; | 
|  | 372   } | 
| 293   if (bundle->current_profiles.find(profile.guid()) == | 373   if (bundle->current_profiles.find(profile.guid()) == | 
| 294       bundle->current_profiles.end()) { | 374       bundle->current_profiles.end()) { | 
| 295     std::string guid(profile.guid()); | 375     std::string guid(profile.guid()); | 
| 296     Associate(&guid, node.GetId()); | 376     Associate(&guid, node.GetId()); | 
| 297     AutoFillProfile* p = new AutoFillProfile(profile.guid()); | 377     AutoFillProfile* p = new AutoFillProfile(profile.guid()); | 
| 298     OverwriteProfileWithServerData(p, profile); | 378     OverwriteProfileWithServerData(p, profile); | 
| 299     bundle->new_profiles.push_back(p); | 379     bundle->new_profiles.push_back(p); | 
|  | 380     if (MigrationLoggingEnabled()) { | 
|  | 381       VLOG(1) << "[AUTOFILL MIGRATION] " | 
|  | 382               << " Did not find one so creating it on web db"; | 
|  | 383     } | 
|  | 384   } else { | 
|  | 385     if (MigrationLoggingEnabled()) { | 
|  | 386       VLOG(1) << "[AUTOFILL MIGRATION] " | 
|  | 387               << " Found it on web db. Moving on "; | 
|  | 388     } | 
| 300   } | 389   } | 
| 301 } | 390 } | 
| 302 | 391 | 
| 303 bool AutofillProfileModelAssociator::SaveChangesToWebData( | 392 bool AutofillProfileModelAssociator::SaveChangesToWebData( | 
| 304     const DataBundle& bundle) { | 393     const DataBundle& bundle) { | 
| 305   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 394   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
| 306 | 395 | 
| 307   if (IsAbortPending()) | 396   if (IsAbortPending()) | 
| 308     return false; | 397     return false; | 
| 309 | 398 | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 355   AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); | 444   AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); | 
| 356   return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; | 445   return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; | 
| 357 } | 446 } | 
| 358 | 447 | 
| 359 void AutofillProfileModelAssociator::AbortAssociation() { | 448 void AutofillProfileModelAssociator::AbortAssociation() { | 
| 360   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 449   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 361   AutoLock lock(abort_association_pending_lock_); | 450   AutoLock lock(abort_association_pending_lock_); | 
| 362   abort_association_pending_ = true; | 451   abort_association_pending_ = true; | 
| 363 } | 452 } | 
| 364 | 453 | 
|  | 454 const std::string* AutofillProfileModelAssociator::GetChromeNodeFromSyncId( | 
|  | 455     int64 sync_id) { | 
|  | 456   SyncIdToAutofillMap::const_iterator iter = id_map_inverse_.find(sync_id); | 
|  | 457   return iter == id_map_inverse_.end() ? NULL : &(iter->second); | 
|  | 458 } | 
|  | 459 | 
| 365 bool AutofillProfileModelAssociator::IsAbortPending() { | 460 bool AutofillProfileModelAssociator::IsAbortPending() { | 
| 366   AutoLock lock(abort_association_pending_lock_); | 461   AutoLock lock(abort_association_pending_lock_); | 
| 367   return abort_association_pending_; | 462   return abort_association_pending_; | 
| 368 } | 463 } | 
| 369 | 464 | 
|  | 465 bool AutofillProfileModelAssociator::MigrationLoggingEnabled() { | 
|  | 466   // [TODO] enable logging via a command line flag. | 
|  | 467   return false; | 
|  | 468 } | 
|  | 469 | 
| 370 }  // namespace browser_sync | 470 }  // namespace browser_sync | 
| 371 | 471 | 
| OLD | NEW | 
|---|