summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2015-04-01 15:54:38 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-01 22:55:50 +0000
commitdacf4b43686accafdd2e9cf0c91f515147204d18 (patch)
treef6c7c36375fe8b0c20216d40a4f66d903d56bffb
parenta9373cadd74221c6aaa77ca5b5fc2e7e7f5c4ed7 (diff)
downloadchromium_src-dacf4b43686accafdd2e9cf0c91f515147204d18.zip
chromium_src-dacf4b43686accafdd2e9cf0c91f515147204d18.tar.gz
chromium_src-dacf4b43686accafdd2e9cf0c91f515147204d18.tar.bz2
Clear wallet data when sync is disabled.
Stop syncing (and therefore clear) wallet data when wallet autofill is disabled in the autofill settings dialog. Stop re-masking cards on shutdown. Now masked and unmasked cards and addresses are deleted and not repopulated when the wallet integration is disabled. Deleted an unused registrar class from the PrefMetricsService I noticed when researching this. BUG=469847,462787,450843 Review URL: https://codereview.chromium.org/1046023002 Cr-Commit-Position: refs/heads/master@{#323354}
-rw-r--r--chrome/browser/prefs/pref_metrics_service.h2
-rw-r--r--chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc73
-rw-r--r--chrome/browser/sync/glue/autofill_wallet_data_type_controller.h11
-rw-r--r--chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc131
-rw-r--r--components/autofill/core/browser/personal_data_manager.cc14
-rw-r--r--components/autofill/core/browser/personal_data_manager.h3
-rw-r--r--components/autofill/core/browser/personal_data_manager_unittest.cc35
-rw-r--r--components/autofill/core/browser/webdata/autofill_table.cc24
-rw-r--r--components/autofill/core/browser/webdata/autofill_table.h5
-rw-r--r--components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc5
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc10
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h2
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_service.cc7
-rw-r--r--components/autofill/core/browser/webdata/autofill_webdata_service.h3
14 files changed, 268 insertions, 57 deletions
diff --git a/chrome/browser/prefs/pref_metrics_service.h b/chrome/browser/prefs/pref_metrics_service.h
index 0335817..f7f7ff4 100644
--- a/chrome/browser/prefs/pref_metrics_service.h
+++ b/chrome/browser/prefs/pref_metrics_service.h
@@ -11,7 +11,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
-#include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/prefs/synced_pref_change_registrar.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
@@ -84,7 +83,6 @@ class PrefMetricsService : public KeyedService {
PrefService* prefs_;
PrefService* local_state_;
- PrefChangeRegistrar pref_registrar_;
scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_;
base::WeakPtrFactory<PrefMetricsService> weak_factory_;
diff --git a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc b/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
index 00ec1a8..2f644ba 100644
--- a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
+++ b/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
#include "chrome/browser/sync/profile_sync_components_factory.h"
@@ -13,6 +14,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/pref_names.h"
+#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "content/public/browser/browser_thread.h"
#include "sync/api/sync_error.h"
@@ -30,12 +32,17 @@ AutofillWalletDataTypeController::AutofillWalletDataTypeController(
base::Bind(&ChromeReportUnrecoverableError),
profile_sync_factory),
profile_(profile),
- callback_registered_(false) {
+ callback_registered_(false),
+ currently_enabled_(IsEnabled()) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
pref_registrar_.Init(profile->GetPrefs());
pref_registrar_.Add(
autofill::prefs::kAutofillWalletSyncExperimentEnabled,
- base::Bind(&AutofillWalletDataTypeController::OnSyncExperimentPrefChanged,
+ base::Bind(&AutofillWalletDataTypeController::OnSyncPrefChanged,
+ base::Unretained(this)));
+ pref_registrar_.Add(
+ autofill::prefs::kAutofillWalletImportEnabled,
+ base::Bind(&AutofillWalletDataTypeController::OnSyncPrefChanged,
base::Unretained(this)));
}
@@ -83,24 +90,55 @@ bool AutofillWalletDataTypeController::StartModels() {
void AutofillWalletDataTypeController::StopModels() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // This function is called when shutting down (nothing is changing), when
+ // sync is disabled completely, or when wallet sync is disabled. In the
+ // cases where wallet sync or sync in general is disabled, clear wallet cards
+ // and addresses copied from the server. This is different than other sync
+ // cases since this type of data reflects what's on the server rather than
+ // syncing local data between clients, so this extra step is required.
+ ProfileSyncService* service =
+ ProfileSyncServiceFactory::GetForProfile(profile_);
+
+ // HasSyncSetupCompleted indicates if sync is currently enabled at all. The
+ // preferred data type indicates if wallet sync is enabled, and
+ // currently_enabled_ indicates if the other prefs are enabled. All of these
+ // have to be enabled to sync wallet cards.
+ if (!service->HasSyncSetupCompleted() ||
+ !service->GetPreferredDataTypes().Has(syncer::AUTOFILL_WALLET_DATA) ||
+ !currently_enabled_) {
+ autofill::PersonalDataManager* pdm =
+ autofill::PersonalDataManagerFactory::GetForProfile(profile_);
+ if (pdm)
+ pdm->ClearAllServerData();
+ }
}
bool AutofillWalletDataTypeController::ReadyForStart() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return profile_->GetPrefs()->GetBoolean(
- autofill::prefs::kAutofillWalletSyncExperimentEnabled);
+ return currently_enabled_;
}
void AutofillWalletDataTypeController::WebDatabaseLoaded() {
OnModelLoaded();
}
-void AutofillWalletDataTypeController::OnSyncExperimentPrefChanged() {
+void AutofillWalletDataTypeController::OnSyncPrefChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!profile_->GetPrefs()->GetBoolean(
- autofill::prefs::kAutofillWalletSyncExperimentEnabled)) {
- // If autofill wallet sync is disabled, post a task to the backend thread to
- // stop the datatype.
+
+ bool new_enabled = IsEnabled();
+ if (currently_enabled_ == new_enabled)
+ return; // No change to sync state.
+ currently_enabled_ = new_enabled;
+
+ if (currently_enabled_) {
+ // The experiment was just enabled. Trigger a reconfiguration. This will do
+ // nothing if the type isn't preferred.
+ ProfileSyncService* sync_service =
+ ProfileSyncServiceFactory::GetForProfile(profile_);
+ sync_service->ReenableDatatype(type());
+ } else {
+ // Post a task to the backend thread to stop the datatype.
if (state() != NOT_RUNNING && state() != STOPPING) {
syncer::SyncError error(FROM_HERE,
syncer::SyncError::DATATYPE_POLICY_ERROR,
@@ -112,13 +150,18 @@ void AutofillWalletDataTypeController::OnSyncExperimentPrefChanged() {
this,
error));
}
- } else {
- // The experiment was just enabled. Trigger a reconfiguration. This will do
- // nothing if the type isn't preferred.
- ProfileSyncService* sync_service =
- ProfileSyncServiceFactory::GetForProfile(profile_);
- sync_service->ReenableDatatype(type());
}
}
+bool AutofillWalletDataTypeController::IsEnabled() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // Require both the sync experiment and the user-visible pref to be
+ // enabled to sync Wallet data.
+ PrefService* ps = profile_->GetPrefs();
+ return
+ ps->GetBoolean(autofill::prefs::kAutofillWalletSyncExperimentEnabled) &&
+ ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled);
+}
+
} // namespace browser_sync
diff --git a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.h b/chrome/browser/sync/glue/autofill_wallet_data_type_controller.h
index a652f6d..18aaf36 100644
--- a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.h
+++ b/chrome/browser/sync/glue/autofill_wallet_data_type_controller.h
@@ -38,12 +38,19 @@ class AutofillWalletDataTypeController
void WebDatabaseLoaded();
- // Callback for changes to kAutofillWalletSyncExperimentEnabled.
- void OnSyncExperimentPrefChanged();
+ // Callback for changes to the autofill prefs.
+ void OnSyncPrefChanged();
+
+ // Returns true if the prefs are set such that wallet sync should be enabled.
+ bool IsEnabled();
Profile* const profile_;
bool callback_registered_;
+ // Stores whether we're currently syncing wallet data. This is the last
+ // value computed by IsEnabled.
+ bool currently_enabled_;
+
// Registrar for listening to kAutofillWalletSyncExperimentEnabled status.
PrefChangeRegistrar pref_registrar_;
diff --git a/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc b/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
index 672e6d1..f61d05a 100644
--- a/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
+++ b/chrome/browser/sync/test/integration/single_client_wallet_sync_test.cc
@@ -5,6 +5,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/sync/profile_sync_service.h"
@@ -13,9 +14,11 @@
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/personal_data_manager.h"
+#include "components/autofill/core/common/autofill_pref_names.h"
#include "content/public/browser/notification_service.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/test/fake_server/fake_server_entity.h"
@@ -33,6 +36,37 @@ const char kWalletSyncEnabledPreferencesContents[] =
const char kWalletSyncExperimentTag[] = "wallet_sync";
+const char kDefaultCardID[] = "wallet entity ID";
+const int kDefaultCardExpMonth = 8;
+const int kDefaultCardExpYear = 2087;
+const char kDefaultCardLastFour[] = "1234";
+const char kDefaultCardName[] = "Patrick Valenzuela";
+const sync_pb::WalletMaskedCreditCard_WalletCardType kDefaultCardType =
+ sync_pb::WalletMaskedCreditCard::AMEX;
+
+void AddDefaultCard(fake_server::FakeServer* server) {
+ sync_pb::EntitySpecifics specifics;
+ sync_pb::AutofillWalletSpecifics* wallet_specifics =
+ specifics.mutable_autofill_wallet();
+ wallet_specifics->set_type(
+ sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD);
+
+ sync_pb::WalletMaskedCreditCard* credit_card =
+ wallet_specifics->mutable_masked_card();
+ credit_card->set_id(kDefaultCardID);
+ credit_card->set_exp_month(kDefaultCardExpMonth);
+ credit_card->set_exp_year(kDefaultCardExpYear);
+ credit_card->set_last_four(kDefaultCardLastFour);
+ credit_card->set_name_on_card(kDefaultCardName);
+ credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID);
+ credit_card->set_type(kDefaultCardType);
+
+ server->InjectEntity(fake_server::UniqueClientEntity::CreateForInjection(
+ syncer::AUTOFILL_WALLET_DATA,
+ kDefaultCardID,
+ specifics));
+}
+
} // namespace
class SingleClientWalletSyncTest : public SyncTest {
@@ -167,49 +201,80 @@ IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest,
IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) {
SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
+ AddDefaultCard(GetFakeServer());
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
- std::string id = "wallet entity ID";
- int expiration_month = 8;
- int expiration_year = 2087;
- std::string last_four_digits = "1234";
- std::string name_on_card = "Patrick Valenzuela";
+ autofill::PersonalDataManager* pdm = GetPersonalDataManager(0);
+ ASSERT_TRUE(pdm != nullptr);
+ std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards();
+ ASSERT_EQ(1uL, cards.size());
- sync_pb::EntitySpecifics specifics;
- sync_pb::AutofillWalletSpecifics* wallet_specifics =
- specifics.mutable_autofill_wallet();
- wallet_specifics->set_type(
- sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD);
+ autofill::CreditCard* card = cards[0];
+ ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type());
+ ASSERT_EQ(kDefaultCardID, card->server_id());
+ ASSERT_EQ(base::UTF8ToUTF16(kDefaultCardLastFour), card->LastFourDigits());
+ ASSERT_EQ(autofill::kAmericanExpressCard, card->type());
+ ASSERT_EQ(kDefaultCardExpMonth, card->expiration_month());
+ ASSERT_EQ(kDefaultCardExpYear, card->expiration_year());
+ ASSERT_EQ(base::UTF8ToUTF16(kDefaultCardName),
+ card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME));
+}
- sync_pb::WalletMaskedCreditCard* credit_card =
- wallet_specifics->mutable_masked_card();
- credit_card->set_id(id);
- credit_card->set_exp_month(expiration_month);
- credit_card->set_exp_year(expiration_year);
- credit_card->set_last_four(last_four_digits);
- credit_card->set_name_on_card(name_on_card);
- credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID);
- credit_card->set_type(sync_pb::WalletMaskedCreditCard::AMEX);
+// Wallet data should get cleared from the database when sync is disabled.
+IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, ClearOnDisableSync) {
+ SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
+ AddDefaultCard(GetFakeServer());
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
- GetFakeServer()->InjectEntity(
- fake_server::UniqueClientEntity::CreateForInjection(
- syncer::AUTOFILL_WALLET_DATA,
- id,
- specifics));
+ // Make sure the card is in the DB.
+ autofill::PersonalDataManager* pdm = GetPersonalDataManager(0);
+ ASSERT_TRUE(pdm != nullptr);
+ std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards();
+ ASSERT_EQ(1uL, cards.size());
+ // Turn off sync, the card should be gone.
+ ASSERT_TRUE(GetClient(0)->DisableSyncForAllDatatypes());
+ cards = pdm->GetCreditCards();
+ ASSERT_EQ(0uL, cards.size());
+}
+
+// Wallet data should get cleared from the database when the wallet sync type
+// flag is disabled.
+IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, ClearOnDisableWalletSync) {
+ SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
+ AddDefaultCard(GetFakeServer());
ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
+ // Make sure the card is in the DB.
autofill::PersonalDataManager* pdm = GetPersonalDataManager(0);
ASSERT_TRUE(pdm != nullptr);
std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards();
ASSERT_EQ(1uL, cards.size());
- autofill::CreditCard* card = cards[0];
- ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type());
- ASSERT_EQ(id, card->server_id());
- ASSERT_EQ(base::UTF8ToUTF16(last_four_digits), card->LastFourDigits());
- ASSERT_EQ(autofill::kAmericanExpressCard, card->type());
- ASSERT_EQ(expiration_month, card->expiration_month());
- ASSERT_EQ(expiration_year, card->expiration_year());
- ASSERT_EQ(base::UTF8ToUTF16(name_on_card),
- card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME));
+ // Turn off autofill sync, the card should be gone.
+ ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncer::AUTOFILL));
+ cards = pdm->GetCreditCards();
+ ASSERT_EQ(0uL, cards.size());
+}
+
+// Wallet data should get cleared from the database when the wallet autofill
+// integration flag is disabled.
+IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest,
+ ClearOnDisableWalletAutofill) {
+ SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
+ AddDefaultCard(GetFakeServer());
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
+
+ // Make sure the card is in the DB.
+ autofill::PersonalDataManager* pdm = GetPersonalDataManager(0);
+ ASSERT_TRUE(pdm != nullptr);
+ std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards();
+ ASSERT_EQ(1uL, cards.size());
+
+ // Turn off the wallet autofill pref, the card should be gone as a side
+ // effect of the wallet data type controller noticing.
+ GetProfile(0)->GetPrefs()->SetBoolean(
+ autofill::prefs::kAutofillWalletImportEnabled, false);
+ cards = pdm->GetCreditCards();
+ ASSERT_EQ(0uL, cards.size());
}
diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc
index 3de3740..283d2ef 100644
--- a/components/autofill/core/browser/personal_data_manager.cc
+++ b/components/autofill/core/browser/personal_data_manager.cc
@@ -706,6 +706,20 @@ void PersonalDataManager::ResetFullServerCards() {
}
}
+void PersonalDataManager::ClearAllServerData() {
+ // This could theoretically be called before we get the data back from the
+ // database on startup, and it could get called when the wallet pref is
+ // off (meaning this class won't even query for the server data) so don't
+ // check the server_credit_cards_/profiles_ before posting to the DB.
+ database_->ClearAllServerData();
+
+ // The above call will eventually clear our server data by notifying us
+ // that the data changed and then this class will re-fetch. Preemptively
+ // clear so that tests can synchronously verify that this data was cleared.
+ server_credit_cards_.clear();
+ server_profiles_.clear();
+}
+
void PersonalDataManager::RemoveByGUID(const std::string& guid) {
if (is_off_the_record_)
return;
diff --git a/components/autofill/core/browser/personal_data_manager.h b/components/autofill/core/browser/personal_data_manager.h
index c9f4cc0..75cbbeb 100644
--- a/components/autofill/core/browser/personal_data_manager.h
+++ b/components/autofill/core/browser/personal_data_manager.h
@@ -127,6 +127,9 @@ class PersonalDataManager : public KeyedService,
// Resets all unmasked cards to the masked state.
void ResetFullServerCards();
+ // Deletes all server profiles and cards (both masked and unmasked).
+ void ClearAllServerData();
+
// Returns the credit card with the specified |guid|, or NULL if there is
// no credit card with the specified |guid|.
CreditCard* GetCreditCardByGUID(const std::string& guid);
diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc
index 3fdf1b8..74f934d 100644
--- a/components/autofill/core/browser/personal_data_manager_unittest.cc
+++ b/components/autofill/core/browser/personal_data_manager_unittest.cc
@@ -3165,4 +3165,39 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date());
}
+TEST_F(PersonalDataManagerTest, ClearAllServerData) {
+ // Add a server card.
+ std::vector<CreditCard> server_cards;
+ server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
+ test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
+ "9012" /* Visa */, "01", "2010");
+ server_cards.back().SetTypeForMaskedCard(kVisaCard);
+ test::SetServerCreditCards(autofill_table_, server_cards);
+ personal_data_->Refresh();
+
+ // Need to set the google services username
+ EnableWalletCardImport();
+
+ // Add a server profile.
+ std::vector<AutofillProfile> server_profiles;
+ server_profiles.push_back(
+ AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123"));
+ test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "",
+ "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX",
+ "77401", "US", "");
+ autofill_table_->SetServerProfiles(server_profiles);
+
+ // The card and profile should be there.
+ ResetPersonalDataManager(USER_MODE_NORMAL);
+ EXPECT_FALSE(personal_data_->GetCreditCards().empty());
+ EXPECT_FALSE(personal_data_->GetProfiles().empty());
+
+ personal_data_->ClearAllServerData();
+
+ // Reload the database, everything should be gone.
+ ResetPersonalDataManager(USER_MODE_NORMAL);
+ EXPECT_TRUE(personal_data_->GetCreditCards().empty());
+ EXPECT_TRUE(personal_data_->GetProfiles().empty());
+}
+
} // namespace autofill
diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc
index 5a3761b..10ec246 100644
--- a/components/autofill/core/browser/webdata/autofill_table.cc
+++ b/components/autofill/core/browser/webdata/autofill_table.cc
@@ -1326,6 +1326,30 @@ bool AutofillTable::UpdateUnmaskedCardUsageStats(
return db_->GetLastChangeCount() > 0;
}
+bool AutofillTable::ClearAllServerData() {
+ sql::Transaction transaction(db_);
+ if (!transaction.Begin())
+ return false; // Some error, nothing was changed.
+
+ sql::Statement masked(db_->GetUniqueStatement(
+ "DELETE FROM masked_credit_cards"));
+ masked.Run();
+ bool changed = db_->GetLastChangeCount() > 0;
+
+ sql::Statement unmasked(db_->GetUniqueStatement(
+ "DELETE FROM unmasked_credit_cards"));
+ unmasked.Run();
+ changed |= db_->GetLastChangeCount() > 0;
+
+ sql::Statement addresses(db_->GetUniqueStatement(
+ "DELETE FROM server_addresses"));
+ addresses.Run();
+ changed |= db_->GetLastChangeCount() > 0;
+
+ transaction.Commit();
+ return changed;
+}
+
bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) {
DCHECK(base::IsValidGUID(credit_card.guid()));
diff --git a/components/autofill/core/browser/webdata/autofill_table.h b/components/autofill/core/browser/webdata/autofill_table.h
index 81a2916..cd97658 100644
--- a/components/autofill/core/browser/webdata/autofill_table.h
+++ b/components/autofill/core/browser/webdata/autofill_table.h
@@ -323,6 +323,11 @@ class AutofillTable : public WebDatabaseTable {
// Updates the use count and last use date for an unmasked server card.
bool UpdateUnmaskedCardUsageStats(const CreditCard& credit_card);
+ // Deletes all data from the server card and profile tables. Returns true if
+ // any data was deleted, false if not (so false means "commit not needed"
+ // rather than "error").
+ bool ClearAllServerData();
+
// Removes rows from autofill_profiles and credit_cards if they were created
// on or after |delete_begin| and strictly before |delete_end|. Returns the
// list of deleted profile guids in |profile_guids|. Return value is true if
diff --git a/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc b/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc
index cf4a94e..e4e0d05 100644
--- a/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc
+++ b/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc
@@ -200,11 +200,6 @@ void AutofillWalletSyncableService::StopSyncing(syncer::ModelType type) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_EQ(type, syncer::AUTOFILL_WALLET_DATA);
sync_processor_.reset();
-
- // This data type is special. Normal sync data stays on the client when
- // sync is disabled, but this one is supposed to represent the data you
- // have on the server. Explicitly clear our local copy.
- SetSyncData(syncer::SyncDataList());
}
syncer::SyncDataList AutofillWalletSyncableService::GetAllSyncData(
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc
index b320d79..38bc3bc 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc
+++ b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc
@@ -365,6 +365,16 @@ WebDatabase::State AutofillWebDataBackendImpl::UpdateUnmaskedCardUsageStats(
return WebDatabase::COMMIT_NOT_NEEDED;
}
+WebDatabase::State AutofillWebDataBackendImpl::ClearAllServerData(
+ WebDatabase* db) {
+ DCHECK(db_thread_->BelongsToCurrentThread());
+ if (AutofillTable::FromWebDatabase(db)->ClearAllServerData()) {
+ NotifyOfMultipleAutofillChanges();
+ return WebDatabase::COMMIT_NEEDED;
+ }
+ return WebDatabase::COMMIT_NOT_NEEDED;
+}
+
WebDatabase::State
AutofillWebDataBackendImpl::RemoveAutofillDataModifiedBetween(
const base::Time& delete_begin,
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h
index f7572b7..50f510a 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h
+++ b/components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h
@@ -147,6 +147,8 @@ class AutofillWebDataBackendImpl
const CreditCard& credit_card,
WebDatabase* db);
+ WebDatabase::State ClearAllServerData(WebDatabase* db);
+
// Removes Autofill records from the database. Valid only for local
// cards/profiles.
WebDatabase::State RemoveAutofillDataModifiedBetween(
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_service.cc b/components/autofill/core/browser/webdata/autofill_webdata_service.cc
index 162b6b2..82da109 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_service.cc
+++ b/components/autofill/core/browser/webdata/autofill_webdata_service.cc
@@ -198,6 +198,13 @@ void AutofillWebDataService::MaskServerCreditCard(const std::string& id) {
autofill_backend_, id));
}
+void AutofillWebDataService::ClearAllServerData() {
+ wdbs_->ScheduleDBTask(
+ FROM_HERE,
+ Bind(&AutofillWebDataBackendImpl::ClearAllServerData,
+ autofill_backend_));
+}
+
void AutofillWebDataService::UpdateUnmaskedCardUsageStats(
const CreditCard& credit_card) {
wdbs_->ScheduleDBTask(
diff --git a/components/autofill/core/browser/webdata/autofill_webdata_service.h b/components/autofill/core/browser/webdata/autofill_webdata_service.h
index 1b9d5bc..acc23f3 100644
--- a/components/autofill/core/browser/webdata/autofill_webdata_service.h
+++ b/components/autofill/core/browser/webdata/autofill_webdata_service.h
@@ -91,6 +91,9 @@ class AutofillWebDataService : public AutofillWebData,
void UnmaskServerCreditCard(const std::string& id,
const base::string16& full_number) override;
void MaskServerCreditCard(const std::string& id) override;
+
+ void ClearAllServerData();
+
void UpdateUnmaskedCardUsageStats(const CreditCard& credit_card) override;
void RemoveAutofillDataModifiedBetween(const base::Time& delete_begin,