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/autofill/autofill_ie_toolbar_import_win.h" | 5 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/string16.h" | 15 #include "base/string16.h" |
15 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
16 #include "chrome/browser/autofill/autofill_profile.h" | 17 #include "chrome/browser/autofill/autofill_profile.h" |
17 #include "chrome/browser/autofill/credit_card.h" | 18 #include "chrome/browser/autofill/credit_card.h" |
18 #include "chrome/browser/autofill/crypto/rc4_decryptor.h" | 19 #include "chrome/browser/autofill/crypto/rc4_decryptor.h" |
19 #include "chrome/browser/autofill/field_types.h" | 20 #include "chrome/browser/autofill/field_types.h" |
20 #include "chrome/browser/autofill/form_group.h" | 21 #include "chrome/browser/autofill/form_group.h" |
21 #include "chrome/browser/autofill/personal_data_manager.h" | 22 #include "chrome/browser/autofill/personal_data_manager.h" |
| 23 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
22 #include "chrome/browser/autofill/phone_number.h" | 24 #include "chrome/browser/autofill/phone_number.h" |
23 #include "chrome/browser/autofill/phone_number_i18n.h" | 25 #include "chrome/browser/autofill/phone_number_i18n.h" |
24 #include "chrome/browser/sync/util/data_encryption.h" | 26 #include "chrome/browser/sync/util/data_encryption.h" |
25 | 27 |
26 using base::win::RegKey; | 28 using base::win::RegKey; |
27 | 29 |
28 // Forward declaration. This function is not in unnamed namespace as it | 30 // Forward declaration. This function is not in unnamed namespace as it |
29 // is referenced in the unittest. | 31 // is referenced in the unittest. |
30 bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, | 32 bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, |
31 std::vector<CreditCard>* credit_cards); | 33 std::vector<CreditCard>* credit_cards); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 if (!fax.IsEmpty() && | 169 if (!fax.IsEmpty() && |
168 fax.ParseNumber(std::string("US"), &constructed_number)) { | 170 fax.ParseNumber(std::string("US"), &constructed_number)) { |
169 profile->SetCanonicalizedInfo(PHONE_FAX_WHOLE_NUMBER, constructed_number); | 171 profile->SetCanonicalizedInfo(PHONE_FAX_WHOLE_NUMBER, constructed_number); |
170 } | 172 } |
171 | 173 |
172 return has_non_empty_fields; | 174 return has_non_empty_fields; |
173 } | 175 } |
174 | 176 |
175 // Imports profiles from the IE toolbar and stores them. Asynchronous | 177 // Imports profiles from the IE toolbar and stores them. Asynchronous |
176 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. | 178 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. |
177 class AutofillImporter : public PersonalDataManager::Observer { | 179 class AutofillImporter : public PersonalDataManagerObserver { |
178 public: | 180 public: |
179 explicit AutofillImporter(PersonalDataManager* personal_data_manager) | 181 explicit AutofillImporter(PersonalDataManager* personal_data_manager) |
180 : personal_data_manager_(personal_data_manager) { | 182 : personal_data_manager_(personal_data_manager) { |
181 personal_data_manager_->SetObserver(this); | 183 personal_data_manager_->SetObserver(this); |
182 } | 184 } |
183 | 185 |
184 bool ImportProfiles() { | 186 bool ImportProfiles() { |
185 if (!ImportCurrentUserProfiles(&profiles_, &credit_cards_)) { | 187 if (!ImportCurrentUserProfiles(&profiles_, &credit_cards_)) { |
186 delete this; | 188 delete this; |
187 return false; | 189 return false; |
188 } | 190 } |
189 if (personal_data_manager_->IsDataLoaded()) | 191 if (personal_data_manager_->IsDataLoaded()) |
190 OnPersonalDataChanged(); | 192 OnPersonalDataChanged(); |
191 return true; | 193 return true; |
192 } | 194 } |
193 | 195 |
194 // PersonalDataManager::Observer methods: | 196 // PersonalDataManagerObserver: |
195 virtual void OnPersonalDataChanged() { | 197 virtual void OnPersonalDataChanged() OVERRIDE { |
196 for (std::vector<AutofillProfile>::const_iterator iter = profiles_.begin(); | 198 for (std::vector<AutofillProfile>::const_iterator iter = profiles_.begin(); |
197 iter != profiles_.end(); ++iter) { | 199 iter != profiles_.end(); ++iter) { |
198 personal_data_manager_->AddProfile(*iter); | 200 personal_data_manager_->AddProfile(*iter); |
199 } | 201 } |
200 for (std::vector<CreditCard>::const_iterator iter = credit_cards_.begin(); | 202 for (std::vector<CreditCard>::const_iterator iter = credit_cards_.begin(); |
201 iter != credit_cards_.end(); ++iter) { | 203 iter != credit_cards_.end(); ++iter) { |
202 personal_data_manager_->AddCreditCard(*iter); | 204 personal_data_manager_->AddCreditCard(*iter); |
203 } | 205 } |
204 delete this; | 206 delete this; |
205 } | 207 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 276 |
275 bool ImportAutofillDataWin(PersonalDataManager* pdm) { | 277 bool ImportAutofillDataWin(PersonalDataManager* pdm) { |
276 // In incognito mode we do not have PDM - and we should not import anything. | 278 // In incognito mode we do not have PDM - and we should not import anything. |
277 if (!pdm) | 279 if (!pdm) |
278 return false; | 280 return false; |
279 AutofillImporter *importer = new AutofillImporter(pdm); | 281 AutofillImporter *importer = new AutofillImporter(pdm); |
280 // importer will self delete. | 282 // importer will self delete. |
281 return importer->ImportProfiles(); | 283 return importer->ImportProfiles(); |
282 } | 284 } |
283 | 285 |
OLD | NEW |