summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc54
-rw-r--r--chrome/browser/autofill/personal_data_manager.h20
-rw-r--r--chrome/browser/dom_ui/options/autofill_options_handler.cc68
-rw-r--r--chrome/browser/resources/options/autofill_edit_address_overlay.js18
-rw-r--r--chrome/browser/resources/options/autofill_edit_creditcard_overlay.js14
-rw-r--r--chrome/browser/resources/options/autofill_options.js22
6 files changed, 99 insertions, 97 deletions
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index fe4c2ea..80f3a8d 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -26,19 +26,17 @@ namespace {
// before AutoFill will attempt to import the data into a profile.
const int kMinImportSize = 3;
-const char kUnlabeled[] = "Unlabeled";
-
template<typename T>
-class FormGroupIDMatchesFunctor {
+class FormGroupGUIDMatchesFunctor {
public:
- explicit FormGroupIDMatchesFunctor(int id) : id_(id) {}
+ explicit FormGroupGUIDMatchesFunctor(const std::string& guid) : guid_(guid) {}
bool operator()(const T& form_group) {
- return form_group.unique_id() == id_;
+ return form_group.guid() == guid_;
}
private:
- int id_;
+ std::string guid_;
};
template<typename T>
@@ -234,14 +232,7 @@ void PersonalDataManager::GetImportedFormData(AutoFillProfile** profile,
DCHECK(profile);
DCHECK(credit_card);
- if (imported_profile_.get()) {
- imported_profile_->set_label(ASCIIToUTF16(kUnlabeled));
- }
*profile = imported_profile_.get();
-
- if (imported_credit_card_.get()) {
- imported_credit_card_->set_label(ASCIIToUTF16(kUnlabeled));
- }
*credit_card = imported_credit_card_.get();
}
@@ -467,7 +458,12 @@ void PersonalDataManager::UpdateProfile(const AutoFillProfile& profile) {
// Update the cached profile.
for (std::vector<AutoFillProfile*>::iterator iter = web_profiles_->begin();
iter != web_profiles_->end(); ++iter) {
- if ((*iter)->unique_id() == profile.unique_id()) {
+ if ((*iter)->guid() == profile.guid()) {
+ // TODO(dhollowa): Remove |unique_id| once GUID migration work is
+ // complete. Until the |WebDataService::UpdateAutoFillProfile| is changed
+ // to use the GUID we need to preserve the unique ID association.
+ // http:://crbug.com/58813
+ const_cast<AutoFillProfile&>(profile).set_unique_id((*iter)->unique_id());
delete *iter;
*iter = new AutoFillProfile(profile);
break;
@@ -478,26 +474,27 @@ void PersonalDataManager::UpdateProfile(const AutoFillProfile& profile) {
FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
}
-void PersonalDataManager::RemoveProfile(int unique_id) {
+void PersonalDataManager::RemoveProfile(const std::string& guid) {
// TODO(jhawkins): Refactor SetProfiles so this isn't so hacky.
std::vector<AutoFillProfile> profiles(web_profiles_.size());
std::transform(web_profiles_.begin(), web_profiles_.end(),
profiles.begin(),
DereferenceFunctor<AutoFillProfile>());
- // Remove the profile that matches |unique_id|.
+ // Remove the profile that matches |guid|.
profiles.erase(
std::remove_if(profiles.begin(), profiles.end(),
- FormGroupIDMatchesFunctor<AutoFillProfile>(unique_id)),
+ FormGroupGUIDMatchesFunctor<AutoFillProfile>(guid)),
profiles.end());
SetProfiles(&profiles);
}
-AutoFillProfile* PersonalDataManager::GetProfileById(int unique_id) {
+AutoFillProfile* PersonalDataManager::GetProfileByGUID(
+ const std::string& guid) {
for (std::vector<AutoFillProfile*>::iterator iter = web_profiles_->begin();
iter != web_profiles_->end(); ++iter) {
- if ((*iter)->unique_id() == unique_id)
+ if ((*iter)->guid() == guid)
return *iter;
}
return NULL;
@@ -522,7 +519,12 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
// Update the cached credit card.
for (std::vector<CreditCard*>::iterator iter = credit_cards_->begin();
iter != credit_cards_->end(); ++iter) {
- if ((*iter)->unique_id() == credit_card.unique_id()) {
+ if ((*iter)->guid() == credit_card.guid()) {
+ // TODO(dhollowa): Remove |unique_id| once GUID migration work is
+ // complete. Until the |WebDataService::UpdateCreditCard| is changed
+ // to use the GUID we need to preserve the unique ID association.
+ // http:://crbug.com/58813
+ const_cast<CreditCard&>(credit_card).set_unique_id((*iter)->unique_id());
delete *iter;
*iter = new CreditCard(credit_card);
break;
@@ -533,26 +535,26 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
}
-void PersonalDataManager::RemoveCreditCard(int unique_id) {
+void PersonalDataManager::RemoveCreditCard(const std::string& guid) {
// TODO(jhawkins): Refactor SetCreditCards so this isn't so hacky.
std::vector<CreditCard> credit_cards(credit_cards_.size());
std::transform(credit_cards_.begin(), credit_cards_.end(),
credit_cards.begin(),
DereferenceFunctor<CreditCard>());
- // Remove the credit card that matches |unique_id|.
+ // Remove the credit card that matches |guid|.
credit_cards.erase(
std::remove_if(credit_cards.begin(), credit_cards.end(),
- FormGroupIDMatchesFunctor<CreditCard>(unique_id)),
+ FormGroupGUIDMatchesFunctor<CreditCard>(guid)),
credit_cards.end());
SetCreditCards(&credit_cards);
}
-CreditCard* PersonalDataManager::GetCreditCardById(int unique_id) {
+CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) {
for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin();
iter != credit_cards_.end(); ++iter) {
- if ((*iter)->unique_id() == unique_id)
+ if ((*iter)->guid() == guid)
return *iter;
}
return NULL;
@@ -800,8 +802,6 @@ void PersonalDataManager::SaveImportedCreditCard() {
// Set to true if |imported_credit_card_| is merged into the profile list.
bool merged = false;
- imported_credit_card_->set_label(ASCIIToUTF16(kUnlabeled));
-
std::vector<CreditCard> creditcards;
for (std::vector<CreditCard*>::const_iterator iter =
credit_cards_.begin();
diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h
index 9ba06a9..5499903 100644
--- a/chrome/browser/autofill/personal_data_manager.h
+++ b/chrome/browser/autofill/personal_data_manager.h
@@ -106,12 +106,12 @@ class PersonalDataManager
// Updates |profile| which already exists in the web database.
void UpdateProfile(const AutoFillProfile& profile);
- // Removes the profile represented by |unique_id|.
- void RemoveProfile(int unique_id);
+ // Removes the profile represented by |guid|.
+ void RemoveProfile(const std::string& guid);
- // Returns the profile with the specified |unique_id|, or NULL if there is no
- // profile with the specified |unique_id|.
- AutoFillProfile* GetProfileById(int unique_id);
+ // Returns the profile with the specified |guid|, or NULL if there is no
+ // profile with the specified |guid|.
+ AutoFillProfile* GetProfileByGUID(const std::string& guid);
// Adds |credit_card| to the web database.
void AddCreditCard(const CreditCard& credit_card);
@@ -119,12 +119,12 @@ class PersonalDataManager
// Updates |credit_card| which already exists in the web database.
void UpdateCreditCard(const CreditCard& credit_card);
- // Removes the credit card represented by |unique_id|.
- void RemoveCreditCard(int unique_id);
+ // Removes the credit card represented by |guid|.
+ void RemoveCreditCard(const std::string& guid);
- // Returns the credit card with the specified |unique_id|, or NULL if there is
- // no credit card with the specified |unique_id|.
- CreditCard* GetCreditCardById(int unique_id);
+ // Returns the credit card with the specified |guid|, or NULL if there is
+ // no credit card with the specified |guid|.
+ CreditCard* GetCreditCardByGUID(const std::string& guid);
// Gets the possible field types for the given text, determined by matching
// the text with all known personal information and returning matching types.
diff --git a/chrome/browser/dom_ui/options/autofill_options_handler.cc b/chrome/browser/dom_ui/options/autofill_options_handler.cc
index 22ca4aa..b3cd3ce 100644
--- a/chrome/browser/dom_ui/options/autofill_options_handler.cc
+++ b/chrome/browser/dom_ui/options/autofill_options_handler.cc
@@ -13,6 +13,7 @@
#include "base/values.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
+#include "chrome/browser/guid.h"
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
@@ -88,8 +89,8 @@ void AutoFillOptionsHandler::RegisterMessages() {
NewCallback(this, &AutoFillOptionsHandler::UpdateCreditCard));
dom_ui_->RegisterMessageCallback(
- "editCreditCard",
- NewCallback(this, &AutoFillOptionsHandler::EditCreditCard));
+ "editCreditCard",
+ NewCallback(this, &AutoFillOptionsHandler::EditCreditCard));
dom_ui_->RegisterMessageCallback(
"removeCreditCard",
@@ -154,11 +155,11 @@ void AutoFillOptionsHandler::LoadAutoFillData() {
ListValue addresses;
for (std::vector<AutoFillProfile*>::const_iterator i =
- personal_data_->profiles().begin();
- i != personal_data_->profiles().end(); ++i) {
+ personal_data_->web_profiles().begin();
+ i != personal_data_->web_profiles().end(); ++i) {
DictionaryValue* address = new DictionaryValue();
address->SetString("label", (*i)->Label());
- address->SetInteger("uniqueID", (*i)->unique_id());
+ address->SetString("guid", (*i)->guid());
addresses.Append(address);
}
@@ -171,7 +172,7 @@ void AutoFillOptionsHandler::LoadAutoFillData() {
i != personal_data_->credit_cards().end(); ++i) {
DictionaryValue* credit_card = new DictionaryValue();
credit_card->SetString("label", (*i)->PreviewSummary());
- credit_card->SetInteger("uniqueID", (*i)->unique_id());
+ credit_card->SetString("guid", (*i)->guid());
credit_cards.Append(credit_card);
}
@@ -183,14 +184,13 @@ void AutoFillOptionsHandler::UpdateAddress(const ListValue* args) {
if (!personal_data_->IsDataLoaded())
return;
- int unique_id = 0;
- if (!ExtractIntegerValue(args, &unique_id)) {
+ std::string guid;
+ if (!args->GetString(0, &guid)) {
NOTREACHED();
return;
}
- AutoFillProfile profile;
- profile.set_unique_id(unique_id);
+ AutoFillProfile profile(guid);
string16 value;
if (args->GetString(1, &value))
@@ -216,23 +216,25 @@ void AutoFillOptionsHandler::UpdateAddress(const ListValue* args) {
if (args->GetString(11, &value))
profile.SetInfo(AutoFillType(EMAIL_ADDRESS), value);
- if (unique_id == 0)
+ if (!guid::IsValidGUID(profile.guid())) {
+ profile.set_guid(guid::GenerateGUID());
personal_data_->AddProfile(profile);
- else
+ } else {
personal_data_->UpdateProfile(profile);
+ }
}
void AutoFillOptionsHandler::EditAddress(const ListValue* args) {
if (!personal_data_->IsDataLoaded())
return;
- int unique_id = 0;
- if (!ExtractIntegerValue(args, &unique_id)) {
+ std::string guid;
+ if (!args->GetString(0, &guid)) {
NOTREACHED();
return;
}
- AutoFillProfile* profile = personal_data_->GetProfileById(unique_id);
+ AutoFillProfile* profile = personal_data_->GetProfileByGUID(guid);
if (!profile) {
NOTREACHED();
return;
@@ -242,7 +244,7 @@ void AutoFillOptionsHandler::EditAddress(const ListValue* args) {
// directly to CallJavascriptFunction().
ListValue addressList;
DictionaryValue* address = new DictionaryValue();
- address->SetInteger("uniqueID", profile->unique_id());
+ address->SetString("guid", profile->guid());
address->SetString("fullName",
profile->GetFieldText(AutoFillType(NAME_FULL)));
address->SetString("companyName",
@@ -277,27 +279,26 @@ void AutoFillOptionsHandler::RemoveAddress(const ListValue* args) {
if (!personal_data_->IsDataLoaded())
return;
- int unique_id = 0;
- if (!ExtractIntegerValue(args, &unique_id)) {
+ std::string guid;
+ if (!args->GetString(0, &guid)) {
NOTREACHED();
return;
}
- personal_data_->RemoveProfile(unique_id);
+ personal_data_->RemoveProfile(guid);
}
void AutoFillOptionsHandler::UpdateCreditCard(const ListValue* args) {
if (!personal_data_->IsDataLoaded())
return;
- int unique_id = 0;
- if (!ExtractIntegerValue(args, &unique_id)) {
+ std::string guid;
+ if (!args->GetString(0, &guid)) {
NOTREACHED();
return;
}
- CreditCard credit_card;
- credit_card.set_unique_id(unique_id);
+ CreditCard credit_card(guid);
string16 value;
if (args->GetString(1, &value))
@@ -309,23 +310,26 @@ void AutoFillOptionsHandler::UpdateCreditCard(const ListValue* args) {
if (args->GetString(4, &value))
credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value);
- if (unique_id == 0)
+ if (!guid::IsValidGUID(credit_card.guid())) {
+ credit_card.set_guid(guid::GenerateGUID());
personal_data_->AddCreditCard(credit_card);
- else
+ } else {
personal_data_->UpdateCreditCard(credit_card);
+ }
+
}
void AutoFillOptionsHandler::EditCreditCard(const ListValue* args) {
if (!personal_data_->IsDataLoaded())
return;
- int unique_id = 0;
- if (!ExtractIntegerValue(args, &unique_id)) {
+ std::string guid;
+ if (!args->GetString(0, &guid)) {
NOTREACHED();
return;
}
- CreditCard* credit_card = personal_data_->GetCreditCardById(unique_id);
+ CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid);
if (!credit_card) {
NOTREACHED();
@@ -336,7 +340,7 @@ void AutoFillOptionsHandler::EditCreditCard(const ListValue* args) {
// directly to CallJavascriptFunction().
ListValue credit_card_list;
DictionaryValue* credit_card_data = new DictionaryValue();
- credit_card_data->SetInteger("uniqueID", credit_card->unique_id());
+ credit_card_data->SetString("guid", credit_card->guid());
credit_card_data->SetString(
"nameOnCard",
credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NAME)));
@@ -359,11 +363,11 @@ void AutoFillOptionsHandler::RemoveCreditCard(const ListValue* args) {
if (!personal_data_->IsDataLoaded())
return;
- int unique_id = 0;
- if (!ExtractIntegerValue(args, &unique_id)) {
+ std::string guid;
+ if (!args->GetString(0, &guid)) {
NOTREACHED();
return;
}
- personal_data_->RemoveCreditCard(unique_id);
+ personal_data_->RemoveCreditCard(guid);
}
diff --git a/chrome/browser/resources/options/autofill_edit_address_overlay.js b/chrome/browser/resources/options/autofill_edit_address_overlay.js
index a6eb980..46a17d0 100644
--- a/chrome/browser/resources/options/autofill_edit_address_overlay.js
+++ b/chrome/browser/resources/options/autofill_edit_address_overlay.js
@@ -5,8 +5,8 @@
cr.define('options', function() {
const OptionsPage = options.OptionsPage;
- // The unique ID of the loaded address.
- var uniqueID;
+ // The GUID of the loaded address.
+ var guid;
/**
* AutoFillEditAddressOverlay class
@@ -39,19 +39,19 @@ cr.define('options', function() {
self.dismissOverlay_();
}
- self.uniqueID = 0;
+ self.guid = '';
self.clearInputFields_();
self.connectInputEvents_();
},
/**
- * Clears any uncommitted input, resets the stored unique ID and dismisses
- * the overlay.
+ * Clears any uncommitted input, resets the stored GUID and dismisses the
+ * overlay.
* @private
*/
dismissOverlay_: function() {
this.clearInputFields_();
- this.uniqueID = 0;
+ this.guid = '';
OptionsPage.clearOverlays();
},
@@ -62,7 +62,7 @@ cr.define('options', function() {
*/
saveAddress_: function() {
var address = new Array();
- address[0] = String(this.uniqueID);
+ address[0] = this.guid;
address[1] = $('fullName').value;
address[2] = $('companyName').value;
address[3] = $('addrLine1').value;
@@ -129,13 +129,13 @@ cr.define('options', function() {
/**
* Loads the address data from |address|, sets the input fields based on
- * this data and stores the unique ID of the address.
+ * this data and stores the GUID of the address.
* @private
*/
loadAddress_: function(address) {
this.setInputFields_(address);
this.inputFieldChanged_();
- this.uniqueID = address['uniqueID'];
+ this.guid = address['guid'];
},
/**
diff --git a/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js b/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js
index 0ee9e1a..01b1722 100644
--- a/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js
+++ b/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js
@@ -5,8 +5,8 @@
cr.define('options', function() {
const OptionsPage = options.OptionsPage;
- // The unique ID of the loaded credit card.
- var uniqueID;
+ // The GUID of the loaded credit card.
+ var guid;
/**
* AutoFillEditCreditCardOverlay class
@@ -39,7 +39,7 @@ cr.define('options', function() {
self.dismissOverlay_();
}
- self.uniqueID = 0;
+ self.guid = '';
self.clearInputFields_();
self.connectInputEvents_();
self.setDefaultSelectOptions_();
@@ -51,7 +51,7 @@ cr.define('options', function() {
*/
dismissOverlay_: function() {
this.clearInputFields_();
- this.uniqueID = 0;
+ this.guid = '';
OptionsPage.clearOverlays();
},
@@ -62,7 +62,7 @@ cr.define('options', function() {
*/
saveCreditCard_: function() {
var creditCard = new Array(5);
- creditCard[0] = String(this.uniqueID);
+ creditCard[0] = this.guid;
creditCard[1] = $('nameOnCard').value;
creditCard[2] = $('creditCardNumber').value;
creditCard[3] = $('expirationMonth').value;
@@ -174,13 +174,13 @@ cr.define('options', function() {
/**
* Loads the credit card data from |creditCard|, sets the input fields based
- * on this data and stores the unique ID of the credit card.
+ * on this data and stores the GUID of the credit card.
* @private
*/
loadCreditCard_: function(creditCard) {
this.setInputFields_(creditCard);
this.inputFieldChanged_();
- this.uniqueID = creditCard['uniqueID'];
+ this.guid = creditCard['guid'];
},
};
diff --git a/chrome/browser/resources/options/autofill_options.js b/chrome/browser/resources/options/autofill_options.js
index 4ee8122..3b662f2 100644
--- a/chrome/browser/resources/options/autofill_options.js
+++ b/chrome/browser/resources/options/autofill_options.js
@@ -23,8 +23,8 @@ cr.define('options', function() {
this.numAddresses = 0;
this.numCreditCards = 0;
this.activeNavTab = null;
- this.addressIDs = null;
- this.creditCardIDs = null;
+ this.addressGUIDs = null;
+ this.creditCardGUIDs = null;
OptionsPage.call(this, 'autoFillOptions',
templateData.autoFillOptionsTitle,
'autoFillOptionsPage');
@@ -150,11 +150,11 @@ cr.define('options', function() {
var profileList = $('profileList');
var blankAddress = profileList.options[addressOffset];
this.numAddresses = addresses.length;
- this.addressIDs = new Array(this.numAddresses);
+ this.addressGUIDs = new Array(this.numAddresses);
for (var i = 0; i < this.numAddresses; i++) {
var address = addresses[i];
var option = new Option(address['label']);
- this.addressIDs[i] = address['uniqueID'];
+ this.addressGUIDs[i] = address['guid'];
profileList.add(option, blankAddress);
}
@@ -170,11 +170,11 @@ cr.define('options', function() {
this.resetCreditCards_();
var profileList = $('profileList');
this.numCreditCards = creditCards.length;
- this.creditCardIDs = new Array(this.numCreditCards);
+ this.creditCardGUIDs = new Array(this.numCreditCards);
for (var i = 0; i < this.numCreditCards; i++) {
var creditCard = creditCards[i];
var option = new Option(creditCard['label']);
- this.creditCardIDs[i] = creditCard['uniqueID'];
+ this.creditCardGUIDs[i] = creditCard['guid'];
profileList.add(option, null);
}
@@ -205,10 +205,9 @@ cr.define('options', function() {
editProfile_: function() {
var idx = $('profileList').selectedIndex;
if ((profileIndex = this.getAddressIndex_(idx)) != -1) {
- chrome.send('editAddress', [String(this.addressIDs[profileIndex])]);
+ chrome.send('editAddress', [this.addressGUIDs[profileIndex]]);
} else if ((profileIndex = this.getCreditCardIndex_(idx)) != -1) {
- chrome.send('editCreditCard',
- [String(this.creditCardIDs[profileIndex])]);
+ chrome.send('editCreditCard', [this.creditCardGUIDs[profileIndex]]);
}
},
@@ -220,10 +219,9 @@ cr.define('options', function() {
removeProfile_: function() {
var idx = $('profileList').selectedIndex;
if ((profileIndex = this.getAddressIndex_(idx)) != -1)
- chrome.send('removeAddress', [String(this.addressIDs[profileIndex])]);
+ chrome.send('removeAddress', [this.addressGUIDs[profileIndex]]);
else if ((profileIndex = this.getCreditCardIndex_(idx)) != -1)
- chrome.send('removeCreditCard',
- [String(this.creditCardIDs[profileIndex])]);
+ chrome.send('removeCreditCard', [this.creditCardGUIDs[profileIndex]]);
},
/**