| 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" |
| 9 #include "chrome/browser/webdata/web_database.h" | 11 #include "chrome/browser/webdata/web_database.h" |
| 10 | 12 |
| 11 using sync_api::ReadNode; | 13 using sync_api::ReadNode; |
| 12 namespace browser_sync { | 14 namespace browser_sync { |
| 13 | 15 |
| 14 const char kAutofillProfileTag[] = "google_chrome_autofill_profile"; | 16 const char kAutofillProfileTag[] = "google_chrome_autofill_profile"; |
| 15 | 17 |
| 16 AutofillProfileModelAssociator::AutofillProfileModelAssociator( | 18 AutofillProfileModelAssociator::AutofillProfileModelAssociator( |
| 17 ProfileSyncService* sync_service, | 19 ProfileSyncService* sync_service, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 new_profiles, | 66 new_profiles, |
| 65 current_profiles, | 67 current_profiles, |
| 66 profiles_to_delete); | 68 profiles_to_delete); |
| 67 } | 69 } |
| 68 | 70 |
| 69 } | 71 } |
| 70 | 72 |
| 71 return true; | 73 return true; |
| 72 } | 74 } |
| 73 | 75 |
| 76 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode( |
| 77 const std::string& tag, |
| 78 int64* sync_id) { |
| 79 sync_api::ReadTransaction trans( |
| 80 sync_service_->backend()->GetUserShareHandle()); |
| 81 sync_api::ReadNode sync_node(&trans); |
| 82 if (!sync_node.InitByTagLookup(tag.c_str())) |
| 83 return false; |
| 84 *sync_id = sync_node.GetId(); |
| 85 return true; |
| 86 } |
| 87 |
| 74 bool AutofillProfileModelAssociator::LoadAutofillData( | 88 bool AutofillProfileModelAssociator::LoadAutofillData( |
| 75 std::vector<AutoFillProfile*>* profiles) { | 89 std::vector<AutoFillProfile*>* profiles) { |
| 76 if (IsAbortPending()) | 90 if (IsAbortPending()) |
| 77 return false; | 91 return false; |
| 78 | 92 |
| 79 if (!web_database_->GetAutoFillProfiles(profiles)) | 93 if (!web_database_->GetAutoFillProfiles(profiles)) |
| 80 return false; | 94 return false; |
| 81 | 95 |
| 82 return true; | 96 return true; |
| 83 } | 97 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { | 133 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { |
| 120 return false; | 134 return false; |
| 121 } | 135 } |
| 122 } | 136 } |
| 123 | 137 |
| 124 if (!SaveChangesToWebData(bundle)) { | 138 if (!SaveChangesToWebData(bundle)) { |
| 125 LOG(ERROR) << "Failed to update autofill entries."; | 139 LOG(ERROR) << "Failed to update autofill entries."; |
| 126 return false; | 140 return false; |
| 127 } | 141 } |
| 128 | 142 |
| 129 // [TODO] - split out the OptimisticRefreshTask into its own class | 143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 130 // from autofill_model_associator | 144 new DoOptimisticRefreshTask(personal_data_)); |
| 131 // Will be done as part of the autofill_model_associator work. | |
| 132 // BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 133 // new DoOptimisticRefreshTask(personal_data_)); | |
| 134 return true; | 145 return true; |
| 135 } | 146 } |
| 136 | 147 |
| 137 bool AutofillProfileModelAssociator::DisassociateModels() { | 148 bool AutofillProfileModelAssociator::DisassociateModels() { |
| 138 id_map_.clear(); | 149 id_map_.clear(); |
| 139 id_map_inverse_.clear(); | 150 id_map_inverse_.clear(); |
| 140 return true; | 151 return true; |
| 141 } | 152 } |
| 142 | 153 |
| 143 // Helper to compare the local value and cloud value of a field, merge into | 154 // Helper to compare the local value and cloud value of a field, merge into |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 current_profiles->insert(autofill_specifics.guid()); | 258 current_profiles->insert(autofill_specifics.guid()); |
| 248 } else { | 259 } else { |
| 249 sync_api::WriteNode node(trans); | 260 sync_api::WriteNode node(trans); |
| 250 if (!node.InitUniqueByCreation( | 261 if (!node.InitUniqueByCreation( |
| 251 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { | 262 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { |
| 252 LOG(ERROR) << "Failed to create autofill sync node."; | 263 LOG(ERROR) << "Failed to create autofill sync node."; |
| 253 return false; | 264 return false; |
| 254 } | 265 } |
| 255 node.SetTitle(UTF8ToWide(profile.guid())); | 266 node.SetTitle(UTF8ToWide(profile.guid())); |
| 256 | 267 |
| 257 // [TODO] This needs rewriting. This will be tackled | 268 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); |
| 258 // when rewriting autofill change processor. | |
| 259 // AutofillChangeProcessor::WriteAutofillProfile(profile, &node); | |
| 260 } | 269 } |
| 261 return true; | 270 return true; |
| 262 } | 271 } |
| 263 | 272 |
| 264 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( | 273 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( |
| 265 sync_api::WriteTransaction* write_trans, | 274 sync_api::WriteTransaction* write_trans, |
| 266 const sync_api::ReadNode& autofill_root, | 275 const sync_api::ReadNode& autofill_root, |
| 267 DataBundle* bundle) { | 276 DataBundle* bundle) { |
| 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 269 | 278 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 283 } | 292 } |
| 284 return true; | 293 return true; |
| 285 } | 294 } |
| 286 | 295 |
| 287 void AutofillProfileModelAssociator::AddNativeProfileIfNeeded( | 296 void AutofillProfileModelAssociator::AddNativeProfileIfNeeded( |
| 288 const sync_pb::AutofillProfileSpecifics& profile, | 297 const sync_pb::AutofillProfileSpecifics& profile, |
| 289 DataBundle* bundle, | 298 DataBundle* bundle, |
| 290 const sync_api::ReadNode& node) { | 299 const sync_api::ReadNode& node) { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 292 | 301 |
| 293 // [TODO] this looping through is costly. Replace this with a binary tree | 302 // [TODO](lipalani) this looping through is costly. |
| 303 // Replace this with a binary tree |
| 294 // at least in case of auto fill entries. | 304 // at least in case of auto fill entries. |
| 295 if (bundle->current_profiles.find(profile.guid()) == | 305 if (bundle->current_profiles.find(profile.guid()) == |
| 296 bundle->current_profiles.end()) { | 306 bundle->current_profiles.end()) { |
| 297 std::string guid(profile.guid()); | 307 std::string guid(profile.guid()); |
| 298 Associate(&guid, node.GetId()); | 308 Associate(&guid, node.GetId()); |
| 299 AutoFillProfile* p = new AutoFillProfile(profile.guid()); | 309 AutoFillProfile* p = new AutoFillProfile(profile.guid()); |
| 300 OverwriteProfileWithServerData(p, profile); | 310 OverwriteProfileWithServerData(p, profile); |
| 301 bundle->new_profiles.push_back(p); | 311 bundle->new_profiles.push_back(p); |
| 302 } | 312 } |
| 303 } | 313 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); | 367 AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); |
| 358 return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; | 368 return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; |
| 359 } | 369 } |
| 360 | 370 |
| 361 void AutofillProfileModelAssociator::AbortAssociation() { | 371 void AutofillProfileModelAssociator::AbortAssociation() { |
| 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 363 AutoLock lock(abort_association_pending_lock_); | 373 AutoLock lock(abort_association_pending_lock_); |
| 364 abort_association_pending_ = true; | 374 abort_association_pending_ = true; |
| 365 } | 375 } |
| 366 | 376 |
| 377 const std::string* AutofillProfileModelAssociator::GetChromeNodeFromSyncId( |
| 378 int64 sync_id) { |
| 379 SyncIdToAutofillMap::const_iterator iter = id_map_inverse_.find(sync_id); |
| 380 return iter == id_map_inverse_.end() ? NULL : &(iter->second); |
| 381 } |
| 382 |
| 367 bool AutofillProfileModelAssociator::IsAbortPending() { | 383 bool AutofillProfileModelAssociator::IsAbortPending() { |
| 368 AutoLock lock(abort_association_pending_lock_); | 384 AutoLock lock(abort_association_pending_lock_); |
| 369 return abort_association_pending_; | 385 return abort_association_pending_; |
| 370 } | 386 } |
| 371 | 387 |
| 372 } // namespace browser_sync | 388 } // namespace browser_sync |
| OLD | NEW |