From b403b7168eb6bacbe1224ce438974e12380ef57a Mon Sep 17 00:00:00 2001 From: Szilard Szaloki Date: Sun, 20 Aug 2023 04:34:52 -0500 Subject: [PATCH] Removes `std::function<>` from the utility process (Part5). --- .../core/credentials/credentials_common.cc | 4 +- .../core/credentials/credentials_promotion.cc | 5 +- .../brave_rewards/core/database/database.cc | 13 ++--- .../brave_rewards/core/database/database.h | 9 ++-- .../core/database/database_balance_report.cc | 31 ++++++------ .../core/database/database_balance_report.h | 6 +-- .../database_balance_report_info_unittest.cc | 8 ++-- .../core/database/database_initialize.cc | 20 ++++---- .../core/database/database_initialize.h | 6 +-- .../core/database/database_migration.cc | 47 ++++++++++--------- .../core/database/database_migration.h | 7 ++- .../brave_rewards/core/promotion/promotion.cc | 7 ++- .../brave_rewards/core/report/report.cc | 15 +++--- components/brave_rewards/core/report/report.h | 8 ++-- .../brave_rewards/core/rewards_callbacks.h | 3 -- .../brave_rewards/core/rewards_engine_impl.cc | 40 ++++++++-------- .../brave_rewards/core/rewards_engine_impl.h | 9 ++-- .../core/rewards_engine_impl_mock.cc | 8 +++- .../core/rewards_engine_impl_mock.h | 2 +- 19 files changed, 127 insertions(+), 121 deletions(-) diff --git a/components/brave_rewards/core/credentials/credentials_common.cc b/components/brave_rewards/core/credentials/credentials_common.cc index 765f31834449..3e082dbf1ae3 100644 --- a/components/brave_rewards/core/credentials/credentials_common.cc +++ b/components/brave_rewards/core/credentials/credentials_common.cc @@ -9,6 +9,7 @@ #include "base/json/json_writer.h" #include "base/strings/string_number_conversions.h" #include "base/uuid.h" +#include "brave/components/brave_rewards/core/common/legacy_callback_helpers.h" #include "brave/components/brave_rewards/core/credentials/credentials_common.h" #include "brave/components/brave_rewards/core/credentials/credentials_util.h" #include "brave/components/brave_rewards/core/database/database.h" @@ -115,8 +116,7 @@ void CredentialsCommon::OnSaveUnblindedCreds(ResultCallback callback, engine_->database()->UpdateCredsBatchStatus( trigger.id, trigger.type, mojom::CredsBatchStatus::FINISHED, - [callback = std::make_shared(std::move(callback))]( - mojom::Result result) { std::move(*callback).Run(result); }); + ToLegacyCallback(std::move(callback))); } } // namespace credential diff --git a/components/brave_rewards/core/credentials/credentials_promotion.cc b/components/brave_rewards/core/credentials/credentials_promotion.cc index 7ab8b682fdad..8a1c4c1b4f25 100644 --- a/components/brave_rewards/core/credentials/credentials_promotion.cc +++ b/components/brave_rewards/core/credentials/credentials_promotion.cc @@ -10,6 +10,7 @@ #include "base/json/json_writer.h" #include "base/strings/string_number_conversions.h" +#include "brave/components/brave_rewards/core/common/legacy_callback_helpers.h" #include "brave/components/brave_rewards/core/credentials/credentials_promotion.h" #include "brave/components/brave_rewards/core/credentials/credentials_util.h" #include "brave/components/brave_rewards/core/database/database.h" @@ -416,9 +417,7 @@ void CredentialsPromotion::Completed(ResultCallback callback, } engine_->database()->PromotionCredentialCompleted( - trigger.id, - [callback = std::make_shared(std::move(callback))]( - mojom::Result result) { std::move(*callback).Run(result); }); + trigger.id, ToLegacyCallback(std::move(callback))); engine_->client()->UnblindedTokensReady(); } diff --git a/components/brave_rewards/core/database/database.cc b/components/brave_rewards/core/database/database.cc index 301621628376..3cf3f93e2442 100644 --- a/components/brave_rewards/core/database/database.cc +++ b/components/brave_rewards/core/database/database.cc @@ -38,8 +38,8 @@ Database::Database(RewardsEngineImpl& engine) Database::~Database() = default; -void Database::Initialize(LegacyResultCallback callback) { - initialize_.Start(callback); +void Database::Initialize(ResultCallback callback) { + initialize_.Start(std::move(callback)); } void Database::Close(LegacyResultCallback callback) { @@ -106,10 +106,11 @@ void Database::SaveBalanceReportInfoItem(mojom::ActivityMonth month, balance_report_.SetAmount(month, year, type, amount, callback); } -void Database::GetBalanceReportInfo(mojom::ActivityMonth month, - int year, - GetBalanceReportCallback callback) { - balance_report_.GetRecord(month, year, callback); +void Database::GetBalanceReportInfo( + mojom::ActivityMonth month, + int year, + mojom::RewardsEngine::GetBalanceReportCallback callback) { + balance_report_.GetRecord(month, year, std::move(callback)); } void Database::GetAllBalanceReports(GetBalanceReportListCallback callback) { diff --git a/components/brave_rewards/core/database/database.h b/components/brave_rewards/core/database/database.h index 9ca72b94d52d..82f384e3ac74 100644 --- a/components/brave_rewards/core/database/database.h +++ b/components/brave_rewards/core/database/database.h @@ -45,7 +45,7 @@ class Database { explicit Database(RewardsEngineImpl& engine); virtual ~Database(); - void Initialize(LegacyResultCallback callback); + void Initialize(ResultCallback callback); void Close(LegacyResultCallback callback); @@ -83,9 +83,10 @@ class Database { double amount, LegacyResultCallback callback); - void GetBalanceReportInfo(mojom::ActivityMonth month, - int year, - GetBalanceReportCallback callback); + void GetBalanceReportInfo( + mojom::ActivityMonth month, + int year, + mojom::RewardsEngine::GetBalanceReportCallback callback); void GetAllBalanceReports(GetBalanceReportListCallback callback); diff --git a/components/brave_rewards/core/database/database_balance_report.cc b/components/brave_rewards/core/database/database_balance_report.cc index 06e6f0ef3c6f..55561fffb86e 100644 --- a/components/brave_rewards/core/database/database_balance_report.cc +++ b/components/brave_rewards/core/database/database_balance_report.cc @@ -169,13 +169,13 @@ void DatabaseBalanceReport::SetAmount(mojom::ActivityMonth month, engine_->RunDBTransaction(std::move(transaction), transaction_callback); } -void DatabaseBalanceReport::GetRecord(mojom::ActivityMonth month, - int year, - GetBalanceReportCallback callback) { +void DatabaseBalanceReport::GetRecord( + mojom::ActivityMonth month, + int year, + mojom::RewardsEngine::GetBalanceReportCallback callback) { if (month == mojom::ActivityMonth::ANY || year == 0) { BLOG(1, "Record size is not correct " << month << "/" << year); - callback(mojom::Result::FAILED, {}); - return; + return std::move(callback).Run(mojom::Result::FAILED, {}); } auto transaction = mojom::DBTransaction::New(); @@ -215,25 +215,24 @@ void DatabaseBalanceReport::GetRecord(mojom::ActivityMonth month, transaction->commands.push_back(std::move(command)); - auto transaction_callback = - std::bind(&DatabaseBalanceReport::OnGetRecord, this, _1, callback); - - engine_->RunDBTransaction(std::move(transaction), transaction_callback); + engine_->RunDBTransaction( + std::move(transaction), + base::BindOnce(&DatabaseBalanceReport::OnGetRecord, + base::Unretained(this), std::move(callback))); } -void DatabaseBalanceReport::OnGetRecord(mojom::DBCommandResponsePtr response, - GetBalanceReportCallback callback) { +void DatabaseBalanceReport::OnGetRecord( + mojom::RewardsEngine::GetBalanceReportCallback callback, + mojom::DBCommandResponsePtr response) { if (!response || response->status != mojom::DBCommandResponse::Status::RESPONSE_OK) { BLOG(0, "Response is wrong"); - callback(mojom::Result::FAILED, {}); - return; + return std::move(callback).Run(mojom::Result::FAILED, {}); } if (response->result->get_records().size() != 1) { BLOG(1, "Record size is not correct: " << response->result->get_records().size()); - callback(mojom::Result::FAILED, {}); - return; + return std::move(callback).Run(mojom::Result::FAILED, {}); } auto* record = response->result->get_records()[0].get(); @@ -246,7 +245,7 @@ void DatabaseBalanceReport::OnGetRecord(mojom::DBCommandResponsePtr response, info->recurring_donation = GetDoubleColumn(record, 4); info->one_time_donation = GetDoubleColumn(record, 5); - callback(mojom::Result::OK, std::move(info)); + std::move(callback).Run(mojom::Result::OK, std::move(info)); } void DatabaseBalanceReport::GetAllRecords( diff --git a/components/brave_rewards/core/database/database_balance_report.h b/components/brave_rewards/core/database/database_balance_report.h index 5fb69e4526c8..3c86581163a3 100644 --- a/components/brave_rewards/core/database/database_balance_report.h +++ b/components/brave_rewards/core/database/database_balance_report.h @@ -33,15 +33,15 @@ class DatabaseBalanceReport : public DatabaseTable { void GetRecord(mojom::ActivityMonth month, int year, - GetBalanceReportCallback callback); + mojom::RewardsEngine::GetBalanceReportCallback callback); void GetAllRecords(GetBalanceReportListCallback callback); void DeleteAllRecords(LegacyResultCallback callback); private: - void OnGetRecord(mojom::DBCommandResponsePtr response, - GetBalanceReportCallback callback); + void OnGetRecord(mojom::RewardsEngine::GetBalanceReportCallback callback, + mojom::DBCommandResponsePtr response); void OnGetAllRecords(mojom::DBCommandResponsePtr response, GetBalanceReportListCallback callback); diff --git a/components/brave_rewards/core/database/database_balance_report_info_unittest.cc b/components/brave_rewards/core/database/database_balance_report_info_unittest.cc index d16abefb790c..195df9adba61 100644 --- a/components/brave_rewards/core/database/database_balance_report_info_unittest.cc +++ b/components/brave_rewards/core/database/database_balance_report_info_unittest.cc @@ -7,6 +7,7 @@ #include #include +#include "base/test/mock_callback.h" #include "base/test/task_environment.h" #include "brave/components/brave_rewards/core/database/database_balance_report.h" #include "brave/components/brave_rewards/core/database/database_util.h" @@ -102,10 +103,9 @@ TEST_F(DatabaseBalanceReportTest, GetRecordOk) { std::move(callback).Run(db_error_response->Clone()); }); - MockFunction callback; - EXPECT_CALL(callback, Call).Times(1); - balance_report_.GetRecord(mojom::ActivityMonth::MAY, 2020, - callback.AsStdFunction()); + base::MockCallback callback; + EXPECT_CALL(callback, Run).Times(1); + balance_report_.GetRecord(mojom::ActivityMonth::MAY, 2020, callback.Get()); task_environment_.RunUntilIdle(); } diff --git a/components/brave_rewards/core/database/database_initialize.cc b/components/brave_rewards/core/database/database_initialize.cc index 329b7793e6f1..c69916581e1c 100644 --- a/components/brave_rewards/core/database/database_initialize.cc +++ b/components/brave_rewards/core/database/database_initialize.cc @@ -10,9 +10,6 @@ #include "brave/components/brave_rewards/core/rewards_engine_impl.h" #include "brave/components/brave_rewards/core/state/state_keys.h" -using std::placeholders::_1; -using std::placeholders::_2; - namespace brave_rewards::internal { namespace database { @@ -21,7 +18,7 @@ DatabaseInitialize::DatabaseInitialize(RewardsEngineImpl& engine) DatabaseInitialize::~DatabaseInitialize() = default; -void DatabaseInitialize::Start(LegacyResultCallback callback) { +void DatabaseInitialize::Start(ResultCallback callback) { auto transaction = mojom::DBTransaction::New(); transaction->version = GetCurrentVersion(); transaction->compatible_version = GetCompatibleVersion(); @@ -31,27 +28,26 @@ void DatabaseInitialize::Start(LegacyResultCallback callback) { engine_->RunDBTransaction( std::move(transaction), - std::bind(&DatabaseInitialize::OnInitialize, this, _1, callback)); + base::BindOnce(&DatabaseInitialize::OnInitialize, base::Unretained(this), + std::move(callback))); } -void DatabaseInitialize::OnInitialize(mojom::DBCommandResponsePtr response, - LegacyResultCallback callback) { +void DatabaseInitialize::OnInitialize(ResultCallback callback, + mojom::DBCommandResponsePtr response) { if (!response || response->status != mojom::DBCommandResponse::Status::RESPONSE_OK) { BLOG(0, "Response is wrong"); - callback(mojom::Result::DATABASE_INIT_FAILED); - return; + return std::move(callback).Run(mojom::Result::DATABASE_INIT_FAILED); } if (!response->result || !response->result->get_value()->is_int_value()) { BLOG(0, "DB init failed"); - callback(mojom::Result::DATABASE_INIT_FAILED); - return; + return std::move(callback).Run(mojom::Result::DATABASE_INIT_FAILED); } const auto current_table_version = response->result->get_value()->get_int_value(); - migration_.Start(current_table_version, callback); + migration_.Start(current_table_version, std::move(callback)); } } // namespace database diff --git a/components/brave_rewards/core/database/database_initialize.h b/components/brave_rewards/core/database/database_initialize.h index d180b2f6f5b6..1edda659e64e 100644 --- a/components/brave_rewards/core/database/database_initialize.h +++ b/components/brave_rewards/core/database/database_initialize.h @@ -20,11 +20,11 @@ class DatabaseInitialize { explicit DatabaseInitialize(RewardsEngineImpl& engine); ~DatabaseInitialize(); - void Start(LegacyResultCallback callback); + void Start(ResultCallback callback); private: - void OnInitialize(mojom::DBCommandResponsePtr response, - LegacyResultCallback callback); + void OnInitialize(ResultCallback callback, + mojom::DBCommandResponsePtr response); const raw_ref engine_; DatabaseMigration migration_; diff --git a/components/brave_rewards/core/database/database_migration.cc b/components/brave_rewards/core/database/database_migration.cc index e9506c4c2e22..9bc6c60a92bb 100644 --- a/components/brave_rewards/core/database/database_migration.cc +++ b/components/brave_rewards/core/database/database_migration.cc @@ -71,8 +71,7 @@ DatabaseMigration::DatabaseMigration(RewardsEngineImpl& engine) DatabaseMigration::~DatabaseMigration() = default; -void DatabaseMigration::Start(uint32_t table_version, - LegacyResultCallback callback) { +void DatabaseMigration::Start(uint32_t table_version, ResultCallback callback) { const uint32_t start_version = table_version + 1; DCHECK_GT(start_version, 0u); @@ -83,8 +82,7 @@ void DatabaseMigration::Start(uint32_t table_version, : database::GetCurrentVersion(); if (target_version == table_version) { - callback(mojom::Result::OK); - return; + return std::move(callback).Run(mojom::Result::OK); } // Migration 30 archives and clears the user's unblinded tokens table. It @@ -164,24 +162,11 @@ void DatabaseMigration::Start(uint32_t table_version, command->type = mojom::DBCommand::Type::VACUUM; transaction->commands.push_back(std::move(command)); - const std::string message = - base::StringPrintf("%d->%d", start_version, migrated_version); - engine_->RunDBTransaction( - std::move(transaction), [this, callback, message, migrated_version]( - mojom::DBCommandResponsePtr response) { - if (response && - response->status == mojom::DBCommandResponse::Status::RESPONSE_OK) { - // The event_log table was introduced in v29. - if (migrated_version >= 29) { - engine_->database()->SaveEventLog(log::kDatabaseMigrated, message); - } - callback(mojom::Result::OK); - return; - } - - callback(mojom::Result::FAILED); - }); + std::move(transaction), + base::BindOnce(&DatabaseMigration::RunDBTransactionCallback, + base::Unretained(this), std::move(callback), start_version, + migrated_version)); } void DatabaseMigration::SetTargetVersionForTesting(uint32_t version) { @@ -202,5 +187,25 @@ void DatabaseMigration::GenerateCommand(mojom::DBTransaction* transaction, transaction->commands.push_back(std::move(command)); } +void DatabaseMigration::RunDBTransactionCallback( + ResultCallback callback, + uint32_t start_version, + int migrated_version, + mojom::DBCommandResponsePtr response) { + if (response && + response->status == mojom::DBCommandResponse::Status::RESPONSE_OK) { + // The event_log table was introduced in v29. + if (migrated_version >= 29) { + engine_->database()->SaveEventLog( + log::kDatabaseMigrated, + base::StringPrintf("%d->%d", start_version, migrated_version)); + } + + return std::move(callback).Run(mojom::Result::OK); + } + + std::move(callback).Run(mojom::Result::FAILED); +} + } // namespace database } // namespace brave_rewards::internal diff --git a/components/brave_rewards/core/database/database_migration.h b/components/brave_rewards/core/database/database_migration.h index 7dd409d66412..94f4bb305d23 100644 --- a/components/brave_rewards/core/database/database_migration.h +++ b/components/brave_rewards/core/database/database_migration.h @@ -22,7 +22,7 @@ class DatabaseMigration { explicit DatabaseMigration(RewardsEngineImpl& engine); ~DatabaseMigration(); - void Start(uint32_t table_version, LegacyResultCallback callback); + void Start(uint32_t table_version, ResultCallback callback); static void SetTargetVersionForTesting(uint32_t version); @@ -30,6 +30,11 @@ class DatabaseMigration { void GenerateCommand(mojom::DBTransaction* transaction, const std::string& query); + void RunDBTransactionCallback(ResultCallback callback, + uint32_t start_version, + int migrated_version, + mojom::DBCommandResponsePtr response); + const raw_ref engine_; static uint32_t test_target_version_; }; diff --git a/components/brave_rewards/core/promotion/promotion.cc b/components/brave_rewards/core/promotion/promotion.cc index 95c4dd4dad38..61e6517204b4 100644 --- a/components/brave_rewards/core/promotion/promotion.cc +++ b/components/brave_rewards/core/promotion/promotion.cc @@ -13,6 +13,7 @@ #include "base/json/json_writer.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" +#include "brave/components/brave_rewards/core/common/legacy_callback_helpers.h" #include "brave/components/brave_rewards/core/common/time_util.h" #include "brave/components/brave_rewards/core/constants.h" #include "brave/components/brave_rewards/core/credentials/credentials_util.h" @@ -462,8 +463,7 @@ void Promotion::CredentialsProcessed(ResultCallback callback, if (result == mojom::Result::NOT_FOUND) { engine_->database()->UpdatePromotionStatus( promotion_id, mojom::PromotionStatus::OVER, - [callback = std::make_shared(std::move(callback))]( - mojom::Result result) { std::move(*callback).Run(result); }); + ToLegacyCallback(std::move(callback))); return; } @@ -475,8 +475,7 @@ void Promotion::CredentialsProcessed(ResultCallback callback, engine_->database()->UpdatePromotionStatus( promotion_id, mojom::PromotionStatus::FINISHED, - [callback = std::make_shared(std::move(callback))]( - mojom::Result result) { std::move(*callback).Run(result); }); + ToLegacyCallback(std::move(callback))); } void Promotion::Retry( diff --git a/components/brave_rewards/core/report/report.cc b/components/brave_rewards/core/report/report.cc index bf05770240ff..7c270c8d3762 100644 --- a/components/brave_rewards/core/report/report.cc +++ b/components/brave_rewards/core/report/report.cc @@ -14,7 +14,6 @@ #include "brave/components/brave_rewards/core/rewards_engine_impl.h" using std::placeholders::_1; -using std::placeholders::_2; namespace brave_rewards::internal { namespace report { @@ -27,16 +26,18 @@ void Report::GetMonthly(const mojom::ActivityMonth month, const int year, GetMonthlyReportCallback callback) { auto balance_callback = - std::bind(&Report::OnBalance, this, _1, _2, month, year, callback); + base::BindOnce(&Report::OnBalance, base::Unretained(this), month, year, + std::move(callback)); - engine_->database()->GetBalanceReportInfo(month, year, balance_callback); + engine_->database()->GetBalanceReportInfo(month, year, + std::move(balance_callback)); } -void Report::OnBalance(const mojom::Result result, - mojom::BalanceReportInfoPtr balance_report, - const mojom::ActivityMonth month, +void Report::OnBalance(const mojom::ActivityMonth month, const uint32_t year, - GetMonthlyReportCallback callback) { + GetMonthlyReportCallback callback, + const mojom::Result result, + mojom::BalanceReportInfoPtr balance_report) { if (result != mojom::Result::OK || !balance_report) { BLOG(0, "Could not get balance report"); callback(result, nullptr); diff --git a/components/brave_rewards/core/report/report.h b/components/brave_rewards/core/report/report.h index 283939ef3de3..65bd44087248 100644 --- a/components/brave_rewards/core/report/report.h +++ b/components/brave_rewards/core/report/report.h @@ -30,11 +30,11 @@ class Report { void GetAllMonthlyIds(GetAllMonthlyReportIdsCallback callback); private: - void OnBalance(const mojom::Result result, - mojom::BalanceReportInfoPtr balance_report, - const mojom::ActivityMonth month, + void OnBalance(const mojom::ActivityMonth month, const uint32_t year, - GetMonthlyReportCallback callback); + GetMonthlyReportCallback callback, + const mojom::Result result, + mojom::BalanceReportInfoPtr balance_report); void OnTransactions( std::vector transaction_report, diff --git a/components/brave_rewards/core/rewards_callbacks.h b/components/brave_rewards/core/rewards_callbacks.h index cfa44de4bef1..44a9fee2a893 100644 --- a/components/brave_rewards/core/rewards_callbacks.h +++ b/components/brave_rewards/core/rewards_callbacks.h @@ -74,9 +74,6 @@ using GetAllMonthlyReportIdsCallback = using GetAllPromotionsCallback = std::function)>; -using GetBalanceReportCallback = - std::function; - using GetBalanceReportListCallback = std::function)>; // TODO(sszaloki): unused? diff --git a/components/brave_rewards/core/rewards_engine_impl.cc b/components/brave_rewards/core/rewards_engine_impl.cc index 068b3614eff5..6f8c52e23ee1 100644 --- a/components/brave_rewards/core/rewards_engine_impl.cc +++ b/components/brave_rewards/core/rewards_engine_impl.cc @@ -54,7 +54,7 @@ void RewardsEngineImpl::Initialize(InitializeCallback callback) { } ready_state_ = ReadyState::kInitializing; - InitializeDatabase(ToLegacyCallback(std::move(callback))); + InitializeDatabase(std::move(callback)); } void RewardsEngineImpl::GetEnvironment(GetEnvironmentCallback callback) { @@ -321,8 +321,7 @@ void RewardsEngineImpl::SetAutoContributeEnabled(bool enabled) { void RewardsEngineImpl::GetBalanceReport(mojom::ActivityMonth month, int32_t year, GetBalanceReportCallback callback) { - WhenReady([this, month, year, - callback = ToLegacyCallback(std::move(callback))]() mutable { + WhenReady([this, month, year, callback = std::move(callback)]() mutable { database()->GetBalanceReportInfo(month, year, std::move(callback)); }); } @@ -776,25 +775,27 @@ bool RewardsEngineImpl::IsReady() const { return ready_state_ == ReadyState::kReady; } -void RewardsEngineImpl::InitializeDatabase(LegacyResultCallback callback) { +void RewardsEngineImpl::InitializeDatabase(ResultCallback callback) { DCHECK(ready_state_ == ReadyState::kInitializing); - LegacyResultCallback finish_callback = std::bind( - &RewardsEngineImpl::OnInitialized, this, _1, std::move(callback)); + auto finish_callback = + base::BindOnce(&RewardsEngineImpl::OnInitialized, base::Unretained(this), + std::move(callback)); + + auto database_callback = + base::BindOnce(&RewardsEngineImpl::OnDatabaseInitialized, + base::Unretained(this), std::move(finish_callback)); - auto database_callback = std::bind(&RewardsEngineImpl::OnDatabaseInitialized, - this, _1, finish_callback); - database()->Initialize(database_callback); + database()->Initialize(std::move(database_callback)); } -void RewardsEngineImpl::OnDatabaseInitialized(mojom::Result result, - LegacyResultCallback callback) { +void RewardsEngineImpl::OnDatabaseInitialized(ResultCallback callback, + mojom::Result result) { DCHECK(ready_state_ == ReadyState::kInitializing); if (result != mojom::Result::OK) { BLOG(0, "Database could not be initialized. Error: " << result); - callback(result); - return; + return std::move(callback).Run(result); } state()->Initialize(base::BindOnce(&RewardsEngineImpl::OnStateInitialized, @@ -802,21 +803,20 @@ void RewardsEngineImpl::OnDatabaseInitialized(mojom::Result result, std::move(callback))); } -void RewardsEngineImpl::OnStateInitialized(LegacyResultCallback callback, +void RewardsEngineImpl::OnStateInitialized(ResultCallback callback, mojom::Result result) { DCHECK(ready_state_ == ReadyState::kInitializing); if (result != mojom::Result::OK) { BLOG(0, "Failed to initialize state"); - callback(result); - return; + return std::move(callback).Run(result); } - callback(mojom::Result::OK); + std::move(callback).Run(mojom::Result::OK); } -void RewardsEngineImpl::OnInitialized(mojom::Result result, - LegacyResultCallback callback) { +void RewardsEngineImpl::OnInitialized(ResultCallback callback, + mojom::Result result) { DCHECK(ready_state_ == ReadyState::kInitializing); if (result == mojom::Result::OK) { @@ -828,7 +828,7 @@ void RewardsEngineImpl::OnInitialized(mojom::Result result, ready_state_ = ReadyState::kReady; ready_event_.Signal(); - callback(result); + std::move(callback).Run(result); } void RewardsEngineImpl::StartServices() { diff --git a/components/brave_rewards/core/rewards_engine_impl.h b/components/brave_rewards/core/rewards_engine_impl.h index 3f5cb6d476e2..d6ecd1667e68 100644 --- a/components/brave_rewards/core/rewards_engine_impl.h +++ b/components/brave_rewards/core/rewards_engine_impl.h @@ -402,14 +402,13 @@ class RewardsEngineImpl : public mojom::RewardsEngine { bool IsUninitialized() const; - virtual void InitializeDatabase(LegacyResultCallback callback); + virtual void InitializeDatabase(ResultCallback callback); - void OnDatabaseInitialized(mojom::Result result, - LegacyResultCallback callback); + void OnDatabaseInitialized(ResultCallback callback, mojom::Result result); - void OnStateInitialized(LegacyResultCallback callback, mojom::Result result); + void OnStateInitialized(ResultCallback callback, mojom::Result result); - void OnInitialized(mojom::Result result, LegacyResultCallback callback); + void OnInitialized(ResultCallback callback, mojom::Result result); void StartServices(); diff --git a/components/brave_rewards/core/rewards_engine_impl_mock.cc b/components/brave_rewards/core/rewards_engine_impl_mock.cc index 5be201d67ff5..4cf860bec20d 100644 --- a/components/brave_rewards/core/rewards_engine_impl_mock.cc +++ b/components/brave_rewards/core/rewards_engine_impl_mock.cc @@ -4,6 +4,9 @@ * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "brave/components/brave_rewards/core/rewards_engine_impl_mock.h" + +#include + #include "brave/components/brave_rewards/common/mojom/rewards_engine.mojom-test-utils.h" using ::testing::_; @@ -19,8 +22,9 @@ MockRewardsEngineImpl::MockRewardsEngineImpl() : RewardsEngineImpl( mock_client_receiver_.BindNewEndpointAndPassDedicatedRemote()) { ON_CALL(*this, InitializeDatabase(_)) - .WillByDefault( - [](LegacyResultCallback callback) { callback(mojom::Result::OK); }); + .WillByDefault([](ResultCallback callback) { + std::move(callback).Run(mojom::Result::OK); + }); ON_CALL(*this, database()).WillByDefault(Return(&mock_database_)); const auto result = mojom::RewardsEngineAsyncWaiter(this).Initialize(); diff --git a/components/brave_rewards/core/rewards_engine_impl_mock.h b/components/brave_rewards/core/rewards_engine_impl_mock.h index be92d132bd22..50df2b568c33 100644 --- a/components/brave_rewards/core/rewards_engine_impl_mock.h +++ b/components/brave_rewards/core/rewards_engine_impl_mock.h @@ -36,7 +36,7 @@ class MockRewardsEngineImpl : private AddMockRewardsClient, database::MockDatabase* mock_database(); - MOCK_METHOD1(InitializeDatabase, void(LegacyResultCallback)); + MOCK_METHOD1(InitializeDatabase, void(ResultCallback)); MOCK_METHOD0(database, database::Database*());