Commit ea370e2b authored by Anne Lim's avatar Anne Lim Committed by Commit Bot

[AF][Traffic Light] CC Uploads Per-Project Functs

Added per-project functions for credit card uploads. Each project
has its own requirements/parameters, so it must have its own
function to determine its key. Each project also has its own
private function to return a project prefix string.

Bug: 884717
Change-Id: Ib241378a8fa6a99071898f61425cdcefe69a16a0
Reviewed-on: https://chromium-review.googlesource.com/c/1260502Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Anne Lim <annelim@google.com>
Cr-Commit-Position: refs/heads/master@{#596886}
parent 9253b83d
......@@ -17,6 +17,8 @@ namespace autofill {
namespace {
const char kDatabaseClientName[] = "StrikeService";
const char kKeyDeliminator[] = "__";
const char kKeyPrefixForCreditCardSave[] = "creditCardSave";
} // namespace
StrikeDatabase::StrikeDatabase(const base::FilePath& database_dir)
......@@ -48,7 +50,7 @@ void StrikeDatabase::AddStrike(const std::string key,
}
void StrikeDatabase::ClearAllStrikesForKey(
const std::string key,
const std::string& key,
const ClearStrikesCallback& outer_callback) {
std::unique_ptr<std::vector<std::string>> keys_to_remove(
new std::vector<std::string>());
......@@ -61,6 +63,11 @@ void StrikeDatabase::ClearAllStrikesForKey(
base::Unretained(this), outer_callback));
}
std::string StrikeDatabase::GetKeyForCreditCardSave(
const std::string& card_last_four_digits) {
return CreateKey(GetKeyPrefixForCreditCardSave(), card_last_four_digits);
}
void StrikeDatabase::OnDatabaseInit(bool success) {}
void StrikeDatabase::GetStrikeData(const std::string key,
......@@ -68,7 +75,7 @@ void StrikeDatabase::GetStrikeData(const std::string key,
db_->GetEntry(key, callback);
}
void StrikeDatabase::SetStrikeData(const std::string key,
void StrikeDatabase::SetStrikeData(const std::string& key,
const StrikeData& data,
const SetValueCallback& callback) {
std::unique_ptr<StrikeDataProto::KeyEntryVector> entries(
......@@ -123,4 +130,13 @@ void StrikeDatabase::OnClearAllStrikesForKey(ClearStrikesCallback callback,
callback.Run(success);
}
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;
}
} // namespace autofill
......@@ -48,9 +48,13 @@ class StrikeDatabase {
void AddStrike(const std::string key, const StrikesCallback& outer_callback);
// Removes database entry for |key|, which implicitly sets strike count to 0.
void ClearAllStrikesForKey(const std::string key,
void ClearAllStrikesForKey(const std::string& key,
const ClearStrikesCallback& outer_callback);
// Returns concatenation of prefix + |card_last_four_digits| to be used as key
// for credit card save.
std::string GetKeyForCreditCardSave(const std::string& card_last_four_digits);
protected:
std::unique_ptr<leveldb_proto::ProtoDatabase<StrikeData>> db_;
......@@ -63,7 +67,7 @@ class StrikeDatabase {
// Sets the entry for |key| to |strike_data|. Success status is passed to the
// callback.
void SetStrikeData(const std::string key,
void SetStrikeData(const std::string& key,
const StrikeData& strike_data,
const SetValueCallback& inner_callback);
......@@ -86,6 +90,12 @@ class StrikeDatabase {
void OnClearAllStrikesForKey(ClearStrikesCallback outer_callback,
bool success);
// Concatenates type prefix and identifier suffix to create a key.
std::string CreateKey(const std::string& type_prefix,
const std::string& identifier_suffix);
std::string GetKeyPrefixForCreditCardSave();
base::WeakPtrFactory<StrikeDatabase> weak_ptr_factory_;
};
......
......@@ -77,6 +77,10 @@ class StrikeDatabaseTest : public ::testing::Test {
run_loop.Run();
}
protected:
base::test::ScopedTaskEnvironment scoped_task_environment_;
TestStrikeDatabase db_;
private:
static const base::FilePath InitFilePath() {
base::ScopedTempDir temp_dir_;
......@@ -87,9 +91,7 @@ class StrikeDatabaseTest : public ::testing::Test {
}
int num_strikes_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<StrikeData> strike_data_;
TestStrikeDatabase db_;
};
TEST_F(StrikeDatabaseTest, AddStrikeTest) {
......@@ -167,4 +169,9 @@ TEST_F(StrikeDatabaseTest, ClearStrikesForMultipleNonZeroStrikesEntriesTest) {
EXPECT_EQ(5, strikes);
}
TEST_F(StrikeDatabaseTest, GetKeyForCreditCardSave) {
const std::string last_four = "1234";
EXPECT_EQ("creditCardSave__1234", db_.GetKeyForCreditCardSave(last_four));
}
} // namespace autofill
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment