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_change_processor.h" | 5 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/tracked.h" | 11 #include "base/tracked.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/autofill_profile.h" | 13 #include "chrome/browser/autofill/autofill_profile.h" |
14 #include "chrome/browser/autofill/personal_data_manager.h" | 14 #include "chrome/browser/autofill/personal_data_manager.h" |
15 #include "chrome/browser/sync/engine/syncapi.h" | 15 #include "chrome/browser/sync/engine/syncapi.h" |
16 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | 16 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" |
17 #include "chrome/browser/sync/glue/change_processor.h" | 17 #include "chrome/browser/sync/glue/change_processor.h" |
18 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | 18 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" |
19 #include "chrome/browser/sync/unrecoverable_error_handler.h" | 19 #include "chrome/browser/sync/unrecoverable_error_handler.h" |
20 #include "chrome/browser/webdata/autofill_change.h" | 20 #include "chrome/browser/webdata/autofill_change.h" |
21 #include "chrome/browser/webdata/web_database.h" | 21 #include "chrome/browser/webdata/web_database.h" |
| 22 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/guid.h" | 23 #include "chrome/common/guid.h" |
23 #include "content/common/notification_registrar.h" | 24 #include "content/common/notification_registrar.h" |
24 #include "content/common/notification_service.h" | 25 #include "content/common/notification_service.h" |
25 #include "content/common/notification_type.h" | |
26 | 26 |
27 namespace browser_sync { | 27 namespace browser_sync { |
28 | 28 |
29 AutofillProfileChangeProcessor::AutofillProfileChangeProcessor( | 29 AutofillProfileChangeProcessor::AutofillProfileChangeProcessor( |
30 AutofillProfileModelAssociator *model_associator, | 30 AutofillProfileModelAssociator *model_associator, |
31 WebDatabase* web_database, | 31 WebDatabase* web_database, |
32 PersonalDataManager* personal_data_manager, | 32 PersonalDataManager* personal_data_manager, |
33 UnrecoverableErrorHandler* error_handler) | 33 UnrecoverableErrorHandler* error_handler) |
34 : ChangeProcessor(error_handler), | 34 : ChangeProcessor(error_handler), |
35 model_associator_(model_associator), | 35 model_associator_(model_associator), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 const sync_pb::AutofillProfileSpecifics& autofill( | 86 const sync_pb::AutofillProfileSpecifics& autofill( |
87 sync_node.GetAutofillProfileSpecifics()); | 87 sync_node.GetAutofillProfileSpecifics()); |
88 | 88 |
89 autofill_changes_.push_back(AutofillProfileChangeRecord(changes[i].action, | 89 autofill_changes_.push_back(AutofillProfileChangeRecord(changes[i].action, |
90 changes[i].id, | 90 changes[i].id, |
91 autofill)); | 91 autofill)); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 void AutofillProfileChangeProcessor::Observe(NotificationType type, | 95 void AutofillProfileChangeProcessor::Observe(int type, |
96 const NotificationSource& source, | 96 const NotificationSource& source, |
97 const NotificationDetails& details) { | 97 const NotificationDetails& details) { |
98 DCHECK_EQ(type.value, NotificationType::AUTOFILL_PROFILE_CHANGED); | 98 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); |
99 WebDataService* wds = Source<WebDataService>(source).ptr(); | 99 WebDataService* wds = Source<WebDataService>(source).ptr(); |
100 | 100 |
101 if (!wds || wds->GetDatabase() != web_database_) | 101 if (!wds || wds->GetDatabase() != web_database_) |
102 return; | 102 return; |
103 | 103 |
104 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); | 104 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); |
105 sync_api::ReadNode autofill_root(&trans); | 105 sync_api::ReadNode autofill_root(&trans); |
106 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { | 106 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { |
107 error_handler()->OnUnrecoverableError(FROM_HERE, | 107 error_handler()->OnUnrecoverableError(FROM_HERE, |
108 "Server did not create a tolp level node"); | 108 "Server did not create a tolp level node"); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 node.SetTitle(UTF8ToWide(profile.guid())); | 291 node.SetTitle(UTF8ToWide(profile.guid())); |
292 | 292 |
293 WriteAutofillProfile(profile, &node); | 293 WriteAutofillProfile(profile, &node); |
294 | 294 |
295 model_associator_->Associate(&guid, node.GetId()); | 295 model_associator_->Associate(&guid, node.GetId()); |
296 } | 296 } |
297 | 297 |
298 void AutofillProfileChangeProcessor::StartObserving() { | 298 void AutofillProfileChangeProcessor::StartObserving() { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
300 notification_registrar_.Add(this, | 300 notification_registrar_.Add(this, |
301 NotificationType::AUTOFILL_PROFILE_CHANGED, | 301 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
302 NotificationService::AllSources()); | 302 NotificationService::AllSources()); |
303 } | 303 } |
304 | 304 |
305 void AutofillProfileChangeProcessor::StopObserving() { | 305 void AutofillProfileChangeProcessor::StopObserving() { |
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
307 notification_registrar_.RemoveAll(); | 307 notification_registrar_.RemoveAll(); |
308 } | 308 } |
309 | 309 |
310 void AutofillProfileChangeProcessor::WriteAutofillProfile( | 310 void AutofillProfileChangeProcessor::WriteAutofillProfile( |
311 const AutofillProfile& profile, | 311 const AutofillProfile& profile, |
(...skipping 25 matching lines...) Expand all Loading... |
337 specifics.set_email_address(UTF16ToUTF8(profile.GetInfo(EMAIL_ADDRESS))); | 337 specifics.set_email_address(UTF16ToUTF8(profile.GetInfo(EMAIL_ADDRESS))); |
338 specifics.set_company_name(UTF16ToUTF8(profile.GetInfo(COMPANY_NAME))); | 338 specifics.set_company_name(UTF16ToUTF8(profile.GetInfo(COMPANY_NAME))); |
339 specifics.set_phone_fax_whole_number(UTF16ToUTF8(profile.GetInfo( | 339 specifics.set_phone_fax_whole_number(UTF16ToUTF8(profile.GetInfo( |
340 PHONE_FAX_WHOLE_NUMBER))); | 340 PHONE_FAX_WHOLE_NUMBER))); |
341 specifics.set_phone_home_whole_number(UTF16ToUTF8(profile.GetInfo( | 341 specifics.set_phone_home_whole_number(UTF16ToUTF8(profile.GetInfo( |
342 PHONE_HOME_WHOLE_NUMBER))); | 342 PHONE_HOME_WHOLE_NUMBER))); |
343 node->SetAutofillProfileSpecifics(specifics); | 343 node->SetAutofillProfileSpecifics(specifics); |
344 } | 344 } |
345 | 345 |
346 } // namespace browser_sync | 346 } // namespace browser_sync |
OLD | NEW |