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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 DCHECK(web_database); | 39 DCHECK(web_database); |
40 DCHECK(error_handler); | 40 DCHECK(error_handler); |
41 DCHECK(personal_data_manager); | 41 DCHECK(personal_data_manager); |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
43 | 43 |
44 StartObserving(); | 44 StartObserving(); |
45 } | 45 } |
46 | 46 |
47 AutofillProfileChangeProcessor::~AutofillProfileChangeProcessor() {} | 47 AutofillProfileChangeProcessor::~AutofillProfileChangeProcessor() {} |
48 | 48 |
49 AutofillProfileChangeProcessor::ScopedStopObserving::ScopedStopObserving( | |
50 AutofillProfileChangeProcessor* processor) { | |
51 processor_ = processor; | |
52 processor_->StopObserving(); | |
53 } | |
54 | |
55 AutofillProfileChangeProcessor::ScopedStopObserving::~ScopedStopObserving() { | |
56 processor_->StartObserving(); | |
57 } | |
58 | |
59 void AutofillProfileChangeProcessor::ApplyChangesFromSyncModel( | 49 void AutofillProfileChangeProcessor::ApplyChangesFromSyncModel( |
60 const sync_api::BaseTransaction *write_trans, | 50 const sync_api::BaseTransaction *write_trans, |
61 const sync_api::SyncManager::ChangeRecord* changes, | 51 const sync_api::SyncManager::ChangeRecord* changes, |
62 int change_count) { | 52 int change_count) { |
63 | 53 |
64 ScopedStopObserving observer(this); | 54 ScopedStopObserving<AutofillProfileChangeProcessor> observer(this); |
65 | 55 |
66 sync_api::ReadNode autofill_profile_root(write_trans); | 56 sync_api::ReadNode autofill_profile_root(write_trans); |
67 if (!autofill_profile_root.InitByTagLookup(kAutofillProfileTag)) { | 57 if (!autofill_profile_root.InitByTagLookup(kAutofillProfileTag)) { |
68 error_handler()->OnUnrecoverableError(FROM_HERE, | 58 error_handler()->OnUnrecoverableError(FROM_HERE, |
69 "Autofill Profile root node lookup failed"); | 59 "Autofill Profile root node lookup failed"); |
70 return; | 60 return; |
71 } | 61 } |
72 | 62 |
73 for (int i = 0; i < change_count; ++i) { | 63 for (int i = 0; i < change_count; ++i) { |
74 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == | 64 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 NOTREACHED(); | 157 NOTREACHED(); |
168 } | 158 } |
169 } | 159 } |
170 | 160 |
171 void AutofillProfileChangeProcessor::CommitChangesFromSyncModel() { | 161 void AutofillProfileChangeProcessor::CommitChangesFromSyncModel() { |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
173 | 163 |
174 if (!running()) | 164 if (!running()) |
175 return; | 165 return; |
176 | 166 |
177 ScopedStopObserving observer(this); | 167 ScopedStopObserving<AutofillProfileChangeProcessor> observer(this); |
178 | 168 |
179 for (unsigned int i = 0;i < autofill_changes_.size(); ++i) { | 169 for (unsigned int i = 0;i < autofill_changes_.size(); ++i) { |
180 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == | 170 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == |
181 autofill_changes_[i].action_) { | 171 autofill_changes_[i].action_) { |
182 if (!web_database_->GetAutofillTable()->RemoveAutofillProfile( | 172 if (!web_database_->GetAutofillTable()->RemoveAutofillProfile( |
183 autofill_changes_[i].profile_specifics_.guid())) { | 173 autofill_changes_[i].profile_specifics_.guid())) { |
184 LOG(ERROR) << "could not delete the profile " << | 174 LOG(ERROR) << "could not delete the profile " << |
185 autofill_changes_[i].profile_specifics_.guid(); | 175 autofill_changes_[i].profile_specifics_.guid(); |
186 continue; | 176 continue; |
187 } | 177 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 specifics.set_email_address(UTF16ToUTF8(profile.GetInfo(EMAIL_ADDRESS))); | 336 specifics.set_email_address(UTF16ToUTF8(profile.GetInfo(EMAIL_ADDRESS))); |
347 specifics.set_company_name(UTF16ToUTF8(profile.GetInfo(COMPANY_NAME))); | 337 specifics.set_company_name(UTF16ToUTF8(profile.GetInfo(COMPANY_NAME))); |
348 specifics.set_phone_fax_whole_number(UTF16ToUTF8(profile.GetInfo( | 338 specifics.set_phone_fax_whole_number(UTF16ToUTF8(profile.GetInfo( |
349 PHONE_FAX_WHOLE_NUMBER))); | 339 PHONE_FAX_WHOLE_NUMBER))); |
350 specifics.set_phone_home_whole_number(UTF16ToUTF8(profile.GetInfo( | 340 specifics.set_phone_home_whole_number(UTF16ToUTF8(profile.GetInfo( |
351 PHONE_HOME_WHOLE_NUMBER))); | 341 PHONE_HOME_WHOLE_NUMBER))); |
352 node->SetAutofillProfileSpecifics(specifics); | 342 node->SetAutofillProfileSpecifics(specifics); |
353 } | 343 } |
354 | 344 |
355 } // namespace browser_sync | 345 } // namespace browser_sync |
OLD | NEW |