Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Side by Side Diff: chrome/browser/webdata/autofill_profile_syncable_service.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 51 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
52 DCHECK(CalledOnValidThread()); 52 DCHECK(CalledOnValidThread());
53 } 53 }
54 54
55 AutofillProfileSyncableService::AutofillProfileSyncableService() 55 AutofillProfileSyncableService::AutofillProfileSyncableService()
56 : web_data_service_(NULL) { 56 : web_data_service_(NULL) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
58 } 58 }
59 59
60 csync::SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( 60 syncer::SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing(
61 syncable::ModelType type, 61 syncable::ModelType type,
62 const csync::SyncDataList& initial_sync_data, 62 const syncer::SyncDataList& initial_sync_data,
63 scoped_ptr<csync::SyncChangeProcessor> sync_processor, 63 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
64 scoped_ptr<csync::SyncErrorFactory> sync_error_factory) { 64 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
65 DCHECK(CalledOnValidThread()); 65 DCHECK(CalledOnValidThread());
66 DCHECK(!sync_processor_.get()); 66 DCHECK(!sync_processor_.get());
67 DCHECK(sync_processor.get()); 67 DCHECK(sync_processor.get());
68 DCHECK(sync_error_factory.get()); 68 DCHECK(sync_error_factory.get());
69 DVLOG(1) << "Associating Autofill: MergeDataAndStartSyncing"; 69 DVLOG(1) << "Associating Autofill: MergeDataAndStartSyncing";
70 70
71 sync_error_factory_ = sync_error_factory.Pass(); 71 sync_error_factory_ = sync_error_factory.Pass();
72 if (!LoadAutofillData(&profiles_.get())) { 72 if (!LoadAutofillData(&profiles_.get())) {
73 return sync_error_factory_->CreateAndUploadError( 73 return sync_error_factory_->CreateAndUploadError(
74 FROM_HERE, "Could not get the autofill data from WebDatabase."); 74 FROM_HERE, "Could not get the autofill data from WebDatabase.");
(...skipping 13 matching lines...) Expand all
88 } 88 }
89 } 89 }
90 90
91 sync_processor_ = sync_processor.Pass(); 91 sync_processor_ = sync_processor.Pass();
92 92
93 GUIDToProfileMap remaining_profiles; 93 GUIDToProfileMap remaining_profiles;
94 CreateGUIDToProfileMap(profiles_.get(), &remaining_profiles); 94 CreateGUIDToProfileMap(profiles_.get(), &remaining_profiles);
95 95
96 DataBundle bundle; 96 DataBundle bundle;
97 // Go through and check for all the profiles that sync already knows about. 97 // Go through and check for all the profiles that sync already knows about.
98 for (csync::SyncDataList::const_iterator sync_iter = 98 for (syncer::SyncDataList::const_iterator sync_iter =
99 initial_sync_data.begin(); 99 initial_sync_data.begin();
100 sync_iter != initial_sync_data.end(); 100 sync_iter != initial_sync_data.end();
101 ++sync_iter) { 101 ++sync_iter) {
102 GUIDToProfileMap::iterator it = 102 GUIDToProfileMap::iterator it =
103 CreateOrUpdateProfile(*sync_iter, &remaining_profiles, &bundle); 103 CreateOrUpdateProfile(*sync_iter, &remaining_profiles, &bundle);
104 // |it| points to created/updated profile. Add it to the |profiles_map_| and 104 // |it| points to created/updated profile. Add it to the |profiles_map_| and
105 // then remove it from |remaining_profiles|. After this loop is completed 105 // then remove it from |remaining_profiles|. After this loop is completed
106 // |remaining_profiles| will have only those profiles that are not in the 106 // |remaining_profiles| will have only those profiles that are not in the
107 // sync. 107 // sync.
108 profiles_map_[it->first] = it->second; 108 profiles_map_[it->first] = it->second;
(...skipping 20 matching lines...) Expand all
129 remaining_profiles.erase(profile_to_merge); 129 remaining_profiles.erase(profile_to_merge);
130 } 130 }
131 } 131 }
132 132
133 if (!SaveChangesToWebData(bundle)) { 133 if (!SaveChangesToWebData(bundle)) {
134 return sync_error_factory_->CreateAndUploadError( 134 return sync_error_factory_->CreateAndUploadError(
135 FROM_HERE, 135 FROM_HERE,
136 "Failed to update webdata."); 136 "Failed to update webdata.");
137 } 137 }
138 138
139 csync::SyncChangeList new_changes; 139 syncer::SyncChangeList new_changes;
140 for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); 140 for (GUIDToProfileMap::iterator i = remaining_profiles.begin();
141 i != remaining_profiles.end(); ++i) { 141 i != remaining_profiles.end(); ++i) {
142 new_changes.push_back( 142 new_changes.push_back(
143 csync::SyncChange( 143 syncer::SyncChange(
144 csync::SyncChange::ACTION_ADD, CreateData(*(i->second)))); 144 syncer::SyncChange::ACTION_ADD, CreateData(*(i->second))));
145 profiles_map_[i->first] = i->second; 145 profiles_map_[i->first] = i->second;
146 } 146 }
147 147
148 for (size_t i = 0; i < bundle.profiles_to_sync_back.size(); ++i) { 148 for (size_t i = 0; i < bundle.profiles_to_sync_back.size(); ++i) {
149 new_changes.push_back( 149 new_changes.push_back(
150 csync::SyncChange(csync::SyncChange::ACTION_UPDATE, 150 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE,
151 CreateData(*(bundle.profiles_to_sync_back[i])))); 151 CreateData(*(bundle.profiles_to_sync_back[i]))));
152 } 152 }
153 153
154 csync::SyncError error; 154 syncer::SyncError error;
155 if (!new_changes.empty()) 155 if (!new_changes.empty())
156 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 156 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
157 157
158 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 158 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
159 159
160 return error; 160 return error;
161 } 161 }
162 162
163 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) { 163 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) {
164 DCHECK(CalledOnValidThread()); 164 DCHECK(CalledOnValidThread());
165 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); 165 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE);
166 166
167 sync_processor_.reset(); 167 sync_processor_.reset();
168 sync_error_factory_.reset(); 168 sync_error_factory_.reset();
169 profiles_.reset(); 169 profiles_.reset();
170 profiles_map_.clear(); 170 profiles_map_.clear();
171 } 171 }
172 172
173 csync::SyncDataList AutofillProfileSyncableService::GetAllSyncData( 173 syncer::SyncDataList AutofillProfileSyncableService::GetAllSyncData(
174 syncable::ModelType type) const { 174 syncable::ModelType type) const {
175 DCHECK(CalledOnValidThread()); 175 DCHECK(CalledOnValidThread());
176 DCHECK(sync_processor_.get()); 176 DCHECK(sync_processor_.get());
177 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); 177 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE);
178 178
179 csync::SyncDataList current_data; 179 syncer::SyncDataList current_data;
180 180
181 for (GUIDToProfileMap::const_iterator i = profiles_map_.begin(); 181 for (GUIDToProfileMap::const_iterator i = profiles_map_.begin();
182 i != profiles_map_.end(); ++i) { 182 i != profiles_map_.end(); ++i) {
183 current_data.push_back(CreateData(*(i->second))); 183 current_data.push_back(CreateData(*(i->second)));
184 } 184 }
185 return current_data; 185 return current_data;
186 } 186 }
187 187
188 csync::SyncError AutofillProfileSyncableService::ProcessSyncChanges( 188 syncer::SyncError AutofillProfileSyncableService::ProcessSyncChanges(
189 const tracked_objects::Location& from_here, 189 const tracked_objects::Location& from_here,
190 const csync::SyncChangeList& change_list) { 190 const syncer::SyncChangeList& change_list) {
191 DCHECK(CalledOnValidThread()); 191 DCHECK(CalledOnValidThread());
192 if (!sync_processor_.get()) { 192 if (!sync_processor_.get()) {
193 csync::SyncError error(FROM_HERE, "Models not yet associated.", 193 syncer::SyncError error(FROM_HERE, "Models not yet associated.",
194 syncable::AUTOFILL_PROFILE); 194 syncable::AUTOFILL_PROFILE);
195 return error; 195 return error;
196 } 196 }
197 197
198 DataBundle bundle; 198 DataBundle bundle;
199 199
200 for (csync::SyncChangeList::const_iterator i = change_list.begin(); 200 for (syncer::SyncChangeList::const_iterator i = change_list.begin();
201 i != change_list.end(); ++i) { 201 i != change_list.end(); ++i) {
202 DCHECK(i->IsValid()); 202 DCHECK(i->IsValid());
203 switch (i->change_type()) { 203 switch (i->change_type()) {
204 case csync::SyncChange::ACTION_ADD: 204 case syncer::SyncChange::ACTION_ADD:
205 case csync::SyncChange::ACTION_UPDATE: 205 case syncer::SyncChange::ACTION_UPDATE:
206 CreateOrUpdateProfile(i->sync_data(), &profiles_map_, &bundle); 206 CreateOrUpdateProfile(i->sync_data(), &profiles_map_, &bundle);
207 break; 207 break;
208 case csync::SyncChange::ACTION_DELETE: { 208 case syncer::SyncChange::ACTION_DELETE: {
209 std::string guid = i->sync_data().GetSpecifics(). 209 std::string guid = i->sync_data().GetSpecifics().
210 autofill_profile().guid(); 210 autofill_profile().guid();
211 bundle.profiles_to_delete.push_back(guid); 211 bundle.profiles_to_delete.push_back(guid);
212 profiles_map_.erase(guid); 212 profiles_map_.erase(guid);
213 } break; 213 } break;
214 default: 214 default:
215 NOTREACHED() << "Unexpected sync change state."; 215 NOTREACHED() << "Unexpected sync change state.";
216 return sync_error_factory_->CreateAndUploadError( 216 return sync_error_factory_->CreateAndUploadError(
217 FROM_HERE, 217 FROM_HERE,
218 "ProcessSyncChanges failed on ChangeType " + 218 "ProcessSyncChanges failed on ChangeType " +
219 csync::SyncChange::ChangeTypeToString(i->change_type())); 219 syncer::SyncChange::ChangeTypeToString(i->change_type()));
220 } 220 }
221 } 221 }
222 222
223 if (!SaveChangesToWebData(bundle)) { 223 if (!SaveChangesToWebData(bundle)) {
224 return sync_error_factory_->CreateAndUploadError( 224 return sync_error_factory_->CreateAndUploadError(
225 FROM_HERE, 225 FROM_HERE,
226 "Failed to update webdata."); 226 "Failed to update webdata.");
227 } 227 }
228 228
229 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 229 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
230 230
231 return csync::SyncError(); 231 return syncer::SyncError();
232 } 232 }
233 233
234 void AutofillProfileSyncableService::Observe(int type, 234 void AutofillProfileSyncableService::Observe(int type,
235 const content::NotificationSource& source, 235 const content::NotificationSource& source,
236 const content::NotificationDetails& details) { 236 const content::NotificationDetails& details) {
237 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); 237 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED);
238 DCHECK_EQ(web_data_service_, content::Source<WebDataService>(source).ptr()); 238 DCHECK_EQ(web_data_service_, content::Source<WebDataService>(source).ptr());
239 // Check if sync is on. If we receive notification prior to the sync being set 239 // Check if sync is on. If we receive notification prior to the sync being set
240 // up we are going to process all when MergeData..() is called. If we receive 240 // up we are going to process all when MergeData..() is called. If we receive
241 // notification after the sync exited, it will be sinced next time Chrome 241 // notification after the sync exited, it will be sinced next time Chrome
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 const std::vector<AutofillProfile*>& profiles, 363 const std::vector<AutofillProfile*>& profiles,
364 GUIDToProfileMap* profile_map) { 364 GUIDToProfileMap* profile_map) {
365 DCHECK(profile_map); 365 DCHECK(profile_map);
366 profile_map->clear(); 366 profile_map->clear();
367 for (size_t i = 0; i < profiles.size(); ++i) 367 for (size_t i = 0; i < profiles.size(); ++i)
368 (*profile_map)[profiles[i]->guid()] = profiles[i]; 368 (*profile_map)[profiles[i]->guid()] = profiles[i];
369 } 369 }
370 370
371 AutofillProfileSyncableService::GUIDToProfileMap::iterator 371 AutofillProfileSyncableService::GUIDToProfileMap::iterator
372 AutofillProfileSyncableService::CreateOrUpdateProfile( 372 AutofillProfileSyncableService::CreateOrUpdateProfile(
373 const csync::SyncData& data, 373 const syncer::SyncData& data,
374 GUIDToProfileMap* profile_map, 374 GUIDToProfileMap* profile_map,
375 DataBundle* bundle) { 375 DataBundle* bundle) {
376 DCHECK(profile_map); 376 DCHECK(profile_map);
377 DCHECK(bundle); 377 DCHECK(bundle);
378 378
379 DCHECK_EQ(syncable::AUTOFILL_PROFILE, data.GetDataType()); 379 DCHECK_EQ(syncable::AUTOFILL_PROFILE, data.GetDataType());
380 380
381 const sync_pb::EntitySpecifics& specifics = data.GetSpecifics(); 381 const sync_pb::EntitySpecifics& specifics = data.GetSpecifics();
382 const sync_pb::AutofillProfileSpecifics& autofill_specifics( 382 const sync_pb::AutofillProfileSpecifics& autofill_specifics(
383 specifics.autofill_profile()); 383 specifics.autofill_profile());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 return it; 423 return it;
424 } 424 }
425 425
426 void AutofillProfileSyncableService::ActOnChange( 426 void AutofillProfileSyncableService::ActOnChange(
427 const AutofillProfileChange& change) { 427 const AutofillProfileChange& change) {
428 DCHECK((change.type() == AutofillProfileChange::REMOVE && 428 DCHECK((change.type() == AutofillProfileChange::REMOVE &&
429 !change.profile()) || 429 !change.profile()) ||
430 (change.type() != AutofillProfileChange::REMOVE && change.profile())); 430 (change.type() != AutofillProfileChange::REMOVE && change.profile()));
431 DCHECK(sync_processor_.get()); 431 DCHECK(sync_processor_.get());
432 csync::SyncChangeList new_changes; 432 syncer::SyncChangeList new_changes;
433 DataBundle bundle; 433 DataBundle bundle;
434 switch (change.type()) { 434 switch (change.type()) {
435 case AutofillProfileChange::ADD: 435 case AutofillProfileChange::ADD:
436 new_changes.push_back( 436 new_changes.push_back(
437 csync::SyncChange( 437 syncer::SyncChange(
438 csync::SyncChange::ACTION_ADD, CreateData(*(change.profile())))); 438 syncer::SyncChange::ACTION_ADD, CreateData(*(change.profile()))));
439 DCHECK(profiles_map_.find(change.profile()->guid()) == 439 DCHECK(profiles_map_.find(change.profile()->guid()) ==
440 profiles_map_.end()); 440 profiles_map_.end());
441 profiles_.push_back(new AutofillProfile(*(change.profile()))); 441 profiles_.push_back(new AutofillProfile(*(change.profile())));
442 profiles_map_[change.profile()->guid()] = profiles_.get().back(); 442 profiles_map_[change.profile()->guid()] = profiles_.get().back();
443 break; 443 break;
444 case AutofillProfileChange::UPDATE: { 444 case AutofillProfileChange::UPDATE: {
445 GUIDToProfileMap::iterator it = profiles_map_.find( 445 GUIDToProfileMap::iterator it = profiles_map_.find(
446 change.profile()->guid()); 446 change.profile()->guid());
447 DCHECK(it != profiles_map_.end()); 447 DCHECK(it != profiles_map_.end());
448 *(it->second) = *(change.profile()); 448 *(it->second) = *(change.profile());
449 new_changes.push_back( 449 new_changes.push_back(
450 csync::SyncChange(csync::SyncChange::ACTION_UPDATE, 450 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE,
451 CreateData(*(change.profile())))); 451 CreateData(*(change.profile()))));
452 break; 452 break;
453 } 453 }
454 case AutofillProfileChange::REMOVE: { 454 case AutofillProfileChange::REMOVE: {
455 AutofillProfile empty_profile(change.key()); 455 AutofillProfile empty_profile(change.key());
456 new_changes.push_back(csync::SyncChange(csync::SyncChange::ACTION_DELETE, 456 new_changes.push_back(
457 CreateData(empty_profile))); 457 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE,
458 CreateData(empty_profile)));
458 profiles_map_.erase(change.key()); 459 profiles_map_.erase(change.key());
459 break; 460 break;
460 } 461 }
461 default: 462 default:
462 NOTREACHED(); 463 NOTREACHED();
463 } 464 }
464 csync::SyncError error = 465 syncer::SyncError error =
465 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 466 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
466 if (error.IsSet()) { 467 if (error.IsSet()) {
467 // TODO(isherman): Investigating http://crbug.com/121592 468 // TODO(isherman): Investigating http://crbug.com/121592
468 VLOG(1) << "[AUTOFILL SYNC] " 469 VLOG(1) << "[AUTOFILL SYNC] "
469 << "Failed processing change:\n" 470 << "Failed processing change:\n"
470 << " Error: " << error.message() << "\n" 471 << " Error: " << error.message() << "\n"
471 << " Guid: " << change.key(); 472 << " Guid: " << change.key();
472 } 473 }
473 } 474 }
474 475
475 csync::SyncData AutofillProfileSyncableService::CreateData( 476 syncer::SyncData AutofillProfileSyncableService::CreateData(
476 const AutofillProfile& profile) { 477 const AutofillProfile& profile) {
477 sync_pb::EntitySpecifics specifics; 478 sync_pb::EntitySpecifics specifics;
478 WriteAutofillProfile(profile, &specifics); 479 WriteAutofillProfile(profile, &specifics);
479 return 480 return
480 csync::SyncData::CreateLocalData( 481 syncer::SyncData::CreateLocalData(
481 profile.guid(), profile.guid(), specifics); 482 profile.guid(), profile.guid(), specifics);
482 } 483 }
483 484
484 bool AutofillProfileSyncableService::UpdateField( 485 bool AutofillProfileSyncableService::UpdateField(
485 AutofillFieldType field_type, 486 AutofillFieldType field_type,
486 const std::string& new_value, 487 const std::string& new_value,
487 AutofillProfile* autofill_profile) { 488 AutofillProfile* autofill_profile) {
488 if (UTF16ToUTF8(autofill_profile->GetInfo(field_type)) == new_value) 489 if (UTF16ToUTF8(autofill_profile->GetInfo(field_type)) == new_value)
489 return false; 490 return false;
490 autofill_profile->SetInfo(field_type, UTF8ToUTF16(new_value)); 491 autofill_profile->SetInfo(field_type, UTF8ToUTF16(new_value));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 525 }
525 526
526 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { 527 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {
527 return web_data_service_->GetDatabase()->GetAutofillTable(); 528 return web_data_service_->GetDatabase()->GetAutofillTable();
528 } 529 }
529 530
530 AutofillProfileSyncableService::DataBundle::DataBundle() {} 531 AutofillProfileSyncableService::DataBundle::DataBundle() {}
531 532
532 AutofillProfileSyncableService::DataBundle::~DataBundle() { 533 AutofillProfileSyncableService::DataBundle::~DataBundle() {
533 } 534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698