diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 19:45:04 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 19:45:04 +0000 |
commit | e43783403ec799f226d7b6d9dde5ecd363f0b339 (patch) | |
tree | ea812df19a608f589ae53760a4ee5c63b6cdd101 /chrome | |
parent | 206167f1286d23440b8fa60dfd2bf1a8e0036ce8 (diff) | |
download | chromium_src-e43783403ec799f226d7b6d9dde5ecd363f0b339.zip chromium_src-e43783403ec799f226d7b6d9dde5ecd363f0b339.tar.gz chromium_src-e43783403ec799f226d7b6d9dde5ecd363f0b339.tar.bz2 |
Autofill deprecate unique_ids in favor of guids for PersonalDataManager
Final round of unique_id deprecation. These changes migrated web_database schemas for profiles and credit cards, clean up the web_dataservice interface, bring the personal_data_manager interface inline with the GUID interfaces for web_dataservice, convert remaining unit tests to be GUID-based, and some changes to platform UI code that used unique IDs for edits.
BUG=58813
TEST=WebDataServiceTest.*, WebDatabaseTest.*, WebDatabaseMigrationTest.*, PersonalDataManagerTest.*, AutoFillTest.*, AutoFillDialogControllerTest.AddNewProfile, AutoFillDialogControllerTest.AddNewCreditCard, AutoFillProfileTest.MergeWith, ProfileSyncServiceAutofillTest.*, TwoClientLiveAutofillSyncTest.*
Review URL: http://codereview.chromium.org/4388001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
25 files changed, 964 insertions, 1387 deletions
diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index 4c80100c..579f08c 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -32,7 +32,7 @@ class AutoFillTest : public InProcessBrowserTest { void SetUpProfile() { autofill_test::DisableSystemServices(browser()->profile()); - AutoFillProfile profile(string16(), 0); + AutoFillProfile profile; autofill_test::SetProfileInfo( &profile, "Office Space", "Milton", "C.", "Waddams", "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm index a3359db..13aeb4f 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm @@ -358,8 +358,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewProfile) { // New address should match. Don't compare labels. AutoFillProfile new_profile; new_profile.SetInfo(AutoFillType(NAME_FULL), ASCIIToUTF16("Don")); - observer_.profiles_[1].set_label(string16()); - ASSERT_EQ(observer_.profiles_[1], new_profile); + ASSERT_EQ(0, observer_.profiles_[1].Compare(new_profile)); } TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { @@ -387,8 +386,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { // New credit card should match. Don't compare labels. CreditCard new_credit_card; new_credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Don")); - observer_.credit_cards_[1].set_label(string16()); - ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); + ASSERT_EQ(0, observer_.credit_cards_[1].Compare(new_credit_card)); } TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) { diff --git a/chrome/browser/autofill/autofill_editor_gtk.cc b/chrome/browser/autofill/autofill_editor_gtk.cc index 05675ec..21f7ef3 100644 --- a/chrome/browser/autofill/autofill_editor_gtk.cc +++ b/chrome/browser/autofill/autofill_editor_gtk.cc @@ -201,7 +201,7 @@ class AutoFillProfileEditor { // If is_new_ is false this is the unique id of the profile the user is // editing. - const int profile_id_; + const std::string profile_guid_; AutoFillDialogObserver* observer_; @@ -231,7 +231,8 @@ AutoFillProfileEditor::AutoFillProfileEditor( Profile* profile, AutoFillProfile* auto_fill_profile) : is_new_(!auto_fill_profile ? true : false), - profile_id_(auto_fill_profile ? auto_fill_profile->unique_id() : 0), + profile_guid_(auto_fill_profile ? auto_fill_profile->guid() + : std::string()), observer_(observer), profile_(profile) { Init(); @@ -391,7 +392,7 @@ void AutoFillProfileEditor::ApplyEdits() { // The user is editing an existing profile, find it. for (std::vector<AutoFillProfile>::iterator i = profiles.begin(); i != profiles.end(); ++i) { - if (i->unique_id() == profile_id_) { + if (i->guid() == profile_guid_) { profile = &(*i); break; } @@ -570,7 +571,7 @@ class AutoFillCreditCardEditor { // If is_new_ is false this is the unique id of the credit card the user is // editing. - const int credit_card_id_; + const std::string credit_card_guid_; AutoFillDialogObserver* observer_; @@ -597,7 +598,7 @@ AutoFillCreditCardEditor::AutoFillCreditCardEditor( Profile* profile, CreditCard* credit_card) : is_new_(!credit_card ? true : false), - credit_card_id_(credit_card ? credit_card->unique_id() : 0), + credit_card_guid_(credit_card ? credit_card->guid() : std::string()), observer_(observer), profile_(profile), base_year_(0), @@ -747,7 +748,7 @@ void AutoFillCreditCardEditor::ApplyEdits() { // The user is editing an existing credit card, find it. for (std::vector<CreditCard>::iterator i = cards.begin(); i != cards.end(); ++i) { - if (i->unique_id() == credit_card_id_) { + if (i->guid() == credit_card_guid_) { card = &(*i); break; } diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc index 76ac13c..35be858 100644 --- a/chrome/browser/autofill/autofill_profile.cc +++ b/chrome/browser/autofill/autofill_profile.cc @@ -33,22 +33,13 @@ void InitPersonalInfo(FormGroupMap* personal_info) { } // namespace -AutoFillProfile::AutoFillProfile(const string16& label, int unique_id) - : label_(label), - unique_id_(unique_id), - guid_(guid::GenerateGUID()) { - InitPersonalInfo(&personal_info_); -} - AutoFillProfile::AutoFillProfile(const std::string& guid) - : unique_id_(0), - guid_(guid) { + : guid_(guid) { InitPersonalInfo(&personal_info_); } AutoFillProfile::AutoFillProfile() - : unique_id_(0), - guid_(guid::GenerateGUID()) { + : guid_(guid::GenerateGUID()) { InitPersonalInfo(&personal_info_); } @@ -158,7 +149,6 @@ void AutoFillProfile::SetInfo(const AutoFillType& type, const string16& value) { FormGroup* AutoFillProfile::Clone() const { AutoFillProfile* profile = new AutoFillProfile(); profile->label_ = label_; - profile->unique_id_ = unique_id(); profile->guid_ = guid(); FormGroupMap::const_iterator iter; @@ -355,7 +345,6 @@ bool AutoFillProfile::IsEmpty() const { void AutoFillProfile::operator=(const AutoFillProfile& source) { label_ = source.label_; - unique_id_ = source.unique_id_; guid_ = source.guid_; STLDeleteContainerPairSecondPointers(personal_info_.begin(), @@ -398,7 +387,7 @@ int AutoFillProfile::Compare(const AutoFillProfile& profile) const { } bool AutoFillProfile::operator==(const AutoFillProfile& profile) const { - if (label_ != profile.label_ || unique_id_ != profile.unique_id_) + if (label_ != profile.label_ || guid_ != profile.guid_) return false; return Compare(profile) == 0; @@ -441,8 +430,6 @@ std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile) { return os << UTF16ToUTF8(profile.Label()) << " " - << profile.unique_id() - << " " << profile.guid() << " " << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_FIRST))) diff --git a/chrome/browser/autofill/autofill_profile.h b/chrome/browser/autofill/autofill_profile.h index 91b08fe..ea83730 100644 --- a/chrome/browser/autofill/autofill_profile.h +++ b/chrome/browser/autofill/autofill_profile.h @@ -21,9 +21,6 @@ typedef std::map<FieldTypeGroup, FormGroup*> FormGroupMap; // to the requested form group type. class AutoFillProfile : public FormGroup { public: - // DEPRECATED - // TODO(dhollowa): Remove unique ID and label. http://crbug.com/58813 - AutoFillProfile(const string16& label, int unique_id); explicit AutoFillProfile(const std::string& guid); // For use in STL containers. @@ -51,9 +48,6 @@ class AutoFillProfile : public FormGroup { // profiles. See AdjustInferredLabels() further down for more description. virtual const string16 Label() const; - int unique_id() const { return unique_id_; } - void set_unique_id(int id) { unique_id_ = id; } - // This guid is the primary identifier for |AutoFillProfile| objects. const std::string guid() const { return guid_; } void set_guid(const std::string& guid) { guid_ = guid; } @@ -118,9 +112,6 @@ class AutoFillProfile : public FormGroup { // The label presented to the user when selecting a profile. string16 label_; - // The unique ID of this profile. - int unique_id_; - // The guid of this profile. std::string guid_; diff --git a/chrome/browser/autofill/autofill_profile_unittest.cc b/chrome/browser/autofill/autofill_profile_unittest.cc index a38e9c3..a290242 100644 --- a/chrome/browser/autofill/autofill_profile_unittest.cc +++ b/chrome/browser/autofill/autofill_profile_unittest.cc @@ -396,8 +396,8 @@ TEST(AutoFillProfileTest, MergeWith) { "constitutionalist@gmail.com", "United States Government", "Monticello", NULL, "Charlottesville", "Virginia", "22902", NULL, "12134759123", "19384284720"); - EXPECT_EQ(expected_a, *a); - EXPECT_EQ(expected_b, *b); + EXPECT_EQ(0, expected_a.Compare(*a)); + EXPECT_EQ(0, expected_b.Compare(*b)); } TEST(AutoFillProfileTest, Compare) { diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc index 5fe1e38..b4e92b8 100644 --- a/chrome/browser/autofill/credit_card.cc +++ b/chrome/browser/autofill/credit_card.cc @@ -126,26 +126,15 @@ std::string GetCreditCardType(const string16& number) { } // namespace -CreditCard::CreditCard(const string16& label, - int unique_id) - : expiration_month_(0), - expiration_year_(0), - label_(label), - unique_id_(unique_id), - guid_(guid::GenerateGUID()) { -} - CreditCard::CreditCard(const std::string& guid) : expiration_month_(0), expiration_year_(0), - unique_id_(0), guid_(guid) { } CreditCard::CreditCard() : expiration_month_(0), expiration_year_(0), - unique_id_(0), guid_(guid::GenerateGUID()) { } @@ -380,7 +369,6 @@ void CreditCard::operator=(const CreditCard& credit_card) { expiration_month_ = credit_card.expiration_month_; expiration_year_ = credit_card.expiration_year_; label_ = credit_card.label_; - unique_id_ = credit_card.unique_id_; guid_ = credit_card.guid_; } @@ -403,7 +391,7 @@ int CreditCard::Compare(const CreditCard& credit_card) const { } bool CreditCard::operator==(const CreditCard& credit_card) const { - if (label_ != credit_card.label_ || unique_id_ != credit_card.unique_id_) + if (label_ != credit_card.label_ || guid_ != credit_card.guid_) return false; return Compare(credit_card) == 0; @@ -615,8 +603,6 @@ std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { return os << UTF16ToUTF8(credit_card.Label()) << " " - << credit_card.unique_id() - << " " << credit_card.guid() << " " << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME))) diff --git a/chrome/browser/autofill/credit_card.h b/chrome/browser/autofill/credit_card.h index be7579f..91fc6ce 100644 --- a/chrome/browser/autofill/credit_card.h +++ b/chrome/browser/autofill/credit_card.h @@ -14,9 +14,6 @@ // A form group that stores credit card information. class CreditCard : public FormGroup { public: - // DEPRECATED - // TODO(dhollowa): Remove unique ID and label. http://crbug.com/58813 - CreditCard(const string16& label, int unique_id); explicit CreditCard(const std::string& guid); // For use in STL containers. @@ -46,9 +43,6 @@ class CreditCard : public FormGroup { const string16& type() const { return type_; } - int unique_id() const { return unique_id_; } - void set_unique_id(int id) { unique_id_ = id; } - // The guid is the primary identifier for |CreditCard| objects. const std::string guid() const { return guid_; } void set_guid(const std::string& guid) { guid_ = guid; } @@ -149,9 +143,6 @@ class CreditCard : public FormGroup { // This is the display name of the card set by the user, e.g., Amazon Visa. string16 label_; - // The unique ID of this credit card. - int unique_id_; - // The guid of this credit card. std::string guid_; }; diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc index 1ca1cf1..1fb398e 100644 --- a/chrome/browser/autofill/personal_data_manager.cc +++ b/chrome/browser/autofill/personal_data_manager.cc @@ -53,6 +53,51 @@ T* address_of(T& v) { return &v; } +bool FindInProfilesByGUID(const std::vector<AutoFillProfile>& profiles, + const std::string& guid) { + for (std::vector<AutoFillProfile>::const_iterator iter = profiles.begin(); + iter != profiles.end(); + ++iter) { + if (iter->guid() == guid) + return true; + } + return false; +} + +bool FindInScopedProfilesByGUID(const ScopedVector<AutoFillProfile>& profiles, + const std::string& guid) { + for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); + iter != profiles.end(); + ++iter) { + if ((*iter)->guid() == guid) + return true; + } + return false; +} + +bool FindInCreditCardsByGUID(const std::vector<CreditCard>& credit_cards, + const std::string& guid) { + for (std::vector<CreditCard>::const_iterator iter = credit_cards.begin(); + iter != credit_cards.end(); + ++iter) { + if (iter->guid() == guid) + return true; + } + return false; +} + +bool FindInScopedCreditCardsByGUID( + const ScopedVector<CreditCard>& credit_cards, const std::string& guid) { + for (std::vector<CreditCard*>::const_iterator iter = + credit_cards.begin(); + iter != credit_cards.end(); + ++iter) { + if ((*iter)->guid() == guid) + return true; + } + return false; +} + } // namespace PersonalDataManager::~PersonalDataManager() { @@ -126,14 +171,13 @@ void PersonalDataManager::RemoveObserver( bool PersonalDataManager::ImportFormData( const std::vector<FormStructure*>& form_structures, AutoFillManager* autofill_manager) { - AutoLock lock(unique_ids_lock_); // Parse the form and construct a profile based on the information that is // possible to import. int importable_fields = 0; int importable_credit_card_fields = 0; - imported_profile_.reset(new AutoFillProfile(string16(), 0)); + imported_profile_.reset(new AutoFillProfile); // TODO(jhawkins): Use a hash of the CC# instead of a list of unique IDs? - imported_credit_card_.reset(new CreditCard(string16(), 0)); + imported_credit_card_.reset(new CreditCard); bool billing_address_info = false; std::vector<FormStructure*>::const_iterator iter; @@ -212,17 +256,8 @@ bool PersonalDataManager::ImportFormData( if (importable_credit_card_fields == 0) imported_credit_card_.reset(); - { - // We're now done with the unique IDs, and SaveImportedProfile() needs the - // lock, so release it. - AutoUnlock unlock(unique_ids_lock_); - - // We always save imported profiles. - SaveImportedProfile(); - - // We never save an imported credit card at this point. If there was one we - // found, we'll be asked to save it later once the user gives their OK. - } + // We always save imported profiles. + SaveImportedProfile(); return true; } @@ -246,66 +281,43 @@ void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { std::mem_fun_ref(&AutoFillProfile::IsEmpty)), profiles->end()); + // Ensure that profile labels are up to date. Currently, sync relies on + // labels to identify a profile. + // TODO(dhollowa): We need to deprecate labels and update the way sync + // identifies profiles. + std::vector<AutoFillProfile*> profile_pointers(profiles->size()); + std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), + address_of<AutoFillProfile>); + AutoFillProfile::AdjustInferredLabels(&profile_pointers); + WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); if (!wds) return; - AutoLock lock(unique_ids_lock_); - - // Remove the unique IDs of the new set of profiles from the unique ID set. - for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); - iter != profiles->end(); ++iter) { - if (iter->unique_id() != 0) - unique_profile_ids_.erase(iter->unique_id()); - } - - // Any remaining IDs are not in the new profile list and should be removed - // from the web database. - for (std::set<int>::iterator iter = unique_profile_ids_.begin(); - iter != unique_profile_ids_.end(); ++iter) { - wds->RemoveAutoFillProfile(*iter); - - // Also remove these IDs from the total set of unique IDs. - unique_ids_.erase(*iter); + // Any profiles that are not in the new profile list should be removed from + // the web database. + for (std::vector<AutoFillProfile*>::const_iterator iter = + web_profiles_.begin(); + iter != web_profiles_.end(); ++iter) { + if (!FindInProfilesByGUID(*profiles, (*iter)->guid())) + wds->RemoveAutoFillProfileGUID((*iter)->guid()); } - // Clear the unique IDs. The set of unique IDs is updated for each profile - // added to |web_profiles_| below. - unique_profile_ids_.clear(); - - // Update the web database with the existing profiles. We need to handle - // these first so that |unique_profile_ids_| is reset with the IDs of the - // existing profiles; otherwise, new profiles added before older profiles can - // take their unique ID. + // Update the web database with the existing profiles. for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); iter != profiles->end(); ++iter) { - if (iter->unique_id() != 0) { - unique_profile_ids_.insert(iter->unique_id()); - wds->UpdateAutoFillProfile(*iter); - } + if (FindInScopedProfilesByGUID(web_profiles_, iter->guid())) + wds->UpdateAutoFillProfileGUID(*iter); } - // Ensure that profile labels are up to date. Currently, sync relies on - // labels to identify a profile. - // TODO(dhollowa): We need to deprecate labels and update the way sync - // identifies profiles. - std::vector<AutoFillProfile*> profile_pointers(profiles->size()); - std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), - address_of<AutoFillProfile>); - AutoFillProfile::AdjustInferredLabels(&profile_pointers); - // Add the new profiles to the web database. for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); iter != profiles->end(); ++iter) { - // The profile was added by the AutoFill dialog, so we need to set the - // unique ID. This also means we need to add this profile to the web - // database. - if (iter->unique_id() == 0) { - iter->set_unique_id(CreateNextUniqueIDFor(&unique_profile_ids_)); - wds->AddAutoFillProfile(*iter); - } + if (!FindInScopedProfilesByGUID(web_profiles_, iter->guid())) + wds->AddAutoFillProfileGUID(*iter); } + // Copy in the new profiles. web_profiles_.reset(); for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); iter != profiles->end(); ++iter) { @@ -315,15 +327,7 @@ void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { // Read our writes to ensure consistency with the database. Refresh(); - { - // We're now done with the unique IDs, and observers might call into a - // method that needs the lock, so release it. For example, observers on Mac - // might call profiles() which calls LoadAuxiliaryProfiles(), which needs - // the lock. - AutoUnlock unlock(unique_ids_lock_); - - FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); - } + FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); } void PersonalDataManager::SetCreditCards( @@ -344,54 +348,29 @@ void PersonalDataManager::SetCreditCards( if (!wds) return; - AutoLock lock(unique_ids_lock_); - - // Remove the unique IDs of the new set of credit cards from the unique ID - // set. - for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); - iter != credit_cards->end(); ++iter) { - if (iter->unique_id() != 0) - unique_creditcard_ids_.erase(iter->unique_id()); - } - - // Any remaining IDs are not in the new credit card list and should be removed - // from the web database. - for (std::set<int>::iterator iter = unique_creditcard_ids_.begin(); - iter != unique_creditcard_ids_.end(); ++iter) { - wds->RemoveCreditCard(*iter); - - // Also remove these IDs from the total set of unique IDs. - unique_ids_.erase(*iter); + // Any credit cards that are not in the new credit card list should be + // removed. + for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); + iter != credit_cards_.end(); ++iter) { + if (!FindInCreditCardsByGUID(*credit_cards, (*iter)->guid())) + wds->RemoveCreditCardGUID((*iter)->guid()); } - // Clear the unique IDs. The set of unique IDs is updated for each credit - // card added to |credit_cards_| below. - unique_creditcard_ids_.clear(); - - // Update the web database with the existing credit cards. We need to handle - // these first so that |unique_creditcard_ids_| is reset with the IDs of the - // existing credit cards; otherwise, new credit cards added before older - // credit cards can take their unique ID. + // Update the web database with the existing credit cards. for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); iter != credit_cards->end(); ++iter) { - if (iter->unique_id() != 0) { - unique_creditcard_ids_.insert(iter->unique_id()); - wds->UpdateCreditCard(*iter); - } + if (FindInScopedCreditCardsByGUID(credit_cards_, iter->guid())) + wds->UpdateCreditCardGUID(*iter); } // Add the new credit cards to the web database. for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); iter != credit_cards->end(); ++iter) { - // The credit card was added by the AutoFill dialog, so we need to set the - // unique ID. This also means we need to add this credit card to the web - // database. - if (iter->unique_id() == 0) { - iter->set_unique_id(CreateNextUniqueIDFor(&unique_creditcard_ids_)); - wds->AddCreditCard(*iter); - } + if (!FindInScopedCreditCardsByGUID(credit_cards_, iter->guid())) + wds->AddCreditCardGUID(*iter); } + // Copy in the new credit cards. credit_cards_.reset(); for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); iter != credit_cards->end(); ++iter) { @@ -401,15 +380,7 @@ void PersonalDataManager::SetCreditCards( // Read our writes to ensure consistency with the database. Refresh(); - { - // We're now done with the unique IDs, and observers might call into a - // method that needs the lock, so release it. For example, observers on Mac - // might call profiles() which calls LoadAuxiliaryProfiles(), which needs - // the lock. - AutoUnlock unlock(unique_ids_lock_); - - FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); - } + FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); } // TODO(jhawkins): Refactor SetProfiles so this isn't so hacky. @@ -459,11 +430,6 @@ void PersonalDataManager::UpdateProfile(const AutoFillProfile& profile) { for (std::vector<AutoFillProfile*>::iterator iter = web_profiles_->begin(); iter != web_profiles_->end(); ++iter) { 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; @@ -473,7 +439,7 @@ void PersonalDataManager::UpdateProfile(const AutoFillProfile& profile) { // Ensure that profile labels are up to date. AutoFillProfile::AdjustInferredLabels(&web_profiles_.get()); - wds->UpdateAutoFillProfile(profile); + wds->UpdateAutoFillProfileGUID(profile); FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); } @@ -523,18 +489,13 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { for (std::vector<CreditCard*>::iterator iter = credit_cards_->begin(); iter != credit_cards_->end(); ++iter) { 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; } } - wds->UpdateCreditCard(credit_card); + wds->UpdateCreditCardGUID(credit_card); FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); } @@ -638,9 +599,8 @@ AutoFillProfile* PersonalDataManager::CreateNewEmptyAutoFillProfileForDBThread( const string16& label) { // See comment in header for thread details. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); - AutoLock lock(unique_ids_lock_); - AutoFillProfile* p = new AutoFillProfile(label, - CreateNextUniqueIDFor(&unique_profile_ids_)); + AutoFillProfile* p = new AutoFillProfile; + p->set_label(label); return p; } @@ -662,18 +622,6 @@ void PersonalDataManager::Init(Profile* profile) { LoadCreditCards(); } -int PersonalDataManager::CreateNextUniqueIDFor(std::set<int>* id_set) { - // Profile IDs MUST start at 1 to allow 0 as an error value when reading - // the ID from the WebDB (see LoadData()). - unique_ids_lock_.AssertAcquired(); - int id = 1; - while (unique_ids_.count(id) != 0) - ++id; - unique_ids_.insert(id); - id_set->insert(id); - return id; -} - void PersonalDataManager::LoadProfiles() { WebDataService* web_data_service = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); @@ -710,10 +658,8 @@ void PersonalDataManager::LoadCreditCards() { void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, const WDTypedResult* result) { DCHECK_EQ(pending_profiles_query_, h); - pending_profiles_query_ = 0; - AutoLock lock(unique_ids_lock_); - unique_profile_ids_.clear(); + pending_profiles_query_ = 0; web_profiles_.reset(); const WDResult<std::vector<AutoFillProfile*> >* r = @@ -722,8 +668,6 @@ void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, std::vector<AutoFillProfile*> profiles = r->GetValue(); for (std::vector<AutoFillProfile*>::iterator iter = profiles.begin(); iter != profiles.end(); ++iter) { - unique_profile_ids_.insert((*iter)->unique_id()); - unique_ids_.insert((*iter)->unique_id()); web_profiles_.push_back(*iter); } } @@ -731,10 +675,8 @@ void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, void PersonalDataManager::ReceiveLoadedCreditCards( WebDataService::Handle h, const WDTypedResult* result) { DCHECK_EQ(pending_creditcards_query_, h); - pending_creditcards_query_ = 0; - AutoLock lock(unique_ids_lock_); - unique_creditcard_ids_.clear(); + pending_creditcards_query_ = 0; credit_cards_.reset(); const WDResult<std::vector<CreditCard*> >* r = @@ -743,8 +685,6 @@ void PersonalDataManager::ReceiveLoadedCreditCards( std::vector<CreditCard*> credit_cards = r->GetValue(); for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); iter != credit_cards.end(); ++iter) { - unique_creditcard_ids_.insert((*iter)->unique_id()); - unique_ids_.insert((*iter)->unique_id()); credit_cards_.push_back(*iter); } } diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index 5499903..d73bc7c 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -82,8 +82,7 @@ class PersonalDataManager void SaveImportedCreditCard(); // Sets |web_profiles_| to the contents of |profiles| and updates the web - // database by adding, updating and removing profiles. Sets the unique ID of - // newly-added profiles. + // database by adding, updating and removing profiles. // // The relationship between this and Refresh is subtle. // A call to |SetProfiles| could include out-of-date data that may conflict @@ -96,8 +95,7 @@ class PersonalDataManager void SetProfiles(std::vector<AutoFillProfile>* profiles); // Sets |credit_cards_| to the contents of |credit_cards| and updates the web - // database by adding, updating and removing credit cards. Sets the unique - // ID of newly-added profiles. + // database by adding, updating and removing credit cards. void SetCreditCards(std::vector<CreditCard>* credit_cards); // Adds |profile| to the web database. @@ -147,7 +145,7 @@ class PersonalDataManager return credit_cards_.get(); } - // Creates a profile labeled |label|, with it's own locally unique ID. + // Creates a profile labeled |label|. // This must be called on the DB thread with the expectation that the // returned form will be synchronously persisted to the WebDatabase. See // Refresh and SetProfiles for details. @@ -161,15 +159,6 @@ class PersonalDataManager // engine processed a change from the cloud, we will learn of these as a // result of this call. // - // Note that there is a subtle relationship with ID generation. IDs can be - // generated by CreateNewEmptyAutoFillProfileForDBThread (in a synchronized - // way), meaning that it is possible we are aware of this new profile only - // by having it's ID tracked in unique_profile_ids_ for a period of time. - // Because the expectation of that call is that the ID we generate will be - // synchronously persisted to the DB, we are guaranteed to read it via - // the next call to Refresh. It could get deleted before we - // manage, but this is safe (we just hold on to the ID a bit longer). - // // Also see SetProfile for more details. virtual void Refresh(); @@ -190,12 +179,6 @@ class PersonalDataManager // Returns the profile of the tab contents. Profile* profile(); - // This will create and reserve a new unique ID for the id pool |id_set|. - // The |id_set| is typically |unique_profile_ids_| or - // |unique_creditcard_ids_|. The global pool |unique_ids_| is used to ensure - // uniqueness of ids across all pools. The new (next) unique id is returned. - int CreateNextUniqueIDFor(std::set<int>* id_set); - // Loads the saved profiles from the web database. virtual void LoadProfiles(); @@ -234,25 +217,6 @@ class PersonalDataManager // True if personal data has been loaded from the web database. bool is_data_loaded_; - // The set of already created unique IDs, shared by both profiles and credit - // cards, since IDs must be unique among the two groups. - std::set<int> unique_ids_; - - // The set of already created unique profile IDs, used to create a new unique - // profile ID. - std::set<int> unique_profile_ids_; - - // The set of already created unique profile IDs for auxiliary profiles, used - // to create a new unique auxiliary profile ID. - std::set<int> unique_auxiliary_profile_ids_; - - // The set of already created unique credit card IDs, used to create a new - // unique credit card ID. - std::set<int> unique_creditcard_ids_; - - // Protects unique_*_ids_ members. - Lock unique_ids_lock_; - // The loaded web profiles. ScopedVector<AutoFillProfile> web_profiles_; diff --git a/chrome/browser/autofill/personal_data_manager_mac.mm b/chrome/browser/autofill/personal_data_manager_mac.mm index 36b6efc..4a9fb25 100644 --- a/chrome/browser/autofill/personal_data_manager_mac.mm +++ b/chrome/browser/autofill/personal_data_manager_mac.mm @@ -256,28 +256,6 @@ void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers( // Populate |auxiliary_profiles_| with the Address Book data. void PersonalDataManager::LoadAuxiliaryProfiles() { - AutoLock lock(unique_ids_lock_); - - // Before loading new auxiliary profiles remove the unique ids from the - // id pools. The |GetAddressBookMeCard()| call below clears the - // |auxiliary_profiles_|. - unique_auxiliary_profile_ids_.clear(); - for (ScopedVector<AutoFillProfile>::iterator iter - = auxiliary_profiles_.begin(); - iter != auxiliary_profiles_.end(); ++iter) { - if ((*iter)->unique_id() != 0) { - unique_ids_.erase((*iter)->unique_id()); - } - } - AuxiliaryProfilesImpl impl(&auxiliary_profiles_); impl.GetAddressBookMeCard(); - - // For newly fetched auxiliary profiles, ensure that we have unique ids set. - for (ScopedVector<AutoFillProfile>::iterator iter - = auxiliary_profiles_.begin(); - iter != auxiliary_profiles_.end(); ++iter) { - (*iter)->set_unique_id( - CreateNextUniqueIDFor(&unique_auxiliary_profile_ids_)); - } } diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc index 1317f82..2d2d94f 100644 --- a/chrome/browser/autofill/personal_data_manager_unittest.cc +++ b/chrome/browser/autofill/personal_data_manager_unittest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/autofill/form_structure.h" #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/browser_thread.h" +#include "chrome/browser/guid.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/password_manager/encryptor.h" #include "chrome/common/notification_details.h" @@ -72,13 +73,6 @@ class PersonalDataManagerTest : public testing::Test { personal_data_->SetObserver(&personal_data_observer_); } - AutoFillProfile* MakeProfile() { - AutoLock lock(personal_data_->unique_ids_lock_); - return new AutoFillProfile(string16(), - personal_data_->CreateNextUniqueIDFor( - &personal_data_->unique_profile_ids_)); - } - MessageLoopForUI message_loop_; BrowserThread ui_thread_; BrowserThread db_thread_; @@ -91,19 +85,19 @@ class PersonalDataManagerTest : public testing::Test { // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. TEST_F(PersonalDataManagerTest, SetProfiles) { - AutoFillProfile profile0(string16(), 0); + AutoFillProfile profile0; autofill_test::SetProfileInfo(&profile0, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); - AutoFillProfile profile1(string16(), 0); + AutoFillProfile profile1; autofill_test::SetProfileInfo(&profile1, "Home", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", "US", "19482937549", "13502849239"); - AutoFillProfile profile2(string16(), 0); + AutoFillProfile profile2; autofill_test::SetProfileInfo(&profile2, "Work", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -123,18 +117,10 @@ TEST_F(PersonalDataManagerTest, SetProfiles) { update.push_back(profile1); personal_data_->SetProfiles(&update); - // The PersonalDataManager will update the unique IDs when saving the - // profiles, so we have to update the expectations. - // Same for labels. - profile0.set_unique_id(update[0].unique_id()); - profile1.set_unique_id(update[1].unique_id()); - profile0.set_label(update[0].Label()); - profile1.set_label(update[1].Label()); - const std::vector<AutoFillProfile*>& results1 = personal_data_->profiles(); ASSERT_EQ(2U, results1.size()); - EXPECT_EQ(profile0, *results1.at(0)); - EXPECT_EQ(profile1, *results1.at(1)); + EXPECT_EQ(0, profile0.Compare(*results1.at(0))); + EXPECT_EQ(0, profile1.Compare(*results1.at(1))); // Three operations in one: // - Update profile0 @@ -146,20 +132,10 @@ TEST_F(PersonalDataManagerTest, SetProfiles) { update.push_back(profile2); personal_data_->SetProfiles(&update); - // Set the expected unique ID for profile2. - // Same for labels. - profile0.set_label(update[0].Label()); - profile2.set_unique_id(update[1].unique_id()); - profile2.set_label(update[1].Label()); - - // AutoFillProfile IDs are re-used, so the third profile to be added will have - // a unique ID that matches the old unique ID of the removed profile1, even - // though that ID has already been used. const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); ASSERT_EQ(2U, results2.size()); - EXPECT_EQ(profile0, *results2.at(0)); - EXPECT_EQ(profile2, *results2.at(1)); - EXPECT_EQ(profile1.unique_id(), profile2.unique_id()); + EXPECT_EQ(0, profile0.Compare(*results2.at(0))); + EXPECT_EQ(0, profile2.Compare(*results2.at(1))); // Reset the PersonalDataManager. This tests that the personal data was saved // to the web database, and that we can load the profiles from the web @@ -177,23 +153,21 @@ TEST_F(PersonalDataManagerTest, SetProfiles) { // Verify that we've loaded the profiles from the web database. const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); ASSERT_EQ(2U, results3.size()); - profile0.set_label(results3.at(0)->Label()); - EXPECT_EQ(profile0, *results3.at(0)); - profile2.set_label(results3.at(1)->Label()); - EXPECT_EQ(profile2, *results3.at(1)); + EXPECT_EQ(0, profile0.Compare(*results3.at(0))); + EXPECT_EQ(0, profile2.Compare(*results3.at(1))); } // TODO(jhawkins): Test SetCreditCards w/out a WebDataService in the profile. TEST_F(PersonalDataManagerTest, SetCreditCards) { - CreditCard creditcard0(string16(), 0); + CreditCard creditcard0; autofill_test::SetCreditCardInfo(&creditcard0, "Corporate", "John Dillinger", "423456789012" /* Visa */, "01", "2010"); - CreditCard creditcard1(string16(), 0); + CreditCard creditcard1; autofill_test::SetCreditCardInfo(&creditcard1, "Personal", "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); - CreditCard creditcard2(string16(), 0); + CreditCard creditcard2; autofill_test::SetCreditCardInfo(&creditcard2, "Savings", "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); @@ -211,18 +185,10 @@ TEST_F(PersonalDataManagerTest, SetCreditCards) { update.push_back(creditcard1); personal_data_->SetCreditCards(&update); - // The PersonalDataManager will update the unique IDs when saving the - // credit cards, so we have to update the expectations. - // Same for labels. - creditcard0.set_unique_id(update[0].unique_id()); - creditcard1.set_unique_id(update[1].unique_id()); - creditcard0.set_label(update[0].Label()); - creditcard1.set_label(update[1].Label()); - const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); ASSERT_EQ(2U, results1.size()); - EXPECT_EQ(creditcard0, *results1.at(0)); - EXPECT_EQ(creditcard1, *results1.at(1)); + EXPECT_EQ(0, creditcard0.Compare(*results1.at(0))); + EXPECT_EQ(0, creditcard1.Compare(*results1.at(1))); // Three operations in one: // - Update creditcard0 @@ -234,19 +200,10 @@ TEST_F(PersonalDataManagerTest, SetCreditCards) { update.push_back(creditcard2); personal_data_->SetCreditCards(&update); - // Set the expected unique ID for creditcard2. - // Same for labels. - creditcard2.set_unique_id(update[1].unique_id()); - creditcard2.set_label(update[1].Label()); - - // CreditCard IDs are re-used, so the third credit card to be added will have - // a unique ID that matches the old unique ID of the removed creditcard1, even - // though that ID has already been used. const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); ASSERT_EQ(2U, results2.size()); EXPECT_EQ(creditcard0, *results2.at(0)); EXPECT_EQ(creditcard2, *results2.at(1)); - EXPECT_EQ(creditcard2.unique_id(), creditcard1.unique_id()); // Reset the PersonalDataManager. This tests that the personal data was saved // to the web database, and that we can load the credit cards from the web @@ -269,23 +226,23 @@ TEST_F(PersonalDataManagerTest, SetCreditCards) { } TEST_F(PersonalDataManagerTest, SetProfilesAndCreditCards) { - AutoFillProfile profile0(string16(), 0); + AutoFillProfile profile0; autofill_test::SetProfileInfo(&profile0, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); - AutoFillProfile profile1(string16(), 0); + AutoFillProfile profile1; autofill_test::SetProfileInfo(&profile1, "Home", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", "US", "19482937549", "13502849239"); - CreditCard creditcard0(string16(), 0); + CreditCard creditcard0; autofill_test::SetCreditCardInfo(&creditcard0, "Corporate", "John Dillinger", "423456789012" /* Visa */, "01", "2010"); - CreditCard creditcard1(string16(), 0); + CreditCard creditcard1; autofill_test::SetCreditCardInfo(&creditcard1, "Personal", "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); @@ -304,18 +261,10 @@ TEST_F(PersonalDataManagerTest, SetProfilesAndCreditCards) { update.push_back(profile1); personal_data_->SetProfiles(&update); - // The PersonalDataManager will update the unique IDs when saving the - // profiles, so we have to update the expectations. - // Same for labels. - profile0.set_unique_id(update[0].unique_id()); - profile1.set_unique_id(update[1].unique_id()); - profile0.set_label(update[0].Label()); - profile1.set_label(update[1].Label()); - const std::vector<AutoFillProfile*>& results1 = personal_data_->profiles(); ASSERT_EQ(2U, results1.size()); - EXPECT_EQ(profile0, *results1.at(0)); - EXPECT_EQ(profile1, *results1.at(1)); + EXPECT_EQ(0, profile0.Compare(*results1.at(0))); + EXPECT_EQ(0, profile1.Compare(*results1.at(1))); // Add two test credit cards to the database. std::vector<CreditCard> update_cc; @@ -323,33 +272,26 @@ TEST_F(PersonalDataManagerTest, SetProfilesAndCreditCards) { update_cc.push_back(creditcard1); personal_data_->SetCreditCards(&update_cc); - // The PersonalDataManager will update the unique IDs when saving the - // credit cards, so we have to update the expectations. - // Same for labels. - creditcard0.set_unique_id(update_cc[0].unique_id()); - creditcard1.set_unique_id(update_cc[1].unique_id()); - creditcard0.set_label(update_cc[0].Label()); - creditcard1.set_label(update_cc[1].Label()); const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); ASSERT_EQ(2U, results2.size()); EXPECT_EQ(creditcard0, *results2.at(0)); EXPECT_EQ(creditcard1, *results2.at(1)); - // Determine uniqueness by inserting all of the IDs into a set and verifying - // the size of the set matches the number of IDs. - std::set<int> ids; - ids.insert(profile0.unique_id()); - ids.insert(profile1.unique_id()); - ids.insert(creditcard0.unique_id()); - ids.insert(creditcard1.unique_id()); - EXPECT_EQ(4U, ids.size()); + // Determine uniqueness by inserting all of the GUIDs into a set and verifying + // the size of the set matches the number of GUIDs. + std::set<std::string> guids; + guids.insert(profile0.guid()); + guids.insert(profile1.guid()); + guids.insert(creditcard0.guid()); + guids.insert(creditcard1.guid()); + EXPECT_EQ(4U, guids.size()); } // Test care for 50047. Makes sure that unique_ids_ is populated correctly on // load. TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { - AutoFillProfile profile0(string16(), 0); + AutoFillProfile profile0; autofill_test::SetProfileInfo(&profile0, "", "y", "", "", "", "", "", "", "", "", "", "", "", ""); @@ -378,7 +320,7 @@ TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { ASSERT_EQ(1U, results2.size()); // Add a new profile. - AutoFillProfile profile1(string16(), 0); + AutoFillProfile profile1; autofill_test::SetProfileInfo(&profile1, "", "y", "", "", "", "", "", "", "", "", "", "", "", ""); update.clear(); @@ -390,13 +332,13 @@ TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { // which is an invalid id). const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); ASSERT_EQ(2U, results3.size()); - EXPECT_NE(results3[0]->unique_id(), results3[1]->unique_id()); - EXPECT_NE(0, results3[0]->unique_id()); - EXPECT_NE(0, results3[1]->unique_id()); + EXPECT_NE(results3[0]->guid(), results3[1]->guid()); + EXPECT_TRUE(guid::IsValidGUID(results3[0]->guid())); + EXPECT_TRUE(guid::IsValidGUID(results3[1]->guid())); } TEST_F(PersonalDataManagerTest, SetEmptyProfile) { - AutoFillProfile profile0(string16(), 0); + AutoFillProfile profile0; autofill_test::SetProfileInfo(&profile0, "", "", "", "", "", "", "", "", "", "", "", "", "", ""); @@ -436,7 +378,7 @@ TEST_F(PersonalDataManagerTest, SetEmptyProfile) { } TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { - CreditCard creditcard0(string16(), 0); + CreditCard creditcard0; autofill_test::SetCreditCardInfo(&creditcard0, "", "", "", "", ""); // This will verify that the web database has been loaded and the notification @@ -475,13 +417,13 @@ TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { } TEST_F(PersonalDataManagerTest, Refresh) { - AutoFillProfile profile0(string16(), 0); + AutoFillProfile profile0; autofill_test::SetProfileInfo(&profile0, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); - AutoFillProfile profile1(string16(), 0); + AutoFillProfile profile1; autofill_test::SetProfileInfo(&profile1, "Home", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", @@ -498,9 +440,7 @@ TEST_F(PersonalDataManagerTest, Refresh) { update.push_back(profile1); personal_data_->SetProfiles(&update); - profile0.set_unique_id(update[0].unique_id()); - profile1.set_unique_id(update[1].unique_id()); - // Labels depend on other profiles in the list - update labels manually/ + // Labels depend on other profiles in the list - update labels manually. std::vector<AutoFillProfile *> profile_pointers; profile_pointers.push_back(&profile0); profile_pointers.push_back(&profile1); @@ -517,7 +457,7 @@ TEST_F(PersonalDataManagerTest, Refresh) { EXPECT_EQ(profile0, *results1.at(0)); EXPECT_EQ(profile1, *results1.at(1)); - scoped_ptr<AutoFillProfile> profile2(MakeProfile()); + scoped_ptr<AutoFillProfile> profile2(new AutoFillProfile); autofill_test::SetProfileInfo(profile2.get(), "Work", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -529,7 +469,7 @@ TEST_F(PersonalDataManagerTest, Refresh) { WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); ASSERT_TRUE(wds); - wds->AddAutoFillProfile(*profile2.get()); + wds->AddAutoFillProfileGUID(*profile2.get()); personal_data_->Refresh(); @@ -545,8 +485,8 @@ TEST_F(PersonalDataManagerTest, Refresh) { EXPECT_EQ(profile1, *results2.at(1)); EXPECT_EQ(*profile2.get(), *results2.at(2)); - wds->RemoveAutoFillProfile(profile1.unique_id()); - wds->RemoveAutoFillProfile(profile2->unique_id()); + wds->RemoveAutoFillProfileGUID(profile1.guid()); + wds->RemoveAutoFillProfileGUID(profile2->guid()); // Before telling the PDM to refresh, simulate an edit to one of the profiles // via a SetProfile update (this would happen if the AutoFill window was @@ -594,28 +534,33 @@ TEST_F(PersonalDataManagerTest, ImportFormData) { MessageLoop::current()->Run(); - AutoFillProfile expected(string16(), 1); + AutoFillProfile expected; autofill_test::SetProfileInfo(&expected, NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); const std::vector<AutoFillProfile*>& results = personal_data_->profiles(); ASSERT_EQ(1U, results.size()); - expected.set_label(results[0]->Label()); - EXPECT_EQ(expected, *results[0]); + EXPECT_EQ(0, expected.Compare(*results[0])); } TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { - CreditCard credit_card0(ASCIIToUTF16("Home"), 0); + CreditCard credit_card0; + credit_card0.set_label(ASCIIToUTF16("Home")); credit_card0.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("John")); - CreditCard credit_card1(ASCIIToUTF16("Home"), 0); + CreditCard credit_card1; + credit_card1.set_label(ASCIIToUTF16("Home")); credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Paul")); - CreditCard credit_card2(ASCIIToUTF16("Home"), 0); + CreditCard credit_card2; + credit_card2.set_label(ASCIIToUTF16("Home")); credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Ringo")); - CreditCard credit_card3(ASCIIToUTF16("NotHome"), 0); + CreditCard credit_card3; + credit_card3.set_label(ASCIIToUTF16("NotHome")); credit_card3.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Other")); - CreditCard credit_card4(ASCIIToUTF16("Work"), 0); + CreditCard credit_card4; + credit_card4.set_label(ASCIIToUTF16("Work")); credit_card4.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Ozzy")); - CreditCard credit_card5(ASCIIToUTF16("Work"), 0); + CreditCard credit_card5; + credit_card5.set_label(ASCIIToUTF16("Work")); credit_card5.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Dio")); // This will verify that the web database has been loaded and the notification @@ -686,14 +631,13 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) { MessageLoop::current()->Run(); scoped_ptr<AutoFillProfile> expected( - new AutoFillProfile(string16(), 1)); + new AutoFillProfile); autofill_test::SetProfileInfo(expected.get(), NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); const std::vector<AutoFillProfile*>& results = personal_data_->profiles(); ASSERT_EQ(1U, results.size()); - expected->set_label(results[0]->Label()); - EXPECT_EQ(*expected, *results[0]); + EXPECT_EQ(0, expected->Compare(*results[0])); // Now create a completely different profile. form.reset(new FormData); @@ -721,19 +665,17 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) { const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); ASSERT_EQ(2U, results2.size()); - expected.reset(new AutoFillProfile(string16(), 1)); + expected.reset(new AutoFillProfile); autofill_test::SetProfileInfo(expected.get(), NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - expected->set_label(results2[0]->Label()); - EXPECT_EQ(*expected, *results2[0]); + EXPECT_EQ(0, expected->Compare(*results2[0])); - expected.reset(new AutoFillProfile(string16(), 2)); + expected.reset(new AutoFillProfile); autofill_test::SetProfileInfo(expected.get(), NULL, "John", NULL, "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - expected->set_label(results2[1]->Label()); - EXPECT_EQ(*expected, *results2[1]); + EXPECT_EQ(0, expected->Compare(*results2[1])); // Submit a form with new data for the first profile. form.reset(new FormData); @@ -770,17 +712,15 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) { const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); ASSERT_EQ(2U, results3.size()); - expected.reset(new AutoFillProfile(string16(), 1)); + expected.reset(new AutoFillProfile); autofill_test::SetProfileInfo(expected.get(), NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL); - expected->set_label(results3[0]->Label()); - EXPECT_EQ(*expected, *results3[0]); + EXPECT_EQ(0, expected->Compare(*results3[0])); - expected.reset(new AutoFillProfile(string16(), 2)); + expected.reset(new AutoFillProfile); autofill_test::SetProfileInfo(expected.get(), NULL, "John", NULL, "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - expected->set_label(results3[1]->Label()); - EXPECT_EQ(*expected, *results3[1]); + EXPECT_EQ(0, expected->Compare(*results3[1])); } diff --git a/chrome/browser/sync/glue/autofill_change_processor.cc b/chrome/browser/sync/glue/autofill_change_processor.cc index a2a8db4..d93f25d 100644 --- a/chrome/browser/sync/glue/autofill_change_processor.cc +++ b/chrome/browser/sync/glue/autofill_change_processor.cc @@ -498,7 +498,7 @@ void AutofillChangeProcessor::ApplySyncAutofillProfileDelete( NOTREACHED() << "Couldn't retrieve autofill profile: " << label; return; } - if (!web_database_->RemoveAutoFillProfile(p->unique_id())) { + if (!web_database_->RemoveAutoFillProfile(p->guid())) { NOTREACHED() << "Couldn't remove autofill profile: " << label; return; } diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index e8e4ec00..179f438 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -265,7 +265,8 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { } entries->push_back(AutofillEntry(key, timestamps)); } else if (autofill.has_profile()) { - AutoFillProfile p(UTF8ToUTF16(autofill.profile().label()), 0); + AutoFillProfile p; + p.set_label(UTF8ToUTF16(autofill.profile().label())); AutofillModelAssociator::OverwriteProfileWithServerData(&p, autofill.profile()); profiles->push_back(p); @@ -528,7 +529,7 @@ TEST_F(ProfileSyncServiceAutofillTest, HasMixedNativeEmptySync) { std::vector<AutoFillProfile*> profiles; std::vector<AutoFillProfile> expected_profiles; // Owned by GetAutoFillProfiles caller. - AutoFillProfile* profile0 = new AutoFillProfile(string16(), 0); + AutoFillProfile* profile0 = new AutoFillProfile; autofill_test::SetProfileInfo(profile0, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", @@ -548,7 +549,7 @@ TEST_F(ProfileSyncServiceAutofillTest, HasMixedNativeEmptySync) { ASSERT_EQ(1U, entries.size()); EXPECT_TRUE(entries[0] == sync_entries[0]); EXPECT_EQ(1U, sync_profiles.size()); - EXPECT_EQ(expected_profiles[0], sync_profiles[0]); + EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0])); } bool ProfilesMatchExceptLabelImpl(AutoFillProfile p1, AutoFillProfile p2) { @@ -583,12 +584,12 @@ MATCHER_P(ProfileMatchesExceptLabel, profile, "") { TEST_F(ProfileSyncServiceAutofillTest, HasDuplicateProfileLabelsEmptySync) { std::vector<AutoFillProfile> expected_profiles; std::vector<AutoFillProfile*> profiles; - AutoFillProfile* profile0 = new AutoFillProfile(string16(), 0); + AutoFillProfile* profile0 = new AutoFillProfile; autofill_test::SetProfileInfo(profile0, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); - AutoFillProfile* profile1 = new AutoFillProfile(string16(), 0); + AutoFillProfile* profile1 = new AutoFillProfile; autofill_test::SetProfileInfo(profile1, "Billing", "Same", "Label", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", @@ -615,7 +616,7 @@ TEST_F(ProfileSyncServiceAutofillTest, HasDuplicateProfileLabelsEmptySync) { ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); EXPECT_EQ(0U, sync_entries.size()); EXPECT_EQ(2U, sync_profiles.size()); - EXPECT_EQ(expected_profiles[0], sync_profiles[1]); + EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[1])); EXPECT_TRUE(ProfilesMatchExceptLabelImpl(expected_profiles[1], sync_profiles[0])); EXPECT_EQ(sync_profiles[0].Label(), relabelled_profile.Label()); @@ -645,13 +646,13 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) { TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1)); AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2)); - AutoFillProfile sync_profile(string16(), 0); + AutoFillProfile sync_profile; autofill_test::SetProfileInfo(&sync_profile, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); - AutoFillProfile* native_profile = new AutoFillProfile(string16(), 0); + AutoFillProfile* native_profile = new AutoFillProfile; autofill_test::SetProfileInfo(native_profile, "Work", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -677,10 +678,11 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { AddAutofillEntriesTask task(this, sync_entries, sync_profiles); AutoFillProfile to_be_added(sync_profile); - to_be_added.set_unique_id(1); EXPECT_CALL(web_database_, UpdateAutofillEntries(ElementsAre(sync_entry))). WillOnce(Return(true)); - EXPECT_CALL(web_database_, AddAutoFillProfile(Eq(to_be_added))). + // TODO(dhollowa): Duplicate removal when contents match but GUIDs don't. + // http://crbug.com/58813 + EXPECT_CALL(web_database_, AddAutoFillProfile(_)). WillOnce(Return(true)); EXPECT_CALL(*personal_data_manager_, Refresh()); StartSyncService(&task, false); @@ -699,8 +701,8 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { EXPECT_TRUE(expected_entries == new_sync_entries_set); EXPECT_EQ(2U, new_sync_profiles.size()); - EXPECT_EQ(expected_profiles[0], new_sync_profiles[0]); - EXPECT_EQ(expected_profiles[1], new_sync_profiles[1]); + EXPECT_EQ(0, expected_profiles[0].Compare(new_sync_profiles[0])); + EXPECT_EQ(0, expected_profiles[1].Compare(new_sync_profiles[1])); } TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { @@ -734,13 +736,13 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { } TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { - AutoFillProfile sync_profile(string16(), 0); + AutoFillProfile sync_profile; autofill_test::SetProfileInfo(&sync_profile, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); - AutoFillProfile* native_profile = new AutoFillProfile(string16(), 0); + AutoFillProfile* native_profile = new AutoFillProfile; autofill_test::SetProfileInfo(native_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -757,7 +759,9 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { sync_profiles.push_back(sync_profile); AddAutofillEntriesTask task(this, sync_entries, sync_profiles); - EXPECT_CALL(web_database_, UpdateAutoFillProfile(Eq(sync_profile))). + // TODO(dhollowa): Duplicate removal when contents match but GUIDs don't. + // http://crbug.com/58813 + EXPECT_CALL(web_database_, UpdateAutoFillProfile(_)). WillOnce(Return(true)); EXPECT_CALL(*personal_data_manager_, Refresh()); StartSyncService(&task, false); @@ -768,9 +772,7 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); ASSERT_EQ(1U, new_sync_profiles.size()); - // TODO(dhollowa): Replace with |AutoFillProfile::Compare|. - // http://crbug.com/58813 - EXPECT_TRUE(sync_profile == new_sync_profiles[0]); + EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); } TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { @@ -812,7 +814,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { StartSyncService(&task, false); ASSERT_TRUE(task.success()); - AutoFillProfile added_profile(string16(), 0); + AutoFillProfile added_profile; autofill_test::SetProfileInfo(&added_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -830,13 +832,11 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); ASSERT_EQ(1U, new_sync_profiles.size()); - // TODO(dhollowa): Replace with |AutoFillProfile::Compare|. - // http://crbug.com/58813 - EXPECT_TRUE(added_profile == new_sync_profiles[0]); + EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); } TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfileConflict) { - AutoFillProfile sync_profile(string16(), 0); + AutoFillProfile sync_profile; autofill_test::SetProfileInfo(&sync_profile, "Billing", "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", @@ -847,17 +847,18 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfileConflict) { sync_profiles.push_back(sync_profile); AddAutofillEntriesTask task(this, sync_entries, sync_profiles); - sync_profile.set_unique_id(1); EXPECT_CALL(web_database_, GetAllAutofillEntries(_)).WillOnce(Return(true)); EXPECT_CALL(web_database_, GetAutoFillProfiles(_)).WillOnce(Return(true)); - EXPECT_CALL(web_database_, AddAutoFillProfile(Eq(sync_profile))). + // TODO(dhollowa): Duplicate removal when contents match but GUIDs don't. + // http://crbug.com/58813 + EXPECT_CALL(web_database_, AddAutoFillProfile(_)). WillOnce(Return(true)); EXPECT_CALL(*personal_data_manager_, Refresh()); SetIdleChangeProcessorExpectations(); StartSyncService(&task, false); ASSERT_TRUE(task.success()); - AutoFillProfile added_profile(string16(), 0); + AutoFillProfile added_profile; autofill_test::SetProfileInfo(&added_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -882,8 +883,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfileConflict) { ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); ASSERT_EQ(2U, new_sync_profiles.size()); - sync_profile.set_unique_id(0); // The sync DB doesn't store IDs. - EXPECT_EQ(sync_profile, new_sync_profiles[1]); + EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[1])); EXPECT_TRUE(ProfilesMatchExceptLabelImpl(added_profile, new_sync_profiles[0])); EXPECT_EQ(new_sync_profiles[0].Label(), relabelled_profile.Label()); @@ -926,7 +926,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfile) { - AutoFillProfile* native_profile = new AutoFillProfile(string16(), 0); + AutoFillProfile* native_profile = new AutoFillProfile; autofill_test::SetProfileInfo(native_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -941,7 +941,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfile) { StartSyncService(&task, false); ASSERT_TRUE(task.success()); - AutoFillProfile update_profile(string16(), 0); + AutoFillProfile update_profile; autofill_test::SetProfileInfo(&update_profile, "Billing", "Changin'", "Mah", "Namez", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -960,13 +960,11 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfile) { ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); ASSERT_EQ(1U, new_sync_profiles.size()); - // TODO(dhollowa): Replace with |AutoFillProfile::Compare|. - // http://crbug.com/58813 - EXPECT_TRUE(update_profile == new_sync_profiles[0]); + EXPECT_EQ(0, update_profile.Compare(new_sync_profiles[0])); } TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfileRelabel) { - AutoFillProfile* native_profile = new AutoFillProfile(string16(), 0); + AutoFillProfile* native_profile = new AutoFillProfile; autofill_test::SetProfileInfo(native_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -981,7 +979,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfileRelabel) { StartSyncService(&task, false); ASSERT_TRUE(task.success()); - AutoFillProfile update_profile(string16(), 0); + AutoFillProfile update_profile; autofill_test::SetProfileInfo(&update_profile, "TRYIN 2 FOOL U", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -1000,16 +998,14 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfileRelabel) { ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); ASSERT_EQ(1U, new_sync_profiles.size()); - // TODO(dhollowa): Replace with |AutoFillProfile::Compare|. - // http://crbug.com/58813 - EXPECT_TRUE(update_profile == new_sync_profiles[0]); + EXPECT_EQ(0, update_profile.Compare(new_sync_profiles[0])); } TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateProfileRelabelConflict) { std::vector<AutoFillProfile*> native_profiles; - native_profiles.push_back(new AutoFillProfile(string16(), 0)); - native_profiles.push_back(new AutoFillProfile(string16(), 0)); + native_profiles.push_back(new AutoFillProfile); + native_profiles.push_back(new AutoFillProfile); autofill_test::SetProfileInfo(native_profiles[0], "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", @@ -1061,8 +1057,7 @@ TEST_F(ProfileSyncServiceAutofillTest, ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); ASSERT_EQ(2U, new_sync_profiles.size()); - marion.set_unique_id(0); // The sync DB doesn't store IDs. - EXPECT_EQ(marion, new_sync_profiles[1]); + EXPECT_EQ(0, marion.Compare(new_sync_profiles[1])); EXPECT_TRUE(ProfilesMatchExceptLabelImpl(josephine_update, new_sync_profiles[0])); EXPECT_EQ(ASCIIToUTF16("ExistingLabel2"), new_sync_profiles[0].Label()); @@ -1100,12 +1095,12 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { } TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { - AutoFillProfile sync_profile(string16(), 0); + AutoFillProfile sync_profile; autofill_test::SetProfileInfo(&sync_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", "32801", "US", "19482937549", "13502849239"); - AutoFillProfile* native_profile = new AutoFillProfile(string16(), 0); + AutoFillProfile* native_profile = new AutoFillProfile; autofill_test::SetProfileInfo(native_profile, "Billing", "Josephine", "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", diff --git a/chrome/browser/views/autofill_profiles_view_win.cc b/chrome/browser/views/autofill_profiles_view_win.cc index 488ec72..414e0ba 100644 --- a/chrome/browser/views/autofill_profiles_view_win.cc +++ b/chrome/browser/views/autofill_profiles_view_win.cc @@ -56,28 +56,6 @@ const int kDialogPadding = 7; const int kSubViewHorizotalInsets = 18; const int kSubViewVerticalInsets = 5; -// This is a helper to compare items that were just created with items returned -// from the db. -// ProfileType could be either AutofillProfile or CreditCard. -// The second argument could have an incomplete ID (0) - change it to first -// argument's id for comparison and then change it back. -template<class ProfileType> bool IsEqualDataWithIncompleteId( - ProfileType const * data_to_compare, ProfileType* data_with_incomplete_id) { - if (!data_with_incomplete_id->unique_id()) { - bool label_unset = data_with_incomplete_id->Label().empty(); - if (label_unset) - data_with_incomplete_id->set_label(data_to_compare->Label()); - data_with_incomplete_id->set_unique_id(data_to_compare->unique_id()); - bool are_equal = (*data_to_compare == *data_with_incomplete_id); - data_with_incomplete_id->set_unique_id(0); - if (label_unset) - data_with_incomplete_id->set_label(string16()); - return are_equal; - } else { - return (*data_to_compare == *data_with_incomplete_id); - } -} - }; // namespace ///////////////////////////////////////////////////////////////////////////// @@ -155,10 +133,10 @@ void AutoFillProfilesView::AddClicked(int group_type) { std::vector<EditableSetInfo>::iterator it = profiles_set_.end(); int added_item_index = -1; if (group_type == ContentListTableModel::kAddressGroup) { - AutoFillProfile address(std::wstring(), 0); + AutoFillProfile address; info.reset(new EditableSetInfo(&address)); } else if (group_type == ContentListTableModel::kCreditCardGroup) { - CreditCard credit_card(std::wstring(), 0); + CreditCard credit_card; info.reset(new EditableSetInfo(&credit_card)); } else { NOTREACHED(); @@ -214,18 +192,16 @@ void AutoFillProfilesView::EditAccepted(EditableSetInfo* data, std::vector<EditableSetInfo>::iterator end_it; end_it = data->is_address ? profiles_set_.end() : credit_card_set_.end(); for (; it != end_it; ++it) { - if (it->unique_id() == data->unique_id()) { + if (it->guid() == data->guid()) { *it = *data; break; } if (new_item) { if (data->is_address) { - if (IsEqualDataWithIncompleteId<AutoFillProfile>(&it->address, - &data->address)) + if (it->address.Compare(data->address) == 0) break; } else { - if (IsEqualDataWithIncompleteId<CreditCard>(&it->credit_card, - &data->credit_card)) + if (it->credit_card.Compare(data->credit_card) == 0) break; } } diff --git a/chrome/browser/views/autofill_profiles_view_win.h b/chrome/browser/views/autofill_profiles_view_win.h index 7ccfa63..efeaf59 100644 --- a/chrome/browser/views/autofill_profiles_view_win.h +++ b/chrome/browser/views/autofill_profiles_view_win.h @@ -166,11 +166,11 @@ class AutoFillProfilesView : public views::View, is_address(false) { } - int unique_id() const { + std::string guid() const { if (is_address) - return address.unique_id(); + return address.guid(); else - return credit_card.unique_id(); + return credit_card.guid(); } }; diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc index f567995..d99fa73 100644 --- a/chrome/browser/webdata/web_data_service.cc +++ b/chrome/browser/webdata/web_data_service.cc @@ -391,16 +391,6 @@ void WebDataService::RemoveFormValueForElementName( request)); } -void WebDataService::AddAutoFillProfile(const AutoFillProfile& profile) { - GenericRequest<AutoFillProfile>* request = - new GenericRequest<AutoFillProfile>( - this, GetNextRequestHandle(), NULL, profile); - RegisterRequest(request); - ScheduleTask(NewRunnableMethod(this, - &WebDataService::AddAutoFillProfileImpl, - request)); -} - void WebDataService::AddAutoFillProfileGUID(const AutoFillProfile& profile) { GenericRequest<AutoFillProfile>* request = new GenericRequest<AutoFillProfile>( @@ -411,16 +401,6 @@ void WebDataService::AddAutoFillProfileGUID(const AutoFillProfile& profile) { request)); } -void WebDataService::UpdateAutoFillProfile(const AutoFillProfile& profile) { - GenericRequest<AutoFillProfile>* request = - new GenericRequest<AutoFillProfile>( - this, GetNextRequestHandle(), NULL, profile); - RegisterRequest(request); - ScheduleTask(NewRunnableMethod(this, - &WebDataService::UpdateAutoFillProfileImpl, - request)); -} - void WebDataService::UpdateAutoFillProfileGUID(const AutoFillProfile& profile) { GenericRequest<AutoFillProfile>* request = new GenericRequest<AutoFillProfile>( @@ -431,16 +411,6 @@ void WebDataService::UpdateAutoFillProfileGUID(const AutoFillProfile& profile) { request)); } -void WebDataService::RemoveAutoFillProfile(int profile_id) { - GenericRequest<int>* request = - new GenericRequest<int>( - this, GetNextRequestHandle(), NULL, profile_id); - RegisterRequest(request); - ScheduleTask(NewRunnableMethod(this, - &WebDataService::RemoveAutoFillProfileImpl, - request)); -} - void WebDataService::RemoveAutoFillProfileGUID(const std::string& guid) { GenericRequest<std::string>* request = new GenericRequest<std::string>( @@ -463,16 +433,6 @@ WebDataService::Handle WebDataService::GetAutoFillProfiles( return request->GetHandle(); } -void WebDataService::AddCreditCard(const CreditCard& credit_card) { - GenericRequest<CreditCard>* request = - new GenericRequest<CreditCard>( - this, GetNextRequestHandle(), NULL, credit_card); - RegisterRequest(request); - ScheduleTask(NewRunnableMethod(this, - &WebDataService::AddCreditCardImpl, - request)); -} - void WebDataService::AddCreditCardGUID(const CreditCard& credit_card) { GenericRequest<CreditCard>* request = new GenericRequest<CreditCard>( @@ -483,16 +443,6 @@ void WebDataService::AddCreditCardGUID(const CreditCard& credit_card) { request)); } -void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { - GenericRequest<CreditCard>* request = - new GenericRequest<CreditCard>( - this, GetNextRequestHandle(), NULL, credit_card); - RegisterRequest(request); - ScheduleTask(NewRunnableMethod(this, - &WebDataService::UpdateCreditCardImpl, - request)); -} - void WebDataService::UpdateCreditCardGUID(const CreditCard& credit_card) { GenericRequest<CreditCard>* request = new GenericRequest<CreditCard>( @@ -503,16 +453,6 @@ void WebDataService::UpdateCreditCardGUID(const CreditCard& credit_card) { request)); } -void WebDataService::RemoveCreditCard(int credit_card_id) { - GenericRequest<int>* request = - new GenericRequest<int>( - this, GetNextRequestHandle(), NULL, credit_card_id); - RegisterRequest(request); - ScheduleTask(NewRunnableMethod(this, - &WebDataService::RemoveCreditCardImpl, - request)); -} - void WebDataService::RemoveCreditCardGUID(const std::string& guid) { GenericRequest<std::string>* request = new GenericRequest<std::string>( @@ -539,11 +479,11 @@ void WebDataService::RemoveAutoFillProfilesAndCreditCardsModifiedBetween( const Time& delete_begin, const Time& delete_end) { GenericRequest2<Time, Time>* request = - new GenericRequest2<Time, Time>(this, - GetNextRequestHandle(), - NULL, - delete_begin, - delete_end); + new GenericRequest2<Time, Time>(this, + GetNextRequestHandle(), + NULL, + delete_begin, + delete_end); RegisterRequest(request); ScheduleTask(NewRunnableMethod( this, @@ -1051,27 +991,6 @@ void WebDataService::RemoveFormValueForElementNameImpl( request->RequestComplete(); } -void WebDataService::AddAutoFillProfileImpl( - GenericRequest<AutoFillProfile>* request) { - InitializeDatabaseIfNecessary(); - if (db_ && !request->IsCancelled()) { - const AutoFillProfile& profile = request->GetArgument(); - if (!db_->AddAutoFillProfile(profile)) { - NOTREACHED(); - return; - } - ScheduleCommit(); - - AutofillProfileChange change(AutofillProfileChange::ADD, - profile.Label(), &profile, string16()); - NotificationService::current()->Notify( - NotificationType::AUTOFILL_PROFILE_CHANGED, - Source<WebDataService>(this), - Details<AutofillProfileChange>(&change)); - } - request->RequestComplete(); -} - void WebDataService::AddAutoFillProfileGUIDImpl( GenericRequest<AutoFillProfile>* request) { InitializeDatabaseIfNecessary(); @@ -1091,7 +1010,7 @@ void WebDataService::AddAutoFillProfileGUIDImpl( Source<WebDataService>(this), Details<AutofillProfileChangeGUID>(&change)); - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 + // TODO(dhollowa): Remove labels. http://crbug.com/58813 // Send out old Label-based notification until sync can switch over to // GUID-based notifications. AutofillProfileChange deprecated_change(AutofillProfileChange::ADD, @@ -1106,52 +1025,20 @@ void WebDataService::AddAutoFillProfileGUIDImpl( request->RequestComplete(); } -void WebDataService::UpdateAutoFillProfileImpl( - GenericRequest<AutoFillProfile>* request) { - InitializeDatabaseIfNecessary(); - if (db_ && !request->IsCancelled()) { - const AutoFillProfile& profile = request->GetArgument(); - // The AUTOFILL_PROFILE_CHANGED contract for an update requires that we - // send along the label of the un-updated profile, to detect label - // changes separately. So first, we query for the existing profile. - AutoFillProfile* old_profile_ptr = NULL; - if (!db_->GetAutoFillProfileForID(profile.unique_id(), &old_profile_ptr)) { - NOTREACHED(); - return; - } - - if (old_profile_ptr) { - scoped_ptr<AutoFillProfile> old_profile(old_profile_ptr); - if (!db_->UpdateAutoFillProfile(profile)) { - NOTREACHED(); - return; - } - ScheduleCommit(); - - AutofillProfileChange change(AutofillProfileChange::UPDATE, - profile.Label(), &profile, - old_profile->Label()); - NotificationService::current()->Notify( - NotificationType::AUTOFILL_PROFILE_CHANGED, - Source<WebDataService>(this), - Details<AutofillProfileChange>(&change)); - } - } - request->RequestComplete(); -} - void WebDataService::UpdateAutoFillProfileGUIDImpl( GenericRequest<AutoFillProfile>* request) { InitializeDatabaseIfNecessary(); if (db_ && !request->IsCancelled()) { const AutoFillProfile& profile = request->GetArgument(); - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 + // TODO(dhollowa): Remove labels. http://crbug.com/58813 // Send out old Label-based notification until sync can switch over to // GUID-based notifications. + // Only perform the update if the profile exists. It is currently + // valid to try to update a missing profile. We simply drop the write and + // the caller will detect this on the next refresh. AutoFillProfile* original_profile = NULL; if (!db_->GetAutoFillProfileForGUID(profile.guid(), &original_profile)) { - NOTREACHED(); return; } scoped_ptr<AutoFillProfile> scoped_profile(original_profile); @@ -1170,7 +1057,7 @@ void WebDataService::UpdateAutoFillProfileGUIDImpl( Source<WebDataService>(this), Details<AutofillProfileChangeGUID>(&change)); - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 + // TODO(dhollowa): Remove labels. http://crbug.com/58813 // Send old Label-based notification. AutofillProfileChange deprecated_change(AutofillProfileChange::UPDATE, profile.Label(), &profile, @@ -1183,44 +1070,13 @@ void WebDataService::UpdateAutoFillProfileGUIDImpl( request->RequestComplete(); } -void WebDataService::RemoveAutoFillProfileImpl( - GenericRequest<int>* request) { - InitializeDatabaseIfNecessary(); - if (db_ && !request->IsCancelled()) { - int profile_id = request->GetArgument(); - AutoFillProfile* profile = NULL; - if (!db_->GetAutoFillProfileForID(profile_id, &profile)) { - NOTREACHED(); - return; - } - - if (profile) { - scoped_ptr<AutoFillProfile> dead_profile(profile); - if (!db_->RemoveAutoFillProfile(profile_id)) { - NOTREACHED(); - return; - } - ScheduleCommit(); - - AutofillProfileChange change(AutofillProfileChange::REMOVE, - dead_profile->Label(), - NULL, string16()); - NotificationService::current()->Notify( - NotificationType::AUTOFILL_PROFILE_CHANGED, - Source<WebDataService>(this), - Details<AutofillProfileChange>(&change)); - } - } - request->RequestComplete(); -} - void WebDataService::RemoveAutoFillProfileGUIDImpl( GenericRequest<std::string>* request) { InitializeDatabaseIfNecessary(); if (db_ && !request->IsCancelled()) { std::string guid = request->GetArgument(); - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 + // TODO(dhollowa): Remove labels. http://crbug.com/58813 // Send out old Label-based notification until sync can switch over to // GUID-based notifications. AutoFillProfile* profile = NULL; @@ -1244,7 +1100,7 @@ void WebDataService::RemoveAutoFillProfileGUIDImpl( Source<WebDataService>(this), Details<AutofillProfileChangeGUID>(&change)); - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 + // TODO(dhollowa): Remove labels. http://crbug.com/58813 // Send old Label-based notification. AutofillProfileChange deprecated_change(AutofillProfileChange::REMOVE, scoped_profile->Label(), @@ -1269,27 +1125,6 @@ void WebDataService::GetAutoFillProfilesImpl(WebDataRequest* request) { request->RequestComplete(); } -void WebDataService::AddCreditCardImpl( - GenericRequest<CreditCard>* request) { - InitializeDatabaseIfNecessary(); - if (db_ && !request->IsCancelled()) { - const CreditCard& credit_card = request->GetArgument(); - if (!db_->AddCreditCard(credit_card)) { - NOTREACHED(); - return; - } - ScheduleCommit(); - - AutofillCreditCardChange change(AutofillCreditCardChange::ADD, - credit_card.Label(), &credit_card); - NotificationService::current()->Notify( - NotificationType::AUTOFILL_CREDIT_CARD_CHANGED, - Source<WebDataService>(this), - Details<AutofillCreditCardChange>(&change)); - } - request->RequestComplete(); -} - void WebDataService::AddCreditCardGUIDImpl( GenericRequest<CreditCard>* request) { InitializeDatabaseIfNecessary(); @@ -1312,32 +1147,20 @@ void WebDataService::AddCreditCardGUIDImpl( request->RequestComplete(); } -void WebDataService::UpdateCreditCardImpl( +void WebDataService::UpdateCreditCardGUIDImpl( GenericRequest<CreditCard>* request) { InitializeDatabaseIfNecessary(); if (db_ && !request->IsCancelled()) { const CreditCard& credit_card = request->GetArgument(); - if (!db_->UpdateCreditCard(credit_card)) { - NOTREACHED(); + + // It is currently valid to try to update a missing profile. We simply drop + // the write and the caller will detect this on the next refresh. + CreditCard* original_credit_card = NULL; + if (!db_->GetCreditCardForGUID(credit_card.guid(), &original_credit_card)) { return; } - ScheduleCommit(); + scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); - AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, - credit_card.Label(), &credit_card); - NotificationService::current()->Notify( - NotificationType::AUTOFILL_CREDIT_CARD_CHANGED, - Source<WebDataService>(this), - Details<AutofillCreditCardChange>(&change)); - } - request->RequestComplete(); -} - -void WebDataService::UpdateCreditCardGUIDImpl( - GenericRequest<CreditCard>* request) { - InitializeDatabaseIfNecessary(); - if (db_ && !request->IsCancelled()) { - const CreditCard& credit_card = request->GetArgument(); if (!db_->UpdateCreditCard(credit_card)) { NOTREACHED(); return; @@ -1355,36 +1178,6 @@ void WebDataService::UpdateCreditCardGUIDImpl( request->RequestComplete(); } -void WebDataService::RemoveCreditCardImpl( - GenericRequest<int>* request) { - InitializeDatabaseIfNecessary(); - if (db_ && !request->IsCancelled()) { - int credit_card_id = request->GetArgument(); - CreditCard* credit_card = NULL; - if (!db_->GetCreditCardForID(credit_card_id, &credit_card)) { - NOTREACHED(); - return; - } - - if (credit_card) { - scoped_ptr<CreditCard> dead_credit_card(credit_card); - if (!db_->RemoveCreditCard(credit_card_id)) { - NOTREACHED(); - return; - } - ScheduleCommit(); - - AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, - dead_credit_card->Label(), NULL); - NotificationService::current()->Notify( - NotificationType::AUTOFILL_CREDIT_CARD_CHANGED, - Source<WebDataService>(this), - Details<AutofillCreditCardChange>(&change)); - } - } - request->RequestComplete(); -} - void WebDataService::RemoveCreditCardGUIDImpl( GenericRequest<std::string>* request) { InitializeDatabaseIfNecessary(); diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h index 6fe669e..42f204e 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -436,28 +436,12 @@ class WebDataService void RemoveFormValueForElementName(const string16& name, const string16& value); - // DEPRECATED - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - // Schedules a task to add an AutoFill profile to the web database. - void AddAutoFillProfile(const AutoFillProfile& profile); - // Schedules a task to add an AutoFill profile to the web database. void AddAutoFillProfileGUID(const AutoFillProfile& profile); - // DEPRECATED - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - // Schedules a task to update an AutoFill profile in the web database. - void UpdateAutoFillProfile(const AutoFillProfile& profile); - // Schedules a task to update an AutoFill profile in the web database. void UpdateAutoFillProfileGUID(const AutoFillProfile& profile); - // DEPRECATED - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - // Schedules a task to remove an AutoFill profile from the web database. - // |profile_id| is the unique ID of the profile to remove. - void RemoveAutoFillProfile(int profile_id); - // Schedules a task to remove an AutoFill profile from the web database. // |guid| is the identifer of the profile to remove. void RemoveAutoFillProfileGUID(const std::string& guid); @@ -468,28 +452,12 @@ class WebDataService // consumer owns the profiles. Handle GetAutoFillProfiles(WebDataServiceConsumer* consumer); - // DEPRECATED - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - // Schedules a task to add credit card to the web database. - void AddCreditCard(const CreditCard& credit_card); - // Schedules a task to add credit card to the web database. void AddCreditCardGUID(const CreditCard& credit_card); - // DEPRECATED - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - // Schedules a task to update credit card in the web database. - void UpdateCreditCard(const CreditCard& credit_card); - // Schedules a task to update credit card in the web database. void UpdateCreditCardGUID(const CreditCard& credit_card); - // DEPRECATED - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - // Schedules a task to remove a credit card from the web database. - // |credit_card_id| is the unique ID of the credit card to remove. - void RemoveCreditCard(int credit_card_id); - // Schedules a task to remove a credit card from the web database. // |guid| is identifer of the credit card to remove. void RemoveCreditCardGUID(const std::string& guid); @@ -630,18 +598,12 @@ class WebDataService GenericRequest2<base::Time, base::Time>* request); void RemoveFormValueForElementNameImpl( GenericRequest2<string16, string16>* request); - void AddAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request); void AddAutoFillProfileGUIDImpl(GenericRequest<AutoFillProfile>* request); - void UpdateAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request); void UpdateAutoFillProfileGUIDImpl(GenericRequest<AutoFillProfile>* request); - void RemoveAutoFillProfileImpl(GenericRequest<int>* request); void RemoveAutoFillProfileGUIDImpl(GenericRequest<std::string>* request); void GetAutoFillProfilesImpl(WebDataRequest* request); - void AddCreditCardImpl(GenericRequest<CreditCard>* request); void AddCreditCardGUIDImpl(GenericRequest<CreditCard>* request); - void UpdateCreditCardImpl(GenericRequest<CreditCard>* request); void UpdateCreditCardGUIDImpl(GenericRequest<CreditCard>* request); - void RemoveCreditCardImpl(GenericRequest<int>* request); void RemoveCreditCardGUIDImpl(GenericRequest<std::string>* request); void GetCreditCardsImpl(WebDataRequest* request); void RemoveAutoFillProfilesAndCreditCardsModifiedBetweenImpl( diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc index 741a574..2b4401c 100644 --- a/chrome/browser/webdata/web_data_service_unittest.cc +++ b/chrome/browser/webdata/web_data_service_unittest.cc @@ -256,23 +256,6 @@ TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { done_event_.TimedWait(test_timeout_); } -TEST_F(WebDataServiceAutofillTest, ProfileAdd) { - AutoFillProfile profile(name1_, unique_id1_); - const AutofillProfileChange expected_change( - AutofillProfileChange::ADD, name1_, &profile, string16()); - - EXPECT_CALL( - *observer_helper_->observer(), - Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), - Source<WebDataService>(wds_.get()), - Property(&Details<const AutofillProfileChange>::ptr, - Pointee(expected_change)))). - WillOnce(SignalEvent(&done_event_)); - - wds_->AddAutoFillProfile(profile); - done_event_.TimedWait(test_timeout_); -} - TEST_F(WebDataServiceAutofillTest, ProfileAddGUID) { AutoFillProfile profile; @@ -314,28 +297,6 @@ TEST_F(WebDataServiceAutofillTest, ProfileAddGUID) { STLDeleteElements(&consumer.result()); } -TEST_F(WebDataServiceAutofillTest, ProfileRemove) { - AutoFillProfile profile(name1_, unique_id1_); - - EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). - WillOnce(SignalEvent(&done_event_)); - wds_->AddAutoFillProfile(profile); - done_event_.TimedWait(test_timeout_); - - const AutofillProfileChange expected_change( - AutofillProfileChange::REMOVE, name1_, NULL, string16()); - EXPECT_CALL( - *observer_helper_->observer(), - Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), - Source<WebDataService>(wds_.get()), - Property(&Details<const AutofillProfileChange>::ptr, - Pointee(expected_change)))). - WillOnce(SignalEvent(&done_event_)); - - wds_->RemoveAutoFillProfile(profile.unique_id()); - done_event_.TimedWait(test_timeout_); -} - TEST_F(WebDataServiceAutofillTest, ProfileRemoveGUID) { AutoFillProfile profile; profile.set_label(name1_); @@ -393,50 +354,12 @@ TEST_F(WebDataServiceAutofillTest, ProfileRemoveGUID) { ASSERT_EQ(0U, consumer2.result().size()); } -TEST_F(WebDataServiceAutofillTest, ProfileUpdate) { - AutoFillProfile profile1(name1_, unique_id1_); - AutoFillProfile profile2(name2_, unique_id2_); - - EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). - Times(2). - WillOnce(DoDefault()). - WillOnce(SignalEvent(&done_event_)); - wds_->AddAutoFillProfile(profile1); - wds_->AddAutoFillProfile(profile2); - - done_event_.TimedWait(test_timeout_); - - AutoFillProfile profile1_delta(profile1); - string16 new_label(ASCIIToUTF16("new_label!")); - profile1_delta.set_label(new_label); - const AutofillProfileChange expected_change( - AutofillProfileChange::UPDATE, new_label, &profile1_delta, name1_); - - EXPECT_CALL( - *observer_helper_->observer(), - Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), - Source<WebDataService>(wds_.get()), - Property(&Details<const AutofillProfileChange>::ptr, - Pointee(expected_change)))). - WillOnce(SignalEvent(&done_event_)); - - wds_->UpdateAutoFillProfile(profile1_delta); - done_event_.TimedWait(test_timeout_); -} - TEST_F(WebDataServiceAutofillTest, ProfileUpdateGUID) { AutoFillProfile profile1; profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Abe")); AutoFillProfile profile2; profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Alice")); - // TODO(dhollowa): Remove once unique_ids are deprecated from the db. - // http://crbug.com/58813 - profile1.set_unique_id(unique_id1_); - profile1.set_label(name1_); - profile2.set_unique_id(unique_id2_); - profile2.set_label(name2_); - EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). WillOnce(DoDefault()). WillOnce(DoDefault()). @@ -502,23 +425,6 @@ TEST_F(WebDataServiceAutofillTest, ProfileUpdateGUID) { STLDeleteElements(&consumer2.result()); } -TEST_F(WebDataServiceAutofillTest, CreditAdd) { - CreditCard card(name1_, unique_id1_); - const AutofillCreditCardChange expected_change( - AutofillCreditCardChange::ADD, name1_, &card); - - EXPECT_CALL( - *observer_helper_->observer(), - Observe(NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), - Source<WebDataService>(wds_.get()), - Property(&Details<const AutofillCreditCardChange>::ptr, - Pointee(expected_change)))). - WillOnce(SignalEvent(&done_event_)); - - wds_->AddCreditCard(card); - done_event_.TimedWait(test_timeout_); -} - TEST_F(WebDataServiceAutofillTest, CreditAddGUID) { CreditCard card; const AutofillCreditCardChangeGUID expected_change( @@ -546,28 +452,6 @@ TEST_F(WebDataServiceAutofillTest, CreditAddGUID) { STLDeleteElements(&consumer.result()); } -TEST_F(WebDataServiceAutofillTest, CreditRemove) { - CreditCard card(name1_, unique_id1_); - EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). - WillOnce(SignalEvent(&done_event_)); - wds_->AddCreditCard(card); - done_event_.TimedWait(test_timeout_); - - const AutofillCreditCardChange expected_change( - AutofillCreditCardChange::REMOVE, name1_, NULL); - - EXPECT_CALL( - *observer_helper_->observer(), - Observe(NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), - Source<WebDataService>(wds_.get()), - Property(&Details<const AutofillCreditCardChange>::ptr, - Pointee(expected_change)))). - WillOnce(SignalEvent(&done_event_)); - - wds_->RemoveCreditCard(card.unique_id()); - done_event_.TimedWait(test_timeout_); -} - TEST_F(WebDataServiceAutofillTest, CreditCardRemoveGUID) { CreditCard credit_card; @@ -608,46 +492,12 @@ TEST_F(WebDataServiceAutofillTest, CreditCardRemoveGUID) { ASSERT_EQ(0U, consumer2.result().size()); } -TEST_F(WebDataServiceAutofillTest, CreditUpdate) { - CreditCard card1(name1_, unique_id1_); - CreditCard card2(name2_, unique_id2_); - - EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). - Times(2). - WillOnce(DoDefault()). - WillOnce(SignalEvent(&done_event_)); - wds_->AddCreditCard(card1); - wds_->AddCreditCard(card2); - done_event_.TimedWait(test_timeout_); - - CreditCard card1_delta(card1); - card1_delta.set_label(ASCIIToUTF16("new_label!")); - const AutofillCreditCardChange expected_change( - AutofillCreditCardChange::UPDATE, name1_, &card1_delta); - - EXPECT_CALL( - *observer_helper_->observer(), - Observe(NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), - Source<WebDataService>(wds_.get()), - Property(&Details<const AutofillCreditCardChange>::ptr, - Pointee(expected_change)))). - WillOnce(SignalEvent(&done_event_)); - - wds_->UpdateCreditCard(card1_delta); - done_event_.TimedWait(test_timeout_); -} - TEST_F(WebDataServiceAutofillTest, CreditUpdateGUID) { CreditCard card1; card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Abe")); CreditCard card2; card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Alice")); - // TODO(dhollowa): Remove once unique_ids are deprecated from the db. - // http://crbug.com/58813 - card1.set_unique_id(unique_id1_); - card2.set_unique_id(unique_id2_); - EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). Times(2). WillOnce(DoDefault()). diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index c40bfca..2b9c029 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -109,9 +109,10 @@ using webkit_glue::PasswordForm; // user with the AutoFill dialog. Most of the columns are // standard entries in a contact information form. // +// guid A guid string to uniquely identify the profile. +// Added in version 31. // label The label of the profile. Presented to the user when // selecting profiles. -// unique_id The unique ID of this profile. // first_name // middle_name // last_name @@ -127,45 +128,21 @@ using webkit_glue::PasswordForm; // fax // date_modified The date on which this profile was last modified. // Added in version 30. -// guid A guid string to uniquely identify the profile. This -// will eventually replace the unique_id above. We need -// to keep both during the transition. -// Added in version 31. -// TODO(dhollowa): Deprecate and remove unique_id. -// http://crbug.com/58813 // // credit_cards This table contains credit card data added by the user // with the AutoFill dialog. Most of the columns are // standard entries in a credit card form. // +// guid A guid string to uniquely identify the profile. +// Added in version 31. // label The label of the credit card. Presented to the user // when selecting credit cards. -// unique_id The unique ID of this credit card. // name_on_card -// type -// card_number Before version 23 stores credit card number, 23 and -// after stores empty string. // expiration_month // expiration_year -// verification_code Before version 23 stores the CVC/CVV/CVV2 card security -// code. After that stores the empty string. -// billing_address A foreign key into the autofill_profiles table. -// shipping_address A foreign key into the autofill_profiles table. -// For the following two fields encryption is used. Currently it uses -// Encryptor, that does encryption on windows only. As on the other -// systems this file is readable by owner only, it is good for now. -// For potentially going over the wire other encryption is used, see -// chrome/browser/sync/protocol/autofill_specifics.proto // card_number_encrypted Stores encrypted credit card number. -// verification_code_encrypted The CVC/CVV/CVV2 card security code. // date_modified The date on which this entry was last modified. // Added in version 30. -// guid A guid string to uniquely identify the profile. This -// will eventually replace the unique_id above. We need -// to keep both during the transition. -// Added in version 31. -// TODO(dhollowa): Deprecate and remove unique_id. -// http://crbug.com/58813 // // web_app_icons // url URL of the web app. @@ -188,8 +165,8 @@ typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; // Current version number. Note: when changing the current version number, // corresponding changes must happen in the unit tests, and new migration test // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. -const int kCurrentVersionNumber = 31; -const int kCompatibleVersionNumber = 31; +const int kCurrentVersionNumber = 32; +const int kCompatibleVersionNumber = 32; // ID of the url column in keywords. const int kUrlIdPosition = 16; @@ -278,8 +255,9 @@ string16 LimitDataSize(const string16& data) { void BindAutoFillProfileToStatement(const AutoFillProfile& profile, sql::Statement* s) { - s->BindString16(0, profile.Label()); - s->BindInt(1, profile.unique_id()); + DCHECK(guid::IsValidGUID(profile.guid())); + s->BindString(0, profile.guid()); + s->BindString16(1, profile.Label()); string16 text = profile.GetFieldText(AutoFillType(NAME_FIRST)); s->BindString16(2, LimitDataSize(text)); @@ -308,13 +286,14 @@ void BindAutoFillProfileToStatement(const AutoFillProfile& profile, text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER)); s->BindString16(14, LimitDataSize(text)); s->BindInt64(15, Time::Now().ToTimeT()); - DCHECK(guid::IsValidGUID(profile.guid())); - s->BindString(16, profile.guid()); } AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) { - AutoFillProfile* profile = new AutoFillProfile(s.ColumnString16(0), - s.ColumnInt(1)); + AutoFillProfile* profile = new AutoFillProfile; + profile->set_guid(s.ColumnString(0)); + DCHECK(guid::IsValidGUID(profile->guid())); + profile->set_label(s.ColumnString16(1)); + profile->SetInfo(AutoFillType(NAME_FIRST), s.ColumnString16(2)); profile->SetInfo(AutoFillType(NAME_MIDDLE), @@ -342,80 +321,53 @@ AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) { profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14)); // Intentionally skip column 15, which stores the profile's modification date. - profile->set_guid(s.ColumnString(16)); - DCHECK(guid::IsValidGUID(profile->guid())); return profile; } void BindCreditCardToStatement(const CreditCard& credit_card, sql::Statement* s) { - s->BindString16(0, credit_card.Label()); - s->BindInt(1, credit_card.unique_id()); + DCHECK(guid::IsValidGUID(credit_card.guid())); + s->BindString(0, credit_card.guid()); + s->BindString16(1, credit_card.Label()); string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME)); s->BindString16(2, LimitDataSize(text)); - text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)); - s->BindString16(3, LimitDataSize(text)); - text.clear(); // No unencrypted cc info. - s->BindString16(4, LimitDataSize(text)); text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)); - s->BindString16(5, LimitDataSize(text)); + s->BindString16(3, LimitDataSize(text)); text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); - s->BindString16(6, LimitDataSize(text)); - text.clear(); - s->BindString16(7, LimitDataSize(text)); - // We don't store the billing address id anymore. - s->BindInt(8, 0); - // We don't store the shipping address anymore. - text.clear(); - s->BindString16(9, LimitDataSize(text)); + s->BindString16(4, LimitDataSize(text)); text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); std::string encrypted_data; Encryptor::EncryptString16(text, &encrypted_data); - s->BindBlob(10, encrypted_data.data(), + s->BindBlob(5, encrypted_data.data(), static_cast<int>(encrypted_data.length())); - // We don't store the CVV anymore. - text.clear(); - s->BindBlob(11, text.data(), static_cast<int>(text.length())); - s->BindInt64(12, Time::Now().ToTimeT()); - DCHECK(guid::IsValidGUID(credit_card.guid())); - s->BindString(13, credit_card.guid()); + s->BindInt64(6, Time::Now().ToTimeT()); } CreditCard* CreditCardFromStatement(const sql::Statement& s) { - CreditCard* credit_card = new CreditCard(s.ColumnString16(0), s.ColumnInt(1)); + CreditCard* credit_card = new CreditCard; + + credit_card->set_guid(s.ColumnString(0)); + DCHECK(guid::IsValidGUID(credit_card->guid())); + credit_card->set_label(s.ColumnString16(1)); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2)); - credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE), + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), s.ColumnString16(3)); - string16 credit_card_number = s.ColumnString16(4); - // It could be non-empty prior to version 23. After that it encrypted in - // the column 10. - if (credit_card_number.empty()) { - int encrypted_cc_len = s.ColumnByteLength(10); - std::string encrypted_cc; - if (encrypted_cc_len) { - encrypted_cc.resize(encrypted_cc_len); - memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len); - Encryptor::DecryptString16(encrypted_cc, &credit_card_number); - } + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), + s.ColumnString16(4)); + int encrypted_number_len = s.ColumnByteLength(5); + string16 credit_card_number; + if (encrypted_number_len) { + std::string encrypted_number; + encrypted_number.resize(encrypted_number_len); + memcpy(&encrypted_number[0], s.ColumnBlob(5), encrypted_number_len); + Encryptor::DecryptString16(encrypted_number, &credit_card_number); } credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number); - credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), - s.ColumnString16(5)); - credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), - s.ColumnString16(6)); - - string16 credit_card_verification_code = s.ColumnString16(7); - // We don't store the CVV anymore. - // We don't store the billing address anymore. - // We don't store the shipping address anymore. - // Column 10 is processed above. - // We don't store the encrypted CVV anymore. - // Intentionally skip column 12, which stores the modification date. - credit_card->set_guid(s.ColumnString(13)); - DCHECK(guid::IsValidGUID(credit_card->guid())); + // Intentionally skip column 6, which stores the modification date. return credit_card; } @@ -767,8 +719,8 @@ bool WebDatabase::InitAutofillDatesTable() { bool WebDatabase::InitAutoFillProfilesTable() { if (!db_.DoesTableExist("autofill_profiles")) { if (!db_.Execute("CREATE TABLE autofill_profiles ( " + "guid VARCHAR PRIMARY KEY, " "label VARCHAR, " - "unique_id INTEGER PRIMARY KEY, " "first_name VARCHAR, " "middle_name VARCHAR, " "last_name VARCHAR, " @@ -782,8 +734,7 @@ bool WebDatabase::InitAutoFillProfilesTable() { "country VARCHAR, " "phone VARCHAR, " "fax VARCHAR, " - "date_modified INTEGER NOT NULL DEFAULT 0, " - "guid VARCHAR NOT NULL DEFAULT \"\")")) { + "date_modified INTEGER NOT NULL DEFAULT 0)")) { NOTREACHED(); return false; } @@ -799,20 +750,13 @@ bool WebDatabase::InitAutoFillProfilesTable() { bool WebDatabase::InitCreditCardsTable() { if (!db_.DoesTableExist("credit_cards")) { if (!db_.Execute("CREATE TABLE credit_cards ( " + "guid VARCHAR PRIMARY KEY, " "label VARCHAR, " - "unique_id INTEGER PRIMARY KEY, " "name_on_card VARCHAR, " - "type VARCHAR, " - "card_number VARCHAR, " "expiration_month INTEGER, " "expiration_year INTEGER, " - "verification_code VARCHAR, " - "billing_address VARCHAR, " - "shipping_address VARCHAR, " "card_number_encrypted BLOB, " - "verification_code_encrypted BLOB, " - "date_modified INTEGER NOT NULL DEFAULT 0, " - "guid VARCHAR NOT NULL DEFAULT \"\")")) { + "date_modified INTEGER NOT NULL DEFAULT 0)")) { NOTREACHED(); return false; } @@ -1660,10 +1604,10 @@ bool WebDatabase::RemoveFormElement(const string16& name, bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) { sql::Statement s(db_.GetUniqueStatement( "INSERT INTO autofill_profiles" - "(label, unique_id, first_name, middle_name, last_name, email," + "(guid, label, first_name, middle_name, last_name, email," " company_name, address_line_1, address_line_2, city, state, zipcode," - " country, phone, fax, date_modified, guid)" - "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); + " country, phone, fax, date_modified)" + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); if (!s) { NOTREACHED() << "Statement prepare failed"; return false; @@ -1683,9 +1627,9 @@ bool WebDatabase::GetAutoFillProfileForLabel(const string16& label, AutoFillProfile** profile) { DCHECK(profile); sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, first_name, middle_name, last_name, email, " + "SELECT guid, label, first_name, middle_name, last_name, email, " "company_name, address_line_1, address_line_2, city, state, zipcode, " - "country, phone, fax, date_modified, guid " + "country, phone, fax, date_modified " "FROM autofill_profiles " "WHERE label = ?")); if (!s) { @@ -1707,9 +1651,9 @@ bool WebDatabase::GetAutoFillProfileForGUID(const std::string& guid, DCHECK(guid::IsValidGUID(guid)); DCHECK(profile); sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, first_name, middle_name, last_name, email, " + "SELECT guid, label, first_name, middle_name, last_name, email, " "company_name, address_line_1, address_line_2, city, state, zipcode, " - "country, phone, fax, date_modified, guid " + "country, phone, fax, date_modified " "FROM autofill_profiles " "WHERE guid = ?")); if (!s) { @@ -1732,9 +1676,9 @@ bool WebDatabase::GetAutoFillProfiles( profiles->clear(); sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, first_name, middle_name, last_name, email, " + "SELECT guid, label, first_name, middle_name, last_name, email, " "company_name, address_line_1, address_line_2, city, state, zipcode, " - "country, phone, fax, date_modified, guid " + "country, phone, fax, date_modified " "FROM autofill_profiles")); if (!s) { NOTREACHED() << "Statement prepare failed"; @@ -1748,39 +1692,26 @@ bool WebDatabase::GetAutoFillProfiles( } bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) { - DCHECK(profile.unique_id()); + DCHECK(guid::IsValidGUID(profile.guid())); sql::Statement s(db_.GetUniqueStatement( "UPDATE autofill_profiles " - "SET label=?, unique_id=?, first_name=?, middle_name=?, last_name=?, " + "SET guid=?, label=?, first_name=?, middle_name=?, last_name=?, " " email=?, company_name=?, address_line_1=?, address_line_2=?, " " city=?, state=?, zipcode=?, country=?, phone=?, fax=?, " - " date_modified=?, guid=? " - "WHERE unique_id=?")); + " date_modified=? " + "WHERE guid=?")); if (!s) { NOTREACHED() << "Statement prepare failed"; return false; } BindAutoFillProfileToStatement(profile, &s); - s.BindInt(17, profile.unique_id()); + s.BindString(16, profile.guid()); bool result = s.Run(); DCHECK_GT(db_.GetLastChangeCount(), 0); return result; } -bool WebDatabase::RemoveAutoFillProfile(int profile_id) { - DCHECK_NE(0, profile_id); - sql::Statement s(db_.GetUniqueStatement( - "DELETE FROM autofill_profiles WHERE unique_id = ?")); - if (!s) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - - s.BindInt(0, profile_id); - return s.Run(); -} - bool WebDatabase::RemoveAutoFillProfile(const std::string& guid) { DCHECK(guid::IsValidGUID(guid)); sql::Statement s(db_.GetUniqueStatement( @@ -1794,34 +1725,12 @@ bool WebDatabase::RemoveAutoFillProfile(const std::string& guid) { return s.Run(); } -bool WebDatabase::GetAutoFillProfileForID(int profile_id, - AutoFillProfile** profile) { - sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, first_name, middle_name, last_name, email, " - "company_name, address_line_1, address_line_2, city, state, zipcode, " - "country, phone, fax, date_modified, guid " - "FROM autofill_profiles " - "WHERE unique_id = ?")); - if (!s) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - - s.BindInt(0, profile_id); - if (s.Step()) - *profile = AutoFillProfileFromStatement(s); - - return s.Succeeded(); -} - bool WebDatabase::AddCreditCard(const CreditCard& credit_card) { sql::Statement s(db_.GetUniqueStatement( "INSERT INTO credit_cards" - "(label, unique_id, name_on_card, type, card_number, expiration_month," - " expiration_year, verification_code, billing_address, shipping_address," - " card_number_encrypted, verification_code_encrypted, date_modified," - " guid)" - "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); + "(guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified)" + "VALUES (?,?,?,?,?,?,?)")); if (!s) { NOTREACHED() << "Statement prepare failed"; return false; @@ -1842,10 +1751,8 @@ bool WebDatabase::GetCreditCardForLabel(const string16& label, CreditCard** credit_card) { DCHECK(credit_card); sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, name_on_card, type, card_number, " - "expiration_month, expiration_year, verification_code, billing_address, " - "shipping_address, card_number_encrypted, verification_code_encrypted, " - "date_modified, guid " + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " "FROM credit_cards " "WHERE label = ?")); if (!s) { @@ -1862,37 +1769,12 @@ bool WebDatabase::GetCreditCardForLabel(const string16& label, return s.Succeeded(); } -bool WebDatabase::GetCreditCardForID(int credit_card_id, - CreditCard** credit_card) { - sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, name_on_card, type, card_number, " - "expiration_month, expiration_year, verification_code, billing_address, " - "shipping_address, card_number_encrypted, verification_code_encrypted, " - "date_modified, guid " - "FROM credit_cards " - "WHERE unique_id = ?")); - if (!s) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - - s.BindInt(0, credit_card_id); - if (!s.Step()) - return false; - - *credit_card = CreditCardFromStatement(s); - - return s.Succeeded(); -} - bool WebDatabase::GetCreditCardForGUID(const std::string& guid, CreditCard** credit_card) { DCHECK(guid::IsValidGUID(guid)); sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, name_on_card, type, card_number, " - "expiration_month, expiration_year, verification_code, billing_address, " - "shipping_address, card_number_encrypted, verification_code_encrypted, " - "date_modified, guid " + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " "FROM credit_cards " "WHERE guid = ?")); if (!s) { @@ -1915,10 +1797,8 @@ bool WebDatabase::GetCreditCards( credit_cards->clear(); sql::Statement s(db_.GetUniqueStatement( - "SELECT label, unique_id, name_on_card, type, card_number, " - "expiration_month, expiration_year, verification_code, billing_address, " - "shipping_address, card_number_encrypted, verification_code_encrypted, " - "date_modified, guid " + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " "FROM credit_cards")); if (!s) { NOTREACHED() << "Statement prepare failed"; @@ -1932,39 +1812,24 @@ bool WebDatabase::GetCreditCards( } bool WebDatabase::UpdateCreditCard(const CreditCard& credit_card) { - DCHECK(credit_card.unique_id()); + DCHECK(guid::IsValidGUID(credit_card.guid())); sql::Statement s(db_.GetUniqueStatement( "UPDATE credit_cards " - "SET label=?, unique_id=?, name_on_card=?, type=?, card_number=?, " - " expiration_month=?, expiration_year=?, verification_code=?, " - " billing_address=?, shipping_address=?, card_number_encrypted=?, " - " verification_code_encrypted=?, date_modified=?, guid=?" - "WHERE unique_id=?")); + "SET guid=?, label=?, name_on_card=?, expiration_month=?, " + " expiration_year=?, card_number_encrypted=?, date_modified=? " + "WHERE guid=?")); if (!s) { NOTREACHED() << "Statement prepare failed"; return false; } BindCreditCardToStatement(credit_card, &s); - s.BindInt(14, credit_card.unique_id()); + s.BindString(7, credit_card.guid()); bool result = s.Run(); DCHECK_GT(db_.GetLastChangeCount(), 0); return result; } -bool WebDatabase::RemoveCreditCard(int credit_card_id) { - DCHECK_NE(0, credit_card_id); - sql::Statement s(db_.GetUniqueStatement( - "DELETE FROM credit_cards WHERE unique_id = ?")); - if (!s) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - - s.BindInt(0, credit_card_id); - return s.Run(); -} - bool WebDatabase::RemoveCreditCard(const std::string& guid) { DCHECK(guid::IsValidGUID(guid)); sql::Statement s(db_.GetUniqueStatement( @@ -2194,13 +2059,23 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ NOTREACHED(); return sql::INIT_FAILURE; } - query = "DELETE FROM credit_cards WHERE (" + credit_cards_is_too_big + - ") OR label IN (SELECT label FROM autofill_profiles WHERE " + - autofill_profiles_is_too_big + ")"; - if (!db_.Execute(query.c_str())) { - LOG(WARNING) << "Unable to update web database to version 24."; - NOTREACHED(); - return sql::INIT_FAILURE; + // Only delete from legacy credit card tables where specific columns + // exist. + if (db_.DoesColumnExist("credit_cards", "label") && + db_.DoesColumnExist("credit_cards", "name_on_card") && + db_.DoesColumnExist("credit_cards", "type") && + db_.DoesColumnExist("credit_cards", "expiration_month") && + db_.DoesColumnExist("credit_cards", "expiration_year") && + db_.DoesColumnExist("credit_cards", "billing_address") && + db_.DoesColumnExist("credit_cards", "shipping_address")) { + query = "DELETE FROM credit_cards WHERE (" + credit_cards_is_too_big + + ") OR label IN (SELECT label FROM autofill_profiles WHERE " + + autofill_profiles_is_too_big + ")"; + if (!db_.Execute(query.c_str())) { + LOG(WARNING) << "Unable to update web database to version 24."; + NOTREACHED(); + return sql::INIT_FAILURE; + } } query = "DELETE FROM autofill_profiles WHERE " + autofill_profiles_is_too_big; @@ -2243,30 +2118,19 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ // FALL THROUGH case 26: { - // Change the credit_cards.billing_address column from a string to an int. - // The stored string is the label of an address, so we have to select the - // unique ID of this address using the label as a foreign key into the - // |autofill_profiles| table. - std::string stmt = - "SELECT credit_cards.unique_id, autofill_profiles.unique_id " - "FROM autofill_profiles, credit_cards " - "WHERE credit_cards.billing_address = autofill_profiles.label"; - sql::Statement s(db_.GetUniqueStatement(stmt.c_str())); - if (!s) { - LOG(WARNING) << "Statement prepare failed"; - NOTREACHED(); - return sql::INIT_FAILURE; - } - - std::map<int, int> cc_billing_map; - while (s.Step()) - cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1); - - // Windows already stores the IDs as strings in |billing_address|. Try to - // convert those. - if (cc_billing_map.empty()) { + // Only migrate from legacy credit card tables where specific columns + // exist. + if (db_.DoesColumnExist("credit_cards", "unique_id") && + db_.DoesColumnExist("credit_cards", "billing_address") && + db_.DoesColumnExist("autofill_profiles", "unique_id")) { + // Change the credit_cards.billing_address column from a string to an + // int. The stored string is the label of an address, so we have to + // select the unique ID of this address using the label as a foreign + // key into the |autofill_profiles| table. std::string stmt = - "SELECT unique_id,billing_address FROM credit_cards"; + "SELECT credit_cards.unique_id, autofill_profiles.unique_id " + "FROM autofill_profiles, credit_cards " + "WHERE credit_cards.billing_address = autofill_profiles.label"; sql::Statement s(db_.GetUniqueStatement(stmt.c_str())); if (!s) { LOG(WARNING) << "Statement prepare failed"; @@ -2274,74 +2138,91 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ return sql::INIT_FAILURE; } - while (s.Step()) { - int id = 0; - if (base::StringToInt(s.ColumnString(1), &id)) - cc_billing_map[s.ColumnInt(0)] = id; - } - } - - if (!db_.Execute("CREATE TABLE credit_cards_temp ( " - "label VARCHAR, " - "unique_id INTEGER PRIMARY KEY, " - "name_on_card VARCHAR, " - "type VARCHAR, " - "card_number VARCHAR, " - "expiration_month INTEGER, " - "expiration_year INTEGER, " - "verification_code VARCHAR, " - "billing_address INTEGER, " - "shipping_address VARCHAR, " - "card_number_encrypted BLOB, " - "verification_code_encrypted BLOB)")) { - LOG(WARNING) << "Unable to update web database to version 27."; - NOTREACHED(); - return sql::INIT_FAILURE; - } - - if (!db_.Execute( - "INSERT INTO credit_cards_temp " - "SELECT label,unique_id,name_on_card,type,card_number," - "expiration_month,expiration_year,verification_code,0," - "shipping_address,card_number_encrypted,verification_code_encrypted " - "FROM credit_cards")) { - LOG(WARNING) << "Unable to update web database to version 27."; - NOTREACHED(); - return sql::INIT_FAILURE; - } + std::map<int, int> cc_billing_map; + while (s.Step()) + cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1); + + // Windows already stores the IDs as strings in |billing_address|. Try + // to convert those. + if (cc_billing_map.empty()) { + std::string stmt = + "SELECT unique_id,billing_address FROM credit_cards"; + sql::Statement s(db_.GetUniqueStatement(stmt.c_str())); + if (!s) { + LOG(WARNING) << "Statement prepare failed"; + NOTREACHED(); + return sql::INIT_FAILURE; + } - if (!db_.Execute("DROP TABLE credit_cards")) { - LOG(WARNING) << "Unable to update web database to version 27."; - NOTREACHED(); - return sql::INIT_FAILURE; - } + while (s.Step()) { + int id = 0; + if (base::StringToInt(s.ColumnString(1), &id)) + cc_billing_map[s.ColumnInt(0)] = id; + } + } - if (!db_.Execute( - "ALTER TABLE credit_cards_temp RENAME TO credit_cards")) { - LOG(WARNING) << "Unable to update web database to version 27."; - NOTREACHED(); - return sql::INIT_FAILURE; - } + if (!db_.Execute("CREATE TABLE credit_cards_temp ( " + "label VARCHAR, " + "unique_id INTEGER PRIMARY KEY, " + "name_on_card VARCHAR, " + "type VARCHAR, " + "card_number VARCHAR, " + "expiration_month INTEGER, " + "expiration_year INTEGER, " + "verification_code VARCHAR, " + "billing_address INTEGER, " + "shipping_address VARCHAR, " + "card_number_encrypted BLOB, " + "verification_code_encrypted BLOB)")) { + LOG(WARNING) << "Unable to update web database to version 27."; + NOTREACHED(); + return sql::INIT_FAILURE; + } - for (std::map<int, int>::const_iterator iter = cc_billing_map.begin(); - iter != cc_billing_map.end(); ++iter) { - sql::Statement s(db_.GetCachedStatement( - SQL_FROM_HERE, - "UPDATE credit_cards SET billing_address=? WHERE unique_id=?")); - if (!s) { - LOG(WARNING) << "Statement prepare failed"; + if (!db_.Execute( + "INSERT INTO credit_cards_temp " + "SELECT label,unique_id,name_on_card,type,card_number," + "expiration_month,expiration_year,verification_code,0," + "shipping_address,card_number_encrypted,verification_code_encrypted " + "FROM credit_cards")) { + LOG(WARNING) << "Unable to update web database to version 27."; NOTREACHED(); return sql::INIT_FAILURE; } - s.BindInt(0, (*iter).second); - s.BindInt(1, (*iter).first); + if (!db_.Execute("DROP TABLE credit_cards")) { + LOG(WARNING) << "Unable to update web database to version 27."; + NOTREACHED(); + return sql::INIT_FAILURE; + } - if (!s.Run()) { + if (!db_.Execute( + "ALTER TABLE credit_cards_temp RENAME TO credit_cards")) { LOG(WARNING) << "Unable to update web database to version 27."; NOTREACHED(); return sql::INIT_FAILURE; } + + for (std::map<int, int>::const_iterator iter = cc_billing_map.begin(); + iter != cc_billing_map.end(); ++iter) { + sql::Statement s(db_.GetCachedStatement( + SQL_FROM_HERE, + "UPDATE credit_cards SET billing_address=? WHERE unique_id=?")); + if (!s) { + LOG(WARNING) << "Statement prepare failed"; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + s.BindInt(0, (*iter).second); + s.BindInt(1, (*iter).first); + + if (!s.Run()) { + LOG(WARNING) << "Unable to update web database to version 27."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + } } meta_table_.SetVersionNumber(27); @@ -2499,35 +2380,35 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ NOTREACHED(); return sql::INIT_FAILURE; } - } - - // Set all the |guid| fields to valid values. - { - sql::Statement s(db_.GetUniqueStatement("SELECT unique_id " - "FROM autofill_profiles")); - if (!s) { - LOG(WARNING) << "Unable to update web database to version 30."; - NOTREACHED(); - return sql::INIT_FAILURE; - } + // Set all the |guid| fields to valid values. + { + sql::Statement s(db_.GetUniqueStatement("SELECT unique_id " + "FROM autofill_profiles")); - while (s.Step()) { - sql::Statement update_s( - db_.GetUniqueStatement("UPDATE autofill_profiles " - "SET guid=? WHERE unique_id=?")); - if (!update_s) { + if (!s) { LOG(WARNING) << "Unable to update web database to version 30."; NOTREACHED(); return sql::INIT_FAILURE; } - update_s.BindString(0, guid::GenerateGUID()); - update_s.BindInt(1, s.ColumnInt(0)); - if (!update_s.Run()) { - LOG(WARNING) << "Unable to update web database to version 30."; - NOTREACHED(); - return sql::INIT_FAILURE; + while (s.Step()) { + sql::Statement update_s( + db_.GetUniqueStatement("UPDATE autofill_profiles " + "SET guid=? WHERE unique_id=?")); + if (!update_s) { + LOG(WARNING) << "Unable to update web database to version 30."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + update_s.BindString(0, guid::GenerateGUID()); + update_s.BindInt(1, s.ColumnInt(0)); + + if (!update_s.Run()) { + LOG(WARNING) << "Unable to update web database to version 30."; + NOTREACHED(); + return sql::INIT_FAILURE; + } } } } @@ -2543,34 +2424,34 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ NOTREACHED(); return sql::INIT_FAILURE; } - } - // Set all the |guid| fields to valid values. - { - sql::Statement s(db_.GetUniqueStatement("SELECT unique_id " - "FROM credit_cards")); - if (!s) { - LOG(WARNING) << "Unable to update web database to version 30."; - NOTREACHED(); - return sql::INIT_FAILURE; - } - - while (s.Step()) { - sql::Statement update_s( - db_.GetUniqueStatement("UPDATE credit_cards " - "set guid=? WHERE unique_id=?")); - if (!update_s) { + // Set all the |guid| fields to valid values. + { + sql::Statement s(db_.GetUniqueStatement("SELECT unique_id " + "FROM credit_cards")); + if (!s) { LOG(WARNING) << "Unable to update web database to version 30."; NOTREACHED(); return sql::INIT_FAILURE; } - update_s.BindString(0, guid::GenerateGUID()); - update_s.BindInt(1, s.ColumnInt(0)); - if (!update_s.Run()) { - LOG(WARNING) << "Unable to update web database to version 30."; - NOTREACHED(); - return sql::INIT_FAILURE; + while (s.Step()) { + sql::Statement update_s( + db_.GetUniqueStatement("UPDATE credit_cards " + "set guid=? WHERE unique_id=?")); + if (!update_s) { + LOG(WARNING) << "Unable to update web database to version 30."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + update_s.BindString(0, guid::GenerateGUID()); + update_s.BindInt(1, s.ColumnInt(0)); + + if (!update_s.Run()) { + LOG(WARNING) << "Unable to update web database to version 30."; + NOTREACHED(); + return sql::INIT_FAILURE; + } } } } @@ -2581,6 +2462,99 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ // FALL THROUGH + case 31: + if (db_.DoesColumnExist("autofill_profiles", "unique_id")) { + if (!db_.Execute("CREATE TABLE autofill_profiles_temp ( " + "guid VARCHAR PRIMARY KEY, " + "label VARCHAR, " + "first_name VARCHAR, " + "middle_name VARCHAR, " + "last_name VARCHAR, " + "email VARCHAR, " + "company_name VARCHAR, " + "address_line_1 VARCHAR, " + "address_line_2 VARCHAR, " + "city VARCHAR, " + "state VARCHAR, " + "zipcode VARCHAR, " + "country VARCHAR, " + "phone VARCHAR, " + "fax VARCHAR, " + "date_modified INTEGER NOT NULL DEFAULT 0)")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + if (!db_.Execute( + "INSERT INTO autofill_profiles_temp " + "SELECT guid, label, first_name, middle_name, last_name, email, " + "company_name, address_line_1, address_line_2, city, state, zipcode, " + "country, phone, fax, date_modified " + "FROM autofill_profiles")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + if (!db_.Execute("DROP TABLE autofill_profiles")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + if (!db_.Execute( + "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + } + + if (db_.DoesColumnExist("credit_cards", "unique_id")) { + if (!db_.Execute("CREATE TABLE credit_cards_temp ( " + "guid VARCHAR PRIMARY KEY, " + "label VARCHAR, " + "name_on_card VARCHAR, " + "expiration_month INTEGER, " + "expiration_year INTEGER, " + "card_number_encrypted BLOB, " + "date_modified INTEGER NOT NULL DEFAULT 0)")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + if (!db_.Execute( + "INSERT INTO credit_cards_temp " + "SELECT guid, label, name_on_card, expiration_month, " + "expiration_year, card_number_encrypted, date_modified " + "FROM credit_cards")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + if (!db_.Execute("DROP TABLE credit_cards")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + + if (!db_.Execute( + "ALTER TABLE credit_cards_temp RENAME TO credit_cards")) { + LOG(WARNING) << "Unable to update web database to version 32."; + NOTREACHED(); + return sql::INIT_FAILURE; + } + } + + meta_table_.SetVersionNumber(32); + meta_table_.SetCompatibleVersionNumber( + std::min(32, kCompatibleVersionNumber)); + + // FALL THROUGH + // Add successive versions here. Each should set the version number and // compatible version number as appropriate, then fall through to the next // case. diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h index e7fd295..2d80437 100644 --- a/chrome/browser/webdata/web_database.h +++ b/chrome/browser/webdata/web_database.h @@ -226,21 +226,10 @@ class WebDatabase { // Updates the database values for the specified profile. virtual bool UpdateAutoFillProfile(const AutoFillProfile& profile); - // Removes a row from the autofill_profiles table. |profile_id| is the - // unique ID of the profile to remove. - // DEPRECATED: In favor of |RemoveAutoFillProfile(const std::string& guid)|. - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - virtual bool RemoveAutoFillProfile(int profile_id); - // Removes a row from the autofill_profiles table. |guid| is the identifier // of the profile to remove. virtual bool RemoveAutoFillProfile(const std::string& guid); - // Retrieves profile for unique id |profile_id|, owned by caller. - // DEPRECATED: In favor of |GetAutoFillProfileForGUID(...)|. - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - bool GetAutoFillProfileForID(int profile_id, AutoFillProfile** profile); - // Retrieves a profile with label |label|. The caller owns |profile|. // DEPRECATED: In favor of |GetAutoFillProfileForGUID(...)|. // TODO(dhollowa): Remove labels. http://crbug.com/58813 @@ -260,12 +249,6 @@ class WebDatabase { // Updates the database values for the specified credit card. bool UpdateCreditCard(const CreditCard& credit_card); - // Removes a row from the credit_cards table. |credit_card_id| is the - // unique ID of the credit card to remove. - // DEPRECATED: In favor of |RemoveCreditCard(const std::string& guid)|. - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - bool RemoveCreditCard(int credit_card_id); - // Removes a row from the credit_cards table. |guid| is the identifer of the // credit card to remove. bool RemoveCreditCard(const std::string& guid); @@ -277,11 +260,6 @@ class WebDatabase { bool GetCreditCardForLabel(const string16& label, CreditCard** credit_card); - // Retrieves credit card for a card with unique id |credit_card_id|. - // DEPRECATED: In favor of |GetCreditCardForGUID()|. - // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813 - bool GetCreditCardForID(int credit_card_id, CreditCard** credit_card); - // Retrieves a credit card with guid |guid|. The caller owns // |credit_card_id|. bool GetCreditCardForGUID(const std::string& guid, CreditCard** credit_card); diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 89cda5a..a49b7ee 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -94,6 +94,115 @@ bool CompareAutofillEntries(const AutofillEntry& a, const AutofillEntry& b) { return timestamps2.size() != 0U; } +void AutoFillProfile31FromStatement(const sql::Statement& s, + AutoFillProfile* profile, + string16* label, + int* unique_id, + int64* date_modified) { + DCHECK(profile); + DCHECK(label); + DCHECK(unique_id); + DCHECK(date_modified); + *label = s.ColumnString16(0); + *unique_id = s.ColumnInt(1); + profile->SetInfo(AutoFillType(NAME_FIRST), s.ColumnString16(2)); + profile->SetInfo(AutoFillType(NAME_MIDDLE), s.ColumnString16(3)); + profile->SetInfo(AutoFillType(NAME_LAST),s.ColumnString16(4)); + profile->SetInfo(AutoFillType(EMAIL_ADDRESS), s.ColumnString16(5)); + profile->SetInfo(AutoFillType(COMPANY_NAME), s.ColumnString16(6)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(11)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12)); + profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13)); + profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14)); + *date_modified = s.ColumnInt64(15); + profile->set_guid(s.ColumnString(16)); + EXPECT_TRUE(guid::IsValidGUID(profile->guid())); +} + +void AutoFillProfile32FromStatement(const sql::Statement& s, + AutoFillProfile* profile, + string16* label, + int64* date_modified) { + DCHECK(profile); + DCHECK(label); + DCHECK(date_modified); + profile->set_guid(s.ColumnString(0)); + EXPECT_TRUE(guid::IsValidGUID(profile->guid())); + *label = s.ColumnString16(1); + profile->SetInfo(AutoFillType(NAME_FIRST), s.ColumnString16(2)); + profile->SetInfo(AutoFillType(NAME_MIDDLE), s.ColumnString16(3)); + profile->SetInfo(AutoFillType(NAME_LAST),s.ColumnString16(4)); + profile->SetInfo(AutoFillType(EMAIL_ADDRESS), s.ColumnString16(5)); + profile->SetInfo(AutoFillType(COMPANY_NAME), s.ColumnString16(6)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(11)); + profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12)); + profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13)); + profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14)); + *date_modified = s.ColumnInt64(15); +} + +void CreditCard31FromStatement(const sql::Statement& s, + CreditCard* credit_card, + string16* label, + int* unique_id, + std::string* encrypted_number, + int64* date_modified) { + DCHECK(credit_card); + DCHECK(label); + DCHECK(unique_id); + DCHECK(encrypted_number); + DCHECK(date_modified); + *label = s.ColumnString16(0); + *unique_id = s.ColumnInt(1); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2)); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE), s.ColumnString16(3)); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), + s.ColumnString16(5)); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), + s.ColumnString16(6)); + int encrypted_number_len = s.ColumnByteLength(10); + if (encrypted_number_len) { + encrypted_number->resize(encrypted_number_len); + memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len); + } + *date_modified = s.ColumnInt64(12); + credit_card->set_guid(s.ColumnString(13)); + EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); +} + +void CreditCard32FromStatement(const sql::Statement& s, + CreditCard* credit_card, + string16* label, + std::string* encrypted_number, + int64* date_modified) { + DCHECK(credit_card); + DCHECK(label); + DCHECK(encrypted_number); + DCHECK(date_modified); + credit_card->set_guid(s.ColumnString(0)); + EXPECT_TRUE(guid::IsValidGUID(credit_card->guid())); + *label = s.ColumnString16(1); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2)); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), + s.ColumnString16(3)); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), + s.ColumnString16(4)); + int encrypted_number_len = s.ColumnByteLength(5); + if (encrypted_number_len) { + encrypted_number->resize(encrypted_number_len); + memcpy(&(*encrypted_number)[0], s.ColumnBlob(5), encrypted_number_len); + } + *date_modified = s.ColumnInt64(6); +} + } // namespace class WebDatabaseTest : public testing::Test { @@ -1258,7 +1367,8 @@ TEST_F(WebDatabaseTest, AutoFillProfile) { ASSERT_EQ(sql::INIT_OK, db.Init(file_)); // Add a 'Home' profile. - AutoFillProfile home_profile(ASCIIToUTF16("Home"), 17); + AutoFillProfile home_profile; + home_profile.set_label(ASCIIToUTF16("Home")); home_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John")); home_profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("Q.")); home_profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith")); @@ -1288,18 +1398,18 @@ TEST_F(WebDatabaseTest, AutoFillProfile) { ASSERT_TRUE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Home"), &db_profile)); EXPECT_EQ(home_profile, *db_profile); sql::Statement s_home(db.db_.GetUniqueStatement( - "SELECT * FROM autofill_profiles WHERE label='Home'")); + "SELECT date_modified " + "FROM autofill_profiles WHERE label='Home'")); ASSERT_TRUE(s_home); ASSERT_TRUE(s_home.Step()); - EXPECT_GE(s_home.ColumnInt64(15), pre_creation_time.ToTimeT()); - EXPECT_LE(s_home.ColumnInt64(15), post_creation_time.ToTimeT()); + EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT()); + EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT()); EXPECT_FALSE(s_home.Step()); delete db_profile; // Add a 'Billing' profile. AutoFillProfile billing_profile = home_profile; billing_profile.set_label(ASCIIToUTF16("Billing")); - billing_profile.set_unique_id(13); billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), ASCIIToUTF16("5678 Bottom Street")); billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), @@ -1315,11 +1425,11 @@ TEST_F(WebDatabaseTest, AutoFillProfile) { &db_profile)); EXPECT_EQ(billing_profile, *db_profile); sql::Statement s_billing(db.db_.GetUniqueStatement( - "SELECT * FROM autofill_profiles WHERE label='Billing'")); + "SELECT date_modified FROM autofill_profiles WHERE label='Billing'")); ASSERT_TRUE(s_billing); ASSERT_TRUE(s_billing.Step()); - EXPECT_GE(s_billing.ColumnInt64(15), pre_creation_time.ToTimeT()); - EXPECT_LE(s_billing.ColumnInt64(15), post_creation_time.ToTimeT()); + EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT()); + EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT()); EXPECT_FALSE(s_billing.Step()); delete db_profile; @@ -1332,25 +1442,24 @@ TEST_F(WebDatabaseTest, AutoFillProfile) { &db_profile)); EXPECT_EQ(billing_profile, *db_profile); sql::Statement s_billing_updated(db.db_.GetUniqueStatement( - "SELECT * FROM autofill_profiles WHERE label='Billing'")); + "SELECT date_modified FROM autofill_profiles WHERE label='Billing'")); ASSERT_TRUE(s_billing_updated); ASSERT_TRUE(s_billing_updated.Step()); - EXPECT_GE(s_billing_updated.ColumnInt64(15), + EXPECT_GE(s_billing_updated.ColumnInt64(0), pre_modification_time.ToTimeT()); - EXPECT_LE(s_billing_updated.ColumnInt64(15), + EXPECT_LE(s_billing_updated.ColumnInt64(0), post_modification_time.ToTimeT()); EXPECT_FALSE(s_billing_updated.Step()); delete db_profile; // Remove the 'Billing' profile. - EXPECT_TRUE(db.RemoveAutoFillProfile(billing_profile.unique_id())); + EXPECT_TRUE(db.RemoveAutoFillProfile(billing_profile.guid())); EXPECT_FALSE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Billing"), &db_profile)); // Add a 'GUID' profile. AutoFillProfile guid_profile = home_profile; guid_profile.set_label(ASCIIToUTF16("GUID")); - guid_profile.set_unique_id(14); guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), ASCIIToUTF16("5678 Top Street")); guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), @@ -1383,11 +1492,10 @@ TEST_F(WebDatabaseTest, CreditCard) { ASSERT_EQ(sql::INIT_OK, db.Init(file_)); // Add a 'Work' credit card. - CreditCard work_creditcard(ASCIIToUTF16("Work"), 13); + CreditCard work_creditcard; + work_creditcard.set_label(ASCIIToUTF16("Work")); work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Jack Torrance")); - work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_TYPE), - ASCIIToUTF16("Visa")); work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234567890123456")); work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), @@ -1404,20 +1512,21 @@ TEST_F(WebDatabaseTest, CreditCard) { ASSERT_TRUE(db.GetCreditCardForLabel(ASCIIToUTF16("Work"), &db_creditcard)); EXPECT_EQ(work_creditcard, *db_creditcard); sql::Statement s_work(db.db_.GetUniqueStatement( - "SELECT * FROM credit_cards WHERE label='Work'")); + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " + "FROM credit_cards WHERE label='Work'")); ASSERT_TRUE(s_work); ASSERT_TRUE(s_work.Step()); - EXPECT_GE(s_work.ColumnInt64(12), pre_creation_time.ToTimeT()); - EXPECT_LE(s_work.ColumnInt64(12), post_creation_time.ToTimeT()); + EXPECT_GE(s_work.ColumnInt64(6), pre_creation_time.ToTimeT()); + EXPECT_LE(s_work.ColumnInt64(6), post_creation_time.ToTimeT()); EXPECT_FALSE(s_work.Step()); delete db_creditcard; // Add a 'Target' credit card. - CreditCard target_creditcard(ASCIIToUTF16("Target"), 7); + CreditCard target_creditcard; + target_creditcard.set_label(ASCIIToUTF16("Target")); target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Jack Torrance")); - target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_TYPE), - ASCIIToUTF16("Mastercard")); target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1111222233334444")); target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), @@ -1432,11 +1541,13 @@ TEST_F(WebDatabaseTest, CreditCard) { &db_creditcard)); EXPECT_EQ(target_creditcard, *db_creditcard); sql::Statement s_target(db.db_.GetUniqueStatement( - "SELECT * FROM credit_cards WHERE label='Target'")); + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " + "FROM credit_cards WHERE label='Target'")); ASSERT_TRUE(s_target); ASSERT_TRUE(s_target.Step()); - EXPECT_GE(s_target.ColumnInt64(12), pre_creation_time.ToTimeT()); - EXPECT_LE(s_target.ColumnInt64(12), post_creation_time.ToTimeT()); + EXPECT_GE(s_target.ColumnInt64(6), pre_creation_time.ToTimeT()); + EXPECT_LE(s_target.ColumnInt64(6), post_creation_time.ToTimeT()); EXPECT_FALSE(s_target.Step()); delete db_creditcard; @@ -1449,27 +1560,28 @@ TEST_F(WebDatabaseTest, CreditCard) { ASSERT_TRUE(db.GetCreditCardForLabel(ASCIIToUTF16("Target"), &db_creditcard)); EXPECT_EQ(target_creditcard, *db_creditcard); sql::Statement s_target_updated(db.db_.GetUniqueStatement( - "SELECT * FROM credit_cards WHERE label='Target'")); + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " + "FROM credit_cards WHERE label='Target'")); ASSERT_TRUE(s_target_updated); ASSERT_TRUE(s_target_updated.Step()); - EXPECT_GE(s_target_updated.ColumnInt64(12), + EXPECT_GE(s_target_updated.ColumnInt64(6), pre_modification_time.ToTimeT()); - EXPECT_LE(s_target_updated.ColumnInt64(12), + EXPECT_LE(s_target_updated.ColumnInt64(6), post_modification_time.ToTimeT()); EXPECT_FALSE(s_target_updated.Step()); delete db_creditcard; // Remove the 'Target' credit card. - EXPECT_TRUE(db.RemoveCreditCard(target_creditcard.unique_id())); + EXPECT_TRUE(db.RemoveCreditCard(target_creditcard.guid())); EXPECT_FALSE(db.GetCreditCardForLabel(ASCIIToUTF16("Target"), &db_creditcard)); // Add a 'GUID' profile. - CreditCard guid_creditcard(ASCIIToUTF16("GUID"), 7); + CreditCard guid_creditcard; + guid_creditcard.set_label(ASCIIToUTF16("GUID")); guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Jimmy Jones")); - guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_TYPE), - ASCIIToUTF16("Amex")); guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("9999222233334444")); guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), @@ -1503,84 +1615,84 @@ TEST_F(WebDatabaseTest, RemoveAutoFillProfilesAndCreditCardsModifiedBetween) { // Populate the autofill_profiles and credit_cards tables. ASSERT_TRUE(db.db_.Execute( - "INSERT INTO \"autofill_profiles\" VALUES('P1',1,'','','','','','','',''," - "'','','','','',11,'00000000-0000-0000-0000-000000000000');" - "INSERT INTO \"autofill_profiles\" VALUES('P2',2,'','','','','','','',''," - "'','','','','',21,'00000000-0000-0000-0000-000000000001');" - "INSERT INTO \"autofill_profiles\" VALUES('P3',3,'','','','','','','',''," - "'','','','','',31,'00000000-0000-0000-0000-000000000002');" - "INSERT INTO \"autofill_profiles\" VALUES('P4',4,'','','','','','','',''," - "'','','','','',41,'00000000-0000-0000-0000-000000000003');" - "INSERT INTO \"autofill_profiles\" VALUES('P5',5,'','','','','','','',''," - "'','','','','',51,'00000000-0000-0000-0000-000000000004');" - "INSERT INTO \"autofill_profiles\" VALUES('P6',6,'','','','','','','',''," - "'','','','','',61,'00000000-0000-0000-0000-000000000005');" - "INSERT INTO \"credit_cards\" VALUES('C10',10,'','','',10,2010,'','',''," - "X'',X'',17,'00000000-0000-0000-0000-000000000006');" - "INSERT INTO \"credit_cards\" VALUES('C20',20,'','','',10,2010,'','',''," - "X'',X'',27,'00000000-0000-0000-0000-000000000007');" - "INSERT INTO \"credit_cards\" VALUES('C30',30,'','','',10,2010,'','',''," - "X'',X'',37,'00000000-0000-0000-0000-000000000008');" - "INSERT INTO \"credit_cards\" VALUES('C40',40,'','','',10,2010,'','',''," - "X'',X'',47,'00000000-0000-0000-0000-000000000009');" - "INSERT INTO \"credit_cards\" VALUES('C50',50,'','','',10,2010,'','',''," - "X'',X'',57,'00000000-0000-0000-0000-000000000010');" - "INSERT INTO \"credit_cards\" VALUES('C60',60,'','','',10,2010,'','',''," - "X'',X'',67,'00000000-0000-0000-0000-000000000011');")); + "INSERT INTO autofill_profiles (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000000', 11);" + "INSERT INTO autofill_profiles (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000001', 21);" + "INSERT INTO autofill_profiles (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000002', 31);" + "INSERT INTO autofill_profiles (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000003', 41);" + "INSERT INTO autofill_profiles (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000004', 51);" + "INSERT INTO autofill_profiles (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000005', 61);" + "INSERT INTO credit_cards (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000006', 17);" + "INSERT INTO credit_cards (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000007', 27);" + "INSERT INTO credit_cards (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000008', 37);" + "INSERT INTO credit_cards (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000009', 47);" + "INSERT INTO credit_cards (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000010', 57);" + "INSERT INTO credit_cards (guid, date_modified) " + "VALUES('00000000-0000-0000-0000-000000000011', 67);")); // Remove all entries modified in the bounded time range [17,41). db.RemoveAutoFillProfilesAndCreditCardsModifiedBetween( base::Time::FromTimeT(17), base::Time::FromTimeT(41)); sql::Statement s_autofill_profiles_bounded(db.db_.GetUniqueStatement( - "SELECT * FROM autofill_profiles")); + "SELECT date_modified FROM autofill_profiles")); ASSERT_TRUE(s_autofill_profiles_bounded); ASSERT_TRUE(s_autofill_profiles_bounded.Step()); - EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(15)); + EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(0)); ASSERT_TRUE(s_autofill_profiles_bounded.Step()); - EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(15)); + EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(0)); ASSERT_TRUE(s_autofill_profiles_bounded.Step()); - EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(15)); + EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(0)); ASSERT_TRUE(s_autofill_profiles_bounded.Step()); - EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(15)); + EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(0)); EXPECT_FALSE(s_autofill_profiles_bounded.Step()); sql::Statement s_credit_cards_bounded(db.db_.GetUniqueStatement( - "SELECT * FROM credit_cards")); + "SELECT date_modified FROM credit_cards")); ASSERT_TRUE(s_credit_cards_bounded); ASSERT_TRUE(s_credit_cards_bounded.Step()); - EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(12)); + EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(0)); ASSERT_TRUE(s_credit_cards_bounded.Step()); - EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(12)); + EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(0)); ASSERT_TRUE(s_credit_cards_bounded.Step()); - EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(12)); + EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(0)); EXPECT_FALSE(s_credit_cards_bounded.Step()); // Remove all entries modified on or after time 51 (unbounded range). db.RemoveAutoFillProfilesAndCreditCardsModifiedBetween( base::Time::FromTimeT(51), base::Time()); sql::Statement s_autofill_profiles_unbounded(db.db_.GetUniqueStatement( - "SELECT * FROM autofill_profiles")); + "SELECT date_modified FROM autofill_profiles")); ASSERT_TRUE(s_autofill_profiles_unbounded); ASSERT_TRUE(s_autofill_profiles_unbounded.Step()); - EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(15)); + EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(0)); ASSERT_TRUE(s_autofill_profiles_unbounded.Step()); - EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(15)); + EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(0)); EXPECT_FALSE(s_autofill_profiles_unbounded.Step()); sql::Statement s_credit_cards_unbounded(db.db_.GetUniqueStatement( - "SELECT * FROM credit_cards")); + "SELECT date_modified FROM credit_cards")); ASSERT_TRUE(s_credit_cards_unbounded); ASSERT_TRUE(s_credit_cards_unbounded.Step()); - EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(12)); + EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(0)); EXPECT_FALSE(s_credit_cards_unbounded.Step()); // Remove all remaining entries. db.RemoveAutoFillProfilesAndCreditCardsModifiedBetween(base::Time(), base::Time()); sql::Statement s_autofill_profiles_empty(db.db_.GetUniqueStatement( - "SELECT * FROM autofill_profiles")); + "SELECT date_modified FROM autofill_profiles")); ASSERT_TRUE(s_autofill_profiles_empty); EXPECT_FALSE(s_autofill_profiles_empty.Step()); sql::Statement s_credit_cards_empty(db.db_.GetUniqueStatement( - "SELECT * FROM credit_cards")); + "SELECT date_modified FROM credit_cards")); ASSERT_TRUE(s_credit_cards_empty); EXPECT_FALSE(s_credit_cards_empty.Step()); } @@ -1813,7 +1925,7 @@ class WebDatabaseMigrationTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); }; -const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 31; +const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 32; void WebDatabaseMigrationTest::LoadDatabase(const FilePath& file) { std::string contents; @@ -1931,7 +2043,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) { ASSERT_TRUE(connection.Open(GetDatabasePath())); // No |credit_card| table prior to version 23. - ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id")); + ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "guid")); ASSERT_FALSE( connection.DoesColumnExist("credit_cards", "card_number_encrypted")); } @@ -1953,7 +2065,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) { EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); // |credit_card| table now exists. - EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); EXPECT_TRUE( connection.DoesColumnExist("credit_cards", "card_number_encrypted")); } @@ -2003,7 +2115,8 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) { // Columns existing and not existing before version 25. - EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); EXPECT_TRUE( connection.DoesColumnExist("credit_cards", "card_number_encrypted")); EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); @@ -2146,24 +2259,20 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) { // Check version. EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); - EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address")); - // |billing_address| is an integer. Also Verify the credit card data is - // converted. - std::string stmt = "SELECT * FROM credit_cards"; - sql::Statement s(connection.GetUniqueStatement(stmt.c_str())); + // Verify the credit card data is converted. + sql::Statement s(connection.GetUniqueStatement( + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " + "FROM credit_cards")); ASSERT_TRUE(s.Step()); - EXPECT_EQ(s.ColumnType(8), sql::COLUMN_TYPE_INTEGER); - EXPECT_EQ("label", s.ColumnString(0)); - EXPECT_EQ(2, s.ColumnInt(1)); + EXPECT_EQ("label", s.ColumnString(1)); EXPECT_EQ("Jack", s.ColumnString(2)); - EXPECT_EQ("Visa", s.ColumnString(3)); - EXPECT_EQ("1234", s.ColumnString(4)); - EXPECT_EQ(2, s.ColumnInt(5)); - EXPECT_EQ(2012, s.ColumnInt(6)); - EXPECT_EQ(std::string(), s.ColumnString(7)); - EXPECT_EQ(1, s.ColumnInt(8)); - // The remaining columns are unused or blobs. + EXPECT_EQ(2, s.ColumnInt(3)); + EXPECT_EQ(2012, s.ColumnInt(4)); + // Column 5 is encrypted number blob. + // Column 6 is date_modified. } } @@ -2226,24 +2335,20 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) { // |keywords| |logo_id| column should have been added. EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy")); - EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address")); - // |billing_address| is an integer. Also Verify the credit card data is - // converted. - std::string stmt = "SELECT * FROM credit_cards"; - sql::Statement s(connection.GetUniqueStatement(stmt.c_str())); + // Verify the credit card data is converted. + sql::Statement s(connection.GetUniqueStatement( + "SELECT guid, label, name_on_card, expiration_month, expiration_year, " + "card_number_encrypted, date_modified " + "FROM credit_cards")); ASSERT_TRUE(s.Step()); - EXPECT_EQ(s.ColumnType(8), sql::COLUMN_TYPE_INTEGER); - EXPECT_EQ("label", s.ColumnString(0)); - EXPECT_EQ(2, s.ColumnInt(1)); + EXPECT_EQ("label", s.ColumnString(1)); EXPECT_EQ("Jack", s.ColumnString(2)); - EXPECT_EQ("Visa", s.ColumnString(3)); - EXPECT_EQ("1234", s.ColumnString(4)); - EXPECT_EQ(2, s.ColumnInt(5)); - EXPECT_EQ(2012, s.ColumnInt(6)); - EXPECT_EQ(std::string(), s.ColumnString(7)); - EXPECT_EQ(1, s.ColumnInt(8)); - // The remaining columns are unused or blobs. + EXPECT_EQ(2, s.ColumnInt(3)); + EXPECT_EQ(2012, s.ColumnInt(4)); + // Column 5 is encrypted credit card number blob. + // Column 6 is date_modified. } } @@ -2330,23 +2435,23 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) { "date_modified")); sql::Statement s_profiles(connection.GetUniqueStatement( - "SELECT * FROM autofill_profiles ")); + "SELECT date_modified FROM autofill_profiles ")); ASSERT_TRUE(s_profiles); while (s_profiles.Step()) { - EXPECT_GE(s_profiles.ColumnInt64(15), + EXPECT_GE(s_profiles.ColumnInt64(0), pre_creation_time.ToTimeT()); - EXPECT_LE(s_profiles.ColumnInt64(15), + EXPECT_LE(s_profiles.ColumnInt64(0), post_creation_time.ToTimeT()); } EXPECT_TRUE(s_profiles.Succeeded()); sql::Statement s_credit_cards(connection.GetUniqueStatement( - "SELECT * FROM credit_cards ")); + "SELECT date_modified FROM credit_cards ")); ASSERT_TRUE(s_credit_cards); while (s_credit_cards.Step()) { - EXPECT_GE(s_credit_cards.ColumnInt64(12), + EXPECT_GE(s_credit_cards.ColumnInt64(0), pre_creation_time.ToTimeT()); - EXPECT_LE(s_credit_cards.ColumnInt64(12), + EXPECT_LE(s_credit_cards.ColumnInt64(0), post_creation_time.ToTimeT()); } EXPECT_TRUE(s_credit_cards.Succeeded()); @@ -2404,3 +2509,142 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) { EXPECT_NE(guid1, guid2); } } + +// Removes unique IDs and make GUIDs the primary key. Also removes unused +// columns. +TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { + // Initialize the database. + ASSERT_NO_FATAL_FAILURE( + LoadDatabase(FilePath(FILE_PATH_LITERAL("version_31.sql")))); + + // Verify pre-conditions. These are expectations for version 30 of the + // database. + AutoFillProfile profile; + string16 profile_label; + int profile_unique_id = 0; + int64 profile_date_modified = 0; + CreditCard credit_card; + string16 cc_label; + int cc_unique_id = 0; + std::string cc_number_encrypted; + int64 cc_date_modified = 0; + { + sql::Connection connection; + ASSERT_TRUE(connection.Open(GetDatabasePath())); + + // Verify existence of columns we'll be changing. + EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid")); + EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "unique_id")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "type")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "card_number")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", + "verification_code")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "shipping_address")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", + "verification_code_encrypted")); + + // Fetch data in the database prior to migration. + sql::Statement s1( + connection.GetUniqueStatement( + "SELECT label, unique_id, first_name, middle_name, last_name, " + "email, company_name, address_line_1, address_line_2, city, state, " + "zipcode, country, phone, fax, date_modified, guid " + "FROM autofill_profiles")); + ASSERT_TRUE(s1.Step()); + EXPECT_NO_FATAL_FAILURE(AutoFillProfile31FromStatement( + s1, &profile, &profile_label, &profile_unique_id, + &profile_date_modified)); + + sql::Statement s2( + connection.GetUniqueStatement( + "SELECT label, unique_id, name_on_card, type, card_number, " + "expiration_month, expiration_year, verification_code, " + "billing_address, shipping_address, card_number_encrypted, " + "verification_code_encrypted, date_modified, guid " + "FROM credit_cards")); + ASSERT_TRUE(s2.Step()); + EXPECT_NO_FATAL_FAILURE(CreditCard31FromStatement(s2, + &credit_card, + &cc_label, + &cc_unique_id, + &cc_number_encrypted, + &cc_date_modified)); + + EXPECT_NE(profile_unique_id, cc_unique_id); + EXPECT_NE(profile.guid(), credit_card.guid()); + } + + // Load the database via the WebDatabase class and migrate the database to + // the current version. + { + WebDatabase db; + ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); + } + + // Verify post-conditions. These are expectations for current version of the + // database. + { + sql::Connection connection; + ASSERT_TRUE(connection.Open(GetDatabasePath())); + + // Check version. + EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); + + // Verify existence of columns we'll be changing. + EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid")); + EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "unique_id")); + EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "type")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "card_number")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", + "verification_code")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", + "shipping_address")); + EXPECT_FALSE(connection.DoesColumnExist("credit_cards", + "verification_code_encrypted")); + + // Verify data in the database after the migration. + sql::Statement s1( + connection.GetUniqueStatement( + "SELECT guid, label, first_name, middle_name, last_name, " + "email, company_name, address_line_1, address_line_2, city, state, " + "zipcode, country, phone, fax, date_modified " + "FROM autofill_profiles")); + ASSERT_TRUE(s1.Step()); + + AutoFillProfile profile_a; + string16 profile_label_a; + int64 profile_date_modified_a = 0; + EXPECT_NO_FATAL_FAILURE(AutoFillProfile32FromStatement( + s1, &profile_a, &profile_label_a, &profile_date_modified_a)); + EXPECT_EQ(profile, profile_a); + EXPECT_EQ(profile_label, profile_label_a); + EXPECT_EQ(profile_date_modified, profile_date_modified_a); + + sql::Statement s2( + connection.GetUniqueStatement( + "SELECT guid, label, name_on_card, expiration_month, " + "expiration_year, card_number_encrypted, date_modified " + "FROM credit_cards")); + ASSERT_TRUE(s2.Step()); + + CreditCard credit_card_a; + string16 cc_label_a; + std::string cc_number_encrypted_a; + int64 cc_date_modified_a = 0; + EXPECT_NO_FATAL_FAILURE(CreditCard32FromStatement(s2, + &credit_card_a, + &cc_label_a, + &cc_number_encrypted_a, + &cc_date_modified_a)); + EXPECT_EQ(credit_card, credit_card_a); + EXPECT_EQ(cc_label, cc_label_a); + EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); + EXPECT_EQ(cc_date_modified, cc_date_modified_a); + } +} diff --git a/chrome/test/data/web_database/version_31.sql b/chrome/test/data/web_database/version_31.sql new file mode 100644 index 0000000..feb12b4 --- /dev/null +++ b/chrome/test/data/web_database/version_31.sql @@ -0,0 +1,29 @@ +PRAGMA foreign_keys=OFF; +BEGIN TRANSACTION; +CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,value LONGVARCHAR); +INSERT INTO "meta" VALUES('version','31'); +INSERT INTO "meta" VALUES('last_compatible_version','31'); +INSERT INTO "meta" VALUES('Default Search Provider ID','2'); +INSERT INTO "meta" VALUES('Builtin Keyword Version','32'); +CREATE TABLE keywords (id INTEGER PRIMARY KEY,short_name VARCHAR NOT NULL,keyword VARCHAR NOT NULL,favicon_url VARCHAR NOT NULL,url VARCHAR NOT NULL,show_in_default_list INTEGER,safe_for_autoreplace INTEGER,originating_url VARCHAR,date_created INTEGER DEFAULT 0,usage_count INTEGER DEFAULT 0,input_encodings VARCHAR,suggest_url VARCHAR,prepopulate_id INTEGER DEFAULT 0,autogenerate_keyword INTEGER DEFAULT 0,logo_id INTEGER DEFAULT 0,created_by_policy INTEGER DEFAULT 0,instant_url VARCHAR); +INSERT INTO "keywords" VALUES(2,'Google','google.com','http://www.google.com/favicon.ico','{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}&q={searchTerms}',1,1,'',0,0,'UTF-8','{google:baseSuggestURL}search?client=chrome&hl={language}&q={searchTerms}',1,1,6247,0,'{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&ie={inputEncoding}&ion=1{searchTerms}'); +INSERT INTO "keywords" VALUES(3,'Yahoo!','yahoo.com','http://search.yahoo.com/favicon.ico','http://search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}',1,1,'',0,0,'UTF-8','http://ff.search.yahoo.com/gossip?output=fxjson&command={searchTerms}',2,0,6264,0,''); +INSERT INTO "keywords" VALUES(4,'Bing','bing.com','http://www.bing.com/s/wlflag.ico','http://www.bing.com/search?q={searchTerms}',1,1,'',0,0,'UTF-8','http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}',3,0,6241,0,''); +CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR, username_element VARCHAR, username_value VARCHAR, password_element VARCHAR, password_value BLOB, submit_element VARCHAR, signon_realm VARCHAR NOT NULL,ssl_valid INTEGER NOT NULL,preferred INTEGER NOT NULL,date_created INTEGER NOT NULL,blacklisted_by_user INTEGER NOT NULL,scheme INTEGER NOT NULL,UNIQUE (origin_url, username_element, username_value, password_element, submit_element, signon_realm)); +CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int,image BLOB, UNIQUE (url, width, height)); +CREATE TABLE web_apps (url LONGVARCHAR UNIQUE,has_all_images INTEGER NOT NULL); +CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR, pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1); +CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0, date_created INTEGER DEFAULT 0); +CREATE TABLE autofill_profiles ( label VARCHAR, unique_id INTEGER PRIMARY KEY, first_name VARCHAR, middle_name VARCHAR, last_name VARCHAR, email VARCHAR, company_name VARCHAR, address_line_1 VARCHAR, address_line_2 VARCHAR, city VARCHAR, state VARCHAR, zipcode VARCHAR, country VARCHAR, phone VARCHAR, fax VARCHAR, date_modified INTEGER NOT NULL DEFAULT 0, guid VARCHAR NOT NULL DEFAULT ""); +INSERT INTO "autofill_profiles" VALUES('Elvis Presley, 1122 PBJ Lane',1,'Elvis','','Presley','elvis@elvis.com','Hip Shake Inc.','1122 PBJ Lane','Suite 1','Memphis','TN','38116','USA','9013323322','',1288642516,'A4FF32F6-EF3F-379A-87F2-40A8811182A7'); +CREATE TABLE credit_cards ( label VARCHAR, unique_id INTEGER PRIMARY KEY, name_on_card VARCHAR, type VARCHAR, card_number VARCHAR, expiration_month INTEGER, expiration_year INTEGER, verification_code VARCHAR, billing_address VARCHAR, shipping_address VARCHAR, card_number_encrypted BLOB, verification_code_encrypted BLOB, date_modified INTEGER NOT NULL DEFAULT 0, guid VARCHAR NOT NULL DEFAULT ""); +INSERT INTO "credit_cards" VALUES('',2,'Jim J Jones','','',1,2011,'','0','',X'7631309863E9F1F33C2BDBFBFC86708448BDD8B37A495B628C8459A60D0CCD1047E69F',X'',1288642516,'B77F749C-8B0E-44B2-D299-3C80A95E0ADD'); +CREATE TABLE token_service (service VARCHAR PRIMARY KEY NOT NULL,encrypted_token BLOB); +CREATE INDEX logins_signon ON logins (signon_realm); +CREATE INDEX web_apps_url_index ON web_apps (url); +CREATE INDEX autofill_name ON autofill (name); +CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower); +CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id); +CREATE INDEX autofill_profiles_label_index ON autofill_profiles (label); +CREATE INDEX credit_cards_label_index ON credit_cards (label); +COMMIT; diff --git a/chrome/test/live_sync/live_autofill_sync_test.h b/chrome/test/live_sync/live_autofill_sync_test.h index 32cb2d3..0a12b1d 100644 --- a/chrome/test/live_sync/live_autofill_sync_test.h +++ b/chrome/test/live_sync/live_autofill_sync_test.h @@ -275,7 +275,7 @@ class LiveAutofillSyncTest : public LiveSyncTest { return false; } AutoFillProfile* expected_profile = &expected_profiles_map[p->Label()]; - expected_profile->set_unique_id(p->unique_id()); + expected_profile->set_guid(p->guid()); if (*expected_profile != *p) { VLOG(1) << "Profile mismatch"; return false; diff --git a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc index 916782f..db522f1 100644 --- a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc @@ -145,9 +145,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ProfileClient1HasData) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, expected_profiles[0]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[1]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[1]); @@ -168,11 +168,11 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ConflictLabels) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; AutoFillProfiles profiles1; - profiles1.push_back(new AutoFillProfile(string16(), 0)); + profiles1.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, profiles1[0]); AutoFillProfiles profiles2; - profiles2.push_back(new AutoFillProfile(string16(), 0)); + profiles2.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, profiles2[0]); profiles2[0]->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("1234567890")); @@ -200,9 +200,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[0]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[1]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); @@ -230,7 +230,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, FAILS_ProfileSteady) { // Client0 adds a profile. AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -242,7 +242,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, FAILS_ProfileSteady) { GetAllAutoFillProfiles(GetPersonalDataManager(1)))); // Client1 adds a profile. - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, expected_profiles[1]); AddProfile(GetPersonalDataManager(1), *expected_profiles[1]); ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); @@ -254,7 +254,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, FAILS_ProfileSteady) { GetAllAutoFillProfiles(GetPersonalDataManager(1)))); // Client0 adds a conflicting profile. - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, expected_profiles[2]); AddProfile(GetPersonalDataManager(0), *expected_profiles[2]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -313,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddEmptyProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_NULL, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -331,7 +331,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -351,19 +351,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[1]); AddProfile(GetPersonalDataManager(0), *expected_profiles[1]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_NULL, expected_profiles[2]); AddProfile(GetPersonalDataManager(0), *expected_profiles[2]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_FRASIER, expected_profiles[3]); AddProfile(GetPersonalDataManager(0), *expected_profiles[3]); @@ -398,7 +398,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DeleteProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -427,19 +427,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, FAILS_MergeProfiles) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_NULL, expected_profiles[1]); AddProfile(GetPersonalDataManager(0), *expected_profiles[1]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, expected_profiles[2]); AddProfile(GetPersonalDataManager(1), *expected_profiles[2]); - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_FRASIER, expected_profiles[3]); AddProfile(GetPersonalDataManager(1), *expected_profiles[3]); ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); @@ -457,7 +457,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateFields) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -489,12 +489,12 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateLabel) { AutoFillProfiles expected_profiles; AutoFillProfiles profiles0; - profiles0.push_back(new AutoFillProfile(string16(), 0)); + profiles0.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, profiles0[0]); expected_profiles.push_back(profiles0[0]); AutoFillProfiles profiles1; - profiles1.push_back(new AutoFillProfile(string16(), 0)); + profiles1.push_back(new AutoFillProfile); FillProfile(PROFILE_MARION, profiles1[0]); profiles1[0]->set_label(ASCIIToUTF16("Shipping")); expected_profiles.push_back(profiles1[0]); @@ -518,7 +518,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ConflictFields) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; AutoFillProfiles expected_profiles; - expected_profiles.push_back(new AutoFillProfile(string16(), 0)); + expected_profiles.push_back(new AutoFillProfile); FillProfile(PROFILE_HOMER, expected_profiles[0]); AddProfile(GetPersonalDataManager(0), *expected_profiles[0]); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |