| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_syncable_service.h" | 5 #include "chrome/browser/sync/glue/autofill_profile_syncable_service.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/autofill_profile.h" |
| 11 #include "chrome/browser/autofill/form_group.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sync/api/sync_error.h" | 13 #include "chrome/browser/sync/api/sync_error.h" |
| 12 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | |
| 13 #include "chrome/browser/webdata/autofill_table.h" | 14 #include "chrome/browser/webdata/autofill_table.h" |
| 14 #include "chrome/browser/webdata/web_database.h" | 15 #include "chrome/browser/webdata/web_database.h" |
| 16 #include "chrome/browser/webdata/web_data_service.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/guid.h" | 18 #include "chrome/common/guid.h" |
| 19 #include "content/browser/browser_thread.h" |
| 17 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 // Helper to compare the local value and cloud value of a field, merge into | 24 // Helper to compare the local value and cloud value of a field, merge into |
| 22 // the local value if they differ, and return whether the merge happened. | 25 // the local value if they differ, and return whether the merge happened. |
| 23 bool MergeField(FormGroup* form_group, | 26 bool MergeField(FormGroup* form_group, |
| 24 AutofillFieldType field_type, | 27 AutofillFieldType field_type, |
| 25 const std::string& specifics_field) { | 28 const std::string& specifics_field) { |
| 26 if (UTF16ToUTF8(form_group->GetInfo(field_type)) == specifics_field) | 29 if (UTF16ToUTF8(form_group->GetInfo(field_type)) == specifics_field) |
| 27 return false; | 30 return false; |
| 28 form_group->SetInfo(field_type, UTF8ToUTF16(specifics_field)); | 31 form_group->SetInfo(field_type, UTF8ToUTF16(specifics_field)); |
| 29 return true; | 32 return true; |
| 30 } | 33 } |
| 31 | 34 |
| 32 } // namespace | 35 } // namespace |
| 33 | 36 |
| 34 namespace browser_sync { | 37 namespace browser_sync { |
| 35 | 38 |
| 36 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; | 39 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; |
| 37 | 40 |
| 38 AutofillProfileSyncableService::AutofillProfileSyncableService( | 41 AutofillProfileSyncableService::AutofillProfileSyncableService( |
| 39 WebDatabase* web_database, | 42 WebDatabase* web_database, |
| 40 PersonalDataManager* personal_data, | |
| 41 Profile* profile) | 43 Profile* profile) |
| 42 : web_database_(web_database), | 44 : web_database_(web_database), |
| 43 personal_data_(personal_data), | 45 profile_(profile), |
| 44 sync_processor_(NULL) { | 46 sync_processor_(NULL) { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 46 DCHECK(web_database_); | 48 DCHECK(web_database_); |
| 47 DCHECK(personal_data_); | |
| 48 DCHECK(profile); | 49 DCHECK(profile); |
| 49 notification_registrar_.Add(this, | 50 notification_registrar_.Add(this, |
| 50 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 51 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 51 Source<WebDataService>( | 52 Source<WebDataService>( |
| 52 profile->GetWebDataService(Profile::EXPLICIT_ACCESS))); | 53 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS))); |
| 53 } | 54 } |
| 54 | 55 |
| 55 AutofillProfileSyncableService::~AutofillProfileSyncableService() { | 56 AutofillProfileSyncableService::~AutofillProfileSyncableService() { |
| 56 DCHECK(CalledOnValidThread()); | 57 DCHECK(CalledOnValidThread()); |
| 57 } | 58 } |
| 58 | 59 |
| 59 AutofillProfileSyncableService::AutofillProfileSyncableService() | 60 AutofillProfileSyncableService::AutofillProfileSyncableService() |
| 60 : web_database_(NULL), | 61 : web_database_(NULL), |
| 61 personal_data_(NULL), | 62 profile_(NULL), |
| 62 sync_processor_(NULL) { | 63 sync_processor_(NULL) { |
| 63 } | 64 } |
| 64 | 65 |
| 65 SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( | 66 SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( |
| 66 syncable::ModelType type, | 67 syncable::ModelType type, |
| 67 const SyncDataList& initial_sync_data, | 68 const SyncDataList& initial_sync_data, |
| 68 SyncChangeProcessor* sync_processor) { | 69 SyncChangeProcessor* sync_processor) { |
| 69 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
| 70 DCHECK(sync_processor_ == NULL); | 71 DCHECK(sync_processor_ == NULL); |
| 71 VLOG(1) << "Associating Autofill: MergeDataAndStartSyncing"; | 72 VLOG(1) << "Associating Autofill: MergeDataAndStartSyncing"; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 SyncChangeList new_changes; | 113 SyncChangeList new_changes; |
| 113 for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); | 114 for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); |
| 114 i != remaining_profiles.end(); ++i) { | 115 i != remaining_profiles.end(); ++i) { |
| 115 new_changes.push_back( | 116 new_changes.push_back( |
| 116 SyncChange(SyncChange::ACTION_ADD, CreateData(*(i->second)))); | 117 SyncChange(SyncChange::ACTION_ADD, CreateData(*(i->second)))); |
| 117 profiles_map_[i->first] = i->second; | 118 profiles_map_[i->first] = i->second; |
| 118 } | 119 } |
| 119 | 120 |
| 120 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 121 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
| 121 | 122 |
| 122 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 123 WebDataService::NotifyOfMultipleAutofillChanges(profile_); |
| 123 new DoOptimisticRefreshForAutofill(personal_data_)); | |
| 124 | 124 |
| 125 return error; | 125 return error; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) { | 128 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) { |
| 129 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
| 130 DCHECK(sync_processor_ != NULL); | 130 DCHECK(sync_processor_ != NULL); |
| 131 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); | 131 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); |
| 132 | 132 |
| 133 sync_processor_ = NULL; | 133 sync_processor_ = NULL; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 NOTREACHED() << "Unexpected sync change state."; | 181 NOTREACHED() << "Unexpected sync change state."; |
| 182 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + | 182 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + |
| 183 SyncChange::ChangeTypeToString(i->change_type()), | 183 SyncChange::ChangeTypeToString(i->change_type()), |
| 184 syncable::AUTOFILL_PROFILE); | 184 syncable::AUTOFILL_PROFILE); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 if (!SaveChangesToWebData(bundle)) | 188 if (!SaveChangesToWebData(bundle)) |
| 189 return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); | 189 return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); |
| 190 | 190 |
| 191 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 191 WebDataService::NotifyOfMultipleAutofillChanges(profile_); |
| 192 new DoOptimisticRefreshForAutofill(personal_data_)); | 192 |
| 193 return SyncError(); | 193 return SyncError(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void AutofillProfileSyncableService::Observe(int type, | 196 void AutofillProfileSyncableService::Observe(int type, |
| 197 const NotificationSource& source, | 197 const NotificationSource& source, |
| 198 const NotificationDetails& details) { | 198 const NotificationDetails& details) { |
| 199 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); | 199 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); |
| 200 // Check if sync is on. If we receive notification prior to the sync being set | 200 // Check if sync is on. If we receive notification prior to the sync being set |
| 201 // up we are going to process all when MergeData..() is called. If we receive | 201 // up we are going to process all when MergeData..() is called. If we receive |
| 202 // notification after the sync exited, it will be sinced next time Chrome | 202 // notification after the sync exited, it will be sinced next time Chrome |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 WriteAutofillProfile(profile, &specifics); | 407 WriteAutofillProfile(profile, &specifics); |
| 408 return SyncData::CreateLocalData(profile.guid(), profile.guid(), specifics); | 408 return SyncData::CreateLocalData(profile.guid(), profile.guid(), specifics); |
| 409 } | 409 } |
| 410 | 410 |
| 411 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 411 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
| 412 | 412 |
| 413 AutofillProfileSyncableService::DataBundle::~DataBundle() { | 413 AutofillProfileSyncableService::DataBundle::~DataBundle() { |
| 414 } | 414 } |
| 415 | 415 |
| 416 } // namespace browser_sync | 416 } // namespace browser_sync |
| OLD | NEW |