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