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 1bb8ac3bc014..087078381da1 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 @@ -12,6 +12,7 @@ #include "base/functional/bind.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" +#include "base/location.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_feature.h" @@ -303,7 +304,8 @@ void ConfirmationQueue::Save( Insert(mojom_db_transaction, batch); } - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void ConfirmationQueue::DeleteAll(ResultCallback callback) const { @@ -312,7 +314,8 @@ void ConfirmationQueue::DeleteAll(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void ConfirmationQueue::Delete(const std::string& transaction_id, @@ -327,7 +330,8 @@ void ConfirmationQueue::Delete(const std::string& transaction_id, )", {GetTableName(), transaction_id}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void ConfirmationQueue::Retry(const std::string& transaction_id, @@ -360,7 +364,8 @@ void ConfirmationQueue::Retry(const std::string& transaction_id, {GetTableName(), TimeToSqlValueAsString(base::Time::Now()), retry_after, max_retry_delay, retry_after, max_retry_delay, transaction_id}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void ConfirmationQueue::GetAll(GetConfirmationQueueCallback callback) const { @@ -393,7 +398,7 @@ void ConfirmationQueue::GetAll(GetConfirmationQueueCallback callback) const { BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -429,7 +434,7 @@ void ConfirmationQueue::GetNext(GetConfirmationQueueCallback callback) const { BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } 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 bdfe48b7bdc6..066419d02273 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 @@ -10,6 +10,7 @@ #include "base/check.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_statement_util.h" @@ -133,7 +134,8 @@ void Deposits::Save(const DepositInfo& deposit, ResultCallback callback) { Insert(mojom_db_transaction, deposit); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void Deposits::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, @@ -186,7 +188,7 @@ void Deposits::GetForCreativeInstanceId(const std::string& creative_instance_id, BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForCreativeInstanceIdCallback, creative_instance_id, std::move(callback))); } @@ -201,7 +203,8 @@ void Deposits::PurgeExpired(ResultCallback callback) const { $2 >= expire_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string Deposits::GetTableName() 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 4d19f33b8db9..26471e3705f4 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 @@ -12,6 +12,7 @@ #include "base/check.h" #include "base/debug/dump_without_crashing.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "base/time/time.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" @@ -208,7 +209,8 @@ void Transactions::Save(const TransactionList& transactions, Insert(mojom_db_transaction, transactions); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void Transactions::GetForDateRange(base::Time from_time, @@ -239,7 +241,7 @@ void Transactions::GetForDateRange(base::Time from_time, BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -280,7 +282,8 @@ void Transactions::Reconcile(const PaymentTokenList& payment_tokens, mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void Transactions::PurgeExpired(ResultCallback callback) const { @@ -295,7 +298,8 @@ void Transactions::PurgeExpired(ResultCallback callback) const { {GetTableName(), TimeToSqlValueAsString(base::Time::Now() - base::Days(90))}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string Transactions::GetTableName() const { 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 22edbc38e5b3..bf19fe9f631a 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 @@ -5,22 +5,58 @@ #include "brave/components/brave_ads/core/internal/common/database/database_transaction_util.h" +#include #include #include "base/functional/bind.h" #include "base/strings/string_util.h" +#include "base/trace_event/trace_event.h" +#include "base/trace_event/trace_id_helper.h" #include "brave/components/brave_ads/core/internal/database/database_manager.h" #include "brave/components/brave_ads/core/internal/global_state/global_state.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client_callback.h" +#include "brave/components/brave_ads/core/public/ads_constants.h" namespace brave_ads::database { namespace { void RunDBTransactionCallback( + ::brave_ads::RunDBTransactionCallback callback, + uint64_t trace_id, + mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { + if (mojom_db_transaction_result) { + TRACE_EVENT_NESTABLE_ASYNC_END2( + kTraceEventCategory, "RunDBTransaction", + TRACE_ID_WITH_SCOPE("Database", trace_id), "statusCode", + mojom_db_transaction_result->status_code, "rowCount", + mojom_db_transaction_result->rows_union->get_rows().size()); + } else { + TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceEventCategory, "RunDBTransaction", + TRACE_ID_WITH_SCOPE("Database", trace_id), + "mojom_db_transaction_result", "nullptr"); + } + + std::move(callback).Run(std::move(mojom_db_transaction_result)); +} + +void RunDBTransactionForSuccessOrFailureCallback( ResultCallback callback, + uint64_t trace_id, mojom::DBTransactionResultInfoPtr mojom_db_transaction_result) { + if (mojom_db_transaction_result) { + TRACE_EVENT_NESTABLE_ASYNC_END2( + kTraceEventCategory, "RunDBTransaction", + TRACE_ID_WITH_SCOPE("Database", trace_id), "statusCode", + mojom_db_transaction_result->status_code, "rowCount", + mojom_db_transaction_result->rows_union->get_rows().size()); + } else { + TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceEventCategory, "RunDBTransaction", + TRACE_ID_WITH_SCOPE("Database", trace_id), + "mojom_db_transaction_result", "nullptr"); + } + if (IsError(mojom_db_transaction_result)) { return std::move(callback).Run(/*success=*/false); } @@ -44,17 +80,33 @@ bool IsError( mojom::DBTransactionResultInfo::StatusCode::kSuccess; } -void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, +void RunDBTransaction(const base::Location& location, + mojom::DBTransactionInfoPtr mojom_db_transaction, ::brave_ads::RunDBTransactionCallback callback) { + const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId(); + TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(kTraceEventCategory, "RunDBTransaction", + TRACE_ID_WITH_SCOPE("Database", trace_id), + "location", location.ToString()); + GlobalState::GetInstance()->GetDatabaseManager().RunDBTransaction( - std::move(mojom_db_transaction), std::move(callback)); + std::move(mojom_db_transaction), + base::BindOnce(&RunDBTransactionCallback, std::move(callback), trace_id), + trace_id); } -void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, +void RunDBTransaction(const base::Location& location, + mojom::DBTransactionInfoPtr mojom_db_transaction, ResultCallback callback) { + const uint64_t trace_id = base::trace_event::GetNextGlobalTraceId(); + TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(kTraceEventCategory, "RunDBTransaction", + TRACE_ID_WITH_SCOPE("Database", trace_id), + "location", location.ToString()); + GlobalState::GetInstance()->GetDatabaseManager().RunDBTransaction( std::move(mojom_db_transaction), - base::BindOnce(&RunDBTransactionCallback, std::move(callback))); + base::BindOnce(&RunDBTransactionForSuccessOrFailureCallback, + std::move(callback), trace_id), + trace_id); } void Raze(const mojom::DBTransactionInfoPtr& mojom_db_transaction) { 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 ba1705afcba3..af3faf7712c9 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 @@ -9,6 +9,7 @@ #include #include +#include "base/location.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client_callback.h" @@ -24,11 +25,13 @@ bool IsError( // Run a database transaction. The callback takes one argument - // `mojom::DBTransactionResultInfoPtr` containing the info of the transaction. -void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, +void RunDBTransaction(const base::Location& location, + mojom::DBTransactionInfoPtr mojom_db_transaction, RunDBTransactionCallback callback); // Run a database transaction. -void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, +void RunDBTransaction(const base::Location& location, + mojom::DBTransactionInfoPtr mojom_db_transaction, ResultCallback callback); // Raze the database. This must be done before any other actions are run. All 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 06514eb11339..1f8b940fd9ef 100644 --- a/components/brave_ads/core/internal/creatives/campaigns_database_table.cc +++ b/components/brave_ads/core/internal/creatives/campaigns_database_table.cc @@ -9,6 +9,7 @@ #include #include "base/check.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_statement_util.h" @@ -54,7 +55,8 @@ void Campaigns::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void Campaigns::Insert(const mojom::DBTransactionInfoPtr& mojom_db_transaction, 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 eec8170fcb84..e88d3241fe49 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 @@ -12,6 +12,7 @@ #include "base/check.h" #include "base/debug/dump_without_crashing.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "base/time/time.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" @@ -192,7 +193,8 @@ void CreativeSetConversions::Save( Insert(mojom_db_transaction, creative_set_conversions); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeSetConversions::GetUnexpired( @@ -217,7 +219,7 @@ void CreativeSetConversions::GetUnexpired( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -248,7 +250,7 @@ void CreativeSetConversions::GetActive( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -262,7 +264,8 @@ void CreativeSetConversions::PurgeExpired(ResultCallback callback) const { $2 >= expire_at;)", {GetTableName(), TimeToSqlValueAsString(base::Time::Now())}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string CreativeSetConversions::GetTableName() 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 01f43e304f36..afb0b8cf8b2a 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 @@ -12,6 +12,7 @@ #include "base/check.h" #include "base/containers/contains.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/strcat.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" @@ -177,7 +178,8 @@ void CreativeAds::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeAds::GetForCreativeInstanceId( @@ -214,7 +216,7 @@ void CreativeAds::GetForCreativeInstanceId( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForCreativeInstanceIdCallback, creative_instance_id, std::move(callback))); } 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 cb5c15589645..6359fb95cd11 100644 --- a/components/brave_ads/core/internal/creatives/dayparts_database_table.cc +++ b/components/brave_ads/core/internal/creatives/dayparts_database_table.cc @@ -9,6 +9,7 @@ #include #include "base/check.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_table_util.h" @@ -65,7 +66,8 @@ void Dayparts::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string Dayparts::GetTableName() 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 138b6627bd12..b4b428e3be53 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 @@ -9,6 +9,7 @@ #include #include "base/check.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_table_util.h" @@ -63,7 +64,8 @@ void GeoTargets::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string GeoTargets::GetTableName() 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 f5d3e748f681..fecaccee56c3 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 @@ -12,6 +12,7 @@ #include "base/containers/contains.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/strcat.h" #include "base/strings/string_util.h" #include "base/time/time.h" @@ -280,7 +281,8 @@ void CreativeInlineContentAds::Save( segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeInlineContentAds::Delete(ResultCallback callback) const { @@ -289,7 +291,8 @@ void CreativeInlineContentAds::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeInlineContentAds::GetForCreativeInstanceId( @@ -346,7 +349,7 @@ void CreativeInlineContentAds::GetForCreativeInstanceId( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForCreativeInstanceIdCallback, creative_instance_id, std::move(callback))); } @@ -417,7 +420,7 @@ void CreativeInlineContentAds::GetForSegmentsAndDimensions( mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForSegmentsAndDimensionsCallback, segments, std::move(callback))); } @@ -478,7 +481,7 @@ void CreativeInlineContentAds::GetForDimensions( mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); RunDBTransaction( - std::move(mojom_db_transaction), + FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForDimensionsCallback, std::move(callback))); } @@ -530,7 +533,7 @@ void CreativeInlineContentAds::GetForActiveCampaigns( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetAllCallback, std::move(callback))); } 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 ead5feaf83bb..89a84f3ef5ac 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 @@ -12,6 +12,7 @@ #include "base/base64.h" #include "base/check.h" +#include "base/location.h" #include "base/ranges/algorithm.h" #include "base/strings/strcat.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" @@ -96,7 +97,8 @@ void CreativeNewTabPageAdWallpapers::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string CreativeNewTabPageAdWallpapers::GetTableName() 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 b9a42da8afbd..d77564a3b81e 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 @@ -12,6 +12,7 @@ #include "base/base64.h" #include "base/containers/contains.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/strcat.h" #include "base/strings/string_split.h" #include "base/time/time.h" @@ -316,7 +317,8 @@ void CreativeNewTabPageAds::Save(const CreativeNewTabPageAdList& creative_ads, segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeNewTabPageAds::Delete(ResultCallback callback) const { @@ -325,7 +327,8 @@ void CreativeNewTabPageAds::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeNewTabPageAds::GetForCreativeInstanceId( @@ -385,7 +388,7 @@ void CreativeNewTabPageAds::GetForCreativeInstanceId( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForCreativeInstanceIdCallback, creative_instance_id, std::move(callback))); } @@ -458,7 +461,7 @@ void CreativeNewTabPageAds::GetForSegments( mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); RunDBTransaction( - std::move(mojom_db_transaction), + FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForSegmentsCallback, segments, std::move(callback))); } @@ -513,7 +516,7 @@ void CreativeNewTabPageAds::GetForActiveCampaigns( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetAllCallback, std::move(callback))); } 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 e31d21df809b..3f66a32fe423 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 @@ -11,6 +11,7 @@ #include "base/containers/contains.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/strcat.h" #include "base/strings/string_util.h" #include "base/time/time.h" @@ -232,7 +233,8 @@ void CreativeNotificationAds::Save( segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeNotificationAds::Delete(ResultCallback callback) const { @@ -241,7 +243,8 @@ void CreativeNotificationAds::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativeNotificationAds::GetForSegments( @@ -307,7 +310,7 @@ void CreativeNotificationAds::GetForSegments( mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); RunDBTransaction( - std::move(mojom_db_transaction), + FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForSegmentsCallback, segments, std::move(callback))); } @@ -356,7 +359,7 @@ void CreativeNotificationAds::GetForActiveCampaigns( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetAllCallback, std::move(callback))); } 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 0235499532be..84675a2af61a 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 @@ -11,6 +11,7 @@ #include "base/containers/contains.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/strcat.h" #include "base/strings/string_util.h" #include "base/time/time.h" @@ -257,7 +258,8 @@ void CreativePromotedContentAds::Save( segments_database_table_.Insert(mojom_db_transaction, creative_ads_batch); } - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativePromotedContentAds::Delete(ResultCallback callback) const { @@ -266,7 +268,8 @@ void CreativePromotedContentAds::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void CreativePromotedContentAds::GetForCreativeInstanceId( @@ -320,7 +323,7 @@ void CreativePromotedContentAds::GetForCreativeInstanceId( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForCreativeInstanceIdCallback, creative_instance_id, std::move(callback))); } @@ -388,7 +391,7 @@ void CreativePromotedContentAds::GetForSegments( mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); RunDBTransaction( - std::move(mojom_db_transaction), + FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetForSegmentsCallback, segments, std::move(callback))); } @@ -437,7 +440,7 @@ void CreativePromotedContentAds::GetForActiveCampaigns( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetAllCallback, std::move(callback))); } 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 5b7db218a1d3..e74cceeaa24a 100644 --- a/components/brave_ads/core/internal/creatives/segments_database_table.cc +++ b/components/brave_ads/core/internal/creatives/segments_database_table.cc @@ -9,6 +9,7 @@ #include #include "base/check.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_table_util.h" @@ -61,7 +62,8 @@ void Segments::Delete(ResultCallback callback) const { DeleteTable(mojom_db_transaction, GetTableName()); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string Segments::GetTableName() const { diff --git a/components/brave_ads/core/internal/database/database.cc b/components/brave_ads/core/internal/database/database.cc index 19ef10943279..c623471e319d 100644 --- a/components/brave_ads/core/internal/database/database.cc +++ b/components/brave_ads/core/internal/database/database.cc @@ -16,10 +16,12 @@ #include "base/functional/bind.h" #include "base/location.h" #include "base/logging.h" +#include "base/trace_event/trace_event.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_row_util.h" #include "brave/components/brave_ads/core/internal/common/database/database_transaction_util.h" #include "brave/components/brave_ads/core/internal/legacy_migration/database/database_constants.h" +#include "brave/components/brave_ads/core/public/ads_constants.h" #include "sql/meta_table.h" #include "sql/recovery.h" #include "sql/sqlite_result_code.h" @@ -38,11 +40,15 @@ Database::Database(base::FilePath path) : db_path_(std::move(path)) { Database::~Database() = default; mojom::DBTransactionResultInfoPtr Database::RunDBTransaction( - mojom::DBTransactionInfoPtr mojom_db_transaction) { + mojom::DBTransactionInfoPtr mojom_db_transaction, + uint64_t trace_id) { CHECK(mojom_db_transaction); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + TRACE_EVENT(kTraceEventCategory, "Database::RunDBTransaction", "trace_id", + trace_id); + mojom::DBTransactionResultInfoPtr mojom_db_transaction_result = mojom::DBTransactionResultInfo::New(); @@ -56,7 +62,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); + mojom_db_transaction_result->status_code = + MaybeRaze(mojom_db_transaction, trace_id); if (database::IsError(mojom_db_transaction_result)) { VLOG(0) << "Failed to raze database"; return mojom_db_transaction_result; @@ -65,7 +72,7 @@ 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); + RunDBActions(mojom_db_transaction, mojom_db_transaction_result, trace_id); if (database::IsError(mojom_db_transaction_result)) { VLOG(0) << "Failed run database actions"; return mojom_db_transaction_result; @@ -74,7 +81,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); + mojom_db_transaction_result->status_code = + MaybeVacuum(mojom_db_transaction, trace_id); if (database::IsError(mojom_db_transaction_result)) { VLOG(0) << "Failed to vacuum database"; return mojom_db_transaction_result; @@ -87,12 +95,16 @@ mojom::DBTransactionResultInfoPtr Database::RunDBTransaction( mojom::DBTransactionResultInfo::StatusCode Database::RunDBActions( const mojom::DBTransactionInfoPtr& mojom_db_transaction, - const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result) { + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result, + uint64_t trace_id) { CHECK(mojom_db_transaction); CHECK(mojom_db_transaction_result); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + TRACE_EVENT(kTraceEventCategory, "Database::RunDBActions", "trace_id", + trace_id); + sql::Transaction transaction(&db_); if (!transaction.Begin()) { return mojom::DBTransactionResultInfo::StatusCode::kTransactionError; @@ -102,6 +114,9 @@ mojom::DBTransactionResultInfo::StatusCode Database::RunDBActions( mojom::DBTransactionResultInfo::StatusCode result_code = mojom::DBTransactionResultInfo::StatusCode::kSuccess; + TRACE_EVENT(kTraceEventCategory, "Database::RunDBAction", "type", + mojom_db_action->type, "trace_id", trace_id); + switch (mojom_db_action->type) { case mojom::DBActionInfo::Type::kInitialize: { result_code = Initialize(mojom_db_transaction_result); @@ -146,10 +161,17 @@ mojom::DBTransactionResultInfo::StatusCode Database::RunDBActions( } mojom::DBTransactionResultInfo::StatusCode Database::MaybeRaze( - const mojom::DBTransactionInfoPtr& mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + uint64_t trace_id) { CHECK(mojom_db_transaction); - if (mojom_db_transaction->should_raze && !db_.Raze()) { + if (!mojom_db_transaction->should_raze) { + return mojom::DBTransactionResultInfo::StatusCode::kSuccess; + } + + TRACE_EVENT(kTraceEventCategory, "Database::Raze", "trace_id", trace_id); + + if (!db_.Raze()) { return mojom::DBTransactionResultInfo::StatusCode::kFailedToRazeDatabase; } @@ -319,10 +341,17 @@ mojom::DBTransactionResultInfo::StatusCode Database::Migrate() { } mojom::DBTransactionResultInfo::StatusCode Database::MaybeVacuum( - const mojom::DBTransactionInfoPtr& mojom_db_transaction) { + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + uint64_t trace_id) { CHECK(mojom_db_transaction); - if (mojom_db_transaction->should_vacuum && !db_.Execute("VACUUM;")) { + if (!mojom_db_transaction->should_vacuum) { + return mojom::DBTransactionResultInfo::StatusCode::kSuccess; + } + + TRACE_EVENT(kTraceEventCategory, "Database::Vacuum", "trace_id", trace_id); + + if (!db_.Execute("VACUUM;")) { // Log the error and continue. The vacuum action is not critical. VLOG(0) << "Failed to vacuum database"; } diff --git a/components/brave_ads/core/internal/database/database.h b/components/brave_ads/core/internal/database/database.h index 923c94df91e8..42c6599e675d 100644 --- a/components/brave_ads/core/internal/database/database.h +++ b/components/brave_ads/core/internal/database/database.h @@ -6,6 +6,7 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_DATABASE_DATABASE_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_DATABASE_DATABASE_H_ +#include #include #include "base/files/file_path.h" @@ -29,15 +30,18 @@ class ADS_EXPORT Database final { ~Database(); mojom::DBTransactionResultInfoPtr RunDBTransaction( - mojom::DBTransactionInfoPtr mojom_db_transaction); + mojom::DBTransactionInfoPtr mojom_db_transaction, + uint64_t trace_id); private: mojom::DBTransactionResultInfo::StatusCode RunDBActions( const mojom::DBTransactionInfoPtr& mojom_db_transaction, - const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); + const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result, + uint64_t trace_id); mojom::DBTransactionResultInfo::StatusCode MaybeRaze( - const mojom::DBTransactionInfoPtr& mojom_db_transaction); + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + uint64_t trace_id); bool InitializeMetaTable(); @@ -58,7 +62,8 @@ class ADS_EXPORT Database final { mojom::DBTransactionResultInfo::StatusCode Migrate(); mojom::DBTransactionResultInfo::StatusCode MaybeVacuum( - const mojom::DBTransactionInfoPtr& mojom_db_transaction); + const mojom::DBTransactionInfoPtr& mojom_db_transaction, + uint64_t trace_id); void ErrorCallback(int error, sql::Statement* statement); diff --git a/components/brave_ads/core/internal/database/database_manager.cc b/components/brave_ads/core/internal/database/database_manager.cc index d925ff2b73e3..b9416829c680 100644 --- a/components/brave_ads/core/internal/database/database_manager.cc +++ b/components/brave_ads/core/internal/database/database_manager.cc @@ -50,6 +50,8 @@ void DatabaseManager::RemoveObserver(DatabaseManagerObserver* const observer) { } void DatabaseManager::CreateOrOpen(ResultCallback callback) { + CHECK(callback); + NotifyWillCreateOrOpenDatabase(); mojom::DBTransactionInfoPtr mojom_db_transaction = @@ -61,17 +63,19 @@ void DatabaseManager::CreateOrOpen(ResultCallback callback) { RunDBTransaction( std::move(mojom_db_transaction), base::BindOnce(&DatabaseManager::CreateOrOpenCallback, - weak_factory_.GetWeakPtr(), std::move(callback))); + weak_factory_.GetWeakPtr(), std::move(callback)), + /*trace_id=*/0); } void DatabaseManager::RunDBTransaction( mojom::DBTransactionInfoPtr mojom_db_transaction, - RunDBTransactionCallback callback) { + RunDBTransactionCallback callback, + uint64_t trace_id) { CHECK(mojom_db_transaction); CHECK(callback); database_.AsyncCall(&Database::RunDBTransaction) - .WithArgs(std::move(mojom_db_transaction)) + .WithArgs(std::move(mojom_db_transaction), trace_id) .Then(std::move(callback)); } diff --git a/components/brave_ads/core/internal/database/database_manager.h b/components/brave_ads/core/internal/database/database_manager.h index a2dffdfa2ede..3f2d4f46fb90 100644 --- a/components/brave_ads/core/internal/database/database_manager.h +++ b/components/brave_ads/core/internal/database/database_manager.h @@ -43,7 +43,8 @@ class DatabaseManager final { // Run a database transaction. The callback takes one argument - // `mojom::DBTransactionResultInfoPtr` containing the info of the transaction. void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, - RunDBTransactionCallback callback); + RunDBTransactionCallback callback, + uint64_t trace_id); private: void CreateOrOpenCallback( 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 f0d861718f7c..260786db8f15 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 @@ -10,6 +10,7 @@ #include #include "base/debug/dump_without_crashing.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "base/time/time.h" #include "brave/components/brave_ads/core/internal/common/containers/container_util.h" @@ -225,7 +226,8 @@ void AdHistory::Save(const AdHistoryList& ad_history, Insert(mojom_db_transaction, batch); } - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void AdHistory::GetForDateRange(base::Time from_time, @@ -262,7 +264,7 @@ void AdHistory::GetForDateRange(base::Time from_time, BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -365,7 +367,7 @@ void AdHistory::GetHighestRankedPlacementsForDateRange( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -399,7 +401,7 @@ void AdHistory::GetForCreativeInstanceId( BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -415,7 +417,8 @@ void AdHistory::PurgeExpired(ResultCallback callback) const { TimeToSqlValueAsString(base::Time::Now() - kAdHistoryRetentionPeriod.Get())}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string AdHistory::GetTableName() const { 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 7e766ec11afb..fb865333aa3d 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 @@ -8,6 +8,7 @@ #include #include "base/check.h" +#include "base/location.h" #include "brave/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h" #include "brave/components/brave_ads/core/internal/account/deposits/deposits_database_table.h" #include "brave/components/brave_ads/core/internal/account/transactions/transactions_database_table.h" @@ -95,7 +96,8 @@ void Create(ResultCallback callback) { mojom::DBTransactionInfo::New(); Create(mojom_db_transaction); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } } // namespace brave_ads::database 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 f32c718751ad..11be333ffa98 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 @@ -8,6 +8,7 @@ #include #include "base/check.h" +#include "base/location.h" #include "brave/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h" #include "brave/components/brave_ads/core/internal/account/deposits/deposits_database_table.h" #include "brave/components/brave_ads/core/internal/account/transactions/transactions_database_table.h" @@ -136,7 +137,8 @@ void MigrateFromVersion(int from_version, ResultCallback callback) { mojom_db_action->type = mojom::DBActionInfo::Type::kMigrate; mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } } // namespace brave_ads::database 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 1e9c76d8b250..dab987b2c9aa 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 @@ -7,6 +7,7 @@ #include +#include "base/location.h" #include "brave/components/brave_ads/core/internal/common/database/database_transaction_util.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" @@ -17,7 +18,8 @@ void Raze(ResultCallback callback) { mojom::DBTransactionInfo::New(); database::Raze(mojom_db_transaction); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } } // namespace brave_ads::database 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 1c9ff2fba76e..93d452a2e1ee 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 @@ -10,6 +10,7 @@ #include "base/check.h" #include "base/functional/bind.h" +#include "base/location.h" #include "base/strings/string_util.h" #include "base/time/time.h" #include "brave/components/brave_ads/core/internal/common/database/database_column_util.h" @@ -177,7 +178,8 @@ void AdEvents::RecordEvent(const AdEventInfo& ad_event, Insert(mojom_db_transaction, {ad_event}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void AdEvents::GetAll(GetAdEventsCallback callback) const { @@ -203,7 +205,7 @@ void AdEvents::GetAll(GetAdEventsCallback callback) const { BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -242,7 +244,7 @@ void AdEvents::Get(mojom::AdType mojom_ad_type, BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -281,7 +283,7 @@ void AdEvents::GetUnexpired(GetAdEventsCallback callback) const { BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -324,7 +326,7 @@ void AdEvents::GetUnexpired(mojom::AdType mojom_ad_type, BindColumnTypes(mojom_db_action); mojom_db_transaction->actions.push_back(std::move(mojom_db_action)); - RunDBTransaction(std::move(mojom_db_transaction), + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), base::BindOnce(&GetCallback, std::move(callback))); } @@ -347,7 +349,8 @@ void AdEvents::PurgeExpired(ResultCallback callback) const { {GetTableName(), TimeToSqlValueAsString(base::Time::Now() - base::Days(days))}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void AdEvents::PurgeOrphaned(mojom::AdType mojom_ad_type, @@ -372,7 +375,8 @@ void AdEvents::PurgeOrphaned(mojom::AdType mojom_ad_type, AND type = '$3';)", {GetTableName(), GetTableName(), ToString(mojom_ad_type)}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void AdEvents::PurgeOrphaned(const std::vector& placement_ids, @@ -409,7 +413,8 @@ void AdEvents::PurgeOrphaned(const std::vector& placement_ids, {GetTableName(), GetTableName(), base::JoinString(quoted_placement_ids, ", ")}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } void AdEvents::PurgeAllOrphaned(ResultCallback callback) const { @@ -432,7 +437,8 @@ void AdEvents::PurgeAllOrphaned(ResultCallback callback) const { AND confirmation_type = 'served';)", {GetTableName(), GetTableName()}); - RunDBTransaction(std::move(mojom_db_transaction), std::move(callback)); + RunDBTransaction(FROM_HERE, std::move(mojom_db_transaction), + std::move(callback)); } std::string AdEvents::GetTableName() const {