diff --git a/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.cc b/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.cc index 99ac605e174f..c6a75abe4ce7 100644 --- a/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.cc +++ b/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.cc @@ -45,7 +45,7 @@ constexpr int kDefaultBatchSize = 50; constexpr base::TimeDelta kMaximumRetryDelay = base::Hours(1); -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -66,7 +66,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const ConfirmationQueueItemList& confirmation_queue_items) { CHECK(mojom_db_action); CHECK(!confirmation_queue_items.empty()); @@ -148,7 +148,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } ConfirmationQueueItemInfo FromMojomRow( - const mojom::DBRowInfo* const mojom_db_row) { + const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); ConfirmationQueueItemInfo confirmation_queue_item; @@ -215,7 +215,7 @@ ConfirmationQueueItemInfo FromMojomRow( void GetCallback( GetConfirmationQueueCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get confirmation queue"); return std::move(callback).Run(/*success=*/false, @@ -229,7 +229,7 @@ void GetCallback( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { const ConfirmationQueueItemInfo confirmation_queue_item = - FromMojomRow(&*mojom_db_row); + FromMojomRow(mojom_db_row); if (!confirmation_queue_item.IsValid()) { BLOG(0, "Invalid confirmation queue item"); @@ -242,7 +242,7 @@ void GetCallback( std::move(callback).Run(/*success=*/true, confirmation_queue_items); } -void MigrateToV36(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV36(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -269,7 +269,7 @@ void MigrateToV36(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"process_at"}); } -void MigrateToV38(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV38(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // The conversion queue is deprecated since all confirmations are now being @@ -277,7 +277,7 @@ void MigrateToV38(mojom::DBTransactionInfo* const mojom_db_transaction) { DropTable(mojom_db_transaction, "conversion_queue"); } -void MigrateToV43(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Optimize database query for `Delete`, and `Retry`. @@ -303,7 +303,7 @@ void ConfirmationQueue::Save( SplitVector(confirmation_queue_items, batch_size_); for (const auto& batch : batches) { - Insert(&*mojom_db_transaction, batch); + Insert(mojom_db_transaction, batch); } RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); @@ -313,7 +313,7 @@ void ConfirmationQueue::DeleteAll(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -322,7 +322,7 @@ void ConfirmationQueue::Delete(const std::string& transaction_id, ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -346,7 +346,7 @@ void ConfirmationQueue::Retry(const std::string& transaction_id, mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); Execute( - &*mojom_db_transaction, R"( + mojom_db_transaction, R"( UPDATE $1 SET @@ -393,7 +393,7 @@ void ConfirmationQueue::GetAll(GetConfirmationQueueCallback callback) const { ORDER BY process_at ASC;)", {GetTableName()}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -430,7 +430,7 @@ void ConfirmationQueue::GetNext(GetConfirmationQueueCallback callback) const { LIMIT 1;)", {GetTableName()}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -443,7 +443,7 @@ std::string ConfirmationQueue::GetTableName() const { } void ConfirmationQueue::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -475,7 +475,7 @@ void ConfirmationQueue::Create( } void ConfirmationQueue::Migrate( - mojom::DBTransactionInfo* const mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -500,7 +500,7 @@ void ConfirmationQueue::Migrate( /////////////////////////////////////////////////////////////////////////////// void ConfirmationQueue::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const ConfirmationQueueItemList& confirmation_queue_items) const { CHECK(mojom_db_transaction); @@ -511,12 +511,12 @@ void ConfirmationQueue::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; mojom_db_action->sql = - BuildInsertSql(&*mojom_db_action, confirmation_queue_items); + BuildInsertSql(mojom_db_action, confirmation_queue_items); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string ConfirmationQueue::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const ConfirmationQueueItemList& confirmation_queue_items) const { CHECK(mojom_db_action); CHECK(!confirmation_queue_items.empty()); diff --git a/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h b/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h index 35e1dd1ed80f..3c6faba1ed99 100644 --- a/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h +++ b/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h @@ -50,16 +50,16 @@ class ConfirmationQueue final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const ConfirmationQueueItemList& confirmation_queue_items) const; std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const ConfirmationQueueItemList& confirmation_queue_items) const; int batch_size_; diff --git a/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc b/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc index aca140cc8f94..73bbc511707f 100644 --- a/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc +++ b/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc @@ -27,7 +27,7 @@ namespace { constexpr char kTableName[] = "deposits"; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -37,7 +37,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -58,7 +58,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, return row_count; } -void BindColumns(mojom::DBActionInfo* const mojom_db_action, +void BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const DepositInfo& deposit) { CHECK(mojom_db_action); CHECK(deposit.IsValid()); @@ -68,7 +68,7 @@ void BindColumns(mojom::DBActionInfo* const mojom_db_action, BindColumnTime(mojom_db_action, 2, deposit.expire_at.value_or(base::Time())); } -DepositInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { +DepositInfo FromMojomRow(const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); DepositInfo deposit; @@ -87,7 +87,7 @@ void GetForCreativeInstanceIdCallback( const std::string& /*creative_instance_id*/, GetDepositsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get deposit value"); return std::move(callback).Run(/*success=*/false, @@ -102,7 +102,7 @@ void GetForCreativeInstanceIdCallback( const mojom::DBRowInfoPtr mojom_db_row = std::move(mojom_db_transaction_result->rows_union->get_rows().front()); - DepositInfo deposit = FromMojomRow(&*mojom_db_row); + DepositInfo deposit = FromMojomRow(mojom_db_row); if (!deposit.IsValid()) { BLOG(0, "Invalid deposit"); @@ -112,7 +112,7 @@ void GetForCreativeInstanceIdCallback( std::move(callback).Run(/*success=*/true, std::move(deposit)); } -void MigrateToV43(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Optimize database query for `GetForCreativeInstanceId`. @@ -136,12 +136,12 @@ void Deposits::Save(const DepositInfo& deposit, ResultCallback callback) { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Insert(&*mojom_db_transaction, deposit); + Insert(mojom_db_transaction, deposit); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } -void Deposits::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void Deposits::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -151,18 +151,18 @@ void Deposits::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } -void Deposits::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void Deposits::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const DepositInfo& deposit) { CHECK(mojom_db_transaction); CHECK(deposit.IsValid()); mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, deposit); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, deposit); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -188,7 +188,7 @@ void Deposits::GetForCreativeInstanceId(const std::string& creative_instance_id, WHERE creative_instance_id = '$2';)", {GetTableName(), creative_instance_id}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -200,7 +200,7 @@ void Deposits::GetForCreativeInstanceId(const std::string& creative_instance_id, void Deposits::PurgeExpired(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -214,7 +214,7 @@ std::string Deposits::GetTableName() const { return kTableName; } -void Deposits::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Deposits::Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -233,7 +233,7 @@ void Deposits::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"expire_at"}); } -void Deposits::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, +void Deposits::Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -247,8 +247,9 @@ void Deposits::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// -std::string Deposits::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, - const CreativeAdList& creative_ads) const { +std::string Deposits::BuildInsertSql( + const mojom::DBActionInfoPtr& mojom_db_action, + const CreativeAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -266,8 +267,9 @@ std::string Deposits::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, nullptr); } -std::string Deposits::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, - const DepositInfo& deposit) const { +std::string Deposits::BuildInsertSql( + const mojom::DBActionInfoPtr& mojom_db_action, + const DepositInfo& deposit) const { CHECK(mojom_db_action); CHECK(deposit.IsValid()); diff --git a/components/brave_ads/core/internal/account/deposits/deposits_database_table.h b/components/brave_ads/core/internal/account/deposits/deposits_database_table.h index 2768e6dcb85d..71960204e93a 100644 --- a/components/brave_ads/core/internal/account/deposits/deposits_database_table.h +++ b/components/brave_ads/core/internal/account/deposits/deposits_database_table.h @@ -26,9 +26,9 @@ class Deposits final : public TableInterface { public: void Save(const DepositInfo& deposit, ResultCallback callback); - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads); - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const DepositInfo& deposit); void GetForCreativeInstanceId(const std::string& creative_instance_id, @@ -38,14 +38,14 @@ class Deposits final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const; - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const DepositInfo& deposit) const; }; diff --git a/components/brave_ads/core/internal/account/transactions/transactions_database_table.cc b/components/brave_ads/core/internal/account/transactions/transactions_database_table.cc index d3993af1a06e..0b744b3c097a 100644 --- a/components/brave_ads/core/internal/account/transactions/transactions_database_table.cc +++ b/components/brave_ads/core/internal/account/transactions/transactions_database_table.cc @@ -32,7 +32,7 @@ namespace { constexpr char kTableName[] = "transactions"; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -47,7 +47,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const TransactionList& transactions) { CHECK(mojom_db_action); CHECK(!transactions.empty()); @@ -81,7 +81,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, return row_count; } -TransactionInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { +TransactionInfo FromMojomRow(const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); TransactionInfo transaction; @@ -108,7 +108,7 @@ TransactionInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { void GetCallback( GetTransactionsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get transactions"); return std::move(callback).Run(/*success=*/false, /*transactions=*/{}); @@ -120,7 +120,7 @@ void GetCallback( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const TransactionInfo transaction = FromMojomRow(&*mojom_db_row); + const TransactionInfo transaction = FromMojomRow(mojom_db_row); if (!transaction.IsValid()) { base::debug::DumpWithoutCrashing(); BLOG(0, "Invalid transaction"); @@ -133,7 +133,7 @@ void GetCallback( std::move(callback).Run(/*success=*/true, transactions); } -void MigrateToV35(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV35(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Optimize database query for `GetForDateRange`. @@ -141,7 +141,7 @@ void MigrateToV35(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"created_at"}); } -void MigrateToV40(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV40(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Delete legacy transactions with an undefined `creative_instance_id`, @@ -186,7 +186,7 @@ void MigrateToV40(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"created_at"}); } -void MigrateToV43(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Optimize database query for `Reconcile`. @@ -209,7 +209,7 @@ void Transactions::Save(const TransactionList& transactions, mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Insert(&*mojom_db_transaction, transactions); + Insert(mojom_db_transaction, transactions); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -239,7 +239,7 @@ void Transactions::GetForDateRange(const base::Time from_time, {GetTableName(), TimeToSqlValueAsString(from_time), TimeToSqlValueAsString(to_time)}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -278,7 +278,7 @@ void Transactions::Reconcile(const PaymentTokenList& payment_tokens, int index = 0; for (const auto& transaction_id : transaction_ids) { - BindColumnString(&*mojom_db_action, index, transaction_id); + BindColumnString(mojom_db_action, index, transaction_id); ++index; } @@ -290,7 +290,7 @@ void Transactions::Reconcile(const PaymentTokenList& payment_tokens, void Transactions::PurgeExpired(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -307,7 +307,7 @@ std::string Transactions::GetTableName() const { } void Transactions::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -334,8 +334,9 @@ void Transactions::Create( /*columns=*/{"creative_instance_id"}); } -void Transactions::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, - const int to_version) { +void Transactions::Migrate( + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + const int to_version) { CHECK(mojom_db_transaction); switch (to_version) { @@ -358,8 +359,9 @@ void Transactions::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// -void Transactions::Insert(mojom::DBTransactionInfo* mojom_db_transaction, - const TransactionList& transactions) { +void Transactions::Insert( + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + const TransactionList& transactions) { CHECK(mojom_db_transaction); if (transactions.empty()) { @@ -368,12 +370,12 @@ void Transactions::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, transactions); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, transactions); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string Transactions::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const TransactionList& transactions) const { CHECK(mojom_db_action); CHECK(!transactions.empty()); diff --git a/components/brave_ads/core/internal/account/transactions/transactions_database_table.h b/components/brave_ads/core/internal/account/transactions/transactions_database_table.h index 773da9e10127..50cb4e3de5a4 100644 --- a/components/brave_ads/core/internal/account/transactions/transactions_database_table.h +++ b/components/brave_ads/core/internal/account/transactions/transactions_database_table.h @@ -39,15 +39,15 @@ class Transactions final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const TransactionList& transactions); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const TransactionList& transactions) const; }; diff --git a/components/brave_ads/core/internal/common/database/database_column_util.cc b/components/brave_ads/core/internal/common/database/database_column_util.cc index f100d435e838..78a5dbe0f9ef 100644 --- a/components/brave_ads/core/internal/common/database/database_column_util.cc +++ b/components/brave_ads/core/internal/common/database/database_column_util.cc @@ -92,7 +92,7 @@ void BindColumn(sql::Statement* const statement, } } -void BindColumnInt(mojom::DBActionInfo* const mojom_db_action, +void BindColumnInt(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const int32_t value) { CHECK(mojom_db_action); @@ -106,7 +106,7 @@ void BindColumnInt(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -int ColumnInt(const mojom::DBRowInfo* const mojom_db_row, const size_t column) { +int ColumnInt(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); CHECK_EQ(mojom::DBColumnValueUnion::Tag::kIntValue, @@ -115,7 +115,7 @@ int ColumnInt(const mojom::DBRowInfo* const mojom_db_row, const size_t column) { return mojom_db_row->column_values_union.at(column)->get_int_value(); } -void BindColumnInt64(mojom::DBActionInfo* const mojom_db_action, +void BindColumnInt64(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const int64_t value) { CHECK(mojom_db_action); @@ -129,7 +129,7 @@ void BindColumnInt64(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -int64_t ColumnInt64(const mojom::DBRowInfo* const mojom_db_row, +int64_t ColumnInt64(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); @@ -139,7 +139,7 @@ int64_t ColumnInt64(const mojom::DBRowInfo* const mojom_db_row, return mojom_db_row->column_values_union.at(column)->get_int64_value(); } -void BindColumnDouble(mojom::DBActionInfo* const mojom_db_action, +void BindColumnDouble(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const double value) { CHECK(mojom_db_action); @@ -153,7 +153,7 @@ void BindColumnDouble(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -double ColumnDouble(const mojom::DBRowInfo* const mojom_db_row, +double ColumnDouble(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); @@ -163,7 +163,7 @@ double ColumnDouble(const mojom::DBRowInfo* const mojom_db_row, return mojom_db_row->column_values_union.at(column)->get_double_value(); } -void BindColumnBool(mojom::DBActionInfo* const mojom_db_action, +void BindColumnBool(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const bool value) { CHECK(mojom_db_action); @@ -177,8 +177,7 @@ void BindColumnBool(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -bool ColumnBool(const mojom::DBRowInfo* const mojom_db_row, - const size_t column) { +bool ColumnBool(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); CHECK_EQ(mojom::DBColumnValueUnion::Tag::kBoolValue, @@ -187,7 +186,7 @@ bool ColumnBool(const mojom::DBRowInfo* const mojom_db_row, return mojom_db_row->column_values_union.at(column)->get_bool_value(); } -void BindColumnString(mojom::DBActionInfo* const mojom_db_action, +void BindColumnString(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const std::string& value) { CHECK(mojom_db_action); @@ -201,7 +200,7 @@ void BindColumnString(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -std::string ColumnString(const mojom::DBRowInfo* const mojom_db_row, +std::string ColumnString(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); @@ -211,7 +210,7 @@ std::string ColumnString(const mojom::DBRowInfo* const mojom_db_row, return mojom_db_row->column_values_union.at(column)->get_string_value(); } -void BindColumnTime(mojom::DBActionInfo* const mojom_db_action, +void BindColumnTime(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const base::Time value) { CHECK(mojom_db_action); @@ -225,7 +224,7 @@ void BindColumnTime(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -base::Time ColumnTime(const mojom::DBRowInfo* const mojom_db_row, +base::Time ColumnTime(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); @@ -235,7 +234,7 @@ base::Time ColumnTime(const mojom::DBRowInfo* const mojom_db_row, return mojom_db_row->column_values_union.at(column)->get_time_value(); } -void BindColumnTimeDelta(mojom::DBActionInfo* const mojom_db_action, +void BindColumnTimeDelta(const mojom::DBActionInfoPtr& mojom_db_action, const int32_t index, const base::TimeDelta value) { CHECK(mojom_db_action); @@ -249,7 +248,7 @@ void BindColumnTimeDelta(mojom::DBActionInfo* const mojom_db_action, mojom_db_action->bind_columns.push_back(std::move(mojom_db_bind_column)); } -base::TimeDelta ColumnTimeDelta(const mojom::DBRowInfo* const mojom_db_row, +base::TimeDelta ColumnTimeDelta(const mojom::DBRowInfoPtr& mojom_db_row, const size_t column) { CHECK(mojom_db_row); CHECK_LT(column, mojom_db_row->column_values_union.size()); diff --git a/components/brave_ads/core/internal/common/database/database_column_util.h b/components/brave_ads/core/internal/common/database/database_column_util.h index 8653a7316e73..fdadaeddcc7e 100644 --- a/components/brave_ads/core/internal/common/database/database_column_util.h +++ b/components/brave_ads/core/internal/common/database/database_column_util.h @@ -21,47 +21,47 @@ std::string BuildBindColumnPlaceholders(size_t column_count, size_t row_count); void BindColumn(sql::Statement* statement, const mojom::DBBindColumnInfo& mojom_db_bind_column); -void BindColumnInt(mojom::DBActionInfo* mojom_db_action, +void BindColumnInt(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, int32_t value); -[[nodiscard]] int ColumnInt(const mojom::DBRowInfo* mojom_db_row, +[[nodiscard]] int ColumnInt(const mojom::DBRowInfoPtr& mojom_db_row, size_t column); -void BindColumnInt64(mojom::DBActionInfo* mojom_db_action, +void BindColumnInt64(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, int64_t value); -[[nodiscard]] int64_t ColumnInt64(const mojom::DBRowInfo* mojom_db_row, +[[nodiscard]] int64_t ColumnInt64(const mojom::DBRowInfoPtr& mojom_db_row, size_t column); -void BindColumnDouble(mojom::DBActionInfo* mojom_db_action, +void BindColumnDouble(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, double value); -[[nodiscard]] double ColumnDouble(const mojom::DBRowInfo* mojom_db_row, +[[nodiscard]] double ColumnDouble(const mojom::DBRowInfoPtr& mojom_db_row, size_t column); -void BindColumnBool(mojom::DBActionInfo* mojom_db_action, +void BindColumnBool(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, bool value); -[[nodiscard]] bool ColumnBool(const mojom::DBRowInfo* mojom_db_row, +[[nodiscard]] bool ColumnBool(const mojom::DBRowInfoPtr& mojom_db_row, size_t column); -void BindColumnString(mojom::DBActionInfo* mojom_db_action, +void BindColumnString(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, const std::string& value); -[[nodiscard]] std::string ColumnString(const mojom::DBRowInfo* mojom_db_row, +[[nodiscard]] std::string ColumnString(const mojom::DBRowInfoPtr& mojom_db_row, size_t column); -void BindColumnTime(mojom::DBActionInfo* mojom_db_action, +void BindColumnTime(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, base::Time value); -[[nodiscard]] base::Time ColumnTime(const mojom::DBRowInfo* mojom_db_row, +[[nodiscard]] base::Time ColumnTime(const mojom::DBRowInfoPtr& mojom_db_row, size_t column); -void BindColumnTimeDelta(mojom::DBActionInfo* mojom_db_action, +void BindColumnTimeDelta(const mojom::DBActionInfoPtr& mojom_db_action, int32_t index, base::TimeDelta value); [[nodiscard]] base::TimeDelta ColumnTimeDelta( - const mojom::DBRowInfo* mojom_db_row, + const mojom::DBRowInfoPtr& mojom_db_row, size_t column); } // namespace brave_ads::database diff --git a/components/brave_ads/core/internal/common/database/database_table_util.cc b/components/brave_ads/core/internal/common/database/database_table_util.cc index 0ae7c0640958..66c931c1c401 100644 --- a/components/brave_ads/core/internal/common/database/database_table_util.cc +++ b/components/brave_ads/core/internal/common/database/database_table_util.cc @@ -12,7 +12,7 @@ namespace brave_ads::database { -void CreateTableIndex(mojom::DBTransactionInfo* const mojom_db_transaction, +void CreateTableIndex(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& table_name, const std::vector& columns) { CHECK(mojom_db_transaction); @@ -26,7 +26,7 @@ void CreateTableIndex(mojom::DBTransactionInfo* const mojom_db_transaction, base::JoinString(columns, ", ")}); } -void DropTableIndex(mojom::DBTransactionInfo* const mojom_db_transaction, +void DropTableIndex(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& index_name) { CHECK(mojom_db_transaction); CHECK(!index_name.empty()); @@ -36,7 +36,7 @@ void DropTableIndex(mojom::DBTransactionInfo* const mojom_db_transaction, ad_events_created_at_index;)"); } -void DropTable(mojom::DBTransactionInfo* const mojom_db_transaction, +void DropTable(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& table_name) { CHECK(mojom_db_transaction); CHECK(!table_name.empty()); @@ -47,7 +47,7 @@ void DropTable(mojom::DBTransactionInfo* const mojom_db_transaction, {table_name}); } -void DeleteTable(mojom::DBTransactionInfo* const mojom_db_transaction, +void DeleteTable(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& table_name) { CHECK(mojom_db_transaction); CHECK(!table_name.empty()); @@ -58,7 +58,7 @@ void DeleteTable(mojom::DBTransactionInfo* const mojom_db_transaction, {table_name}); } -void CopyTableColumns(mojom::DBTransactionInfo* const mojom_db_transaction, +void CopyTableColumns(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& from, const std::string& to, const std::vector& from_columns, @@ -88,7 +88,7 @@ void CopyTableColumns(mojom::DBTransactionInfo* const mojom_db_transaction, } } -void CopyTableColumns(mojom::DBTransactionInfo* const mojom_db_transaction, +void CopyTableColumns(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& from, const std::string& to, const std::vector& columns, @@ -97,7 +97,7 @@ void CopyTableColumns(mojom::DBTransactionInfo* const mojom_db_transaction, should_drop); } -void RenameTable(mojom::DBTransactionInfo* const mojom_db_transaction, +void RenameTable(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& from, const std::string& to) { CHECK(mojom_db_transaction); diff --git a/components/brave_ads/core/internal/common/database/database_table_util.h b/components/brave_ads/core/internal/common/database/database_table_util.h index 7cd4dbe992ff..9c4ed1bea552 100644 --- a/components/brave_ads/core/internal/common/database/database_table_util.h +++ b/components/brave_ads/core/internal/common/database/database_table_util.h @@ -13,33 +13,33 @@ namespace brave_ads::database { -void CreateTableIndex(mojom::DBTransactionInfo* mojom_db_transaction, +void CreateTableIndex(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& table_name, const std::vector& columns); -void DropTableIndex(mojom::DBTransactionInfo* mojom_db_transaction, +void DropTableIndex(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& index_name); -void DropTable(mojom::DBTransactionInfo* mojom_db_transaction, +void DropTable(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& table_name); -void DeleteTable(mojom::DBTransactionInfo* mojom_db_transaction, +void DeleteTable(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& table_name); -void CopyTableColumns(mojom::DBTransactionInfo* mojom_db_transaction, +void CopyTableColumns(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& from, const std::string& to, const std::vector& from_columns, const std::vector& to_columns, bool should_drop); -void CopyTableColumns(mojom::DBTransactionInfo* mojom_db_transaction, +void CopyTableColumns(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& from, const std::string& to, const std::vector& columns, bool should_drop); -void RenameTable(mojom::DBTransactionInfo* mojom_db_transaction, +void RenameTable(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& from, const std::string& to); diff --git a/components/brave_ads/core/internal/common/database/database_transaction_util.cc b/components/brave_ads/core/internal/common/database/database_transaction_util.cc index d34111d41d1a..bd1d26d7cfce 100644 --- a/components/brave_ads/core/internal/common/database/database_transaction_util.cc +++ b/components/brave_ads/core/internal/common/database/database_transaction_util.cc @@ -20,7 +20,7 @@ namespace { void RunDBTransactionCallback( ResultCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { return std::move(callback).Run(/*success=*/false); } @@ -30,15 +30,15 @@ void RunDBTransactionCallback( } // namespace bool IsSuccess( - const mojom::DBTransactionResultInfo* const mojom_db_transaction_result) { - return mojom_db_transaction_result != nullptr && + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result) { + return mojom_db_transaction_result && mojom_db_transaction_result->status_code == mojom::DBTransactionResultInfo::StatusCode::kSuccess; } bool IsError( - const mojom::DBTransactionResultInfo* const mojom_db_transaction_result) { - return mojom_db_transaction_result == nullptr || + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result) { + return !mojom_db_transaction_result || mojom_db_transaction_result->status_code != mojom::DBTransactionResultInfo::StatusCode::kSuccess; } @@ -50,13 +50,13 @@ void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, base::BindOnce(&RunDBTransactionCallback, std::move(callback))); } -void Raze(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Raze(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); mojom_db_transaction->should_raze = true; } -void Execute(mojom::DBTransactionInfo* const mojom_db_transaction, +void Execute(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& sql) { CHECK(mojom_db_transaction); @@ -66,7 +66,7 @@ void Execute(mojom::DBTransactionInfo* const mojom_db_transaction, mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } -void Execute(mojom::DBTransactionInfo* const mojom_db_transaction, +void Execute(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& sql, const std::vector& subst) { CHECK(mojom_db_transaction); @@ -77,7 +77,7 @@ void Execute(mojom::DBTransactionInfo* const mojom_db_transaction, mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } -void Vacuum(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Vacuum(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); mojom_db_transaction->should_vacuum = true; diff --git a/components/brave_ads/core/internal/common/database/database_transaction_util.h b/components/brave_ads/core/internal/common/database/database_transaction_util.h index 49e97cd868f8..8d34e50aabc5 100644 --- a/components/brave_ads/core/internal/common/database/database_transaction_util.h +++ b/components/brave_ads/core/internal/common/database/database_transaction_util.h @@ -16,10 +16,11 @@ namespace brave_ads::database { // Returns true if the transaction result is a success. bool IsSuccess( - const mojom::DBTransactionResultInfo* mojom_db_transaction_result); + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); // Returns true if the transaction result is an error. -bool IsError(const mojom::DBTransactionResultInfo* mojom_db_transaction_result); +bool IsError( + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); // Run a database transaction. void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, @@ -27,19 +28,19 @@ void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, // Raze the database. This must be done before any other actions are run. All // tables must be recreated after the raze operation is completed. -void Raze(mojom::DBTransactionInfo* mojom_db_transaction); +void Raze(const mojom::DBTransactionInfoPtr& mojom_db_transaction); // Execute a SQL statement. -void Execute(mojom::DBTransactionInfo* mojom_db_transaction, +void Execute(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& sql); // Execute a SQL statement with placeholders. -void Execute(mojom::DBTransactionInfo* mojom_db_transaction, +void Execute(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const std::string& sql, const std::vector& subst); // Vacuum the database. This must be done after any other actions are run. -void Vacuum(mojom::DBTransactionInfo* mojom_db_transaction); +void Vacuum(const mojom::DBTransactionInfoPtr& mojom_db_transaction); } // namespace brave_ads::database diff --git a/components/brave_ads/core/internal/creatives/campaigns_database_table.cc b/components/brave_ads/core/internal/creatives/campaigns_database_table.cc index 1f5885f71078..0d0708277089 100644 --- a/components/brave_ads/core/internal/creatives/campaigns_database_table.cc +++ b/components/brave_ads/core/internal/creatives/campaigns_database_table.cc @@ -23,7 +23,7 @@ namespace { constexpr char kTableName[] = "campaigns"; -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -52,12 +52,12 @@ void Campaigns::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } -void Campaigns::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void Campaigns::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -67,7 +67,7 @@ void Campaigns::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -75,7 +75,8 @@ std::string Campaigns::GetTableName() const { return kTableName; } -void Campaigns::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Campaigns::Create( + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -90,7 +91,7 @@ void Campaigns::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { );)"); } -void Campaigns::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, +void Campaigns::Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -105,7 +106,7 @@ void Campaigns::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// void Campaigns::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -115,7 +116,7 @@ void Campaigns::MigrateToV43( } std::string Campaigns::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/campaigns_database_table.h b/components/brave_ads/core/internal/creatives/campaigns_database_table.h index c752b1ddcb43..08981b3e59b0 100644 --- a/components/brave_ads/core/internal/creatives/campaigns_database_table.h +++ b/components/brave_ads/core/internal/creatives/campaigns_database_table.h @@ -17,21 +17,21 @@ namespace brave_ads::database::table { class Campaigns final : public TableInterface { public: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads); void Delete(ResultCallback callback) const; std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const; }; diff --git a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.cc b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.cc index 126025ed97b2..5dc373c250ce 100644 --- a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.cc +++ b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.cc @@ -30,7 +30,7 @@ namespace { constexpr char kTableName[] = "creative_set_conversions"; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -42,7 +42,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeSetConversionList& creative_set_conversions) { CHECK(mojom_db_action); CHECK(!creative_set_conversions.empty()); @@ -92,7 +92,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } CreativeSetConversionInfo FromMojomRow( - const mojom::DBRowInfo* const mojom_db_row) { + const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); CreativeSetConversionInfo creative_set_conversion; @@ -118,7 +118,7 @@ CreativeSetConversionInfo FromMojomRow( void GetCallback( GetCreativeSetConversionsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative set conversions"); return std::move(callback).Run(/*success=*/false, @@ -132,7 +132,7 @@ void GetCallback( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { const CreativeSetConversionInfo creative_set_conversion = - FromMojomRow(&*mojom_db_row); + FromMojomRow(mojom_db_row); if (!creative_set_conversion.IsValid()) { // TODO(https://github.com/brave/brave-browser/issues/32066): Detect // potential defects using `DumpWithoutCrashing`. @@ -162,7 +162,7 @@ void GetCallback( std::move(callback).Run(/*success=*/true, creative_set_conversions); } -void MigrateToV35(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV35(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Optimize database query for `GetUnexpired`. @@ -171,7 +171,7 @@ void MigrateToV35(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"expire_at"}); } -void MigrateToV43(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Optimize database query for `database::table::AdEvents`. @@ -192,7 +192,7 @@ void CreativeSetConversions::Save( mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Insert(&*mojom_db_transaction, creative_set_conversions); + Insert(mojom_db_transaction, creative_set_conversions); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -216,7 +216,7 @@ void CreativeSetConversions::GetUnexpired( WHERE $2 < expire_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -227,7 +227,7 @@ void CreativeSetConversions::GetUnexpired( void CreativeSetConversions::PurgeExpired(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -242,7 +242,7 @@ std::string CreativeSetConversions::GetTableName() const { } void CreativeSetConversions::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -264,7 +264,7 @@ void CreativeSetConversions::Create( } void CreativeSetConversions::Migrate( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -284,7 +284,7 @@ void CreativeSetConversions::Migrate( /////////////////////////////////////////////////////////////////////////////// void CreativeSetConversions::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeSetConversionList& creative_set_conversions) { CHECK(mojom_db_transaction); @@ -295,12 +295,12 @@ void CreativeSetConversions::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; mojom_db_action->sql = - BuildInsertSql(&*mojom_db_action, creative_set_conversions); + BuildInsertSql(mojom_db_action, creative_set_conversions); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string CreativeSetConversions::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeSetConversionList& creative_set_conversions) const { CHECK(mojom_db_action); CHECK(!creative_set_conversions.empty()); diff --git a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.h b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.h index 5f23bdc99632..4224ba10e65d 100644 --- a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.h +++ b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.h @@ -31,16 +31,16 @@ class CreativeSetConversions final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeSetConversionList& creative_set_conversions); std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeSetConversionList& creative_set_conversions) const; }; diff --git a/components/brave_ads/core/internal/creatives/creative_ads_database_table.cc b/components/brave_ads/core/internal/creatives/creative_ads_database_table.cc index 26c9cb90e0d8..77d77c886354 100644 --- a/components/brave_ads/core/internal/creatives/creative_ads_database_table.cc +++ b/components/brave_ads/core/internal/creatives/creative_ads_database_table.cc @@ -32,7 +32,7 @@ namespace { constexpr char kTableName[] = "creative_ads"; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -48,7 +48,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -74,7 +74,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, return row_count; } -CreativeAdInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { +CreativeAdInfo FromMojomRow(const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); CreativeAdInfo creative_ad; @@ -101,7 +101,7 @@ CreativeAdList GetCreativeAdsFromResponse( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const CreativeAdInfo creative_ad = FromMojomRow(&*mojom_db_row); + const CreativeAdInfo creative_ad = FromMojomRow(mojom_db_row); const std::string uuid = base::StrCat({creative_ad.creative_instance_id, creative_ad.segment}); @@ -136,7 +136,7 @@ void GetForCreativeInstanceIdCallback( const std::string& creative_instance_id, GetCreativeAdCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative ad"); return std::move(callback).Run(/*success=*/false, creative_instance_id, @@ -160,8 +160,9 @@ void GetForCreativeInstanceIdCallback( } // namespace -void CreativeAds::Insert(mojom::DBTransactionInfo* mojom_db_transaction, - const CreativeAdList& creative_ads) { +void CreativeAds::Insert( + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + const CreativeAdList& creative_ads) { CHECK(mojom_db_transaction); if (creative_ads.empty()) { @@ -170,7 +171,7 @@ void CreativeAds::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -178,7 +179,7 @@ void CreativeAds::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -214,7 +215,7 @@ void CreativeAds::GetForCreativeInstanceId( WHERE creative_instance_id = '$2';)", {GetTableName(), creative_instance_id}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -227,7 +228,8 @@ std::string CreativeAds::GetTableName() const { return kTableName; } -void CreativeAds::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void CreativeAds::Create( + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -244,8 +246,9 @@ void CreativeAds::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { );)"); } -void CreativeAds::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, - const int to_version) { +void CreativeAds::Migrate( + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + const int to_version) { CHECK(mojom_db_transaction); switch (to_version) { @@ -259,7 +262,7 @@ void CreativeAds::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// void CreativeAds::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -269,7 +272,7 @@ void CreativeAds::MigrateToV43( } std::string CreativeAds::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/creative_ads_database_table.h b/components/brave_ads/core/internal/creatives/creative_ads_database_table.h index 05b76c9995e4..c2c5eb3aa5b1 100644 --- a/components/brave_ads/core/internal/creatives/creative_ads_database_table.h +++ b/components/brave_ads/core/internal/creatives/creative_ads_database_table.h @@ -23,7 +23,7 @@ using GetCreativeAdCallback = class CreativeAds final : public TableInterface { public: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads); void Delete(ResultCallback callback) const; @@ -33,14 +33,14 @@ class CreativeAds final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const; }; diff --git a/components/brave_ads/core/internal/creatives/dayparts_database_table.cc b/components/brave_ads/core/internal/creatives/dayparts_database_table.cc index 7974080b4aa6..fc830ac75ef9 100644 --- a/components/brave_ads/core/internal/creatives/dayparts_database_table.cc +++ b/components/brave_ads/core/internal/creatives/dayparts_database_table.cc @@ -21,7 +21,7 @@ namespace { constexpr char kTableName[] = "dayparts"; -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -45,7 +45,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } // namespace -void Dayparts::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void Dayparts::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -55,7 +55,7 @@ void Dayparts::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -63,7 +63,7 @@ void Dayparts::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -72,7 +72,7 @@ std::string Dayparts::GetTableName() const { return kTableName; } -void Dayparts::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Dayparts::Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -90,7 +90,7 @@ void Dayparts::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { );)"); } -void Dayparts::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, +void Dayparts::Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -105,7 +105,7 @@ void Dayparts::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// void Dayparts::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -114,8 +114,9 @@ void Dayparts::MigrateToV43( Create(mojom_db_transaction); } -std::string Dayparts::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, - const CreativeAdList& creative_ads) const { +std::string Dayparts::BuildInsertSql( + const mojom::DBActionInfoPtr& mojom_db_action, + const CreativeAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/dayparts_database_table.h b/components/brave_ads/core/internal/creatives/dayparts_database_table.h index 81836f685faa..b9721d4aefd1 100644 --- a/components/brave_ads/core/internal/creatives/dayparts_database_table.h +++ b/components/brave_ads/core/internal/creatives/dayparts_database_table.h @@ -17,21 +17,21 @@ namespace brave_ads::database::table { class Dayparts final : public TableInterface { public: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads); void Delete(ResultCallback callback) const; std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const; }; diff --git a/components/brave_ads/core/internal/creatives/geo_targets_database_table.cc b/components/brave_ads/core/internal/creatives/geo_targets_database_table.cc index 82fc2223ea59..573093dfeb82 100644 --- a/components/brave_ads/core/internal/creatives/geo_targets_database_table.cc +++ b/components/brave_ads/core/internal/creatives/geo_targets_database_table.cc @@ -21,7 +21,7 @@ namespace { constexpr char kTableName[] = "geo_targets"; -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -43,7 +43,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } // namespace -void GeoTargets::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void GeoTargets::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -53,7 +53,7 @@ void GeoTargets::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -61,7 +61,7 @@ void GeoTargets::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -70,7 +70,8 @@ std::string GeoTargets::GetTableName() const { return kTableName; } -void GeoTargets::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void GeoTargets::Create( + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -84,8 +85,9 @@ void GeoTargets::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { );)"); } -void GeoTargets::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, - const int to_version) { +void GeoTargets::Migrate( + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + const int to_version) { CHECK(mojom_db_transaction); switch (to_version) { @@ -99,7 +101,7 @@ void GeoTargets::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// void GeoTargets::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -109,7 +111,7 @@ void GeoTargets::MigrateToV43( } std::string GeoTargets::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/geo_targets_database_table.h b/components/brave_ads/core/internal/creatives/geo_targets_database_table.h index 60e9f0fc943c..9a2adedba047 100644 --- a/components/brave_ads/core/internal/creatives/geo_targets_database_table.h +++ b/components/brave_ads/core/internal/creatives/geo_targets_database_table.h @@ -17,21 +17,21 @@ namespace brave_ads::database::table { class GeoTargets final : public TableInterface { public: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads); void Delete(ResultCallback callback) const; std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const; }; diff --git a/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc b/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc index 78951fa443b7..af101bdcd102 100644 --- a/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc +++ b/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc @@ -40,7 +40,7 @@ constexpr char kTableName[] = "creative_inline_content_ads"; constexpr int kDefaultBatchSize = 50; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -73,7 +73,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeInlineContentAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -99,7 +99,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } CreativeInlineContentAdInfo FromMojomRow( - const mojom::DBRowInfo* const mojom_db_row) { + const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); CreativeInlineContentAdInfo creative_ad; @@ -146,8 +146,7 @@ CreativeInlineContentAdList GetCreativeAdsFromResponse( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const CreativeInlineContentAdInfo creative_ad = - FromMojomRow(&*mojom_db_row); + const CreativeInlineContentAdInfo creative_ad = FromMojomRow(mojom_db_row); const std::string uuid = base::StrCat({creative_ad.creative_instance_id, creative_ad.segment}); @@ -182,7 +181,7 @@ void GetForCreativeInstanceIdCallback( const std::string& creative_instance_id, GetCreativeInlineContentAdCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative inline content ad"); return std::move(callback).Run(/*success=*/false, creative_instance_id, @@ -208,7 +207,7 @@ void GetForSegmentsAndDimensionsCallback( const SegmentList& segments, GetCreativeInlineContentAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative inline content ads"); return std::move(callback).Run(/*success=*/false, segments, @@ -224,7 +223,7 @@ void GetForSegmentsAndDimensionsCallback( void GetForDimensionsCallback( GetCreativeInlineContentAdsForDimensionsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative inline content ads"); return std::move(callback).Run(/*success=*/false, /*creative_ad=*/{}); @@ -239,7 +238,7 @@ void GetForDimensionsCallback( void GetAllCallback( GetCreativeInlineContentAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get all creative inline content ads"); return std::move(callback).Run(/*success=*/false, /*segments=*/{}, @@ -275,18 +274,17 @@ void CreativeInlineContentAds::Save( SplitVector(creative_ads, batch_size_); for (const auto& batch : batches) { - Insert(&*mojom_db_transaction, batch); + Insert(mojom_db_transaction, batch); const CreativeAdList creative_ads_batch(batch.cbegin(), batch.cend()); - campaigns_database_table_.Insert(&*mojom_db_transaction, - creative_ads_batch); - creative_ads_database_table_.Insert(&*mojom_db_transaction, + campaigns_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + creative_ads_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - dayparts_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - deposits_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - geo_targets_database_table_.Insert(&*mojom_db_transaction, + dayparts_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + deposits_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + geo_targets_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - segments_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); + segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); @@ -296,7 +294,7 @@ void CreativeInlineContentAds::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -352,7 +350,7 @@ void CreativeInlineContentAds::GetForCreativeInstanceId( WHERE creative_inline_content_ad.creative_instance_id = '$2';)", {GetTableName(), creative_instance_id}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -418,11 +416,11 @@ void CreativeInlineContentAds::GetForSegmentsAndDimensions( BuildBindColumnPlaceholder(/*column_count=*/segments.size()), dimensions, TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); int index = 0; for (const auto& segment : segments) { - BindColumnString(&*mojom_db_action, index++, segment); + BindColumnString(mojom_db_action, index++, segment); } mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); @@ -485,7 +483,7 @@ void CreativeInlineContentAds::GetForDimensions( AND $3 BETWEEN campaigns.start_at AND campaigns.end_at;)", {GetTableName(), dimensions, TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -538,7 +536,7 @@ void CreativeInlineContentAds::GetForActiveCampaigns( WHERE $2 BETWEEN campaigns.start_at AND campaigns.end_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -551,7 +549,7 @@ std::string CreativeInlineContentAds::GetTableName() const { } void CreativeInlineContentAds::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -568,7 +566,7 @@ void CreativeInlineContentAds::Create( } void CreativeInlineContentAds::Migrate( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -583,7 +581,7 @@ void CreativeInlineContentAds::Migrate( /////////////////////////////////////////////////////////////////////////////// void CreativeInlineContentAds::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -593,7 +591,7 @@ void CreativeInlineContentAds::MigrateToV43( } void CreativeInlineContentAds::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeInlineContentAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -603,12 +601,12 @@ void CreativeInlineContentAds::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string CreativeInlineContentAds::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeInlineContentAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h b/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h index 6dae15f04407..c103139f0c71 100644 --- a/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h +++ b/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h @@ -80,18 +80,18 @@ class CreativeInlineContentAds final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeInlineContentAdList& creative_ads); std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeInlineContentAdList& creative_ads) const; int batch_size_; diff --git a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc index 54032fc65467..49dec66fa4d0 100644 --- a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc +++ b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc @@ -23,7 +23,7 @@ namespace { constexpr char kTableName[] = "creative_new_tab_page_ad_wallpapers"; -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNewTabPageAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -49,7 +49,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } // namespace void CreativeNewTabPageAdWallpapers::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeNewTabPageAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -65,8 +65,7 @@ void CreativeNewTabPageAdWallpapers::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = - BuildInsertSql(&*mojom_db_action, filtered_creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, filtered_creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -74,7 +73,7 @@ void CreativeNewTabPageAdWallpapers::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -84,7 +83,7 @@ std::string CreativeNewTabPageAdWallpapers::GetTableName() const { } void CreativeNewTabPageAdWallpapers::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -103,7 +102,7 @@ void CreativeNewTabPageAdWallpapers::Create( } void CreativeNewTabPageAdWallpapers::Migrate( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -118,7 +117,7 @@ void CreativeNewTabPageAdWallpapers::Migrate( /////////////////////////////////////////////////////////////////////////////// void CreativeNewTabPageAdWallpapers::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -128,7 +127,7 @@ void CreativeNewTabPageAdWallpapers::MigrateToV43( } std::string CreativeNewTabPageAdWallpapers::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNewTabPageAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.h b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.h index a1cc9b3bea9f..dbb693e71d50 100644 --- a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.h +++ b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.h @@ -17,22 +17,22 @@ namespace brave_ads::database::table { class CreativeNewTabPageAdWallpapers final : public TableInterface { public: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeNewTabPageAdList& creative_ads); void Delete(ResultCallback callback) const; std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNewTabPageAdList& creative_ads) const; }; diff --git a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc index 4999e46ba09b..8d203490c296 100644 --- a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc +++ b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc @@ -39,7 +39,7 @@ constexpr char kTableName[] = "creative_new_tab_page_ads"; constexpr int kDefaultBatchSize = 50; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -76,7 +76,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNewTabPageAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -99,8 +99,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, return row_count; } -CreativeNewTabPageAdInfo FromMojomRow( - const mojom::DBRowInfo* const mojom_db_row) { +CreativeNewTabPageAdInfo FromMojomRow(const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); CreativeNewTabPageAdInfo creative_ad; @@ -151,7 +150,7 @@ CreativeNewTabPageAdList GetCreativeAdsFromResponse( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const CreativeNewTabPageAdInfo creative_ad = FromMojomRow(&*mojom_db_row); + const CreativeNewTabPageAdInfo creative_ad = FromMojomRow(mojom_db_row); const std::string uuid = base::StrCat({creative_ad.creative_instance_id, creative_ad.segment}); @@ -192,7 +191,7 @@ void GetForCreativeInstanceIdCallback( const std::string& creative_instance_id, GetCreativeNewTabPageAdCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative new tab page ad"); return std::move(callback).Run(/*success=*/false, creative_instance_id, @@ -218,7 +217,7 @@ void GetForSegmentsCallback( const SegmentList& segments, GetCreativeNewTabPageAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative new tab page ads"); return std::move(callback).Run(/*success=*/false, segments, @@ -234,7 +233,7 @@ void GetForSegmentsCallback( void GetAllCallback( GetCreativeNewTabPageAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get all creative new tab page ads"); return std::move(callback).Run(/*success=*/false, /*segments=*/{}, @@ -269,20 +268,19 @@ void CreativeNewTabPageAds::Save(const CreativeNewTabPageAdList& creative_ads, SplitVector(creative_ads, batch_size_); for (const auto& batch : batches) { - Insert(&*mojom_db_transaction, batch); + Insert(mojom_db_transaction, batch); const CreativeAdList creative_ads_batch(batch.cbegin(), batch.cend()); - campaigns_database_table_.Insert(&*mojom_db_transaction, - creative_ads_batch); - creative_ads_database_table_.Insert(&*mojom_db_transaction, + campaigns_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + creative_ads_database_table_.Insert(mojom_db_transaction, creative_ads_batch); creative_new_tab_page_ad_wallpapers_database_table_.Insert( - &*mojom_db_transaction, batch); - dayparts_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - deposits_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - geo_targets_database_table_.Insert(&*mojom_db_transaction, + mojom_db_transaction, batch); + dayparts_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + deposits_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + geo_targets_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - segments_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); + segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); @@ -292,7 +290,7 @@ void CreativeNewTabPageAds::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -350,7 +348,7 @@ void CreativeNewTabPageAds::GetForCreativeInstanceId( WHERE creative_new_tab_page_ad.creative_instance_id = '$2';)", {GetTableName(), creative_instance_id}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -416,11 +414,11 @@ void CreativeNewTabPageAds::GetForSegments( BuildBindColumnPlaceholder(/*column_count=*/segments.size()), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); int index = 0; for (const auto& segment : segments) { - BindColumnString(&*mojom_db_action, index++, segment); + BindColumnString(mojom_db_action, index++, segment); } mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); @@ -477,7 +475,7 @@ void CreativeNewTabPageAds::GetForActiveCampaigns( WHERE $2 BETWEEN campaigns.start_at AND campaigns.end_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -490,7 +488,7 @@ std::string CreativeNewTabPageAds::GetTableName() const { } void CreativeNewTabPageAds::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -505,7 +503,7 @@ void CreativeNewTabPageAds::Create( } void CreativeNewTabPageAds::Migrate( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -520,7 +518,7 @@ void CreativeNewTabPageAds::Migrate( /////////////////////////////////////////////////////////////////////////////// void CreativeNewTabPageAds::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -530,7 +528,7 @@ void CreativeNewTabPageAds::MigrateToV43( } void CreativeNewTabPageAds::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeNewTabPageAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -540,12 +538,12 @@ void CreativeNewTabPageAds::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string CreativeNewTabPageAds::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNewTabPageAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h index 0c66affbd2b3..55283689a4b3 100644 --- a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h +++ b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h @@ -69,18 +69,18 @@ class CreativeNewTabPageAds final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeNewTabPageAdList& creative_ads); std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNewTabPageAdList& creative_ads) const; int batch_size_; diff --git a/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.cc b/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.cc index 914b3350bd8e..3f1a41dc3203 100644 --- a/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.cc +++ b/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.cc @@ -39,7 +39,7 @@ constexpr char kTableName[] = "creative_ad_notifications"; constexpr int kDefaultBatchSize = 50; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -69,7 +69,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNotificationAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -92,7 +92,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } CreativeNotificationAdInfo FromMojomRow( - const mojom::DBRowInfo* const mojom_db_row) { + const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); CreativeNotificationAdInfo creative_ad; @@ -136,7 +136,7 @@ CreativeNotificationAdList GetCreativeAdsFromResponse( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const CreativeNotificationAdInfo creative_ad = FromMojomRow(&*mojom_db_row); + const CreativeNotificationAdInfo creative_ad = FromMojomRow(mojom_db_row); const std::string uuid = base::StrCat({creative_ad.creative_instance_id, creative_ad.segment}); @@ -171,7 +171,7 @@ void GetForSegmentsCallback( const SegmentList& segments, GetCreativeNotificationAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative notification ads"); return std::move(callback).Run(/*success=*/false, segments, @@ -187,7 +187,7 @@ void GetForSegmentsCallback( void GetAllCallback( GetCreativeNotificationAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get all creative notification ads"); return std::move(callback).Run(/*success=*/false, /*segments=*/{}, @@ -223,18 +223,17 @@ void CreativeNotificationAds::Save( SplitVector(creative_ads, batch_size_); for (const auto& batch : batches) { - Insert(&*mojom_db_transaction, batch); + Insert(mojom_db_transaction, batch); const CreativeAdList creative_ads_batch(batch.cbegin(), batch.cend()); - campaigns_database_table_.Insert(&*mojom_db_transaction, - creative_ads_batch); - creative_ads_database_table_.Insert(&*mojom_db_transaction, + campaigns_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + creative_ads_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - dayparts_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - deposits_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - geo_targets_database_table_.Insert(&*mojom_db_transaction, + dayparts_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + deposits_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + geo_targets_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - segments_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); + segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); @@ -244,7 +243,7 @@ void CreativeNotificationAds::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -301,11 +300,11 @@ void CreativeNotificationAds::GetForSegments( BuildBindColumnPlaceholder(/*column_count=*/segments.size()), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); int index = 0; for (const auto& segment : segments) { - BindColumnString(&*mojom_db_action, index, segment); + BindColumnString(mojom_db_action, index, segment); ++index; } @@ -358,7 +357,7 @@ void CreativeNotificationAds::GetForActiveCampaigns( WHERE $2 BETWEEN campaigns.start_at AND campaigns.end_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -371,7 +370,7 @@ std::string CreativeNotificationAds::GetTableName() const { } void CreativeNotificationAds::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -385,7 +384,7 @@ void CreativeNotificationAds::Create( } void CreativeNotificationAds::Migrate( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -406,7 +405,7 @@ void CreativeNotificationAds::Migrate( // static void CreativeNotificationAds::MigrateToV37( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); DropTable(mojom_db_transaction, "embeddings"); @@ -414,7 +413,7 @@ void CreativeNotificationAds::MigrateToV37( } void CreativeNotificationAds::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -424,7 +423,7 @@ void CreativeNotificationAds::MigrateToV43( } void CreativeNotificationAds::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeNotificationAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -434,12 +433,12 @@ void CreativeNotificationAds::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string CreativeNotificationAds::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNotificationAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.h b/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.h index 72918057a774..d41e752bb181 100644 --- a/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.h +++ b/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.h @@ -60,19 +60,20 @@ class CreativeNotificationAds final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - static void MigrateToV37(mojom::DBTransactionInfo* mojom_db_transaction); - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + static void MigrateToV37( + const mojom::DBTransactionInfoPtr& mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeNotificationAdList& creative_ads); std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativeNotificationAdList& creative_ads) const; int batch_size_; diff --git a/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc b/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc index 5cfa47a32a27..c919327d3898 100644 --- a/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc +++ b/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc @@ -39,7 +39,7 @@ constexpr char kTableName[] = "creative_promoted_content_ads"; constexpr int kDefaultBatchSize = 50; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -69,7 +69,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativePromotedContentAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -92,7 +92,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } CreativePromotedContentAdInfo FromMojomRow( - const mojom::DBRowInfo* const mojom_db_row) { + const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); CreativePromotedContentAdInfo creative_ad; @@ -137,7 +137,7 @@ CreativePromotedContentAdList GetCreativeAdsFromResponse( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { const CreativePromotedContentAdInfo creative_ad = - FromMojomRow(&*mojom_db_row); + FromMojomRow(mojom_db_row); const std::string uuid = base::StrCat({creative_ad.creative_instance_id, creative_ad.segment}); @@ -172,7 +172,7 @@ void GetForCreativeInstanceIdCallback( const std::string& creative_instance_id, GetCreativePromotedContentAdCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative promoted content ad"); return std::move(callback).Run(/*success=*/false, creative_instance_id, @@ -198,7 +198,7 @@ void GetForSegmentsCallback( const SegmentList& segments, GetCreativePromotedContentAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get creative promoted content ads"); return std::move(callback).Run(/*success=*/false, segments, @@ -214,7 +214,7 @@ void GetForSegmentsCallback( void GetAllCallback( GetCreativePromotedContentAdsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get all creative new tab page ads"); return std::move(callback).Run(/*success=*/false, /*segments=*/{}, @@ -250,18 +250,17 @@ void CreativePromotedContentAds::Save( SplitVector(creative_ads, batch_size_); for (const auto& batch : batches) { - Insert(&*mojom_db_transaction, batch); + Insert(mojom_db_transaction, batch); const CreativeAdList creative_ads_batch(batch.cbegin(), batch.cend()); - campaigns_database_table_.Insert(&*mojom_db_transaction, - creative_ads_batch); - creative_ads_database_table_.Insert(&*mojom_db_transaction, + campaigns_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + creative_ads_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - dayparts_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - deposits_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); - geo_targets_database_table_.Insert(&*mojom_db_transaction, + dayparts_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + deposits_database_table_.Insert(mojom_db_transaction, creative_ads_batch); + geo_targets_database_table_.Insert(mojom_db_transaction, creative_ads_batch); - segments_database_table_.Insert(&*mojom_db_transaction, creative_ads_batch); + segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); @@ -271,7 +270,7 @@ void CreativePromotedContentAds::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -324,7 +323,7 @@ void CreativePromotedContentAds::GetForCreativeInstanceId( WHERE creative_promoted_content_ad.creative_instance_id = '$2';)", {GetTableName(), creative_instance_id}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -385,11 +384,11 @@ void CreativePromotedContentAds::GetForSegments( BuildBindColumnPlaceholder(/*column_count=*/segments.size()), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); int index = 0; for (const auto& segment : segments) { - BindColumnString(&*mojom_db_action, index, segment); + BindColumnString(mojom_db_action, index, segment); ++index; } @@ -442,7 +441,7 @@ void CreativePromotedContentAds::GetForActiveCampaigns( WHERE $2 BETWEEN campaigns.start_at AND campaigns.end_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -455,7 +454,7 @@ std::string CreativePromotedContentAds::GetTableName() const { } void CreativePromotedContentAds::Create( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -469,7 +468,7 @@ void CreativePromotedContentAds::Create( } void CreativePromotedContentAds::Migrate( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -484,7 +483,7 @@ void CreativePromotedContentAds::Migrate( /////////////////////////////////////////////////////////////////////////////// void CreativePromotedContentAds::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -494,7 +493,7 @@ void CreativePromotedContentAds::MigrateToV43( } void CreativePromotedContentAds::Insert( - mojom::DBTransactionInfo* mojom_db_transaction, + const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativePromotedContentAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -504,12 +503,12 @@ void CreativePromotedContentAds::Insert( mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } std::string CreativePromotedContentAds::BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativePromotedContentAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.h b/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.h index 87c398c468cf..808cfb6b7b21 100644 --- a/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.h +++ b/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.h @@ -72,18 +72,18 @@ class CreativePromotedContentAds final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativePromotedContentAdList& creative_ads); std::string BuildInsertSql( - mojom::DBActionInfo* mojom_db_action, + const mojom::DBActionInfoPtr& mojom_db_action, const CreativePromotedContentAdList& creative_ads) const; int batch_size_; diff --git a/components/brave_ads/core/internal/creatives/segments_database_table.cc b/components/brave_ads/core/internal/creatives/segments_database_table.cc index 7211da8cc7e9..cbf22c1549b4 100644 --- a/components/brave_ads/core/internal/creatives/segments_database_table.cc +++ b/components/brave_ads/core/internal/creatives/segments_database_table.cc @@ -21,7 +21,7 @@ namespace { constexpr char kTableName[] = "segments"; -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); @@ -41,7 +41,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, } // namespace -void Segments::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void Segments::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads) { CHECK(mojom_db_transaction); @@ -51,7 +51,7 @@ void Segments::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, creative_ads); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, creative_ads); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } @@ -59,7 +59,7 @@ void Segments::Delete(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - DeleteTable(&*mojom_db_transaction, GetTableName()); + DeleteTable(mojom_db_transaction, GetTableName()); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -68,7 +68,7 @@ std::string Segments::GetTableName() const { return kTableName; } -void Segments::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Segments::Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -82,7 +82,7 @@ void Segments::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { );)"); } -void Segments::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, +void Segments::Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -97,7 +97,7 @@ void Segments::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// void Segments::MigrateToV43( - mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // We can safely recreate the table because it will be repopulated after @@ -106,8 +106,9 @@ void Segments::MigrateToV43( Create(mojom_db_transaction); } -std::string Segments::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, - const CreativeAdList& creative_ads) const { +std::string Segments::BuildInsertSql( + const mojom::DBActionInfoPtr& mojom_db_action, + const CreativeAdList& creative_ads) const { CHECK(mojom_db_action); CHECK(!creative_ads.empty()); diff --git a/components/brave_ads/core/internal/creatives/segments_database_table.h b/components/brave_ads/core/internal/creatives/segments_database_table.h index c6700271a24e..8f342d944996 100644 --- a/components/brave_ads/core/internal/creatives/segments_database_table.h +++ b/components/brave_ads/core/internal/creatives/segments_database_table.h @@ -17,21 +17,21 @@ namespace brave_ads::database::table { class Segments final : public TableInterface { public: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const CreativeAdList& creative_ads); void Delete(ResultCallback callback) const; std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void MigrateToV43(mojom::DBTransactionInfo* mojom_db_transaction); + void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const CreativeAdList& creative_ads) const; }; diff --git a/components/brave_ads/core/internal/database/database.cc b/components/brave_ads/core/internal/database/database.cc index a432c2ffcff9..6a4caa2b1a3f 100644 --- a/components/brave_ads/core/internal/database/database.cc +++ b/components/brave_ads/core/internal/database/database.cc @@ -55,8 +55,8 @@ mojom::DBTransactionResultInfoPtr Database::RunDBTransaction( // Maybe raze the database. This must be done before any other database // actions are run. All tables must be recreated after the raze action has // completed. - mojom_db_transaction_result->status_code = MaybeRaze(&*mojom_db_transaction); - if (database::IsError(&*mojom_db_transaction_result)) { + mojom_db_transaction_result->status_code = MaybeRaze(mojom_db_transaction); + if (database::IsError(mojom_db_transaction_result)) { VLOG(0) << "Failed to raze database"; return mojom_db_transaction_result; } @@ -64,8 +64,8 @@ mojom::DBTransactionResultInfoPtr Database::RunDBTransaction( // Run any actions within the transaction, such as creating or opening the // database, executing a statement, or migrating the database. mojom_db_transaction_result->status_code = - RunDBActions(mojom_db_transaction, &*mojom_db_transaction_result); - if (database::IsError(&*mojom_db_transaction_result)) { + RunDBActions(mojom_db_transaction, mojom_db_transaction_result); + if (database::IsError(mojom_db_transaction_result)) { VLOG(0) << "Failed run database actions"; return mojom_db_transaction_result; } @@ -73,9 +73,8 @@ mojom::DBTransactionResultInfoPtr Database::RunDBTransaction( // Maybe vacuum the database. This must be done after any other actions are // run. The database is configured to auto-vacuum with some limitations, but // it is good practice to run this action manually. - mojom_db_transaction_result->status_code = - MaybeVacuum(&*mojom_db_transaction); - if (database::IsError(&*mojom_db_transaction_result)) { + mojom_db_transaction_result->status_code = MaybeVacuum(mojom_db_transaction); + if (database::IsError(mojom_db_transaction_result)) { VLOG(0) << "Failed to vacuum database"; return mojom_db_transaction_result; } @@ -87,7 +86,7 @@ mojom::DBTransactionResultInfoPtr Database::RunDBTransaction( mojom::DBTransactionResultInfo::StatusCode Database::RunDBActions( const mojom::DBTransactionInfoPtr& mojom_db_transaction, - mojom::DBTransactionResultInfo* const mojom_db_transaction_result) { + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result) { CHECK(mojom_db_transaction); CHECK(mojom_db_transaction_result); @@ -109,18 +108,18 @@ mojom::DBTransactionResultInfo::StatusCode Database::RunDBActions( } case mojom::DBActionInfo::Type::kExecute: { - result_code = Execute(&*mojom_db_action); + result_code = Execute(mojom_db_action); break; } case mojom::DBActionInfo::Type::kRunStatement: { - result_code = RunStatement(&*mojom_db_action); + result_code = RunStatement(mojom_db_action); break; } case mojom::DBActionInfo::Type::kStepStatement: { result_code = - StepStatement(&*mojom_db_action, mojom_db_transaction_result); + StepStatement(mojom_db_action, mojom_db_transaction_result); break; } @@ -146,7 +145,7 @@ mojom::DBTransactionResultInfo::StatusCode Database::RunDBActions( } mojom::DBTransactionResultInfo::StatusCode Database::MaybeRaze( - const mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); if (mojom_db_transaction->should_raze && !db_.Raze()) { @@ -187,7 +186,7 @@ bool Database::ShouldCreateTables() { } mojom::DBTransactionResultInfo::StatusCode Database::Initialize( - mojom::DBTransactionResultInfo* const mojom_db_transaction_result) { + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result) { CHECK(mojom_db_transaction_result); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); @@ -220,7 +219,7 @@ mojom::DBTransactionResultInfo::StatusCode Database::Initialize( } mojom::DBTransactionResultInfo::StatusCode Database::Execute( - const mojom::DBActionInfo* const mojom_db_action) { + const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); CHECK(mojom_db_action->sql); @@ -238,7 +237,7 @@ mojom::DBTransactionResultInfo::StatusCode Database::Execute( } mojom::DBTransactionResultInfo::StatusCode Database::RunStatement( - const mojom::DBActionInfo* const mojom_db_action) { + const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); CHECK(mojom_db_action->sql); @@ -267,8 +266,8 @@ mojom::DBTransactionResultInfo::StatusCode Database::RunStatement( } mojom::DBTransactionResultInfo::StatusCode Database::StepStatement( - const mojom::DBActionInfo* const mojom_db_action, - mojom::DBTransactionResultInfo* const mojom_db_transaction_result) { + const mojom::DBActionInfoPtr& mojom_db_action, + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result) { CHECK(mojom_db_action); CHECK(mojom_db_action->sql); CHECK(mojom_db_transaction_result); @@ -319,7 +318,7 @@ mojom::DBTransactionResultInfo::StatusCode Database::Migrate() { } mojom::DBTransactionResultInfo::StatusCode Database::MaybeVacuum( - const mojom::DBTransactionInfo* const mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); if (mojom_db_transaction->should_vacuum && !db_.Execute("VACUUM;")) { diff --git a/components/brave_ads/core/internal/database/database_manager.cc b/components/brave_ads/core/internal/database/database_manager.cc index 609f5597f318..5436dc1140e5 100644 --- a/components/brave_ads/core/internal/database/database_manager.cc +++ b/components/brave_ads/core/internal/database/database_manager.cc @@ -64,7 +64,7 @@ void DatabaseManager::CreateOrOpen(ResultCallback callback) { void DatabaseManager::CreateOrOpenCallback( ResultCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (database::IsError(&*mojom_db_transaction_result)) { + if (database::IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to create or open database"); NotifyFailedToCreateOrOpenDatabase(); diff --git a/components/brave_ads/core/internal/database/database_table_interface.cc b/components/brave_ads/core/internal/database/database_table_interface.cc index 18850c5c7afa..51e9446292fa 100644 --- a/components/brave_ads/core/internal/database/database_table_interface.cc +++ b/components/brave_ads/core/internal/database/database_table_interface.cc @@ -7,11 +7,13 @@ #include "base/check.h" #include "brave/components/brave_ads/core/internal/legacy_migration/database/database_constants.h" +#include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" namespace brave_ads::database { -void TableInterface::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, - const int to_version) { +void TableInterface::Migrate( + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + const int to_version) { CHECK(mojom_db_transaction); if (to_version == kVersionNumber) { diff --git a/components/brave_ads/core/internal/database/database_table_interface.h b/components/brave_ads/core/internal/database/database_table_interface.h index 54d9dd9905c2..d02698e86d0f 100644 --- a/components/brave_ads/core/internal/database/database_table_interface.h +++ b/components/brave_ads/core/internal/database/database_table_interface.h @@ -18,8 +18,9 @@ class TableInterface { virtual std::string GetTableName() const = 0; - virtual void Create(mojom::DBTransactionInfo* mojom_db_transaction) = 0; - virtual void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + virtual void Create( + const mojom::DBTransactionInfoPtr& mojom_db_transaction) = 0; + virtual void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version); }; diff --git a/components/brave_ads/core/internal/history/ad_history_database_table.cc b/components/brave_ads/core/internal/history/ad_history_database_table.cc index abc684c38646..adb0bca88235 100644 --- a/components/brave_ads/core/internal/history/ad_history_database_table.cc +++ b/components/brave_ads/core/internal/history/ad_history_database_table.cc @@ -34,7 +34,7 @@ constexpr char kTableName[] = "ad_history"; constexpr int kDefaultBatchSize = 50; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -53,7 +53,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const AdHistoryList& ad_history) { CHECK(mojom_db_action); CHECK(!ad_history.empty()); @@ -106,7 +106,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, return row_count; } -AdHistoryItemInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { +AdHistoryItemInfo FromMojomRow(const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); AdHistoryItemInfo ad_history_item; @@ -131,7 +131,7 @@ AdHistoryItemInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { void GetCallback( GetAdHistoryCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get ad history"); return std::move(callback).Run(/*ad_history=*/std::nullopt); @@ -143,7 +143,7 @@ void GetCallback( for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const AdHistoryItemInfo ad_history_item = FromMojomRow(&*mojom_db_row); + const AdHistoryItemInfo ad_history_item = FromMojomRow(mojom_db_row); if (!ad_history_item.IsValid()) { // TODO(https://github.com/brave/brave-browser/issues/32066): Detect // potential defects using `DumpWithoutCrashing`. @@ -172,7 +172,7 @@ void GetCallback( std::move(callback).Run(ad_history); } -void MigrateToV42(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV42(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -225,7 +225,7 @@ void AdHistory::Save(const AdHistoryList& ad_history, SplitVector(ad_history, batch_size_); for (const auto& batch : batches) { - Insert(&*mojom_db_transaction, batch); + Insert(mojom_db_transaction, batch); } RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); @@ -262,7 +262,7 @@ void AdHistory::GetForDateRange(const base::Time from_time, {GetTableName(), TimeToSqlValueAsString(from_time), TimeToSqlValueAsString(to_time)}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -366,7 +366,7 @@ void AdHistory::GetHighestRankedPlacementsForDateRange( {GetTableName(), TimeToSqlValueAsString(from_time), TimeToSqlValueAsString(to_time)}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -401,7 +401,7 @@ void AdHistory::GetForCreativeInstanceId( WHERE creative_instance_id = '$2';)", {GetTableName(), creative_instance_id}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -412,7 +412,7 @@ void AdHistory::GetForCreativeInstanceId( void AdHistory::PurgeExpired(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -428,7 +428,8 @@ std::string AdHistory::GetTableName() const { return kTableName; } -void AdHistory::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void AdHistory::Create( + const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -466,7 +467,7 @@ void AdHistory::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"creative_instance_id"}); } -void AdHistory::Migrate(mojom::DBTransactionInfo* const mojom_db_transaction, +void AdHistory::Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -480,7 +481,7 @@ void AdHistory::Migrate(mojom::DBTransactionInfo* const mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// -void AdHistory::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void AdHistory::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const AdHistoryList& ad_history) const { CHECK(mojom_db_transaction); @@ -490,12 +491,13 @@ void AdHistory::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, ad_history); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, ad_history); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } -std::string AdHistory::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, - const AdHistoryList& ad_history) const { +std::string AdHistory::BuildInsertSql( + const mojom::DBActionInfoPtr& mojom_db_action, + const AdHistoryList& ad_history) const { CHECK(mojom_db_action); CHECK(!ad_history.empty()); diff --git a/components/brave_ads/core/internal/history/ad_history_database_table.h b/components/brave_ads/core/internal/history/ad_history_database_table.h index 4ccfebc40e44..eab13408293c 100644 --- a/components/brave_ads/core/internal/history/ad_history_database_table.h +++ b/components/brave_ads/core/internal/history/ad_history_database_table.h @@ -43,15 +43,15 @@ class AdHistory final : public TableInterface { std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const AdHistoryList& ad_history) const; - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const AdHistoryList& ad_history) const; int batch_size_; diff --git a/components/brave_ads/core/internal/legacy_migration/database/database_creation.cc b/components/brave_ads/core/internal/legacy_migration/database/database_creation.cc index dfc4c4085d6d..7e766ec11afb 100644 --- a/components/brave_ads/core/internal/legacy_migration/database/database_creation.cc +++ b/components/brave_ads/core/internal/legacy_migration/database/database_creation.cc @@ -31,7 +31,7 @@ namespace brave_ads::database { namespace { -void Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, "PRAGMA auto_vacuum = FULL;"); @@ -93,7 +93,7 @@ void Create(mojom::DBTransactionInfo* const mojom_db_transaction) { void Create(ResultCallback callback) { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Create(&*mojom_db_transaction); + Create(mojom_db_transaction); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } diff --git a/components/brave_ads/core/internal/legacy_migration/database/database_migration.cc b/components/brave_ads/core/internal/legacy_migration/database/database_migration.cc index e3ea6048d9d2..4874eac5e23a 100644 --- a/components/brave_ads/core/internal/legacy_migration/database/database_migration.cc +++ b/components/brave_ads/core/internal/legacy_migration/database/database_migration.cc @@ -32,7 +32,7 @@ namespace brave_ads::database { namespace { -void MigrateToV44(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV44(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Normally, whether or not the database supports `auto_vacuum` must be @@ -45,7 +45,7 @@ void MigrateToV44(mojom::DBTransactionInfo* const mojom_db_transaction) { Vacuum(mojom_db_transaction); } -void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, +void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -57,7 +57,7 @@ void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, } } -void MigrateToVersion(mojom::DBTransactionInfo* mojom_db_transaction, +void MigrateToVersion(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -129,7 +129,7 @@ void MigrateFromVersion(const int from_version, ResultCallback callback) { mojom::DBTransactionInfo::New(); for (int i = from_version + 1; i <= kVersionNumber; ++i) { - MigrateToVersion(&*mojom_db_transaction, i); + MigrateToVersion(mojom_db_transaction, i); } mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); diff --git a/components/brave_ads/core/internal/legacy_migration/database/database_raze.cc b/components/brave_ads/core/internal/legacy_migration/database/database_raze.cc index 9cd0bf3c63ec..1e9c76d8b250 100644 --- a/components/brave_ads/core/internal/legacy_migration/database/database_raze.cc +++ b/components/brave_ads/core/internal/legacy_migration/database/database_raze.cc @@ -15,7 +15,7 @@ namespace brave_ads::database { void Raze(ResultCallback callback) { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - database::Raze(&*mojom_db_transaction); + database::Raze(mojom_db_transaction); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.cc b/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.cc index 9b208f4a9439..50cdc877b6fc 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.cc @@ -30,7 +30,7 @@ namespace { constexpr char kTableName[] = "ad_events"; -void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { +void BindColumnTypes(const mojom::DBActionInfoPtr& mojom_db_action) { CHECK(mojom_db_action); mojom_db_action->bind_column_types = { @@ -46,7 +46,7 @@ void BindColumnTypes(mojom::DBActionInfo* const mojom_db_action) { }; } -size_t BindColumns(mojom::DBActionInfo* mojom_db_action, +size_t BindColumns(const mojom::DBActionInfoPtr& mojom_db_action, const AdEventList& ad_events) { CHECK(mojom_db_action); CHECK(!ad_events.empty()); @@ -79,7 +79,7 @@ size_t BindColumns(mojom::DBActionInfo* mojom_db_action, return row_count; } -AdEventInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { +AdEventInfo FromMojomRow(const mojom::DBRowInfoPtr& mojom_db_row) { CHECK(mojom_db_row); AdEventInfo ad_event; @@ -104,7 +104,7 @@ AdEventInfo FromMojomRow(const mojom::DBRowInfo* const mojom_db_row) { void GetCallback( GetAdEventsCallback callback, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { - if (IsError(&*mojom_db_transaction_result)) { + if (IsError(mojom_db_transaction_result)) { BLOG(0, "Failed to get ad events"); return std::move(callback).Run(/*success=*/false, /*ad_events=*/{}); @@ -115,7 +115,7 @@ void GetCallback( AdEventList ad_events; for (const auto& mojom_db_row : mojom_db_transaction_result->rows_union->get_rows()) { - const AdEventInfo ad_event = FromMojomRow(&*mojom_db_row); + const AdEventInfo ad_event = FromMojomRow(mojom_db_row); if (!ad_event.IsValid()) { BLOG(0, "Invalid ad event"); @@ -128,7 +128,7 @@ void GetCallback( std::move(callback).Run(/*success=*/true, ad_events); } -void MigrateToV35(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV35(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); DropTableIndex(mojom_db_transaction, "ad_events_created_at_index"); @@ -140,7 +140,7 @@ void MigrateToV35(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"type", "created_at"}); } -void MigrateToV41(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV41(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); // Remove non-clicked search result ad events for users who have not joined @@ -155,7 +155,7 @@ void MigrateToV41(mojom::DBTransactionInfo* const mojom_db_transaction) { } } -void MigrateToV43(mojom::DBTransactionInfo* const mojom_db_transaction) { +void MigrateToV43(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); DropTableIndex(mojom_db_transaction, "ad_events_type_creative_set_id_index"); @@ -177,7 +177,7 @@ void AdEvents::RecordEvent(const AdEventInfo& ad_event, mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Insert(&*mojom_db_transaction, {ad_event}); + Insert(mojom_db_transaction, {ad_event}); RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); } @@ -202,7 +202,7 @@ void AdEvents::GetAll(GetAdEventsCallback callback) const { FROM $1;)", {GetTableName()}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -242,7 +242,7 @@ void AdEvents::GetUnexpired(GetAdEventsCallback callback) const { {GetTableName(), TimeToSqlValueAsString(base::Time::Now() - base::Days(90))}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -286,7 +286,7 @@ void AdEvents::GetUnexpired(const mojom::AdType mojom_ad_type, {GetTableName(), ToString(mojom_ad_type), TimeToSqlValueAsString(base::Time::Now() - base::Days(90))}, nullptr); - BindColumnTypes(&*mojom_db_action); + BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); GetAdsClient()->RunDBTransaction( @@ -299,7 +299,7 @@ void AdEvents::PurgeExpired(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -320,7 +320,7 @@ void AdEvents::PurgeOrphaned(const mojom::AdType mojom_ad_type, ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -356,7 +356,7 @@ void AdEvents::PurgeOrphaned(const std::vector& placement_ids, mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -381,7 +381,7 @@ void AdEvents::PurgeOrphaned(const std::vector& placement_ids, void AdEvents::PurgeAllOrphaned(ResultCallback callback) const { mojom::DBTransactionInfoPtr mojom_db_transaction = mojom::DBTransactionInfo::New(); - Execute(&*mojom_db_transaction, R"( + Execute(mojom_db_transaction, R"( DELETE FROM $1 WHERE @@ -405,7 +405,7 @@ std::string AdEvents::GetTableName() const { return kTableName; } -void AdEvents::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { +void AdEvents::Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { CHECK(mojom_db_transaction); Execute(mojom_db_transaction, R"( @@ -445,7 +445,7 @@ void AdEvents::Create(mojom::DBTransactionInfo* const mojom_db_transaction) { /*columns=*/{"placement_id"}); } -void AdEvents::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, +void AdEvents::Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const int to_version) { CHECK(mojom_db_transaction); @@ -469,7 +469,7 @@ void AdEvents::Migrate(mojom::DBTransactionInfo* mojom_db_transaction, /////////////////////////////////////////////////////////////////////////////// -void AdEvents::Insert(mojom::DBTransactionInfo* mojom_db_transaction, +void AdEvents::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const AdEventList& ad_events) { CHECK(mojom_db_transaction); @@ -479,12 +479,13 @@ void AdEvents::Insert(mojom::DBTransactionInfo* mojom_db_transaction, mojom::DBActionInfoPtr mojom_db_action = mojom::DBActionInfo::New(); mojom_db_action->type = mojom::DBActionInfo::Type::kRunStatement; - mojom_db_action->sql = BuildInsertSql(&*mojom_db_action, ad_events); + mojom_db_action->sql = BuildInsertSql(mojom_db_action, ad_events); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); } -std::string AdEvents::BuildInsertSql(mojom::DBActionInfo* mojom_db_action, - const AdEventList& ad_events) const { +std::string AdEvents::BuildInsertSql( + const mojom::DBActionInfoPtr& mojom_db_action, + const AdEventList& ad_events) const { CHECK(mojom_db_action); CHECK(!ad_events.empty()); diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.h b/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.h index 9e22ca3c0b15..c3853c889f51 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.h +++ b/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.h @@ -39,15 +39,15 @@ class AdEvents final : public TableInterface { void PurgeAllOrphaned(ResultCallback callback) const; std::string GetTableName() const override; - void Create(mojom::DBTransactionInfo* mojom_db_transaction) override; - void Migrate(mojom::DBTransactionInfo* mojom_db_transaction, + void Create(const mojom::DBTransactionInfoPtr& mojom_db_transaction) override; + void Migrate(const mojom::DBTransactionInfoPtr& mojom_db_transaction, int to_version) override; private: - void Insert(mojom::DBTransactionInfo* mojom_db_transaction, + void Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, const AdEventList& ad_event); - std::string BuildInsertSql(mojom::DBActionInfo* mojom_db_action, + std::string BuildInsertSql(const mojom::DBActionInfoPtr& mojom_db_action, const AdEventList& ad_events) const; }; diff --git a/components/brave_ads/core/public/database/database.h b/components/brave_ads/core/public/database/database.h index c33f15ea1158..a2fcbcbf8aa6 100644 --- a/components/brave_ads/core/public/database/database.h +++ b/components/brave_ads/core/public/database/database.h @@ -37,31 +37,31 @@ class ADS_EXPORT Database final { private: mojom::DBTransactionResultInfo::StatusCode RunDBActions( const mojom::DBTransactionInfoPtr& mojom_db_transaction, - mojom::DBTransactionResultInfo* mojom_db_transaction_result); + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); mojom::DBTransactionResultInfo::StatusCode MaybeRaze( - const mojom::DBTransactionInfo* mojom_db_transaction); + const mojom::DBTransactionInfoPtr& mojom_db_transaction); bool InitializeMetaTable(); bool ShouldCreateTables(); mojom::DBTransactionResultInfo::StatusCode Initialize( - mojom::DBTransactionResultInfo* mojom_db_transaction_result); + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); mojom::DBTransactionResultInfo::StatusCode Execute( - const mojom::DBActionInfo* mojom_db_action); + const mojom::DBActionInfoPtr& mojom_db_action); mojom::DBTransactionResultInfo::StatusCode RunStatement( - const mojom::DBActionInfo* mojom_db_action); + const mojom::DBActionInfoPtr& mojom_db_action); mojom::DBTransactionResultInfo::StatusCode StepStatement( - const mojom::DBActionInfo* mojom_db_action, - mojom::DBTransactionResultInfo* mojom_db_transaction_result); + const mojom::DBActionInfoPtr& mojom_db_action, + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); mojom::DBTransactionResultInfo::StatusCode Migrate(); mojom::DBTransactionResultInfo::StatusCode MaybeVacuum( - const mojom::DBTransactionInfo* mojom_db_transaction); + const mojom::DBTransactionInfoPtr& mojom_db_transaction); void ErrorCallback(int error, sql::Statement* statement);