| 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" |
| 11 #include "chrome/browser/api/webdata/autofill_web_data_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/webdata/autofill_table.h" | 13 #include "chrome/browser/webdata/autofill_table.h" |
| 13 #include "chrome/browser/webdata/web_data_service.h" | |
| 14 #include "chrome/browser/webdata/web_database.h" | 14 #include "chrome/browser/webdata/web_database.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "components/autofill/browser/autofill_profile.h" | 16 #include "components/autofill/browser/autofill_profile.h" |
| 17 #include "components/autofill/browser/form_group.h" | 17 #include "components/autofill/browser/form_group.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 21 #include "sync/api/sync_error.h" | 21 #include "sync/api/sync_error.h" |
| 22 #include "sync/api/sync_error_factory.h" | 22 #include "sync/api/sync_error_factory.h" |
| 23 #include "sync/protocol/sync.pb.h" | 23 #include "sync/protocol/sync.pb.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 // with something else. | 38 // with something else. |
| 39 static int user_data_key = 0; | 39 static int user_data_key = 0; |
| 40 return reinterpret_cast<void*>(&user_data_key); | 40 return reinterpret_cast<void*>(&user_data_key); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; | 45 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; |
| 46 | 46 |
| 47 AutofillProfileSyncableService::AutofillProfileSyncableService( | 47 AutofillProfileSyncableService::AutofillProfileSyncableService( |
| 48 WebDataService* web_data_service) | 48 AutofillWebDataService* web_data_service) |
| 49 : web_data_service_(web_data_service) { | 49 : web_data_service_(web_data_service) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 51 DCHECK(web_data_service_); | 51 DCHECK(web_data_service_); |
| 52 notification_registrar_.Add( | 52 notification_registrar_.Add( |
| 53 this, | 53 this, |
| 54 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 54 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 55 content::Source<WebDataService>(web_data_service_)); | 55 content::Source<AutofillWebDataService>(web_data_service_)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 AutofillProfileSyncableService::~AutofillProfileSyncableService() { | 58 AutofillProfileSyncableService::~AutofillProfileSyncableService() { |
| 59 DCHECK(CalledOnValidThread()); | 59 DCHECK(CalledOnValidThread()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // static | 62 // static |
| 63 void AutofillProfileSyncableService::CreateForWebDataService( | 63 void AutofillProfileSyncableService::CreateForWebDataService( |
| 64 WebDataService* web_data) { | 64 AutofillWebDataService* web_data_service) { |
| 65 web_data->GetDBUserData()->SetUserData( | 65 web_data_service->GetDBUserData()->SetUserData( |
| 66 UserDataKey(), new AutofillProfileSyncableService(web_data)); | 66 UserDataKey(), new AutofillProfileSyncableService(web_data_service)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // static | 69 // static |
| 70 AutofillProfileSyncableService* | 70 AutofillProfileSyncableService* |
| 71 AutofillProfileSyncableService::FromWebDataService( | 71 AutofillProfileSyncableService::FromWebDataService( |
| 72 WebDataService* service) { | 72 AutofillWebDataService* web_data_service) { |
| 73 return static_cast<AutofillProfileSyncableService*>( | 73 return static_cast<AutofillProfileSyncableService*>( |
| 74 service->GetDBUserData()->GetUserData(UserDataKey())); | 74 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 AutofillProfileSyncableService::AutofillProfileSyncableService() | 77 AutofillProfileSyncableService::AutofillProfileSyncableService() |
| 78 : web_data_service_(NULL) { | 78 : web_data_service_(NULL) { |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 syncer::SyncMergeResult | 82 syncer::SyncMergeResult |
| 83 AutofillProfileSyncableService::MergeDataAndStartSyncing( | 83 AutofillProfileSyncableService::MergeDataAndStartSyncing( |
| 84 syncer::ModelType type, | 84 syncer::ModelType type, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 syncer::SyncChange(FROM_HERE, | 177 syncer::SyncChange(FROM_HERE, |
| 178 syncer::SyncChange::ACTION_UPDATE, | 178 syncer::SyncChange::ACTION_UPDATE, |
| 179 CreateData(*(bundle.profiles_to_sync_back[i])))); | 179 CreateData(*(bundle.profiles_to_sync_back[i])))); |
| 180 } | 180 } |
| 181 | 181 |
| 182 if (!new_changes.empty()) { | 182 if (!new_changes.empty()) { |
| 183 merge_result.set_error( | 183 merge_result.set_error( |
| 184 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); | 184 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 187 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
| 188 | 188 |
| 189 return merge_result; | 189 return merge_result; |
| 190 } | 190 } |
| 191 | 191 |
| 192 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) { | 192 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) { |
| 193 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 194 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE); | 194 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE); |
| 195 | 195 |
| 196 sync_processor_.reset(); | 196 sync_processor_.reset(); |
| 197 sync_error_factory_.reset(); | 197 sync_error_factory_.reset(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 syncer::SyncChange::ChangeTypeToString(i->change_type())); | 248 syncer::SyncChange::ChangeTypeToString(i->change_type())); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 if (!SaveChangesToWebData(bundle)) { | 252 if (!SaveChangesToWebData(bundle)) { |
| 253 return sync_error_factory_->CreateAndUploadError( | 253 return sync_error_factory_->CreateAndUploadError( |
| 254 FROM_HERE, | 254 FROM_HERE, |
| 255 "Failed to update webdata."); | 255 "Failed to update webdata."); |
| 256 } | 256 } |
| 257 | 257 |
| 258 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 258 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
| 259 | 259 |
| 260 return syncer::SyncError(); | 260 return syncer::SyncError(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void AutofillProfileSyncableService::Observe(int type, | 263 void AutofillProfileSyncableService::Observe(int type, |
| 264 const content::NotificationSource& source, | 264 const content::NotificationSource& source, |
| 265 const content::NotificationDetails& details) { | 265 const content::NotificationDetails& details) { |
| 266 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); | 266 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); |
| 267 DCHECK_EQ(web_data_service_, content::Source<WebDataService>(source).ptr()); | 267 DCHECK_EQ(web_data_service_, |
| 268 content::Source<AutofillWebDataService>(source).ptr()); |
| 268 // Check if sync is on. If we receive notification prior to the sync being set | 269 // Check if sync is on. If we receive notification prior to the sync being set |
| 269 // up we are going to process all when MergeData..() is called. If we receive | 270 // up we are going to process all when MergeData..() is called. If we receive |
| 270 // notification after the sync exited, it will be sinced next time Chrome | 271 // notification after the sync exited, it will be sinced next time Chrome |
| 271 // starts. | 272 // starts. |
| 272 if (!sync_processor_.get()) | 273 if (!sync_processor_.get()) |
| 273 return; | 274 return; |
| 274 | 275 |
| 275 AutofillProfileChange* change = | 276 AutofillProfileChange* change = |
| 276 content::Details<AutofillProfileChange>(details).ptr(); | 277 content::Details<AutofillProfileChange>(details).ptr(); |
| 277 ActOnChange(*change); | 278 ActOnChange(*change); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 569 } |
| 569 | 570 |
| 570 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { | 571 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { |
| 571 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); | 572 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); |
| 572 } | 573 } |
| 573 | 574 |
| 574 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 575 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
| 575 | 576 |
| 576 AutofillProfileSyncableService::DataBundle::~DataBundle() { | 577 AutofillProfileSyncableService::DataBundle::~DataBundle() { |
| 577 } | 578 } |
| OLD | NEW |