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/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" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
11 #include "chrome/browser/autofill/form_group.h" | 11 #include "chrome/browser/autofill/form_group.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/sync/api/sync_error.h" | 13 #include "chrome/browser/sync/api/sync_error.h" |
| 14 #include "chrome/browser/sync/protocol/sync.pb.h" |
14 #include "chrome/browser/webdata/autofill_table.h" | 15 #include "chrome/browser/webdata/autofill_table.h" |
15 #include "chrome/browser/webdata/web_data_service.h" | 16 #include "chrome/browser/webdata/web_data_service.h" |
16 #include "chrome/browser/webdata/web_database.h" | 17 #include "chrome/browser/webdata/web_database.h" |
17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/guid.h" | 19 #include "chrome/common/guid.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
22 | 23 |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 for (SyncChangeList::const_iterator i = change_list.begin(); | 190 for (SyncChangeList::const_iterator i = change_list.begin(); |
190 i != change_list.end(); ++i) { | 191 i != change_list.end(); ++i) { |
191 DCHECK(i->IsValid()); | 192 DCHECK(i->IsValid()); |
192 switch (i->change_type()) { | 193 switch (i->change_type()) { |
193 case SyncChange::ACTION_ADD: | 194 case SyncChange::ACTION_ADD: |
194 case SyncChange::ACTION_UPDATE: | 195 case SyncChange::ACTION_UPDATE: |
195 CreateOrUpdateProfile(i->sync_data(), &profiles_map_, &bundle); | 196 CreateOrUpdateProfile(i->sync_data(), &profiles_map_, &bundle); |
196 break; | 197 break; |
197 case SyncChange::ACTION_DELETE: { | 198 case SyncChange::ACTION_DELETE: { |
198 std::string guid = i->sync_data().GetSpecifics(). | 199 std::string guid = i->sync_data().GetSpecifics(). |
199 GetExtension(sync_pb::autofill_profile).guid(); | 200 autofill_profile().guid(); |
200 bundle.profiles_to_delete.push_back(guid); | 201 bundle.profiles_to_delete.push_back(guid); |
201 profiles_map_.erase(guid); | 202 profiles_map_.erase(guid); |
202 } break; | 203 } break; |
203 default: | 204 default: |
204 NOTREACHED() << "Unexpected sync change state."; | 205 NOTREACHED() << "Unexpected sync change state."; |
205 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + | 206 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + |
206 SyncChange::ChangeTypeToString(i->change_type()), | 207 SyncChange::ChangeTypeToString(i->change_type()), |
207 syncable::AUTOFILL_PROFILE); | 208 syncable::AUTOFILL_PROFILE); |
208 } | 209 } |
209 } | 210 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 specifics.phone_home_whole_number(), | 294 specifics.phone_home_whole_number(), |
294 profile) || diff; | 295 profile) || diff; |
295 return diff; | 296 return diff; |
296 } | 297 } |
297 | 298 |
298 // static | 299 // static |
299 void AutofillProfileSyncableService::WriteAutofillProfile( | 300 void AutofillProfileSyncableService::WriteAutofillProfile( |
300 const AutofillProfile& profile, | 301 const AutofillProfile& profile, |
301 sync_pb::EntitySpecifics* profile_specifics) { | 302 sync_pb::EntitySpecifics* profile_specifics) { |
302 sync_pb::AutofillProfileSpecifics* specifics = | 303 sync_pb::AutofillProfileSpecifics* specifics = |
303 profile_specifics->MutableExtension(sync_pb::autofill_profile); | 304 profile_specifics->mutable_autofill_profile(); |
304 | 305 |
305 DCHECK(guid::IsValidGUID(profile.guid())); | 306 DCHECK(guid::IsValidGUID(profile.guid())); |
306 | 307 |
307 // Reset all multi-valued fields in the protobuf. | 308 // Reset all multi-valued fields in the protobuf. |
308 specifics->clear_name_first(); | 309 specifics->clear_name_first(); |
309 specifics->clear_name_middle(); | 310 specifics->clear_name_middle(); |
310 specifics->clear_name_last(); | 311 specifics->clear_name_last(); |
311 specifics->clear_email_address(); | 312 specifics->clear_email_address(); |
312 specifics->clear_phone_home_whole_number(); | 313 specifics->clear_phone_home_whole_number(); |
313 | 314 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 AutofillProfileSyncableService::GUIDToProfileMap::iterator | 357 AutofillProfileSyncableService::GUIDToProfileMap::iterator |
357 AutofillProfileSyncableService::CreateOrUpdateProfile( | 358 AutofillProfileSyncableService::CreateOrUpdateProfile( |
358 const SyncData& data, GUIDToProfileMap* profile_map, DataBundle* bundle) { | 359 const SyncData& data, GUIDToProfileMap* profile_map, DataBundle* bundle) { |
359 DCHECK(profile_map); | 360 DCHECK(profile_map); |
360 DCHECK(bundle); | 361 DCHECK(bundle); |
361 | 362 |
362 DCHECK_EQ(syncable::AUTOFILL_PROFILE, data.GetDataType()); | 363 DCHECK_EQ(syncable::AUTOFILL_PROFILE, data.GetDataType()); |
363 | 364 |
364 const sync_pb::EntitySpecifics& specifics = data.GetSpecifics(); | 365 const sync_pb::EntitySpecifics& specifics = data.GetSpecifics(); |
365 const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 366 const sync_pb::AutofillProfileSpecifics& autofill_specifics( |
366 specifics.GetExtension(sync_pb::autofill_profile)); | 367 specifics.autofill_profile()); |
367 | 368 |
368 GUIDToProfileMap::iterator it = profile_map->find( | 369 GUIDToProfileMap::iterator it = profile_map->find( |
369 autofill_specifics.guid()); | 370 autofill_specifics.guid()); |
370 if (it != profile_map->end()) { | 371 if (it != profile_map->end()) { |
371 // Some profile that already present is synced. | 372 // Some profile that already present is synced. |
372 if (OverwriteProfileWithServerData(autofill_specifics, it->second)) | 373 if (OverwriteProfileWithServerData(autofill_specifics, it->second)) |
373 bundle->profiles_to_update.push_back(it->second); | 374 bundle->profiles_to_update.push_back(it->second); |
374 } else { | 375 } else { |
375 // New profile synced. | 376 // New profile synced. |
376 AutofillProfile* new_profile( | 377 AutofillProfile* new_profile( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 } | 503 } |
503 | 504 |
504 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { | 505 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { |
505 return web_data_service_->GetDatabase()->GetAutofillTable(); | 506 return web_data_service_->GetDatabase()->GetAutofillTable(); |
506 } | 507 } |
507 | 508 |
508 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 509 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
509 | 510 |
510 AutofillProfileSyncableService::DataBundle::~DataBundle() { | 511 AutofillProfileSyncableService::DataBundle::~DataBundle() { |
511 } | 512 } |
OLD | NEW |