Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/autofill/autofill_ie_toolbar_import_win.cc

Issue 6877130: These changes *are* for review :) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_ie_toolbar_import_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 13 #include "base/logging.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/win/registry.h" 15 #include "base/win/registry.h"
16 #include "chrome/browser/autofill/autofill_profile.h" 16 #include "chrome/browser/autofill/autofill_profile.h"
17 #include "chrome/browser/autofill/credit_card.h" 17 #include "chrome/browser/autofill/credit_card.h"
18 #include "chrome/browser/autofill/crypto/rc4_decryptor.h" 18 #include "chrome/browser/autofill/crypto/rc4_decryptor.h"
19 #include "chrome/browser/autofill/field_types.h" 19 #include "chrome/browser/autofill/field_types.h"
20 #include "chrome/browser/autofill/form_group.h" 20 #include "chrome/browser/autofill/form_group.h"
21 #include "chrome/browser/autofill/personal_data_manager.h" 21 #include "chrome/browser/autofill/personal_data_manager.h"
22 #include "chrome/browser/autofill/phone_number.h"
23 #include "chrome/browser/autofill/phone_number_i18n.h"
22 #include "chrome/browser/sync/util/data_encryption.h" 24 #include "chrome/browser/sync/util/data_encryption.h"
23 25
24 using base::win::RegKey; 26 using base::win::RegKey;
25 27
26 // Forward declaration. This function is not in unnamed namespace as it 28 // Forward declaration. This function is not in unnamed namespace as it
27 // is referenced in the unittest. 29 // is referenced in the unittest.
28 bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, 30 bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles,
29 std::vector<CreditCard>* credit_cards); 31 std::vector<CreditCard>* credit_cards);
30 namespace { 32 namespace {
31 33
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 126
125 bool ImportSingleProfile(FormGroup* profile, 127 bool ImportSingleProfile(FormGroup* profile,
126 RegKey* key, 128 RegKey* key,
127 const RegToFieldMap& reg_to_field ) { 129 const RegToFieldMap& reg_to_field ) {
128 DCHECK(profile != NULL); 130 DCHECK(profile != NULL);
129 if (!key->Valid()) 131 if (!key->Valid())
130 return false; 132 return false;
131 133
132 bool has_non_empty_fields = false; 134 bool has_non_empty_fields = false;
133 135
136 // Phones need to be rebuilt.
137 PhoneNumber::PhoneCombineHelper home(AutofillType::PHONE_HOME);
138 PhoneNumber::PhoneCombineHelper fax(AutofillType::PHONE_FAX);
139
134 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { 140 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) {
135 std::wstring value_name; 141 std::wstring value_name;
136 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS) 142 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS)
137 continue; 143 continue;
138 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); 144 RegToFieldMap::const_iterator it = reg_to_field.find(value_name);
139 if (it == reg_to_field.end()) 145 if (it == reg_to_field.end())
140 continue; // This field is not imported. 146 continue; // This field is not imported.
141 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); 147 string16 field_value = ReadAndDecryptValue(key, value_name.c_str());
142 if (!field_value.empty()) { 148 if (!field_value.empty()) {
143 has_non_empty_fields = true; 149 has_non_empty_fields = true;
144 if (it->second == CREDIT_CARD_NUMBER) { 150 if (it->second == CREDIT_CARD_NUMBER) {
145 field_value = DecryptCCNumber(field_value); 151 field_value = DecryptCCNumber(field_value);
146 } 152 }
147 profile->SetInfo(it->second, field_value); 153 // We need to store phone data in the variables, before building the whole
154 // number at the end. The rest of the fields are set "as is".
155 if (!home.SetInfo(it->second, field_value) &&
156 !fax.SetInfo(it->second, field_value)) {
157 profile->SetInfo(it->second, field_value);
158 }
148 } 159 }
149 } 160 }
161 // Now re-construct the phones if needed.
162 string16 constructed_number;
163 if (!home.empty() && home.ParseNumber(std::string("US"), &constructed_number))
164 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number);
165 if (!fax.empty() && fax.ParseNumber(std::string("US"), &constructed_number))
166 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, constructed_number);
167
150 return has_non_empty_fields; 168 return has_non_empty_fields;
151 } 169 }
152 170
153 // Imports profiles from the IE toolbar and stores them. Asynchronous 171 // Imports profiles from the IE toolbar and stores them. Asynchronous
154 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. 172 // if PersonalDataManager has not been loaded yet. Deletes itself on completion.
155 class AutofillImporter : public PersonalDataManager::Observer { 173 class AutofillImporter : public PersonalDataManager::Observer {
156 public: 174 public:
157 explicit AutofillImporter(PersonalDataManager* personal_data_manager) 175 explicit AutofillImporter(PersonalDataManager* personal_data_manager)
158 : personal_data_manager_(personal_data_manager) { 176 : personal_data_manager_(personal_data_manager) {
159 personal_data_manager_->SetObserver(this); 177 personal_data_manager_->SetObserver(this);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::win::RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, 230 base::win::RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER,
213 kProfileKey); 231 kProfileKey);
214 for (; iterator_profiles.Valid(); ++iterator_profiles) { 232 for (; iterator_profiles.Valid(); ++iterator_profiles) {
215 std::wstring key_name(kProfileKey); 233 std::wstring key_name(kProfileKey);
216 key_name.append(L"\\"); 234 key_name.append(L"\\");
217 key_name.append(iterator_profiles.Name()); 235 key_name.append(iterator_profiles.Name());
218 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); 236 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ);
219 AutofillProfile profile; 237 AutofillProfile profile;
220 if (ImportSingleProfile(&profile, &key, reg_to_field)) { 238 if (ImportSingleProfile(&profile, &key, reg_to_field)) {
221 // Combine phones into whole phone #. 239 // Combine phones into whole phone #.
222 string16 phone;
223 phone = profile.GetInfo(PHONE_HOME_COUNTRY_CODE);
224 phone.append(profile.GetInfo(PHONE_HOME_CITY_CODE));
225 phone.append(profile.GetInfo(PHONE_HOME_NUMBER));
226 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, phone);
227 phone = profile.GetInfo(PHONE_FAX_COUNTRY_CODE);
228 phone.append(profile.GetInfo(PHONE_FAX_CITY_CODE));
229 phone.append(profile.GetInfo(PHONE_FAX_NUMBER));
230 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, phone);
231 profiles->push_back(profile); 240 profiles->push_back(profile);
232 } 241 }
233 } 242 }
234 string16 password_hash; 243 string16 password_hash;
235 string16 salt; 244 string16 salt;
236 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); 245 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ);
237 if (cc_key.Valid()) { 246 if (cc_key.Valid()) {
238 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); 247 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue);
239 salt = ReadAndDecryptValue(&cc_key, kSaltValue); 248 salt = ReadAndDecryptValue(&cc_key, kSaltValue);
240 } 249 }
(...skipping 20 matching lines...) Expand all
261 270
262 bool ImportAutofillDataWin(PersonalDataManager* pdm) { 271 bool ImportAutofillDataWin(PersonalDataManager* pdm) {
263 // In incognito mode we do not have PDM - and we should not import anything. 272 // In incognito mode we do not have PDM - and we should not import anything.
264 if (!pdm) 273 if (!pdm)
265 return false; 274 return false;
266 AutofillImporter *importer = new AutofillImporter(pdm); 275 AutofillImporter *importer = new AutofillImporter(pdm);
267 // importer will self delete. 276 // importer will self delete.
268 return importer->ImportProfiles(); 277 return importer->ImportProfiles();
269 } 278 }
270 279
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_ie_toolbar_import_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698