Index: chrome/browser/autofill/autofill_ie_toolbar_import_win.cc |
diff --git a/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc b/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc |
index aa08f0719085b13652b75868c31eae8bd733dcbb..94e95f3be8c3cbb7aacbae197e24cafcbc9bfd1c 100644 |
--- a/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc |
+++ b/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc |
@@ -14,6 +14,7 @@ |
#include "base/logging.h" |
#include "base/string16.h" |
#include "base/win/registry.h" |
+#include "chrome/browser/autofill/autofill_country.h" |
#include "chrome/browser/autofill/autofill_profile.h" |
#include "chrome/browser/autofill/credit_card.h" |
#include "chrome/browser/autofill/crypto/rc4_decryptor.h" |
@@ -65,15 +66,15 @@ bool IsEmptySalt(std::wstring const& salt) { |
return true; |
} |
-string16 ReadAndDecryptValue(RegKey* key, const wchar_t* value_name) { |
+string16 ReadAndDecryptValue(const RegKey& key, const wchar_t* value_name) { |
DWORD data_type = REG_BINARY; |
DWORD data_size = 0; |
- LONG result = key->ReadValue(value_name, NULL, &data_size, &data_type); |
+ LONG result = key.ReadValue(value_name, NULL, &data_size, &data_type); |
if ((result != ERROR_SUCCESS) || !data_size || data_type != REG_BINARY) |
return string16(); |
std::vector<uint8> data; |
data.resize(data_size); |
- result = key->ReadValue(value_name, &(data[0]), &data_size, &data_type); |
+ result = key.ReadValue(value_name, &(data[0]), &data_size, &data_type); |
if (result == ERROR_SUCCESS) { |
std::string out_data; |
if (syncer::DecryptData(data, &out_data)) { |
@@ -123,42 +124,61 @@ struct { |
typedef std::map<std::wstring, AutofillFieldType> RegToFieldMap; |
-bool ImportSingleProfile(FormGroup* profile, |
- RegKey* key, |
- const RegToFieldMap& reg_to_field ) { |
- DCHECK(profile != NULL); |
- if (!key->Valid()) |
+// Imports address or credit card data from the given registry |key| into the |
+// given |form_group|, with the help of |reg_to_field|. When importing address |
+// data, writes the phone data into |phone|; otherwise, |phone| should be null. |
+// Returns true if any fields were set, false otherwise. |
+bool ImportSingleFormGroup(const RegKey& key, |
+ const RegToFieldMap& reg_to_field, |
+ FormGroup* form_group, |
+ PhoneNumber::PhoneCombineHelper* phone) { |
+ if (!key.Valid()) |
return false; |
bool has_non_empty_fields = false; |
- // Phones need to be rebuilt. |
- PhoneNumber::PhoneCombineHelper phone; |
- |
- for (uint32 i = 0; i < key->GetValueCount(); ++i) { |
+ for (uint32 i = 0; i < key.GetValueCount(); ++i) { |
std::wstring value_name; |
- if (key->GetValueNameAt(i, &value_name) != ERROR_SUCCESS) |
+ if (key.GetValueNameAt(i, &value_name) != ERROR_SUCCESS) |
continue; |
+ |
RegToFieldMap::const_iterator it = reg_to_field.find(value_name); |
if (it == reg_to_field.end()) |
continue; // This field is not imported. |
+ |
string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); |
if (!field_value.empty()) { |
- has_non_empty_fields = true; |
if (it->second == CREDIT_CARD_NUMBER) |
field_value = DecryptCCNumber(field_value); |
- // We need to store phone data in |phone| before building the whole number |
- // at the end. The rest of the fields are set "as is". |
+ // Phone numbers are stored piece-by-piece, and then reconstructed from |
+ // the pieces. The rest of the fields are set "as is". |
// TODO(isherman): Call SetInfo(), rather than SetRawInfo(). |
- if (!phone.SetInfo(it->second, field_value)) |
- profile->SetRawInfo(it->second, field_value); |
+ if (!phone || !phone->SetInfo(it->second, field_value)) { |
+ has_non_empty_fields = true; |
+ form_group->SetRawInfo(it->second, field_value); |
+ } |
} |
} |
+ |
+ return has_non_empty_fields; |
+} |
+ |
+// Imports address data from the given registry |key| into the given |profile|, |
+// with the help of |reg_to_field|. Returns true if any fields were set, false |
+// otherwise. |
+bool ImportSingleProfile(const RegKey& key, |
+ const RegToFieldMap& reg_to_field, |
+ AutofillProfile* profile) { |
+ PhoneNumber::PhoneCombineHelper phone; |
+ bool has_non_empty_fields = |
+ ImportSingleFormGroup(key, reg_to_field, profile, &phone); |
+ |
// Now re-construct the phones if needed. |
string16 constructed_number; |
- if (!phone.IsEmpty() && |
- phone.ParseNumber(std::string("US"), &constructed_number)) { |
+ const std::string app_locale = AutofillCountry::ApplicationLocale(); |
+ if (phone.ParseNumber(*profile, app_locale, &constructed_number)) { |
+ has_non_empty_fields = true; |
profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number); |
} |
@@ -232,7 +252,7 @@ bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, |
key_name.append(iterator_profiles.Name()); |
RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
AutofillProfile profile; |
- if (ImportSingleProfile(&profile, &key, reg_to_field)) { |
+ if (ImportSingleProfile(key, reg_to_field, &profile)) { |
// Combine phones into whole phone #. |
profiles->push_back(profile); |
} |
@@ -241,8 +261,8 @@ bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, |
string16 salt; |
RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); |
if (cc_key.Valid()) { |
- password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); |
- salt = ReadAndDecryptValue(&cc_key, kSaltValue); |
+ password_hash = ReadAndDecryptValue(cc_key, kPasswordHashValue); |
+ salt = ReadAndDecryptValue(cc_key, kSaltValue); |
} |
// We import CC profiles only if they are not password protected. |
@@ -255,7 +275,7 @@ bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, |
key_name.append(iterator_cc.Name()); |
RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
CreditCard credit_card; |
- if (ImportSingleProfile(&credit_card, &key, reg_to_field)) { |
+ if (ImportSingleFormGroup(key, reg_to_field, &credit_card, NULL)) { |
// TODO(isherman): Call into GetInfo() below, rather than GetRawInfo(). |
string16 cc_number = credit_card.GetRawInfo(CREDIT_CARD_NUMBER); |
if (!cc_number.empty()) |