[Autofill] Rename existing strike_database files
Renamed strike_database.h/cc to legacy_strike_database.h/cc and
strike_database_unittest.cc to legacy_strike_database_unittest.cc.
This is so that the files for the new version of StrikeDatabase
can take the old name.
Bug: 884817
Change-Id: Id4d1496b792d93f7e38afdab1ddad0419ec27f10
Reviewed-on: https://chromium-review.googlesource.com/c/1330724
Reviewed-by: Fabio Tirelo <ftirelo@chromium.org>
Reviewed-by: Martin Šrámek <msramek@chromium.org>
Reviewed-by: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Jared Saul <jsaul@google.com>
Commit-Queue: Anne Lim <annelim@google.com>
Cr-Commit-Position: refs/heads/master@{#607707}
diff --git a/android_webview/browser/aw_autofill_client.cc b/android_webview/browser/aw_autofill_client.cc
index 56869279..9ffa0ad 100644
--- a/android_webview/browser/aw_autofill_client.cc
+++ b/android_webview/browser/aw_autofill_client.cc
@@ -84,7 +84,7 @@
return nullptr;
}
-autofill::StrikeDatabase* AwAutofillClient::GetStrikeDatabase() {
+autofill::LegacyStrikeDatabase* AwAutofillClient::GetLegacyStrikeDatabase() {
return nullptr;
}
diff --git a/android_webview/browser/aw_autofill_client.h b/android_webview/browser/aw_autofill_client.h
index 29c3809..c48665c 100644
--- a/android_webview/browser/aw_autofill_client.h
+++ b/android_webview/browser/aw_autofill_client.h
@@ -21,9 +21,9 @@
class CardUnmaskDelegate;
class CreditCard;
class FormStructure;
+class LegacyStrikeDatabase;
class MigratableCreditCard;
class PersonalDataManager;
-class StrikeDatabase;
}
namespace content {
@@ -66,7 +66,7 @@
identity::IdentityManager* GetIdentityManager() override;
autofill::payments::PaymentsClient* GetPaymentsClient() override;
autofill::FormDataImporter* GetFormDataImporter() override;
- autofill::StrikeDatabase* GetStrikeDatabase() override;
+ autofill::LegacyStrikeDatabase* GetLegacyStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override;
autofill::AddressNormalizer* GetAddressNormalizer() override;
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index cce2015..d107b33 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -112,12 +112,12 @@
"autofill/address_normalizer_factory.h",
"autofill/autofill_profile_validator_factory.cc",
"autofill/autofill_profile_validator_factory.h",
+ "autofill/legacy_strike_database_factory.cc",
+ "autofill/legacy_strike_database_factory.h",
"autofill/personal_data_manager_factory.cc",
"autofill/personal_data_manager_factory.h",
"autofill/risk_util.cc",
"autofill/risk_util.h",
- "autofill/strike_database_factory.cc",
- "autofill/strike_database_factory.h",
"autofill/validation_rules_storage_factory.cc",
"autofill/validation_rules_storage_factory.h",
"background_fetch/background_fetch_delegate_factory.cc",
diff --git a/chrome/browser/autofill/strike_database_factory.cc b/chrome/browser/autofill/legacy_strike_database_factory.cc
similarity index 60%
rename from chrome/browser/autofill/strike_database_factory.cc
rename to chrome/browser/autofill/legacy_strike_database_factory.cc
index 4972606..30a2439a 100644
--- a/chrome/browser/autofill/strike_database_factory.cc
+++ b/chrome/browser/autofill/legacy_strike_database_factory.cc
@@ -2,41 +2,42 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/autofill/strike_database_factory.h"
+#include "chrome/browser/autofill/legacy_strike_database_factory.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
-#include "components/autofill/core/browser/strike_database.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace autofill {
// static
-StrikeDatabase* StrikeDatabaseFactory::GetForProfile(Profile* profile) {
- return static_cast<StrikeDatabase*>(
+LegacyStrikeDatabase* LegacyStrikeDatabaseFactory::GetForProfile(
+ Profile* profile) {
+ return static_cast<LegacyStrikeDatabase*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
-StrikeDatabaseFactory* StrikeDatabaseFactory::GetInstance() {
- return base::Singleton<StrikeDatabaseFactory>::get();
+LegacyStrikeDatabaseFactory* LegacyStrikeDatabaseFactory::GetInstance() {
+ return base::Singleton<LegacyStrikeDatabaseFactory>::get();
}
-StrikeDatabaseFactory::StrikeDatabaseFactory()
+LegacyStrikeDatabaseFactory::LegacyStrikeDatabaseFactory()
: BrowserContextKeyedServiceFactory(
- "AutofillStrikeDatabase",
+ "AutofillLegacyStrikeDatabase",
BrowserContextDependencyManager::GetInstance()) {}
-StrikeDatabaseFactory::~StrikeDatabaseFactory() {}
+LegacyStrikeDatabaseFactory::~LegacyStrikeDatabaseFactory() {}
-KeyedService* StrikeDatabaseFactory::BuildServiceInstanceFor(
+KeyedService* LegacyStrikeDatabaseFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
// Note: This instance becomes owned by an object that never gets destroyed,
// effectively leaking it until browser close. Only one is created per
// profile, and closing-then-opening a profile returns the same instance.
- return new StrikeDatabase(
+ return new LegacyStrikeDatabase(
profile->GetPath().Append(FILE_PATH_LITERAL("AutofillStrikeDatabase")));
}
diff --git a/chrome/browser/autofill/legacy_strike_database_factory.h b/chrome/browser/autofill/legacy_strike_database_factory.h
new file mode 100644
index 0000000..1da13aa
--- /dev/null
+++ b/chrome/browser/autofill/legacy_strike_database_factory.h
@@ -0,0 +1,48 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_AUTOFILL_LEGACY_STRIKE_DATABASE_FACTORY_H_
+#define CHROME_BROWSER_AUTOFILL_LEGACY_STRIKE_DATABASE_FACTORY_H_
+
+#include "base/compiler_specific.h"
+#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
+#include "components/keyed_service/core/keyed_service.h"
+
+namespace base {
+template <typename T>
+struct DefaultSingletonTraits;
+}
+
+class Profile;
+
+namespace autofill {
+
+class LegacyStrikeDatabase;
+
+// Singleton that owns all LegacyStrikeDatabases and associates them with
+// Profiles.
+class LegacyStrikeDatabaseFactory : public BrowserContextKeyedServiceFactory {
+ public:
+ // Returns the LegacyStrikeDatabase for |profile|, creating it if it is not
+ // yet created.
+ static LegacyStrikeDatabase* GetForProfile(Profile* profile);
+
+ static LegacyStrikeDatabaseFactory* GetInstance();
+
+ private:
+ friend struct base::DefaultSingletonTraits<LegacyStrikeDatabaseFactory>;
+
+ LegacyStrikeDatabaseFactory();
+ ~LegacyStrikeDatabaseFactory() override;
+
+ // BrowserContextKeyedServiceFactory:
+ KeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* profile) const override;
+
+ DISALLOW_COPY_AND_ASSIGN(LegacyStrikeDatabaseFactory);
+};
+
+} // namespace autofill
+
+#endif // CHROME_BROWSER_AUTOFILL_LEGACY_STRIKE_DATABASE_FACTORY_H_
diff --git a/chrome/browser/autofill/strike_database_factory.h b/chrome/browser/autofill/strike_database_factory.h
deleted file mode 100644
index 60e2959..0000000
--- a/chrome/browser/autofill/strike_database_factory.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
-#define CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
-
-#include "base/compiler_specific.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-#include "components/keyed_service/core/keyed_service.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-}
-
-class Profile;
-
-namespace autofill {
-
-class StrikeDatabase;
-
-// Singleton that owns all StrikeDatabases and associates them with Profiles.
-class StrikeDatabaseFactory : public BrowserContextKeyedServiceFactory {
- public:
- // Returns the StrikeDatabase for |profile|, creating it if it is not yet
- // created.
- static StrikeDatabase* GetForProfile(Profile* profile);
-
- static StrikeDatabaseFactory* GetInstance();
-
- private:
- friend struct base::DefaultSingletonTraits<StrikeDatabaseFactory>;
-
- StrikeDatabaseFactory();
- ~StrikeDatabaseFactory() override;
-
- // BrowserContextKeyedServiceFactory:
- KeyedService* BuildServiceInstanceFor(
- content::BrowserContext* profile) const override;
-
- DISALLOW_COPY_AND_ASSIGN(StrikeDatabaseFactory);
-};
-
-} // namespace autofill
-
-#endif // CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
index 51c5b25..080c871 100644
--- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
+++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
@@ -18,8 +18,8 @@
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "chrome/browser/android/feed/feed_host_service_factory.h"
+#include "chrome/browser/autofill/legacy_strike_database_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
-#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
@@ -60,8 +60,8 @@
#include "chrome/common/buildflags.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/personal_data_manager.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/browsing_data/core/features.h"
@@ -858,14 +858,14 @@
web_data_service->RemoveAutofillDataModifiedBetween(
delete_begin_, delete_end_);
- // Clear out the Autofill StrikeDatabase in its entirety.
+ // Clear out the Autofill LegacyStrikeDatabase in its entirety.
// TODO(crbug.com/884817): Respect |delete_begin_| and |delete_end_| and
// only clear out entries whose last strikes were created in that
// timeframe.
- autofill::StrikeDatabase* strike_database =
- autofill::StrikeDatabaseFactory::GetForProfile(profile_);
- if (strike_database)
- strike_database->ClearAllStrikes(base::AdaptCallbackForRepeating(
+ autofill::LegacyStrikeDatabase* legacy_strike_database =
+ autofill::LegacyStrikeDatabaseFactory::GetForProfile(profile_);
+ if (legacy_strike_database)
+ legacy_strike_database->ClearAllStrikes(base::AdaptCallbackForRepeating(
IgnoreArgument<bool>(CreatePendingTaskCompletionClosure())));
// Ask for a call back when the above calls are finished.
diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
index 2dbe1df..e5f9091 100644
--- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
+++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
@@ -25,8 +25,8 @@
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "build/build_config.h"
+#include "chrome/browser/autofill/legacy_strike_database_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
-#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
@@ -55,9 +55,9 @@
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/bookmarks/browser/bookmark_model.h"
@@ -1041,18 +1041,18 @@
};
namespace autofill {
-// StrikeDatabaseTester is in the autofill namespace since StrikeDatabase
-// declares it as a friend in the autofill namespace.
-class StrikeDatabaseTester {
+// LegacyStrikeDatabaseTester is in the autofill namespace since
+// LegacyStrikeDatabase declares it as a friend in the autofill namespace.
+class LegacyStrikeDatabaseTester {
public:
- explicit StrikeDatabaseTester(Profile* profile)
- : strike_database_(
- autofill::StrikeDatabaseFactory::GetForProfile(profile)) {}
+ explicit LegacyStrikeDatabaseTester(Profile* profile)
+ : legacy_strike_database_(
+ autofill::LegacyStrikeDatabaseFactory::GetForProfile(profile)) {}
bool IsEmpty() {
int num_keys;
base::RunLoop run_loop;
- strike_database_->LoadKeys(base::BindLambdaForTesting(
+ legacy_strike_database_->LoadKeys(base::BindLambdaForTesting(
[&](bool success, std::unique_ptr<std::vector<std::string>> keys) {
num_keys = keys.get()->size();
run_loop.Quit();
@@ -1062,7 +1062,7 @@
}
private:
- autofill::StrikeDatabase* strike_database_;
+ autofill::LegacyStrikeDatabase* legacy_strike_database_;
};
} // namespace autofill
@@ -1689,7 +1689,7 @@
}
TEST_F(ChromeBrowsingDataRemoverDelegateTest,
- StrikeDatabaseEmptyOnAutofillRemoveEverything) {
+ LegacyStrikeDatabaseEmptyOnAutofillRemoveEverything) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
@@ -1697,14 +1697,15 @@
tester.AddProfilesAndCards();
ASSERT_TRUE(tester.HasProfile());
- autofill::StrikeDatabaseTester strike_database_tester(GetProfile());
+ autofill::LegacyStrikeDatabaseTester legacy_strike_database_tester(
+ GetProfile());
BlockUntilBrowsingDataRemoved(
base::Time(), base::Time::Max(),
ChromeBrowsingDataRemoverDelegate::DATA_TYPE_FORM_DATA, false);
- // StrikeDatabase should be empty when DATA_TYPE_FORM_DATA browsing data gets
- // deleted.
- ASSERT_TRUE(strike_database_tester.IsEmpty());
+ // LegacyStrikeDatabase should be empty when DATA_TYPE_FORM_DATA browsing data
+ // gets deleted.
+ ASSERT_TRUE(legacy_strike_database_tester.IsEmpty());
EXPECT_EQ(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_FORM_DATA,
GetRemovalMask());
EXPECT_EQ(content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
diff --git a/chrome/browser/ui/autofill/chrome_autofill_client.cc b/chrome/browser/ui/autofill/chrome_autofill_client.cc
index 078f8fb..c2d5f9c 100644
--- a/chrome/browser/ui/autofill/chrome_autofill_client.cc
+++ b/chrome/browser/ui/autofill/chrome_autofill_client.cc
@@ -12,9 +12,9 @@
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autofill/address_normalizer_factory.h"
+#include "chrome/browser/autofill/legacy_strike_database_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/autofill/risk_util.h"
-#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/profiles/profile.h"
@@ -168,15 +168,16 @@
return form_data_importer_.get();
}
-StrikeDatabase* ChromeAutofillClient::GetStrikeDatabase() {
+LegacyStrikeDatabase* ChromeAutofillClient::GetLegacyStrikeDatabase() {
Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
- // No need to return a StrikeDatabase in incognito mode. It is primarily used
- // to determine whether or not to offer save of Autofill data. However, we
- // don't allow saving of Autofill data while in incognito anyway, so an
- // incognito code path should never get far enough to query StrikeDatabase.
+ // No need to return a LegacyStrikeDatabase in incognito mode. It is primarily
+ // used to determine whether or not to offer save of Autofill data. However,
+ // we don't allow saving of Autofill data while in incognito anyway, so an
+ // incognito code path should never get far enough to query
+ // LegacyStrikeDatabase.
DCHECK(!profile->IsOffTheRecord());
- return StrikeDatabaseFactory::GetForProfile(profile);
+ return LegacyStrikeDatabaseFactory::GetForProfile(profile);
}
ukm::UkmRecorder* ChromeAutofillClient::GetUkmRecorder() {
@@ -308,7 +309,8 @@
->AddInfoBar(CreateSaveCardInfoBarMobile(
std::make_unique<AutofillSaveCardInfoBarDelegateMobile>(
/*upload=*/false, /*should_request_name_from_user=*/false, card,
- std::make_unique<base::DictionaryValue>(), GetStrikeDatabase(),
+ std::make_unique<base::DictionaryValue>(),
+ GetLegacyStrikeDatabase(),
/*upload_save_card_callback=*/
UserAcceptedUploadCallback(),
/*local_save_card_callback=*/std::move(callback), GetPrefs())));
@@ -352,7 +354,7 @@
save_card_info_bar_delegate_mobile =
std::make_unique<AutofillSaveCardInfoBarDelegateMobile>(
/*upload=*/true, should_request_name_from_user, card,
- std::move(legal_message), GetStrikeDatabase(),
+ std::move(legal_message), GetLegacyStrikeDatabase(),
/*upload_save_card_callback=*/std::move(callback),
/*local_save_card_callback=*/base::Closure(), GetPrefs());
if (save_card_info_bar_delegate_mobile->LegalMessagesParsedSuccessfully()) {
diff --git a/chrome/browser/ui/autofill/chrome_autofill_client.h b/chrome/browser/ui/autofill/chrome_autofill_client.h
index daf1e48d..088c2fb 100644
--- a/chrome/browser/ui/autofill/chrome_autofill_client.h
+++ b/chrome/browser/ui/autofill/chrome_autofill_client.h
@@ -58,7 +58,7 @@
identity::IdentityManager* GetIdentityManager() override;
payments::PaymentsClient* GetPaymentsClient() override;
FormDataImporter* GetFormDataImporter() override;
- StrikeDatabase* GetStrikeDatabase() override;
+ LegacyStrikeDatabase* GetLegacyStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override;
diff --git a/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
index 6e8d6d8d..e01c653 100644
--- a/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
+++ b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
@@ -8,7 +8,7 @@
#include <utility>
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/autofill/strike_database_factory.h"
+#include "chrome/browser/autofill/legacy_strike_database_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
@@ -28,7 +28,7 @@
#include "chrome/common/url_constants.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_metrics.h"
-#include "components/autofill/core/browser/strike_database.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
@@ -398,7 +398,7 @@
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
// If save was cancelled and the bubble was actually shown (NOT just the
// icon), count that as a strike against offering save in the future.
- StrikeDatabase* strike_database = GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database = GetLegacyStrikeDatabase();
strike_database->AddStrike(
strike_database->GetKeyForCreditCardSave(
base::UTF16ToUTF8(card_.LastFourDigits())),
@@ -521,7 +521,7 @@
// If the save offer was ignored and the bubble was actually shown (NOT
// just the icon), count that as a strike against offering save in the
// future.
- StrikeDatabase* strike_database = GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database = GetLegacyStrikeDatabase();
strike_database->AddStrike(
strike_database->GetKeyForCreditCardSave(
base::UTF16ToUTF8(card_.LastFourDigits())),
@@ -556,13 +556,13 @@
signin_manager->GetAuthenticatedAccountId());
}
-StrikeDatabase* SaveCardBubbleControllerImpl::GetStrikeDatabase() {
+LegacyStrikeDatabase* SaveCardBubbleControllerImpl::GetLegacyStrikeDatabase() {
Profile* profile = GetProfile();
- // No need to return a StrikeDatabase in incognito mode. We don't allow saving
- // of Autofill data while in incognito, so an incognito code path should never
- // get this far.
+ // No need to return a LegacyStrikeDatabase in incognito mode. We don't allow
+ // saving of Autofill data while in incognito, so an incognito code path
+ // should never get this far.
DCHECK(profile && !profile->IsOffTheRecord());
- return StrikeDatabaseFactory::GetForProfile(profile);
+ return LegacyStrikeDatabaseFactory::GetForProfile(profile);
}
void SaveCardBubbleControllerImpl::ShowBubble() {
diff --git a/chrome/browser/ui/autofill/save_card_bubble_controller_impl.h b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.h
index 6aba7a03..d6decc2b 100644
--- a/chrome/browser/ui/autofill/save_card_bubble_controller_impl.h
+++ b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.h
@@ -22,7 +22,7 @@
namespace autofill {
enum class BubbleType;
-class StrikeDatabase;
+class LegacyStrikeDatabase;
// Implementation of per-tab class to control the save credit card bubble and
// Omnibox icon.
@@ -140,8 +140,8 @@
void FetchAccountInfo();
- // Fetches the Autofill StrikeDatabase for the current profile.
- StrikeDatabase* GetStrikeDatabase();
+ // Fetches the Autofill LegacyStrikeDatabase for the current profile.
+ LegacyStrikeDatabase* GetLegacyStrikeDatabase();
// Displays both the offer-to-save bubble and is associated omnibox icon.
void ShowBubble();
diff --git a/components/autofill/core/browser/BUILD.gn b/components/autofill/core/browser/BUILD.gn
index c6a4b72..1f369f0d 100644
--- a/components/autofill/core/browser/BUILD.gn
+++ b/components/autofill/core/browser/BUILD.gn
@@ -117,6 +117,8 @@
"form_structure.h",
"form_types.cc",
"form_types.h",
+ "legacy_strike_database.cc",
+ "legacy_strike_database.h",
"legal_message_line.cc",
"legal_message_line.h",
"local_card_migration_manager.cc",
@@ -163,8 +165,6 @@
"search_field.h",
"state_names.cc",
"state_names.h",
- "strike_database.cc",
- "strike_database.h",
"subkey_requester.cc",
"subkey_requester.h",
"suggestion.cc",
@@ -351,14 +351,14 @@
"test_form_data_importer.h",
"test_form_structure.cc",
"test_form_structure.h",
+ "test_legacy_strike_database.cc",
+ "test_legacy_strike_database.h",
"test_local_card_migration_manager.cc",
"test_local_card_migration_manager.h",
"test_personal_data_manager.cc",
"test_personal_data_manager.h",
"test_region_data_loader.cc",
"test_region_data_loader.h",
- "test_strike_database.cc",
- "test_strike_database.h",
"webdata/autofill_sync_bridge_test_util.cc",
"webdata/autofill_sync_bridge_test_util.h",
"webdata/mock_autofill_webdata_backend.cc",
@@ -483,6 +483,7 @@
"form_data_importer_unittest.cc",
"form_field_unittest.cc",
"form_structure_unittest.cc",
+ "legacy_strike_database_unittest.cc",
"legal_message_line_unittest.cc",
"local_card_migration_manager_unittest.cc",
"name_field_unittest.cc",
@@ -501,7 +502,6 @@
"rationalization_util_unittest.cc",
"region_combobox_model_unittest.cc",
"search_field_unittest.cc",
- "strike_database_unittest.cc",
"subkey_requester_unittest.cc",
"ui/card_unmask_prompt_controller_impl_unittest.cc",
"validation_unittest.cc",
diff --git a/components/autofill/core/browser/autofill_client.h b/components/autofill/core/browser/autofill_client.h
index 3078e2d..f1a97bf 100644
--- a/components/autofill/core/browser/autofill_client.h
+++ b/components/autofill/core/browser/autofill_client.h
@@ -53,9 +53,9 @@
class CreditCard;
class FormDataImporter;
class FormStructure;
+class LegacyStrikeDatabase;
class MigratableCreditCard;
class PersonalDataManager;
-class StrikeDatabase;
struct Suggestion;
namespace payments {
@@ -140,8 +140,9 @@
// Gets the payments::PaymentsClient instance owned by the client.
virtual payments::PaymentsClient* GetPaymentsClient() = 0;
- // Gets the StrikeDatabase associated with the client.
- virtual StrikeDatabase* GetStrikeDatabase() = 0;
+ // Gets the LegacyStrikeDatabase associated with the client.
+ // TODO(crbug.com/884817): Delete this once v2 of StrikeDatabase is launched.
+ virtual LegacyStrikeDatabase* GetLegacyStrikeDatabase() = 0;
// Gets the UKM service associated with this client (for metrics).
virtual ukm::UkmRecorder* GetUkmRecorder() = 0;
diff --git a/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.cc b/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.cc
index 4f7c874..2f2afe3 100644
--- a/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.cc
+++ b/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.cc
@@ -11,8 +11,8 @@
#include "base/values.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/credit_card.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/legal_message_line.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
@@ -32,7 +32,7 @@
bool should_request_name_from_user,
const CreditCard& card,
std::unique_ptr<base::DictionaryValue> legal_message,
- StrikeDatabase* strike_database,
+ LegacyStrikeDatabase* strike_database,
AutofillClient::UserAcceptedUploadCallback upload_save_card_callback,
base::OnceClosure local_save_card_callback,
PrefService* pref_service)
@@ -42,7 +42,7 @@
upload_save_card_callback_(std::move(upload_save_card_callback)),
local_save_card_callback_(std::move(local_save_card_callback)),
pref_service_(pref_service),
- strike_database_(strike_database),
+ legacy_strike_database_(strike_database),
had_user_interaction_(false),
issuer_icon_id_(CreditCard::IconResourceId(card.network())),
card_label_(card.NetworkAndLastFourDigits()),
@@ -81,8 +81,8 @@
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
// If the infobar was ignored, count that as a strike against offering
// save in the future.
- strike_database_->AddStrike(
- strike_database_->GetKeyForCreditCardSave(
+ legacy_strike_database_->AddStrike(
+ legacy_strike_database_->GetKeyForCreditCardSave(
base::UTF16ToUTF8(card_last_four_digits_)),
base::DoNothing());
}
@@ -154,9 +154,10 @@
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
// If the infobar was explicitly denied, count that as a strike against
// offering save in the future.
- strike_database_->AddStrike(strike_database_->GetKeyForCreditCardSave(
- base::UTF16ToUTF8(card_last_four_digits_)),
- base::DoNothing());
+ legacy_strike_database_->AddStrike(
+ legacy_strike_database_->GetKeyForCreditCardSave(
+ base::UTF16ToUTF8(card_last_four_digits_)),
+ base::DoNothing());
}
}
diff --git a/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.h b/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.h
index 0307ac8f..9b2af4c7 100644
--- a/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.h
+++ b/components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.h
@@ -24,7 +24,7 @@
namespace autofill {
class CreditCard;
-class StrikeDatabase;
+class LegacyStrikeDatabase;
// An InfoBarDelegate that enables the user to allow or deny storing credit
// card information gathered from a form submission. Only used on mobile.
@@ -35,7 +35,7 @@
bool should_request_name_from_user,
const CreditCard& card,
std::unique_ptr<base::DictionaryValue> legal_message,
- StrikeDatabase* strike_database,
+ LegacyStrikeDatabase* legacy_strike_database,
AutofillClient::UserAcceptedUploadCallback upload_save_card_callback,
base::OnceClosure local_save_card_callback,
PrefService* pref_service);
@@ -92,8 +92,8 @@
// Weak reference to read & write |kAutofillAcceptSaveCreditCardPromptState|,
PrefService* pref_service_;
- // Weak reference to the Autofill StrikeDatabase.
- StrikeDatabase* strike_database_;
+ // Weak reference to the Autofill LegacyStrikeDatabase.
+ LegacyStrikeDatabase* legacy_strike_database_;
// Did the user ever explicitly accept or dismiss this infobar?
bool had_user_interaction_;
diff --git a/components/autofill/core/browser/credit_card_save_manager.cc b/components/autofill/core/browser/credit_card_save_manager.cc
index 02c36d8..1966609 100644
--- a/components/autofill/core/browser/credit_card_save_manager.cc
+++ b/components/autofill/core/browser/credit_card_save_manager.cc
@@ -31,10 +31,10 @@
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/form_structure.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/payments/payments_client.h"
#include "components/autofill/core/browser/payments/payments_util.h"
#include "components/autofill/core/browser/personal_data_manager.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
@@ -90,18 +90,19 @@
local_card_save_candidate_ = card;
show_save_prompt_ = base::nullopt;
- // Query the Autofill StrikeDatabase on if we should pop up the offer-to-save
- // prompt for this card.
+ // Query the Autofill LegacyStrikeDatabase on if we should pop up the
+ // offer-to-save prompt for this card.
if (base::FeatureList::IsEnabled(
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
- StrikeDatabase* strike_database = client_->GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database = client_->GetLegacyStrikeDatabase();
strike_database->GetStrikes(
strike_database->GetKeyForCreditCardSave(
base::UTF16ToUTF8(local_card_save_candidate_.LastFourDigits())),
base::BindRepeating(&CreditCardSaveManager::OnDidGetStrikesForLocalSave,
weak_ptr_factory_.GetWeakPtr()));
} else {
- // Skip retrieving data from the Autofill StrikeDatabase; assume 0 strikes.
+ // Skip retrieving data from the Autofill LegacyStrikeDatabase; assume 0
+ // strikes.
OnDidGetStrikesForLocalSave(0);
}
}
@@ -229,11 +230,11 @@
base::BindOnce(&CreditCardSaveManager::OnDidGetUploadDetails,
weak_ptr_factory_.GetWeakPtr()),
payments::kUploadCardBillableServiceNumber);
- // Query the Autofill StrikeDatabase on if we should pop up the offer-to-save
- // prompt for this card.
+ // Query the Autofill LegacyStrikeDatabase on if we should pop up the
+ // offer-to-save prompt for this card.
if (base::FeatureList::IsEnabled(
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
- StrikeDatabase* strike_database = client_->GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database = client_->GetLegacyStrikeDatabase();
strike_database->GetStrikes(
strike_database->GetKeyForCreditCardSave(
base::UTF16ToUTF8(upload_request_.card.LastFourDigits())),
@@ -241,7 +242,8 @@
&CreditCardSaveManager::OnDidGetStrikesForUploadSave,
weak_ptr_factory_.GetWeakPtr()));
} else {
- // Skip retrieving data from the Autofill StrikeDatabase; assume 0 strikes.
+ // Skip retrieving data from the Autofill LegacyStrikeDatabase; assume 0
+ // strikes.
OnDidGetStrikesForUploadSave(0);
}
}
@@ -294,7 +296,8 @@
}
if (base::FeatureList::IsEnabled(
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
- StrikeDatabase* strike_database = client_->GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database =
+ client_->GetLegacyStrikeDatabase();
// Log how many strikes the card had when it was saved.
strike_database->GetStrikes(
strike_database->GetKeyForCreditCardSave(
@@ -315,7 +318,8 @@
show_save_prompt_.value()) {
// If the upload failed and the bubble was actually shown (NOT just the
// icon), count that as a strike against offering upload in the future.
- StrikeDatabase* strike_database = client_->GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database =
+ client_->GetLegacyStrikeDatabase();
strike_database->AddStrike(
strike_database->GetKeyForCreditCardSave(
base::UTF16ToUTF8(upload_request_.card.LastFourDigits())),
@@ -337,9 +341,10 @@
show_save_prompt_ =
num_strikes < kMaxStrikesToPreventPoppingUpOfferToSavePrompt;
- // Only offer upload once both Payments and the Autofill StrikeDatabase have
- // returned their decisions. Use population of |upload_request_.context_token|
- // as an indicator of the Payments call returning successfully.
+ // Only offer upload once both Payments and the Autofill LegacyStrikeDatabase
+ // have returned their decisions. Use population of
+ // |upload_request_.context_token| as an indicator of the Payments call
+ // returning successfully.
if (!upload_request_.context_token.empty())
OfferCardUploadSave();
}
@@ -356,9 +361,10 @@
upload_request_.context_token = context_token;
legal_message_ = std::move(legal_message);
- // Only offer upload once both Payments and the Autofill StrikeDatabase have
- // returned their decisions. Use presence of |show_save_prompt_| as an
- // indicator of StrikeDatabase retrieving its data.
+ // Only offer upload once both Payments and the Autofill
+ // LegacyStrikeDatabase have returned their decisions. Use presence of
+ // |show_save_prompt_| as an indicator of LegacyStrikeDatabase retrieving
+ // its data.
if (show_save_prompt_ != base::nullopt)
OfferCardUploadSave();
} else {
@@ -374,10 +380,11 @@
// be rare.)
//
// Note that calling AttemptToOfferCardLocalSave(~) pings the Autofill
- // StrikeDatabase again, but A) the result should be cached so this
+ // LegacyStrikeDatabase again, but A) the result should be cached so this
// shouldn't hit the disk, and B) the alternative would require hooking into
- // the StrikeDatabase's GetStrikes() call already in progress, which would
- // be hacky at worst and require additional class state variables at best.
+ // the LegacyStrikeDatabase's GetStrikes() call already in progress, which
+ // would be hacky at worst and require additional class state variables at
+ // best.
bool found_name_and_postal_code_and_cvc =
(upload_request_.detected_values & DetectedValue::CARDHOLDER_NAME ||
upload_request_.detected_values & DetectedValue::ADDRESS_NAME) &&
@@ -466,7 +473,7 @@
// Set that upload was offered.
upload_decision_metrics_ |= AutofillMetrics::UPLOAD_OFFERED;
} else {
- // Set that upload was abandoned due to the Autofill StrikeDatabase
+ // Set that upload was abandoned due to the Autofill LegacyStrikeDatabase
// returning too many strikes for a mobile infobar to be displayed.
upload_decision_metrics_ |=
AutofillMetrics::UPLOAD_NOT_OFFERED_MAX_STRIKES_ON_MOBILE;
@@ -484,7 +491,7 @@
if (base::FeatureList::IsEnabled(
features::kAutofillSaveCreditCardUsesStrikeSystem)) {
- StrikeDatabase* strike_database = client_->GetStrikeDatabase();
+ LegacyStrikeDatabase* strike_database = client_->GetLegacyStrikeDatabase();
// Log how many strikes the card had when it was saved.
strike_database->GetStrikes(
strike_database->GetKeyForCreditCardSave(
diff --git a/components/autofill/core/browser/credit_card_save_manager_unittest.cc b/components/autofill/core/browser/credit_card_save_manager_unittest.cc
index eb4313b..5abd2ee 100644
--- a/components/autofill/core/browser/credit_card_save_manager_unittest.cc
+++ b/components/autofill/core/browser/credit_card_save_manager_unittest.cc
@@ -35,8 +35,8 @@
#include "components/autofill/core/browser/test_autofill_manager.h"
#include "components/autofill/core/browser/test_credit_card_save_manager.h"
#include "components/autofill/core/browser/test_form_data_importer.h"
+#include "components/autofill/core/browser/test_legacy_strike_database.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
-#include "components/autofill/core/browser/test_strike_database.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
@@ -92,9 +92,9 @@
class CreditCardSaveManagerTest : public testing::Test {
public:
void SetUp() override {
- std::unique_ptr<TestStrikeDatabase> test_strike_database =
- std::make_unique<TestStrikeDatabase>();
- strike_database_ = test_strike_database.get();
+ std::unique_ptr<TestLegacyStrikeDatabase> test_strike_database =
+ std::make_unique<TestLegacyStrikeDatabase>();
+ legacy_strike_database_ = test_strike_database.get();
autofill_client_.SetPrefs(test::PrefServiceForTesting());
autofill_client_.set_test_strike_database(std::move(test_strike_database));
personal_data_.Init(/*profile_database=*/autofill_client_.GetDatabase(),
@@ -322,7 +322,7 @@
// Ends up getting owned (and destroyed) by TestAutofillClient:
payments::TestPaymentsClient* payments_client_;
// Ends up getting owned (and destroyed) by TestAutofillClient:
- TestStrikeDatabase* strike_database_;
+ TestLegacyStrikeDatabase* legacy_strike_database_;
private:
int ToHistogramSample(AutofillMetrics::CardUploadDecisionMetric metric) {
@@ -4004,8 +4004,9 @@
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
// Max out strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/3);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/3);
// Set up our credit card form data.
FormData credit_card_form;
@@ -4045,8 +4046,9 @@
features::kAutofillSaveCreditCardUsesStrikeSystem);
// Max out strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/3);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/3);
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
@@ -4097,8 +4099,9 @@
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
// Add a single strike for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/1);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/1);
// Set up our credit card form data.
FormData credit_card_form;
@@ -4136,8 +4139,9 @@
features::kAutofillSaveCreditCardUsesStrikeSystem);
// Add a single strike for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/1);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/1);
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
@@ -4186,8 +4190,9 @@
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
// Max out strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/3);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/3);
// Set up our credit card form data.
FormData credit_card_form;
@@ -4221,8 +4226,9 @@
features::kAutofillSaveCreditCardUsesStrikeSystem);
// Max out strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/3);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/3);
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
@@ -4276,8 +4282,9 @@
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
// Max out strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/3);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/3);
// Set up our credit card form data.
FormData credit_card_form;
@@ -4315,8 +4322,9 @@
features::kAutofillSaveCreditCardUsesStrikeSystem);
// Max out strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/3);
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/3);
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
@@ -4365,10 +4373,11 @@
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
// Add a couple of strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/2);
- EXPECT_EQ(2, strike_database_->GetStrikesForTesting(
- strike_database_->GetKeyForCreditCardSave("1111")));
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/2);
+ EXPECT_EQ(2, legacy_strike_database_->GetStrikesForTesting(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111")));
// Set up our credit card form data.
FormData credit_card_form;
@@ -4388,8 +4397,8 @@
EXPECT_FALSE(credit_card_save_manager_->CreditCardWasUploaded());
// Verify that adding the card reset the strike count for that card.
- EXPECT_EQ(0, strike_database_->GetStrikesForTesting(
- strike_database_->GetKeyForCreditCardSave("1111")));
+ EXPECT_EQ(0, legacy_strike_database_->GetStrikesForTesting(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111")));
}
// Tests that adding a card clears all strikes for that card.
@@ -4398,10 +4407,11 @@
features::kAutofillSaveCreditCardUsesStrikeSystem);
// Add a couple of strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/2);
- EXPECT_EQ(2, strike_database_->GetStrikesForTesting(
- strike_database_->GetKeyForCreditCardSave("1111")));
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/2);
+ EXPECT_EQ(2, legacy_strike_database_->GetStrikesForTesting(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111")));
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
@@ -4431,8 +4441,8 @@
EXPECT_TRUE(credit_card_save_manager_->CreditCardWasUploaded());
// Verify that adding the card reset the strike count for that card.
- EXPECT_EQ(0, strike_database_->GetStrikesForTesting(
- strike_database_->GetKeyForCreditCardSave("1111")));
+ EXPECT_EQ(0, legacy_strike_database_->GetStrikesForTesting(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111")));
}
// Tests that adding a card clears all strikes for that card.
@@ -4442,10 +4452,11 @@
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
// Add a couple of strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/2);
- EXPECT_EQ(2, strike_database_->GetStrikesForTesting(
- strike_database_->GetKeyForCreditCardSave("1111")));
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/2);
+ EXPECT_EQ(2, legacy_strike_database_->GetStrikesForTesting(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111")));
// Set up our credit card form data.
FormData credit_card_form;
@@ -4478,10 +4489,11 @@
features::kAutofillSaveCreditCardUsesStrikeSystem);
// Add a couple of strikes for the card to be added.
- strike_database_->AddEntryWithNumStrikes(
- strike_database_->GetKeyForCreditCardSave("1111"), /*num_strikes=*/2);
- EXPECT_EQ(2, strike_database_->GetStrikesForTesting(
- strike_database_->GetKeyForCreditCardSave("1111")));
+ legacy_strike_database_->AddEntryWithNumStrikes(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111"),
+ /*num_strikes=*/2);
+ EXPECT_EQ(2, legacy_strike_database_->GetStrikesForTesting(
+ legacy_strike_database_->GetKeyForCreditCardSave("1111")));
// Create, fill and submit an address form in order to establish a recent
// profile which can be selected for the upload request.
diff --git a/components/autofill/core/browser/legacy_strike_database.cc b/components/autofill/core/browser/legacy_strike_database.cc
new file mode 100644
index 0000000..0170fdf
--- /dev/null
+++ b/components/autofill/core/browser/legacy_strike_database.cc
@@ -0,0 +1,179 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/autofill/core/browser/legacy_strike_database.h"
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/metrics/histogram_functions.h"
+#include "base/task/post_task.h"
+#include "base/time/time.h"
+#include "components/autofill/core/browser/proto/strike_data.pb.h"
+#include "components/leveldb_proto/proto_database_impl.h"
+
+namespace autofill {
+
+namespace {
+const char kDatabaseClientName[] = "StrikeService";
+const char kKeyDeliminator[] = "__";
+const char kKeyPrefixForCreditCardSave[] = "creditCardSave";
+} // namespace
+
+LegacyStrikeDatabase::LegacyStrikeDatabase(const base::FilePath& database_dir)
+ : db_(std::make_unique<leveldb_proto::ProtoDatabaseImpl<StrikeData>>(
+ base::CreateSequencedTaskRunnerWithTraits(
+ {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
+ base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}))),
+ weak_ptr_factory_(this) {
+ db_->Init(kDatabaseClientName, database_dir,
+ leveldb_proto::CreateSimpleOptions(),
+ base::BindRepeating(&LegacyStrikeDatabase::OnDatabaseInit,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+LegacyStrikeDatabase::~LegacyStrikeDatabase() {}
+
+void LegacyStrikeDatabase::GetStrikes(const std::string key,
+ const StrikesCallback& outer_callback) {
+ GetStrikeData(key, base::BindRepeating(&LegacyStrikeDatabase::OnGetStrikes,
+ base::Unretained(this),
+ std::move(outer_callback)));
+}
+
+void LegacyStrikeDatabase::AddStrike(const std::string key,
+ const StrikesCallback& outer_callback) {
+ GetStrikeData(key, base::BindRepeating(&LegacyStrikeDatabase::OnAddStrike,
+ base::Unretained(this),
+ std::move(outer_callback), key));
+}
+
+void LegacyStrikeDatabase::ClearAllStrikes(
+ const ClearStrikesCallback& outer_callback) {
+ // For deleting all, filter method always returns true.
+ db_->UpdateEntriesWithRemoveFilter(
+ std::make_unique<StrikeDataProto::KeyEntryVector>(),
+ base::BindRepeating([](const std::string& key) { return true; }),
+ base::BindRepeating(&LegacyStrikeDatabase::OnClearAllStrikes,
+ base::Unretained(this), outer_callback));
+}
+
+void LegacyStrikeDatabase::ClearAllStrikesForKey(
+ const std::string& key,
+ const ClearStrikesCallback& outer_callback) {
+ std::unique_ptr<std::vector<std::string>> keys_to_remove(
+ new std::vector<std::string>());
+ keys_to_remove->push_back(key);
+ db_->UpdateEntries(
+ /*entries_to_save=*/std::make_unique<
+ leveldb_proto::ProtoDatabase<StrikeData>::KeyEntryVector>(),
+ /*keys_to_remove=*/std::move(keys_to_remove),
+ base::BindRepeating(&LegacyStrikeDatabase::OnClearAllStrikesForKey,
+ base::Unretained(this), outer_callback));
+}
+
+std::string LegacyStrikeDatabase::GetKeyForCreditCardSave(
+ const std::string& card_last_four_digits) {
+ return CreateKey(GetKeyPrefixForCreditCardSave(), card_last_four_digits);
+}
+
+LegacyStrikeDatabase::LegacyStrikeDatabase()
+ : db_(nullptr), weak_ptr_factory_(this) {}
+
+void LegacyStrikeDatabase::OnDatabaseInit(bool success) {}
+
+void LegacyStrikeDatabase::GetStrikeData(const std::string key,
+ const GetValueCallback& callback) {
+ db_->GetEntry(key, callback);
+}
+
+void LegacyStrikeDatabase::SetStrikeData(const std::string& key,
+ const StrikeData& data,
+ const SetValueCallback& callback) {
+ std::unique_ptr<StrikeDataProto::KeyEntryVector> entries(
+ new StrikeDataProto::KeyEntryVector());
+ entries->push_back(std::make_pair(key, data));
+ db_->UpdateEntries(
+ /*entries_to_save=*/std::move(entries),
+ /*keys_to_remove=*/std::make_unique<std::vector<std::string>>(),
+ callback);
+}
+
+void LegacyStrikeDatabase::OnGetStrikes(
+ StrikesCallback callback,
+ bool success,
+ std::unique_ptr<StrikeData> strike_data) {
+ if (success && strike_data)
+ callback.Run(strike_data->num_strikes());
+ else
+ callback.Run(0);
+}
+
+void LegacyStrikeDatabase::OnAddStrike(
+ StrikesCallback callback,
+ std::string key,
+ bool success,
+ std::unique_ptr<StrikeData> strike_data) {
+ if (!success) {
+ // Failed to get strike data; abort adding strike.
+ callback.Run(0);
+ return;
+ }
+ int num_strikes = strike_data ? strike_data->num_strikes() + 1 : 1;
+ StrikeData data;
+ data.set_num_strikes(num_strikes);
+ data.set_last_update_timestamp(
+ base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds());
+ SetStrikeData(
+ key, data,
+ base::BindRepeating(&LegacyStrikeDatabase::OnAddStrikeComplete,
+ base::Unretained(this), callback, num_strikes, key));
+}
+
+void LegacyStrikeDatabase::OnAddStrikeComplete(StrikesCallback callback,
+ int num_strikes,
+ std::string key,
+ bool success) {
+ if (success) {
+ if (GetPrefixFromKey(key) == kKeyPrefixForCreditCardSave) {
+ base::UmaHistogramCounts1000(
+ "Autofill.StrikeDatabase.NthStrikeAdded.CreditCardSave", num_strikes);
+ }
+ callback.Run(num_strikes);
+ } else {
+ callback.Run(0);
+ }
+}
+
+void LegacyStrikeDatabase::OnClearAllStrikes(ClearStrikesCallback callback,
+ bool success) {
+ callback.Run(success);
+}
+
+void LegacyStrikeDatabase::OnClearAllStrikesForKey(
+ ClearStrikesCallback callback,
+ bool success) {
+ callback.Run(success);
+}
+
+void LegacyStrikeDatabase::LoadKeys(const LoadKeysCallback& callback) {
+ db_->LoadKeys(callback);
+}
+
+std::string LegacyStrikeDatabase::CreateKey(
+ const std::string& type_prefix,
+ const std::string& identifier_suffix) {
+ return type_prefix + kKeyDeliminator + identifier_suffix;
+}
+
+std::string LegacyStrikeDatabase::GetKeyPrefixForCreditCardSave() {
+ return kKeyPrefixForCreditCardSave;
+}
+
+std::string LegacyStrikeDatabase::GetPrefixFromKey(const std::string& key) {
+ return key.substr(0, key.find(kKeyDeliminator));
+}
+
+} // namespace autofill
diff --git a/components/autofill/core/browser/strike_database.h b/components/autofill/core/browser/legacy_strike_database.h
similarity index 84%
rename from components/autofill/core/browser/strike_database.h
rename to components/autofill/core/browser/legacy_strike_database.h
index 46d9388..57b0fe4 100644
--- a/components/autofill/core/browser/strike_database.h
+++ b/components/autofill/core/browser/legacy_strike_database.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_STRIKE_DATABASE_H_
-#define COMPONENTS_AUTOFILL_CORE_BROWSER_STRIKE_DATABASE_H_
+#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_LEGACY_STRIKE_DATABASE_H_
+#define COMPONENTS_AUTOFILL_CORE_BROWSER_LEGACY_STRIKE_DATABASE_H_
#include <memory>
#include <string>
@@ -24,15 +24,16 @@
// Here's how to create a new project type:
// 1) The keys used for this database are in form
-// <ProjectTypePrefixName>__<SomeIdentifierSuffix>. In strike_database.cc, add a
-// char[] variable called kKeyPrefixFor<ProjectType>.
-// 2) In strike_database.h/cc, create the functions
+// <ProjectTypePrefixName>__<SomeIdentifierSuffix>. In
+// legacy_strike_database.cc, add a char[] variable called
+// kKeyPrefixFor<ProjectType>.
+// 2) In legacy_strike_database.h/cc, create the functions
// GetKeyFor<ProjectType>(const std::string& identifier) and
// GetKeyPrefixFor<ProjectType>().
// 3) Add new project type to the if block in
-// StrikeDatabase::OnAddStrikeComplete(~).
+// LegacyStrikeDatabase::OnAddStrikeComplete(~).
-class StrikeDatabase : public KeyedService {
+class LegacyStrikeDatabase : public KeyedService {
public:
using ClearStrikesCallback = base::RepeatingCallback<void(bool success)>;
@@ -50,8 +51,8 @@
using StrikeDataProto = leveldb_proto::ProtoDatabase<StrikeData>;
- explicit StrikeDatabase(const base::FilePath& database_dir);
- ~StrikeDatabase() override;
+ explicit LegacyStrikeDatabase(const base::FilePath& database_dir);
+ ~LegacyStrikeDatabase() override;
// Passes the number of strikes for |key| to |outer_callback|. In the case
// that the database fails to retrieve the strike update or if no entry is
@@ -83,16 +84,16 @@
protected:
// Constructor for testing that does not initialize a ProtoDatabase.
- StrikeDatabase();
+ LegacyStrikeDatabase();
std::unique_ptr<leveldb_proto::ProtoDatabase<StrikeData>> db_;
private:
- FRIEND_TEST_ALL_PREFIXES(StrikeDatabaseTest, GetPrefixFromKey);
+ FRIEND_TEST_ALL_PREFIXES(LegacyStrikeDatabaseTest, GetPrefixFromKey);
FRIEND_TEST_ALL_PREFIXES(ChromeBrowsingDataRemoverDelegateTest,
- StrikeDatabaseEmptyOnAutofillRemoveEverything);
- friend class StrikeDatabaseTest;
- friend class StrikeDatabaseTester;
+ LegacyStrikeDatabaseEmptyOnAutofillRemoveEverything);
+ friend class LegacyStrikeDatabaseTest;
+ friend class LegacyStrikeDatabaseTester;
void OnDatabaseInit(bool success);
@@ -139,9 +140,9 @@
std::string GetPrefixFromKey(const std::string& key);
- base::WeakPtrFactory<StrikeDatabase> weak_ptr_factory_;
+ base::WeakPtrFactory<LegacyStrikeDatabase> weak_ptr_factory_;
};
} // namespace autofill
-#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_STRIKE_DATABASE_H_
+#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_LEGACY_STRIKE_DATABASE_H_
diff --git a/components/autofill/core/browser/strike_database_unittest.cc b/components/autofill/core/browser/legacy_strike_database_unittest.cc
similarity index 73%
rename from components/autofill/core/browser/strike_database_unittest.cc
rename to components/autofill/core/browser/legacy_strike_database_unittest.cc
index 44709d3..af63074 100644
--- a/components/autofill/core/browser/strike_database_unittest.cc
+++ b/components/autofill/core/browser/legacy_strike_database_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/autofill/core/browser/strike_database.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include <utility>
#include <vector>
@@ -18,13 +18,13 @@
namespace autofill {
namespace {
-// Note: This class is NOT the same as test_strike_database.h. This is an actual
-// implementation of StrikeDatabase, but with helper functions added for easier
-// test setup.
-class TestStrikeDatabase : public StrikeDatabase {
+// Note: This class is NOT the same as test_legacy_strike_database.h. This is an
+// actual implementation of LegacyStrikeDatabase, but with helper functions
+// added for easier test setup.
+class TestLegacyStrikeDatabase : public LegacyStrikeDatabase {
public:
- TestStrikeDatabase(const base::FilePath& database_dir)
- : StrikeDatabase(database_dir) {}
+ TestLegacyStrikeDatabase(const base::FilePath& database_dir)
+ : LegacyStrikeDatabase(database_dir) {}
void AddEntries(
std::vector<std::pair<std::string, StrikeData>> entries_to_add,
@@ -41,23 +41,23 @@
}
private:
- DISALLOW_COPY_AND_ASSIGN(TestStrikeDatabase);
+ DISALLOW_COPY_AND_ASSIGN(TestLegacyStrikeDatabase);
};
} // anonymous namespace
-// Runs tests against the actual StrikeDatabase class, complete with
+// Runs tests against the actual LegacyStrikeDatabase class, complete with
// ProtoDatabase.
-class StrikeDatabaseTest : public ::testing::Test {
+class LegacyStrikeDatabaseTest : public ::testing::Test {
public:
- StrikeDatabaseTest() : strike_database_(InitFilePath()) {}
+ LegacyStrikeDatabaseTest() : legacy_strike_database_(InitFilePath()) {}
void AddEntries(
std::vector<std::pair<std::string, StrikeData>> entries_to_add) {
base::RunLoop run_loop;
- strike_database_.AddEntries(
+ legacy_strike_database_.AddEntries(
entries_to_add,
- base::BindRepeating(&StrikeDatabaseTest::OnAddEntries,
+ base::BindRepeating(&LegacyStrikeDatabaseTest::OnAddEntries,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
}
@@ -73,9 +73,9 @@
int GetStrikes(std::string key) {
base::RunLoop run_loop;
- strike_database_.GetStrikes(
+ legacy_strike_database_.GetStrikes(
key,
- base::BindRepeating(&StrikeDatabaseTest::OnGetStrikes,
+ base::BindRepeating(&LegacyStrikeDatabaseTest::OnGetStrikes,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
return num_strikes_;
@@ -88,9 +88,9 @@
int AddStrike(std::string key) {
base::RunLoop run_loop;
- strike_database_.AddStrike(
+ legacy_strike_database_.AddStrike(
key,
- base::BindRepeating(&StrikeDatabaseTest::OnAddStrike,
+ base::BindRepeating(&LegacyStrikeDatabaseTest::OnAddStrike,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
return num_strikes_;
@@ -103,9 +103,9 @@
void ClearAllStrikesForKey(const std::string key) {
base::RunLoop run_loop;
- strike_database_.ClearAllStrikesForKey(
+ legacy_strike_database_.ClearAllStrikesForKey(
key,
- base::BindRepeating(&StrikeDatabaseTest::OnClearAllStrikesForKey,
+ base::BindRepeating(&LegacyStrikeDatabaseTest::OnClearAllStrikesForKey,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
}
@@ -117,8 +117,8 @@
void ClearAllStrikes() {
base::RunLoop run_loop;
- strike_database_.ClearAllStrikes(
- base::BindRepeating(&StrikeDatabaseTest::OnClearAllStrikesForKey,
+ legacy_strike_database_.ClearAllStrikes(
+ base::BindRepeating(&LegacyStrikeDatabaseTest::OnClearAllStrikesForKey,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
}
@@ -126,14 +126,14 @@
protected:
base::HistogramTester* GetHistogramTester() { return &histogram_tester_; }
base::test::ScopedTaskEnvironment scoped_task_environment_;
- TestStrikeDatabase strike_database_;
+ TestLegacyStrikeDatabase legacy_strike_database_;
private:
static const base::FilePath InitFilePath() {
base::ScopedTempDir temp_dir_;
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
const base::FilePath file_path =
- temp_dir_.GetPath().AppendASCII("StrikeDatabaseTest");
+ temp_dir_.GetPath().AppendASCII("LegacyStrikeDatabaseTest");
return file_path;
}
@@ -142,7 +142,7 @@
std::unique_ptr<StrikeData> strike_data_;
};
-TEST_F(StrikeDatabaseTest, AddStrikeTest) {
+TEST_F(LegacyStrikeDatabaseTest, AddStrikeTest) {
const std::string key = "12345";
int strikes = AddStrike(key);
EXPECT_EQ(1, strikes);
@@ -150,13 +150,13 @@
EXPECT_EQ(2, strikes);
}
-TEST_F(StrikeDatabaseTest, GetStrikeForZeroStrikesTest) {
+TEST_F(LegacyStrikeDatabaseTest, GetStrikeForZeroStrikesTest) {
const std::string key = "12345";
int strikes = GetStrikes(key);
EXPECT_EQ(0, strikes);
}
-TEST_F(StrikeDatabaseTest, GetStrikeForNonZeroStrikesTest) {
+TEST_F(LegacyStrikeDatabaseTest, GetStrikeForNonZeroStrikesTest) {
// Set up database with 3 pre-existing strikes at |key|.
const std::string key = "12345";
std::vector<std::pair<std::string, StrikeData>> entries;
@@ -169,14 +169,14 @@
EXPECT_EQ(3, strikes);
}
-TEST_F(StrikeDatabaseTest, ClearStrikesForZeroStrikesTest) {
+TEST_F(LegacyStrikeDatabaseTest, ClearStrikesForZeroStrikesTest) {
const std::string key = "12345";
ClearAllStrikesForKey(key);
int strikes = GetStrikes(key);
EXPECT_EQ(0, strikes);
}
-TEST_F(StrikeDatabaseTest, ClearStrikesForNonZeroStrikesTest) {
+TEST_F(LegacyStrikeDatabaseTest, ClearStrikesForNonZeroStrikesTest) {
// Set up database with 3 pre-existing strikes at |key|.
const std::string key = "12345";
std::vector<std::pair<std::string, StrikeData>> entries;
@@ -192,7 +192,8 @@
EXPECT_EQ(0, strikes);
}
-TEST_F(StrikeDatabaseTest, ClearStrikesForMultipleNonZeroStrikesEntriesTest) {
+TEST_F(LegacyStrikeDatabaseTest,
+ ClearStrikesForMultipleNonZeroStrikesEntriesTest) {
// Set up database with 3 pre-existing strikes at |key1|, and 5 pre-existing
// strikes at |key2|.
const std::string key1 = "12345";
@@ -217,7 +218,7 @@
EXPECT_EQ(5, strikes);
}
-TEST_F(StrikeDatabaseTest, ClearAllStrikesTest) {
+TEST_F(LegacyStrikeDatabaseTest, ClearAllStrikesTest) {
// Set up database with 3 pre-existing strikes at |key1|, and 5 pre-existing
// strikes at |key2|.
const std::string key1 = "12345";
@@ -238,27 +239,27 @@
EXPECT_EQ(0, GetStrikes(key2));
}
-TEST_F(StrikeDatabaseTest, GetKeyForCreditCardSave) {
+TEST_F(LegacyStrikeDatabaseTest, GetKeyForCreditCardSave) {
const std::string last_four = "1234";
EXPECT_EQ("creditCardSave__1234",
- strike_database_.GetKeyForCreditCardSave(last_four));
+ legacy_strike_database_.GetKeyForCreditCardSave(last_four));
}
-TEST_F(StrikeDatabaseTest, GetPrefixFromKey) {
+TEST_F(LegacyStrikeDatabaseTest, GetPrefixFromKey) {
const std::string key = "creditCardSave__1234";
- EXPECT_EQ("creditCardSave", strike_database_.GetPrefixFromKey(key));
+ EXPECT_EQ("creditCardSave", legacy_strike_database_.GetPrefixFromKey(key));
}
-TEST_F(StrikeDatabaseTest, CreditCardSaveNthStrikeAddedHistogram) {
+TEST_F(LegacyStrikeDatabaseTest, CreditCardSaveNthStrikeAddedHistogram) {
const std::string last_four1 = "1234";
const std::string last_four2 = "9876";
const std::string key1 = "NotACreditCard";
// 1st strike added for |last_four1|.
- AddStrike(strike_database_.GetKeyForCreditCardSave(last_four1));
+ AddStrike(legacy_strike_database_.GetKeyForCreditCardSave(last_four1));
// 2nd strike added for |last_four1|.
- AddStrike(strike_database_.GetKeyForCreditCardSave(last_four1));
+ AddStrike(legacy_strike_database_.GetKeyForCreditCardSave(last_four1));
// 1st strike added for |last_four2|.
- AddStrike(strike_database_.GetKeyForCreditCardSave(last_four2));
+ AddStrike(legacy_strike_database_.GetKeyForCreditCardSave(last_four2));
// Shouldn't be counted in histogram since key doesn't have prefix for credit
// cards.
AddStrike(key1);
diff --git a/components/autofill/core/browser/strike_database.cc b/components/autofill/core/browser/strike_database.cc
deleted file mode 100644
index 33ab589..0000000
--- a/components/autofill/core/browser/strike_database.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/autofill/core/browser/strike_database.h"
-
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "base/metrics/histogram_functions.h"
-#include "base/task/post_task.h"
-#include "base/time/time.h"
-#include "components/autofill/core/browser/proto/strike_data.pb.h"
-#include "components/leveldb_proto/proto_database_impl.h"
-
-namespace autofill {
-
-namespace {
-const char kDatabaseClientName[] = "StrikeService";
-const char kKeyDeliminator[] = "__";
-const char kKeyPrefixForCreditCardSave[] = "creditCardSave";
-} // namespace
-
-StrikeDatabase::StrikeDatabase(const base::FilePath& database_dir)
- : db_(std::make_unique<leveldb_proto::ProtoDatabaseImpl<StrikeData>>(
- base::CreateSequencedTaskRunnerWithTraits(
- {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
- base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}))),
- weak_ptr_factory_(this) {
- db_->Init(kDatabaseClientName, database_dir,
- leveldb_proto::CreateSimpleOptions(),
- base::BindRepeating(&StrikeDatabase::OnDatabaseInit,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-StrikeDatabase::~StrikeDatabase() {}
-
-void StrikeDatabase::GetStrikes(const std::string key,
- const StrikesCallback& outer_callback) {
- GetStrikeData(key, base::BindRepeating(&StrikeDatabase::OnGetStrikes,
- base::Unretained(this),
- std::move(outer_callback)));
-}
-
-void StrikeDatabase::AddStrike(const std::string key,
- const StrikesCallback& outer_callback) {
- GetStrikeData(key, base::BindRepeating(&StrikeDatabase::OnAddStrike,
- base::Unretained(this),
- std::move(outer_callback), key));
-}
-
-void StrikeDatabase::ClearAllStrikes(
- const ClearStrikesCallback& outer_callback) {
- // For deleting all, filter method always returns true.
- db_->UpdateEntriesWithRemoveFilter(
- std::make_unique<StrikeDataProto::KeyEntryVector>(),
- base::BindRepeating([](const std::string& key) { return true; }),
- base::BindRepeating(&StrikeDatabase::OnClearAllStrikes,
- base::Unretained(this), outer_callback));
-}
-
-void StrikeDatabase::ClearAllStrikesForKey(
- const std::string& key,
- const ClearStrikesCallback& outer_callback) {
- std::unique_ptr<std::vector<std::string>> keys_to_remove(
- new std::vector<std::string>());
- keys_to_remove->push_back(key);
- db_->UpdateEntries(
- /*entries_to_save=*/std::make_unique<
- leveldb_proto::ProtoDatabase<StrikeData>::KeyEntryVector>(),
- /*keys_to_remove=*/std::move(keys_to_remove),
- base::BindRepeating(&StrikeDatabase::OnClearAllStrikesForKey,
- base::Unretained(this), outer_callback));
-}
-
-std::string StrikeDatabase::GetKeyForCreditCardSave(
- const std::string& card_last_four_digits) {
- return CreateKey(GetKeyPrefixForCreditCardSave(), card_last_four_digits);
-}
-
-StrikeDatabase::StrikeDatabase() : db_(nullptr), weak_ptr_factory_(this) {}
-
-void StrikeDatabase::OnDatabaseInit(bool success) {}
-
-void StrikeDatabase::GetStrikeData(const std::string key,
- const GetValueCallback& callback) {
- db_->GetEntry(key, callback);
-}
-
-void StrikeDatabase::SetStrikeData(const std::string& key,
- const StrikeData& data,
- const SetValueCallback& callback) {
- std::unique_ptr<StrikeDataProto::KeyEntryVector> entries(
- new StrikeDataProto::KeyEntryVector());
- entries->push_back(std::make_pair(key, data));
- db_->UpdateEntries(
- /*entries_to_save=*/std::move(entries),
- /*keys_to_remove=*/std::make_unique<std::vector<std::string>>(),
- callback);
-}
-
-void StrikeDatabase::OnGetStrikes(StrikesCallback callback,
- bool success,
- std::unique_ptr<StrikeData> strike_data) {
- if (success && strike_data)
- callback.Run(strike_data->num_strikes());
- else
- callback.Run(0);
-}
-
-void StrikeDatabase::OnAddStrike(StrikesCallback callback,
- std::string key,
- bool success,
- std::unique_ptr<StrikeData> strike_data) {
- if (!success) {
- // Failed to get strike data; abort adding strike.
- callback.Run(0);
- return;
- }
- int num_strikes = strike_data ? strike_data->num_strikes() + 1 : 1;
- StrikeData data;
- data.set_num_strikes(num_strikes);
- data.set_last_update_timestamp(
- base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds());
- SetStrikeData(
- key, data,
- base::BindRepeating(&StrikeDatabase::OnAddStrikeComplete,
- base::Unretained(this), callback, num_strikes, key));
-}
-
-void StrikeDatabase::OnAddStrikeComplete(StrikesCallback callback,
- int num_strikes,
- std::string key,
- bool success) {
- if (success) {
- if (GetPrefixFromKey(key) == kKeyPrefixForCreditCardSave) {
- base::UmaHistogramCounts1000(
- "Autofill.StrikeDatabase.NthStrikeAdded.CreditCardSave", num_strikes);
- }
- callback.Run(num_strikes);
- } else {
- callback.Run(0);
- }
-}
-
-void StrikeDatabase::OnClearAllStrikes(ClearStrikesCallback callback,
- bool success) {
- callback.Run(success);
-}
-
-void StrikeDatabase::OnClearAllStrikesForKey(ClearStrikesCallback callback,
- bool success) {
- callback.Run(success);
-}
-
-void StrikeDatabase::LoadKeys(const LoadKeysCallback& callback) {
- db_->LoadKeys(callback);
-}
-
-std::string StrikeDatabase::CreateKey(const std::string& type_prefix,
- const std::string& identifier_suffix) {
- return type_prefix + kKeyDeliminator + identifier_suffix;
-}
-
-std::string StrikeDatabase::GetKeyPrefixForCreditCardSave() {
- return kKeyPrefixForCreditCardSave;
-}
-
-std::string StrikeDatabase::GetPrefixFromKey(const std::string& key) {
- return key.substr(0, key.find(kKeyDeliminator));
-}
-
-} // namespace autofill
diff --git a/components/autofill/core/browser/test_autofill_client.cc b/components/autofill/core/browser/test_autofill_client.cc
index 8a5c330f..db0bf1c 100644
--- a/components/autofill/core/browser/test_autofill_client.cc
+++ b/components/autofill/core/browser/test_autofill_client.cc
@@ -45,8 +45,8 @@
return payments_client_.get();
}
-StrikeDatabase* TestAutofillClient::GetStrikeDatabase() {
- return test_strike_database_.get();
+LegacyStrikeDatabase* TestAutofillClient::GetLegacyStrikeDatabase() {
+ return test_legacy_strike_database_.get();
}
ukm::UkmRecorder* TestAutofillClient::GetUkmRecorder() {
diff --git a/components/autofill/core/browser/test_autofill_client.h b/components/autofill/core/browser/test_autofill_client.h
index 19e98f9..2a0bc49 100644
--- a/components/autofill/core/browser/test_autofill_client.h
+++ b/components/autofill/core/browser/test_autofill_client.h
@@ -18,7 +18,7 @@
#include "components/autofill/core/browser/payments/test_payments_client.h"
#include "components/autofill/core/browser/test_address_normalizer.h"
#include "components/autofill/core/browser/test_form_data_importer.h"
-#include "components/autofill/core/browser/test_strike_database.h"
+#include "components/autofill/core/browser/test_legacy_strike_database.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/identity/public/cpp/identity_test_environment.h"
@@ -39,7 +39,7 @@
identity::IdentityManager* GetIdentityManager() override;
FormDataImporter* GetFormDataImporter() override;
payments::PaymentsClient* GetPaymentsClient() override;
- StrikeDatabase* GetStrikeDatabase() override;
+ LegacyStrikeDatabase* GetLegacyStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override;
@@ -116,8 +116,8 @@
}
void set_test_strike_database(
- std::unique_ptr<TestStrikeDatabase> test_strike_database) {
- test_strike_database_ = std::move(test_strike_database);
+ std::unique_ptr<TestLegacyStrikeDatabase> test_strike_database) {
+ test_legacy_strike_database_ = std::move(test_strike_database);
}
void set_test_payments_client(
@@ -166,7 +166,7 @@
// NULL by default.
std::unique_ptr<PrefService> prefs_;
- std::unique_ptr<TestStrikeDatabase> test_strike_database_;
+ std::unique_ptr<TestLegacyStrikeDatabase> test_legacy_strike_database_;
std::unique_ptr<payments::PaymentsClient> payments_client_;
std::unique_ptr<FormDataImporter> form_data_importer_;
GURL form_origin_;
diff --git a/components/autofill/core/browser/test_strike_database.cc b/components/autofill/core/browser/test_legacy_strike_database.cc
similarity index 64%
rename from components/autofill/core/browser/test_strike_database.cc
rename to components/autofill/core/browser/test_legacy_strike_database.cc
index 833528e..28d334b 100644
--- a/components/autofill/core/browser/test_strike_database.cc
+++ b/components/autofill/core/browser/test_legacy_strike_database.cc
@@ -2,23 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/autofill/core/browser/test_strike_database.h"
+#include "components/autofill/core/browser/test_legacy_strike_database.h"
#include "components/autofill/core/browser/proto/strike_data.pb.h"
namespace autofill {
-TestStrikeDatabase::TestStrikeDatabase() {}
+TestLegacyStrikeDatabase::TestLegacyStrikeDatabase() {}
-TestStrikeDatabase::~TestStrikeDatabase() {}
+TestLegacyStrikeDatabase::~TestLegacyStrikeDatabase() {}
-void TestStrikeDatabase::GetStrikes(const std::string key,
- const StrikesCallback& outer_callback) {
+void TestLegacyStrikeDatabase::GetStrikes(
+ const std::string key,
+ const StrikesCallback& outer_callback) {
outer_callback.Run(GetStrikesForTesting(key));
}
-void TestStrikeDatabase::AddStrike(const std::string key,
- const StrikesCallback& outer_callback) {
+void TestLegacyStrikeDatabase::AddStrike(
+ const std::string key,
+ const StrikesCallback& outer_callback) {
std::unordered_map<std::string, StrikeData>::iterator it = db_.find(key);
StrikeData strike_data;
strike_data.set_last_update_timestamp(
@@ -31,21 +33,21 @@
outer_callback.Run(strike_data.num_strikes());
}
-void TestStrikeDatabase::ClearAllStrikes(
+void TestLegacyStrikeDatabase::ClearAllStrikes(
const ClearStrikesCallback& outer_callback) {
db_.clear();
outer_callback.Run(/*success=*/true);
}
-void TestStrikeDatabase::ClearAllStrikesForKey(
+void TestLegacyStrikeDatabase::ClearAllStrikesForKey(
const std::string& key,
const ClearStrikesCallback& outer_callback) {
db_.erase(key);
outer_callback.Run(/*success=*/true);
}
-void TestStrikeDatabase::AddEntryWithNumStrikes(const std::string& key,
- int num_strikes) {
+void TestLegacyStrikeDatabase::AddEntryWithNumStrikes(const std::string& key,
+ int num_strikes) {
StrikeData strike_data;
strike_data.set_num_strikes(num_strikes);
strike_data.set_last_update_timestamp(
@@ -53,7 +55,7 @@
db_[key] = strike_data;
}
-int TestStrikeDatabase::GetStrikesForTesting(const std::string& key) {
+int TestLegacyStrikeDatabase::GetStrikesForTesting(const std::string& key) {
std::unordered_map<std::string, StrikeData>::iterator it = db_.find(key);
if (it != db_.end())
return it->second.num_strikes();
diff --git a/components/autofill/core/browser/test_strike_database.h b/components/autofill/core/browser/test_legacy_strike_database.h
similarity index 64%
rename from components/autofill/core/browser/test_strike_database.h
rename to components/autofill/core/browser/test_legacy_strike_database.h
index 198ef6e..ddf878f 100644
--- a/components/autofill/core/browser/test_strike_database.h
+++ b/components/autofill/core/browser/test_legacy_strike_database.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_STRIKE_DATABASE_H_
-#define COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_STRIKE_DATABASE_H_
+#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_LEGACY_STRIKE_DATABASE_H_
+#define COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_LEGACY_STRIKE_DATABASE_H_
#include <memory>
#include <string>
@@ -11,17 +11,17 @@
#include <utility>
#include <vector>
-#include "components/autofill/core/browser/strike_database.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
namespace autofill {
-// An in-memory-only test version of StrikeDatabase.
-class TestStrikeDatabase : public StrikeDatabase {
+// An in-memory-only test version of LegacyStrikeDatabase.
+class TestLegacyStrikeDatabase : public LegacyStrikeDatabase {
public:
- TestStrikeDatabase();
- ~TestStrikeDatabase() override;
+ TestLegacyStrikeDatabase();
+ ~TestLegacyStrikeDatabase() override;
- // StrikeDatabase:
+ // LegacyStrikeDatabase:
void GetStrikes(const std::string key,
const StrikesCallback& outer_callback) override;
void AddStrike(const std::string key,
@@ -31,7 +31,7 @@
const std::string& key,
const ClearStrikesCallback& outer_callback) override;
- // TestStrikeDatabase:
+ // TestLegacyStrikeDatabase:
void AddEntryWithNumStrikes(const std::string& key, int num_strikes);
int GetStrikesForTesting(const std::string& key);
@@ -42,4 +42,4 @@
} // namespace autofill
-#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_STRIKE_DATABASE_H_
+#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_LEGACY_STRIKE_DATABASE_H_
diff --git a/components/autofill/core/common/autofill_constants.h b/components/autofill/core/common/autofill_constants.h
index ddc3cda..2ab64b6 100644
--- a/components/autofill/core/common/autofill_constants.h
+++ b/components/autofill/core/common/autofill_constants.h
@@ -37,10 +37,12 @@
IS_PASSWORD_FIELD = 1 << 1 /* input field is a password field */
};
-// Autofill StrikeDatabase: Maximum strikes allowed for the credit card save
-// project. If the StrikeDatabase returns this many strikes for a given card, it
-// will not show the offer-to-save bubble on Desktop or infobar on Android.
-// On Desktop, however, the omnibox icon will still be available.
+// Autofill LegacyStrikeDatabase: Maximum strikes allowed for the credit card
+// save project. If the LegacyStrikeDatabase returns this many strikes for a
+// given card, it will not show the offer-to-save bubble on Desktop or infobar
+// on Android. On Desktop, however, the omnibox icon will still be available.
+// TODO(crbug.com/884817): Remove once StrikeDatabase v2 moves this constant to
+// its own credit card save policy.
const int kMaxStrikesToPreventPoppingUpOfferToSavePrompt = 3;
} // namespace autofill
diff --git a/ios/chrome/browser/autofill/BUILD.gn b/ios/chrome/browser/autofill/BUILD.gn
index 1d4fb8f..ee6986a 100644
--- a/ios/chrome/browser/autofill/BUILD.gn
+++ b/ios/chrome/browser/autofill/BUILD.gn
@@ -23,10 +23,10 @@
"form_suggestion_tab_helper.mm",
"form_suggestion_view.h",
"form_suggestion_view.mm",
+ "legacy_strike_database_factory.cc",
+ "legacy_strike_database_factory.h",
"personal_data_manager_factory.cc",
"personal_data_manager_factory.h",
- "strike_database_factory.cc",
- "strike_database_factory.h",
"validation_rules_storage_factory.cc",
"validation_rules_storage_factory.h",
]
diff --git a/ios/chrome/browser/autofill/legacy_strike_database_factory.cc b/ios/chrome/browser/autofill/legacy_strike_database_factory.cc
new file mode 100644
index 0000000..057c6b5
--- /dev/null
+++ b/ios/chrome/browser/autofill/legacy_strike_database_factory.cc
@@ -0,0 +1,46 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/autofill/legacy_strike_database_factory.h"
+
+#include <utility>
+
+#include "base/memory/singleton.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
+#include "components/keyed_service/ios/browser_state_dependency_manager.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+
+namespace autofill {
+
+// static
+LegacyStrikeDatabase* LegacyStrikeDatabaseFactory::GetForBrowserState(
+ ios::ChromeBrowserState* browser_state) {
+ return static_cast<LegacyStrikeDatabase*>(
+ GetInstance()->GetServiceForBrowserState(browser_state, true));
+}
+
+// static
+LegacyStrikeDatabaseFactory* LegacyStrikeDatabaseFactory::GetInstance() {
+ return base::Singleton<LegacyStrikeDatabaseFactory>::get();
+}
+
+LegacyStrikeDatabaseFactory::LegacyStrikeDatabaseFactory()
+ : BrowserStateKeyedServiceFactory(
+ "AutofillLegacyStrikeDatabase",
+ BrowserStateDependencyManager::GetInstance()) {}
+
+LegacyStrikeDatabaseFactory::~LegacyStrikeDatabaseFactory() {}
+
+std::unique_ptr<KeyedService>
+LegacyStrikeDatabaseFactory::BuildServiceInstanceFor(
+ web::BrowserState* context) const {
+ ios::ChromeBrowserState* chrome_browser_state =
+ ios::ChromeBrowserState::FromBrowserState(context);
+ return std::make_unique<autofill::LegacyStrikeDatabase>(
+ chrome_browser_state->GetStatePath().Append(
+ FILE_PATH_LITERAL("AutofillStrikeDatabase")));
+}
+
+} // namespace autofill
diff --git a/ios/chrome/browser/autofill/legacy_strike_database_factory.h b/ios/chrome/browser/autofill/legacy_strike_database_factory.h
new file mode 100644
index 0000000..4f56462
--- /dev/null
+++ b/ios/chrome/browser/autofill/legacy_strike_database_factory.h
@@ -0,0 +1,49 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_CHROME_BROWSER_AUTOFILL_LEGACY_STRIKE_DATABASE_FACTORY_H_
+#define IOS_CHROME_BROWSER_AUTOFILL_LEGACY_STRIKE_DATABASE_FACTORY_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
+
+namespace base {
+template <typename T>
+struct DefaultSingletonTraits;
+} // namespace base
+
+namespace ios {
+class ChromeBrowserState;
+}
+
+namespace autofill {
+
+class LegacyStrikeDatabase;
+
+// Singleton that owns all LegacyStrikeDatabases and associates them with
+// ios::ChromeBrowserState.
+class LegacyStrikeDatabaseFactory : public BrowserStateKeyedServiceFactory {
+ public:
+ static LegacyStrikeDatabase* GetForBrowserState(
+ ios::ChromeBrowserState* browser_state);
+ static LegacyStrikeDatabaseFactory* GetInstance();
+
+ private:
+ friend struct base::DefaultSingletonTraits<LegacyStrikeDatabaseFactory>;
+
+ LegacyStrikeDatabaseFactory();
+ ~LegacyStrikeDatabaseFactory() override;
+
+ // BrowserStateKeyedServiceFactory implementation.
+ std::unique_ptr<KeyedService> BuildServiceInstanceFor(
+ web::BrowserState* context) const override;
+
+ DISALLOW_COPY_AND_ASSIGN(LegacyStrikeDatabaseFactory);
+};
+
+} // namespace autofill
+
+#endif // IOS_CHROME_BROWSER_AUTOFILL_LEGACY_STRIKE_DATABASE_FACTORY_H_
diff --git a/ios/chrome/browser/autofill/strike_database_factory.cc b/ios/chrome/browser/autofill/strike_database_factory.cc
deleted file mode 100644
index 6e5d6f9..0000000
--- a/ios/chrome/browser/autofill/strike_database_factory.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ios/chrome/browser/autofill/strike_database_factory.h"
-
-#include <utility>
-
-#include "base/memory/singleton.h"
-#include "components/autofill/core/browser/strike_database.h"
-#include "components/keyed_service/ios/browser_state_dependency_manager.h"
-#include "ios/chrome/browser/application_context.h"
-#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
-
-namespace autofill {
-
-// static
-StrikeDatabase* StrikeDatabaseFactory::GetForBrowserState(
- ios::ChromeBrowserState* browser_state) {
- return static_cast<StrikeDatabase*>(
- GetInstance()->GetServiceForBrowserState(browser_state, true));
-}
-
-// static
-StrikeDatabaseFactory* StrikeDatabaseFactory::GetInstance() {
- return base::Singleton<StrikeDatabaseFactory>::get();
-}
-
-StrikeDatabaseFactory::StrikeDatabaseFactory()
- : BrowserStateKeyedServiceFactory(
- "AutofillStrikeDatabase",
- BrowserStateDependencyManager::GetInstance()) {}
-
-StrikeDatabaseFactory::~StrikeDatabaseFactory() {}
-
-std::unique_ptr<KeyedService> StrikeDatabaseFactory::BuildServiceInstanceFor(
- web::BrowserState* context) const {
- ios::ChromeBrowserState* chrome_browser_state =
- ios::ChromeBrowserState::FromBrowserState(context);
- return std::make_unique<autofill::StrikeDatabase>(
- chrome_browser_state->GetStatePath().Append(
- FILE_PATH_LITERAL("AutofillStrikeDatabase")));
-}
-
-} // namespace autofill
diff --git a/ios/chrome/browser/autofill/strike_database_factory.h b/ios/chrome/browser/autofill/strike_database_factory.h
deleted file mode 100644
index 6822440..0000000
--- a/ios/chrome/browser/autofill/strike_database_factory.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IOS_CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
-#define IOS_CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-} // namespace base
-
-namespace ios {
-class ChromeBrowserState;
-}
-
-namespace autofill {
-
-class StrikeDatabase;
-
-// Singleton that owns all StrikeDatabases and associates them with
-// ios::ChromeBrowserState.
-class StrikeDatabaseFactory : public BrowserStateKeyedServiceFactory {
- public:
- static StrikeDatabase* GetForBrowserState(
- ios::ChromeBrowserState* browser_state);
- static StrikeDatabaseFactory* GetInstance();
-
- private:
- friend struct base::DefaultSingletonTraits<StrikeDatabaseFactory>;
-
- StrikeDatabaseFactory();
- ~StrikeDatabaseFactory() override;
-
- // BrowserStateKeyedServiceFactory implementation.
- std::unique_ptr<KeyedService> BuildServiceInstanceFor(
- web::BrowserState* context) const override;
-
- DISALLOW_COPY_AND_ASSIGN(StrikeDatabaseFactory);
-};
-
-} // namespace autofill
-
-#endif // IOS_CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
diff --git a/ios/chrome/browser/browsing_data/browsing_data_remover_impl.mm b/ios/chrome/browser/browsing_data/browsing_data_remover_impl.mm
index fd0d9c0d..ec02f9a 100644
--- a/ios/chrome/browser/browsing_data/browsing_data_remover_impl.mm
+++ b/ios/chrome/browser/browsing_data/browsing_data_remover_impl.mm
@@ -22,8 +22,8 @@
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"
#include "base/threading/sequenced_task_runner_handle.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/personal_data_manager.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/history/core/browser/history_service.h"
#include "components/keyed_service/core/service_access_type.h"
@@ -37,8 +37,8 @@
#include "components/signin/core/browser/signin_pref_names.h"
#include "components/signin/ios/browser/account_consistency_service.h"
#include "ios/chrome/browser/application_context.h"
+#include "ios/chrome/browser/autofill/legacy_strike_database_factory.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
-#include "ios/chrome/browser/autofill/strike_database_factory.h"
#include "ios/chrome/browser/bookmarks/bookmark_remover_helper.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remove_mask.h"
@@ -479,11 +479,12 @@
web_data_service->RemoveAutofillDataModifiedBetween(delete_begin,
delete_end);
- // Clear out the Autofill StrikeDatabase in its entirety.
- autofill::StrikeDatabase* strike_database =
- autofill::StrikeDatabaseFactory::GetForBrowserState(browser_state_);
- if (strike_database)
- strike_database->ClearAllStrikes(AdaptCallbackForRepeating(
+ // Clear out the Autofill LegacyStrikeDatabase in its entirety.
+ autofill::LegacyStrikeDatabase* legacy_strike_database =
+ autofill::LegacyStrikeDatabaseFactory::GetForBrowserState(
+ browser_state_);
+ if (legacy_strike_database)
+ legacy_strike_database->ClearAllStrikes(AdaptCallbackForRepeating(
IgnoreArgument<bool>(CreatePendingTaskCompletionClosure())));
// Ask for a call back when the above calls are finished.
diff --git a/ios/chrome/browser/ios_chrome_flag_descriptions.h b/ios/chrome/browser/ios_chrome_flag_descriptions.h
index 8dba9867..c5db2f9 100644
--- a/ios/chrome/browser/ios_chrome_flag_descriptions.h
+++ b/ios/chrome/browser/ios_chrome_flag_descriptions.h
@@ -36,8 +36,8 @@
kEnableAutofillCreditCardUploadUpdatePromptExplanationDescription[];
// Title and description for the flag to control if credit card save should
-// utilize the Autofill StrikeDatabase when determining whether save should be
-// offered.
+// utilize the Autofill StrikeDatabase when determining whether save
+// should be offered.
extern const char kEnableAutofillSaveCreditCardUsesStrikeSystemName[];
extern const char kEnableAutofillSaveCreditCardUsesStrikeSystemDescription[];
diff --git a/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.h b/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.h
index 2ddf47e..ead138f 100644
--- a/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.h
+++ b/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.h
@@ -13,8 +13,8 @@
#include "base/memory/weak_ptr.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/card_unmask_delegate.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/personal_data_manager.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#import "components/autofill/ios/browser/autofill_client_ios_bridge.h"
@@ -50,7 +50,7 @@
identity::IdentityManager* GetIdentityManager() override;
FormDataImporter* GetFormDataImporter() override;
payments::PaymentsClient* GetPaymentsClient() override;
- StrikeDatabase* GetStrikeDatabase() override;
+ LegacyStrikeDatabase* GetLegacyStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override;
@@ -119,7 +119,7 @@
identity::IdentityManager* identity_manager_;
std::unique_ptr<payments::PaymentsClient> payments_client_;
std::unique_ptr<FormDataImporter> form_data_importer_;
- StrikeDatabase* strike_database_;
+ LegacyStrikeDatabase* legacy_strike_database_;
scoped_refptr<AutofillWebDataService> autofill_web_data_service_;
infobars::InfoBarManager* infobar_manager_;
password_manager::PasswordGenerationManager* password_generation_manager_;
diff --git a/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.mm b/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.mm
index feec33f..4c3571e2 100644
--- a/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.mm
+++ b/ios/chrome/browser/ui/autofill/chrome_autofill_client_ios.mm
@@ -24,8 +24,8 @@
#include "components/keyed_service/core/service_access_type.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/autofill/address_normalizer_factory.h"
+#include "ios/chrome/browser/autofill/legacy_strike_database_factory.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
-#include "ios/chrome/browser/autofill/strike_database_factory.h"
#include "ios/chrome/browser/infobars/infobar.h"
#include "ios/chrome/browser/infobars/infobar_utils.h"
#include "ios/chrome/browser/metrics/ukm_url_recorder.h"
@@ -85,7 +85,7 @@
payments_client_.get(),
personal_data_manager_,
GetApplicationContext()->GetApplicationLocale())),
- strike_database_(StrikeDatabaseFactory::GetForBrowserState(
+ legacy_strike_database_(LegacyStrikeDatabaseFactory::GetForBrowserState(
browser_state->GetOriginalChromeBrowserState())),
autofill_web_data_service_(
ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState(
@@ -129,8 +129,8 @@
return payments_client_.get();
}
-StrikeDatabase* ChromeAutofillClientIOS::GetStrikeDatabase() {
- return strike_database_;
+LegacyStrikeDatabase* ChromeAutofillClientIOS::GetLegacyStrikeDatabase() {
+ return legacy_strike_database_;
}
ukm::UkmRecorder* ChromeAutofillClientIOS::GetUkmRecorder() {
@@ -199,7 +199,7 @@
infobar_manager_->AddInfoBar(CreateSaveCardInfoBarMobile(
std::make_unique<AutofillSaveCardInfoBarDelegateMobile>(
/*upload=*/false, /*should_request_name_from_user=*/false, card,
- std::make_unique<base::DictionaryValue>(), GetStrikeDatabase(),
+ std::make_unique<base::DictionaryValue>(), GetLegacyStrikeDatabase(),
/*upload_save_card_callback=*/UserAcceptedUploadCallback(),
/*local_save_card_callback=*/std::move(callback), GetPrefs())));
}
@@ -233,7 +233,7 @@
auto save_card_info_bar_delegate_mobile =
std::make_unique<AutofillSaveCardInfoBarDelegateMobile>(
/*upload=*/true, /*should_request_name_from_user=*/false, card,
- std::move(legal_message), GetStrikeDatabase(),
+ std::move(legal_message), GetLegacyStrikeDatabase(),
/*upload_save_card_callback=*/std::move(callback),
/*local_save_card_callback=*/base::Closure(), GetPrefs());
// Allow user to save card only if legal messages are successfully parsed.
diff --git a/ios/web_view/BUILD.gn b/ios/web_view/BUILD.gn
index 7b79a35..1bf50f1 100644
--- a/ios/web_view/BUILD.gn
+++ b/ios/web_view/BUILD.gn
@@ -103,8 +103,8 @@
"internal/autofill/web_view_autofill_client_ios.mm",
"internal/autofill/web_view_personal_data_manager_factory.cc",
"internal/autofill/web_view_personal_data_manager_factory.h",
- "internal/autofill/web_view_strike_database_factory.cc",
- "internal/autofill/web_view_strike_database_factory.h",
+ "internal/autofill/web_view_legacy_strike_database_factory.cc",
+ "internal/autofill/web_view_legacy_strike_database_factory.h",
"internal/content_settings/web_view_cookie_settings_factory.cc",
"internal/content_settings/web_view_cookie_settings_factory.h",
"internal/content_settings/web_view_host_content_settings_map_factory.cc",
diff --git a/ios/web_view/internal/autofill/cwv_autofill_controller.mm b/ios/web_view/internal/autofill/cwv_autofill_controller.mm
index a2ef0af..2944915 100644
--- a/ios/web_view/internal/autofill/cwv_autofill_controller.mm
+++ b/ios/web_view/internal/autofill/cwv_autofill_controller.mm
@@ -33,8 +33,8 @@
#import "ios/web_view/internal/autofill/cwv_credit_card_internal.h"
#import "ios/web_view/internal/autofill/cwv_credit_card_verifier_internal.h"
#import "ios/web_view/internal/autofill/web_view_autofill_client_ios.h"
+#include "ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.h"
#include "ios/web_view/internal/autofill/web_view_personal_data_manager_factory.h"
-#include "ios/web_view/internal/autofill/web_view_strike_database_factory.h"
#import "ios/web_view/internal/passwords/cwv_password_controller.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#import "ios/web_view/internal/sync/web_view_profile_sync_service_factory.h"
@@ -130,7 +130,7 @@
_webState, self,
ios_web_view::WebViewIdentityManagerFactory::GetForBrowserState(
browserState->GetRecordingBrowserState()),
- ios_web_view::WebViewStrikeDatabaseFactory::GetForBrowserState(
+ ios_web_view::WebViewLegacyStrikeDatabaseFactory::GetForBrowserState(
browserState->GetRecordingBrowserState()),
ios_web_view::WebViewWebDataServiceWrapperFactory::
GetAutofillWebDataForBrowserState(
diff --git a/ios/web_view/internal/autofill/web_view_autofill_client_ios.h b/ios/web_view/internal/autofill/web_view_autofill_client_ios.h
index 3ffa716..93377b8 100644
--- a/ios/web_view/internal/autofill/web_view_autofill_client_ios.h
+++ b/ios/web_view/internal/autofill/web_view_autofill_client_ios.h
@@ -13,8 +13,8 @@
#include "base/memory/weak_ptr.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/card_unmask_delegate.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
#include "components/autofill/core/browser/personal_data_manager.h"
-#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h"
@@ -32,7 +32,7 @@
web::WebState* web_state,
id<CWVAutofillClientIOSBridge> bridge,
identity::IdentityManager* identity_manager,
- StrikeDatabase* strike_database,
+ LegacyStrikeDatabase* strike_database,
scoped_refptr<AutofillWebDataService> autofill_web_data_service,
syncer::SyncService* sync_service);
~WebViewAutofillClientIOS() override;
@@ -44,7 +44,7 @@
identity::IdentityManager* GetIdentityManager() override;
FormDataImporter* GetFormDataImporter() override;
payments::PaymentsClient* GetPaymentsClient() override;
- StrikeDatabase* GetStrikeDatabase() override;
+ LegacyStrikeDatabase* GetLegacyStrikeDatabase() override;
ukm::UkmRecorder* GetUkmRecorder() override;
ukm::SourceId GetUkmSourceId() override;
AddressNormalizer* GetAddressNormalizer() override;
@@ -112,7 +112,7 @@
identity::IdentityManager* identity_manager_;
std::unique_ptr<payments::PaymentsClient> payments_client_;
std::unique_ptr<FormDataImporter> form_data_importer_;
- StrikeDatabase* strike_database_;
+ LegacyStrikeDatabase* legacy_strike_database_;
scoped_refptr<AutofillWebDataService> autofill_web_data_service_;
syncer::SyncService* sync_service_ = nullptr;
diff --git a/ios/web_view/internal/autofill/web_view_autofill_client_ios.mm b/ios/web_view/internal/autofill/web_view_autofill_client_ios.mm
index 7eb086e..39bfa02 100644
--- a/ios/web_view/internal/autofill/web_view_autofill_client_ios.mm
+++ b/ios/web_view/internal/autofill/web_view_autofill_client_ios.mm
@@ -30,7 +30,7 @@
web::WebState* web_state,
id<CWVAutofillClientIOSBridge> bridge,
identity::IdentityManager* identity_manager,
- StrikeDatabase* strike_database,
+ LegacyStrikeDatabase* strike_database,
scoped_refptr<AutofillWebDataService> autofill_web_data_service,
syncer::SyncService* sync_service)
: pref_service_(pref_service),
@@ -51,7 +51,7 @@
personal_data_manager_,
ios_web_view::ApplicationContext::GetInstance()
->GetApplicationLocale())),
- strike_database_(strike_database),
+ legacy_strike_database_(strike_database),
autofill_web_data_service_(autofill_web_data_service),
sync_service_(sync_service) {}
@@ -83,8 +83,8 @@
return payments_client_.get();
}
-StrikeDatabase* WebViewAutofillClientIOS::GetStrikeDatabase() {
- return strike_database_;
+LegacyStrikeDatabase* WebViewAutofillClientIOS::GetLegacyStrikeDatabase() {
+ return legacy_strike_database_;
}
ukm::UkmRecorder* WebViewAutofillClientIOS::GetUkmRecorder() {
diff --git a/ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.cc b/ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.cc
new file mode 100644
index 0000000..299ec02
--- /dev/null
+++ b/ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.cc
@@ -0,0 +1,48 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.h"
+
+#include <utility>
+
+#include "base/memory/singleton.h"
+#include "components/autofill/core/browser/legacy_strike_database.h"
+#include "components/keyed_service/ios/browser_state_dependency_manager.h"
+#include "ios/web_view/internal/app/application_context.h"
+#include "ios/web_view/internal/web_view_browser_state.h"
+
+namespace ios_web_view {
+
+// static
+autofill::LegacyStrikeDatabase*
+WebViewLegacyStrikeDatabaseFactory::GetForBrowserState(
+ WebViewBrowserState* browser_state) {
+ return static_cast<autofill::LegacyStrikeDatabase*>(
+ GetInstance()->GetServiceForBrowserState(browser_state, true));
+}
+
+// static
+WebViewLegacyStrikeDatabaseFactory*
+WebViewLegacyStrikeDatabaseFactory::GetInstance() {
+ return base::Singleton<WebViewLegacyStrikeDatabaseFactory>::get();
+}
+
+WebViewLegacyStrikeDatabaseFactory::WebViewLegacyStrikeDatabaseFactory()
+ : BrowserStateKeyedServiceFactory(
+ "AutofillLegacyStrikeDatabase",
+ BrowserStateDependencyManager::GetInstance()) {}
+
+WebViewLegacyStrikeDatabaseFactory::~WebViewLegacyStrikeDatabaseFactory() {}
+
+std::unique_ptr<KeyedService>
+WebViewLegacyStrikeDatabaseFactory::BuildServiceInstanceFor(
+ web::BrowserState* context) const {
+ WebViewBrowserState* browser_state =
+ WebViewBrowserState::FromBrowserState(context);
+ return std::make_unique<autofill::LegacyStrikeDatabase>(
+ browser_state->GetStatePath().Append(
+ FILE_PATH_LITERAL("AutofillStrikeDatabase")));
+}
+
+} // namespace ios_web_view
diff --git a/ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.h b/ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.h
new file mode 100644
index 0000000..206ac15
--- /dev/null
+++ b/ios/web_view/internal/autofill/web_view_legacy_strike_database_factory.h
@@ -0,0 +1,50 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_LEGACY_STRIKE_DATABASE_FACTORY_H_
+#define IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_LEGACY_STRIKE_DATABASE_FACTORY_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
+
+namespace base {
+template <typename T>
+struct DefaultSingletonTraits;
+} // namespace base
+
+namespace autofill {
+class LegacyStrikeDatabase;
+}
+
+namespace ios_web_view {
+class WebViewBrowserState;
+
+// Singleton that owns all LegacyStrikeDatabases and associates them with
+// ios_web_view::WebViewBrowserState.
+class WebViewLegacyStrikeDatabaseFactory
+ : public BrowserStateKeyedServiceFactory {
+ public:
+ static autofill::LegacyStrikeDatabase* GetForBrowserState(
+ WebViewBrowserState* browser_state);
+ static WebViewLegacyStrikeDatabaseFactory* GetInstance();
+
+ private:
+ friend struct base::DefaultSingletonTraits<
+ WebViewLegacyStrikeDatabaseFactory>;
+
+ WebViewLegacyStrikeDatabaseFactory();
+ ~WebViewLegacyStrikeDatabaseFactory() override;
+
+ // BrowserStateKeyedServiceFactory implementation.
+ std::unique_ptr<KeyedService> BuildServiceInstanceFor(
+ web::BrowserState* context) const override;
+
+ DISALLOW_COPY_AND_ASSIGN(WebViewLegacyStrikeDatabaseFactory);
+};
+
+} // namespace ios_web_view
+
+#endif // IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_LEGACY_STRIKE_DATABASE_FACTORY_H_
diff --git a/ios/web_view/internal/autofill/web_view_strike_database_factory.cc b/ios/web_view/internal/autofill/web_view_strike_database_factory.cc
deleted file mode 100644
index f0ce6c3..0000000
--- a/ios/web_view/internal/autofill/web_view_strike_database_factory.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ios/web_view/internal/autofill/web_view_strike_database_factory.h"
-
-#include <utility>
-
-#include "base/memory/singleton.h"
-#include "components/autofill/core/browser/strike_database.h"
-#include "components/keyed_service/ios/browser_state_dependency_manager.h"
-#include "ios/web_view/internal/app/application_context.h"
-#include "ios/web_view/internal/web_view_browser_state.h"
-
-namespace ios_web_view {
-
-// static
-autofill::StrikeDatabase* WebViewStrikeDatabaseFactory::GetForBrowserState(
- WebViewBrowserState* browser_state) {
- return static_cast<autofill::StrikeDatabase*>(
- GetInstance()->GetServiceForBrowserState(browser_state, true));
-}
-
-// static
-WebViewStrikeDatabaseFactory* WebViewStrikeDatabaseFactory::GetInstance() {
- return base::Singleton<WebViewStrikeDatabaseFactory>::get();
-}
-
-WebViewStrikeDatabaseFactory::WebViewStrikeDatabaseFactory()
- : BrowserStateKeyedServiceFactory(
- "AutofillStrikeDatabase",
- BrowserStateDependencyManager::GetInstance()) {}
-
-WebViewStrikeDatabaseFactory::~WebViewStrikeDatabaseFactory() {}
-
-std::unique_ptr<KeyedService>
-WebViewStrikeDatabaseFactory::BuildServiceInstanceFor(
- web::BrowserState* context) const {
- WebViewBrowserState* browser_state =
- WebViewBrowserState::FromBrowserState(context);
- return std::make_unique<autofill::StrikeDatabase>(
- browser_state->GetStatePath().Append(
- FILE_PATH_LITERAL("AutofillStrikeDatabase")));
-}
-
-} // namespace ios_web_view
diff --git a/ios/web_view/internal/autofill/web_view_strike_database_factory.h b/ios/web_view/internal/autofill/web_view_strike_database_factory.h
deleted file mode 100644
index 93b48395..0000000
--- a/ios/web_view/internal/autofill/web_view_strike_database_factory.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_STRIKE_DATABASE_FACTORY_H_
-#define IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_STRIKE_DATABASE_FACTORY_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-} // namespace base
-
-namespace autofill {
-class StrikeDatabase;
-}
-
-namespace ios_web_view {
-class WebViewBrowserState;
-
-// Singleton that owns all StrikeDatabases and associates them with
-// ios_web_view::WebViewBrowserState.
-class WebViewStrikeDatabaseFactory : public BrowserStateKeyedServiceFactory {
- public:
- static autofill::StrikeDatabase* GetForBrowserState(
- WebViewBrowserState* browser_state);
- static WebViewStrikeDatabaseFactory* GetInstance();
-
- private:
- friend struct base::DefaultSingletonTraits<WebViewStrikeDatabaseFactory>;
-
- WebViewStrikeDatabaseFactory();
- ~WebViewStrikeDatabaseFactory() override;
-
- // BrowserStateKeyedServiceFactory implementation.
- std::unique_ptr<KeyedService> BuildServiceInstanceFor(
- web::BrowserState* context) const override;
-
- DISALLOW_COPY_AND_ASSIGN(WebViewStrikeDatabaseFactory);
-};
-
-} // namespace ios_web_view
-
-#endif // IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_STRIKE_DATABASE_FACTORY_H_