| OLD | NEW |
| 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/autofill_profile_syncable_service.h" | 5 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // with something else. | 41 // with something else. |
| 42 static int user_data_key = 0; | 42 static int user_data_key = 0; |
| 43 return reinterpret_cast<void*>(&user_data_key); | 43 return reinterpret_cast<void*>(&user_data_key); |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; | 48 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; |
| 49 | 49 |
| 50 AutofillProfileSyncableService::AutofillProfileSyncableService( | 50 AutofillProfileSyncableService::AutofillProfileSyncableService( |
| 51 AutofillWebDataService* web_data_service, | 51 autofill::AutofillWebDataBackend* webdata_backend, |
| 52 const std::string& app_locale) | 52 const std::string& app_locale) |
| 53 : web_data_service_(web_data_service), | 53 : webdata_backend_(webdata_backend), |
| 54 app_locale_(app_locale), | 54 app_locale_(app_locale), |
| 55 scoped_observer_(this) { | 55 scoped_observer_(this) { |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 57 DCHECK(web_data_service_); | 57 DCHECK(webdata_backend_); |
| 58 | 58 |
| 59 scoped_observer_.Add(web_data_service_); | 59 scoped_observer_.Add(webdata_backend_); |
| 60 } | 60 } |
| 61 | 61 |
| 62 AutofillProfileSyncableService::~AutofillProfileSyncableService() { | 62 AutofillProfileSyncableService::~AutofillProfileSyncableService() { |
| 63 DCHECK(CalledOnValidThread()); | 63 DCHECK(CalledOnValidThread()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // static | 66 // static |
| 67 void AutofillProfileSyncableService::CreateForWebDataService( | 67 void AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( |
| 68 AutofillWebDataService* web_data_service, | 68 AutofillWebDataService* web_data_service, |
| 69 autofill::AutofillWebDataBackend* webdata_backend, |
| 69 const std::string& app_locale) { | 70 const std::string& app_locale) { |
| 70 web_data_service->GetDBUserData()->SetUserData( | 71 web_data_service->GetDBUserData()->SetUserData( |
| 71 UserDataKey(), | 72 UserDataKey(), |
| 72 new AutofillProfileSyncableService(web_data_service, app_locale)); | 73 new AutofillProfileSyncableService(webdata_backend, app_locale)); |
| 73 } | 74 } |
| 74 | 75 |
| 75 // static | 76 // static |
| 76 AutofillProfileSyncableService* | 77 AutofillProfileSyncableService* |
| 77 AutofillProfileSyncableService::FromWebDataService( | 78 AutofillProfileSyncableService::FromWebDataService( |
| 78 AutofillWebDataService* web_data_service) { | 79 AutofillWebDataService* web_data_service) { |
| 79 return static_cast<AutofillProfileSyncableService*>( | 80 return static_cast<AutofillProfileSyncableService*>( |
| 80 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); | 81 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); |
| 81 } | 82 } |
| 82 | 83 |
| 83 AutofillProfileSyncableService::AutofillProfileSyncableService() | 84 AutofillProfileSyncableService::AutofillProfileSyncableService() |
| 84 : web_data_service_(NULL), | 85 : webdata_backend_(NULL), |
| 85 scoped_observer_(this) { | 86 scoped_observer_(this) { |
| 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 87 } | 88 } |
| 88 | 89 |
| 89 syncer::SyncMergeResult | 90 syncer::SyncMergeResult |
| 90 AutofillProfileSyncableService::MergeDataAndStartSyncing( | 91 AutofillProfileSyncableService::MergeDataAndStartSyncing( |
| 91 syncer::ModelType type, | 92 syncer::ModelType type, |
| 92 const syncer::SyncDataList& initial_sync_data, | 93 const syncer::SyncDataList& initial_sync_data, |
| 93 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 94 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 94 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { | 95 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 syncer::SyncChange(FROM_HERE, | 185 syncer::SyncChange(FROM_HERE, |
| 185 syncer::SyncChange::ACTION_UPDATE, | 186 syncer::SyncChange::ACTION_UPDATE, |
| 186 CreateData(*(bundle.profiles_to_sync_back[i])))); | 187 CreateData(*(bundle.profiles_to_sync_back[i])))); |
| 187 } | 188 } |
| 188 | 189 |
| 189 if (!new_changes.empty()) { | 190 if (!new_changes.empty()) { |
| 190 merge_result.set_error( | 191 merge_result.set_error( |
| 191 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); | 192 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); |
| 192 } | 193 } |
| 193 | 194 |
| 194 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 195 if (webdata_backend_) |
| 196 webdata_backend_->NotifyOfMultipleAutofillChanges(); |
| 195 | 197 |
| 196 return merge_result; | 198 return merge_result; |
| 197 } | 199 } |
| 198 | 200 |
| 199 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) { | 201 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) { |
| 200 DCHECK(CalledOnValidThread()); | 202 DCHECK(CalledOnValidThread()); |
| 201 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE); | 203 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE); |
| 202 | 204 |
| 203 sync_processor_.reset(); | 205 sync_processor_.reset(); |
| 204 sync_error_factory_.reset(); | 206 sync_error_factory_.reset(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 syncer::SyncChange::ChangeTypeToString(i->change_type())); | 257 syncer::SyncChange::ChangeTypeToString(i->change_type())); |
| 256 } | 258 } |
| 257 } | 259 } |
| 258 | 260 |
| 259 if (!SaveChangesToWebData(bundle)) { | 261 if (!SaveChangesToWebData(bundle)) { |
| 260 return sync_error_factory_->CreateAndUploadError( | 262 return sync_error_factory_->CreateAndUploadError( |
| 261 FROM_HERE, | 263 FROM_HERE, |
| 262 "Failed to update webdata."); | 264 "Failed to update webdata."); |
| 263 } | 265 } |
| 264 | 266 |
| 265 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 267 if (webdata_backend_) |
| 268 webdata_backend_->NotifyOfMultipleAutofillChanges(); |
| 266 | 269 |
| 267 return syncer::SyncError(); | 270 return syncer::SyncError(); |
| 268 } | 271 } |
| 269 | 272 |
| 270 void AutofillProfileSyncableService::AutofillProfileChanged( | 273 void AutofillProfileSyncableService::AutofillProfileChanged( |
| 271 const AutofillProfileChange& change) { | 274 const AutofillProfileChange& change) { |
| 272 // Check if sync is on. If we receive notification prior to the sync being set | 275 // Check if sync is on. If we receive notification prior to the sync being set |
| 273 // up we are going to process all when MergeData..() is called. If we receive | 276 // up we are going to process all when MergeData..() is called. If we receive |
| 274 // notification after the sync exited, it will be sinced next time Chrome | 277 // notification after the sync exited, it will be sinced next time Chrome |
| 275 // starts. | 278 // starts. |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 579 |
| 577 bool AutofillProfileSyncableService::MergeProfile( | 580 bool AutofillProfileSyncableService::MergeProfile( |
| 578 const AutofillProfile& merge_from, | 581 const AutofillProfile& merge_from, |
| 579 AutofillProfile* merge_into, | 582 AutofillProfile* merge_into, |
| 580 const std::string& app_locale) { | 583 const std::string& app_locale) { |
| 581 merge_into->OverwriteWithOrAddTo(merge_from, app_locale); | 584 merge_into->OverwriteWithOrAddTo(merge_from, app_locale); |
| 582 return (merge_into->Compare(merge_from) != 0); | 585 return (merge_into->Compare(merge_from) != 0); |
| 583 } | 586 } |
| 584 | 587 |
| 585 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { | 588 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { |
| 586 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); | 589 return AutofillTable::FromWebDatabase(webdata_backend_->GetDatabase()); |
| 587 } | 590 } |
| 588 | 591 |
| 589 void AutofillProfileSyncableService::InjectStartSyncFlare( | 592 void AutofillProfileSyncableService::InjectStartSyncFlare( |
| 590 const syncer::SyncableService::StartSyncFlare& flare) { | 593 const syncer::SyncableService::StartSyncFlare& flare) { |
| 591 flare_ = flare; | 594 flare_ = flare; |
| 592 } | 595 } |
| 593 | 596 |
| 594 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 597 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
| 595 | 598 |
| 596 AutofillProfileSyncableService::DataBundle::~DataBundle() {} | 599 AutofillProfileSyncableService::DataBundle::~DataBundle() {} |
| OLD | NEW |