From 6da908798fd021f14bc92c365b719834f22d49ba Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Sun, 9 Jul 2023 11:28:09 -0500 Subject: [PATCH 1/2] Followup to "Decouple Brave Ads conversions and resolve #16090 and #26834" --- components/brave_ads/core/internal/BUILD.gn | 10 +++--- .../user_data/conversion_user_data_util.cc | 4 +-- .../conversions/conversion/conversion_util.cc | 9 +++++- .../core/internal/conversions/conversions.cc | 31 ++++++++++++------- .../conversions/queue/conversion_queue.cc | 2 +- .../queue/conversion_queue_database_table.cc | 4 +-- .../queue/conversion_queue_database_table.h | 7 +++-- .../conversion_queue_item_unittest_util.cc | 2 +- .../verifiable_conversion_envelope_info.cc | 2 +- .../verifiable_conversion_envelope_info.h | 6 ++-- ...iable_conversion_envelope_unittest_util.cc | 4 +-- ...fiable_conversion_envelope_unittest_util.h | 6 ++-- .../verifiable_conversion_envelope_util.cc | 6 ++-- .../verifiable_conversion_envelope_util.h | 6 ++-- ...iable_conversion_envelope_util_constants.h | 6 ++-- ...iable_conversion_envelope_util_unittest.cc | 8 ++--- .../creative_set_conversion_util.cc | 1 + components/brave_ads/core/test/BUILD.gn | 6 ++-- 18 files changed, 68 insertions(+), 52 deletions(-) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_info.cc (96%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_info.h (86%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_unittest_util.cc (95%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_unittest_util.h (79%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_util.cc (93%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_util.h (79%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_util_constants.h (72%) rename components/brave_ads/core/internal/conversions/types/verifiable_conversion/{ => envelope}/verifiable_conversion_envelope_util_unittest.cc (91%) diff --git a/components/brave_ads/core/internal/BUILD.gn b/components/brave_ads/core/internal/BUILD.gn index 7a0a1dbd06db..84f1581a9bea 100644 --- a/components/brave_ads/core/internal/BUILD.gn +++ b/components/brave_ads/core/internal/BUILD.gn @@ -690,15 +690,15 @@ source_set("internal") { "conversions/queue/queue_item/conversion_queue_item_util_constants.h", "conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util.cc", "conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util.h", + "conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.cc", + "conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h", + "conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.cc", + "conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h", + "conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_constants.h", "conversions/types/verifiable_conversion/verifiable_conversion_builder.cc", "conversions/types/verifiable_conversion/verifiable_conversion_builder.h", "conversions/types/verifiable_conversion/verifiable_conversion_builder_util.cc", "conversions/types/verifiable_conversion/verifiable_conversion_builder_util.h", - "conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.cc", - "conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h", - "conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.cc", - "conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h", - "conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_constants.h", "conversions/types/verifiable_conversion/verifiable_conversion_id_pattern/parsers/verifiable_conversion_id_html_meta_tag_parser_util.cc", "conversions/types/verifiable_conversion/verifiable_conversion_id_pattern/parsers/verifiable_conversion_id_html_meta_tag_parser_util.h", "conversions/types/verifiable_conversion/verifiable_conversion_id_pattern/parsers/verifiable_conversion_id_html_parser_util.cc", diff --git a/components/brave_ads/core/internal/account/user_data/conversion_user_data_util.cc b/components/brave_ads/core/internal/account/user_data/conversion_user_data_util.cc index 25f0ffb89644..a6f2314c9847 100644 --- a/components/brave_ads/core/internal/account/user_data/conversion_user_data_util.cc +++ b/components/brave_ads/core/internal/account/user_data/conversion_user_data_util.cc @@ -12,8 +12,8 @@ #include "brave/components/brave_ads/core/internal/conversions/actions/conversion_action_types.h" #include "brave/components/brave_ads/core/internal/conversions/actions/conversion_action_types_util.h" #include "brave/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_info.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h" #include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_info.h" #include "third_party/abseil-cpp/absl/types/optional.h" diff --git a/components/brave_ads/core/internal/conversions/conversion/conversion_util.cc b/components/brave_ads/core/internal/conversions/conversion/conversion_util.cc index 74e10fd8bcb5..4b9a1eb34f55 100644 --- a/components/brave_ads/core/internal/conversions/conversion/conversion_util.cc +++ b/components/brave_ads/core/internal/conversions/conversion/conversion_util.cc @@ -9,8 +9,15 @@ namespace brave_ads { +namespace { + +constexpr char kVerifiableConversion[] = "verifiable conversion"; +constexpr char kDefaultConversion[] = "conversion"; + +} // namespace + std::string ConversionTypeToString(const ConversionInfo& conversion) { - return conversion.verifiable ? "verifiable conversion" : "conversion"; + return conversion.verifiable ? kVerifiableConversion : kDefaultConversion; } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/conversions/conversions.cc b/components/brave_ads/core/internal/conversions/conversions.cc index 45e3744ef0ef..b6504c9091c6 100644 --- a/components/brave_ads/core/internal/conversions/conversions.cc +++ b/components/brave_ads/core/internal/conversions/conversions.cc @@ -120,21 +120,23 @@ void Conversions::CheckForConversions( const CreativeSetConversionList filtered_creative_set_conversions = FilterConvertedAndNonMatchingCreativeSetConversions( creative_set_conversions, ad_events, redirect_chain); - - BLOG(1, "There are " << creative_set_conversions.size() - << " eligible creative set conversions"); + if (filtered_creative_set_conversions.empty()) { + return BLOG(1, "There are no eligible creative set conversions"); + } CreativeSetConversionBuckets creative_set_conversion_buckets = SortCreativeSetConversionsIntoBuckets(filtered_creative_set_conversions); - if (creative_set_conversion_buckets.empty()) { - // There are no matching eligible creative set conversion URL patterns for - // the redirect chain. - return; - } + + BLOG(1, filtered_creative_set_conversions.size() + << " out of " << creative_set_conversions.size() + << " eligible creative set conversions are sorted into " + << creative_set_conversion_buckets.size() << " buckets"); + + bool did_convert = false; // Click-through conversions should take priority over view-through - // conversions. Ad events are ordered in descending order by created at; click - // events are guaranteed to occur after view events. + // conversions. Ad events are ordered in descending order by |created_at|; + // click events are guaranteed to occur after view events. for (const auto& ad_event : ad_events) { // Do we have a bucket with creative set conversions for this ad event? const auto iter = @@ -161,8 +163,10 @@ void Conversions::CheckForConversions( redirect_chain, html, resource_.get().id_patterns, *creative_set_conversion)); + did_convert = true; + // Remove the bucket for this creative set because we should not convert - // another ad from the same creative set. + // another ad event from the same creative set. creative_set_conversion_buckets.erase(ad_event.creative_set_id); if (creative_set_conversion_buckets.empty()) { // All the buckets have drained, so they will no longer contain @@ -170,6 +174,10 @@ void Conversions::CheckForConversions( break; } } + + if (!did_convert) { + BLOG(1, "There are no matching conversions"); + } } void Conversions::Convert( @@ -199,7 +207,6 @@ void Conversions::ConvertCallback( const ConversionInfo conversion = BuildConversion(ad_event, verifiable_conversion); - queue_.Add(conversion); } diff --git a/components/brave_ads/core/internal/conversions/queue/conversion_queue.cc b/components/brave_ads/core/internal/conversions/queue/conversion_queue.cc index 0587ab2fef57..608eeec07249 100644 --- a/components/brave_ads/core/internal/conversions/queue/conversion_queue.cc +++ b/components/brave_ads/core/internal/conversions/queue/conversion_queue.cc @@ -31,7 +31,7 @@ void ConversionQueue::Add(const ConversionInfo& conversion) { BuildConversionQueueItem(conversion, ProcessQueueItemAt()); CHECK(conversion_queue_item.IsValid()); - database::table::ConversionQueue database_table; + const database::table::ConversionQueue database_table; database_table.Save( {conversion_queue_item}, base::BindOnce(&ConversionQueue::AddCallback, weak_factory_.GetWeakPtr(), diff --git a/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.cc b/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.cc index c38aa5e2dbdc..fe44a2e03bff 100644 --- a/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.cc +++ b/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.cc @@ -386,7 +386,7 @@ ConversionQueue::ConversionQueue() : batch_size_(kDefaultBatchSize) {} void ConversionQueue::Save( const ConversionQueueItemList& conversion_queue_items, - ResultCallback callback) { + ResultCallback callback) const { if (conversion_queue_items.empty()) { return std::move(callback).Run(/*success*/ true); } @@ -569,7 +569,7 @@ void ConversionQueue::Migrate(mojom::DBTransactionInfo* transaction, void ConversionQueue::InsertOrUpdate( mojom::DBTransactionInfo* transaction, - const ConversionQueueItemList& conversion_queue_items) { + const ConversionQueueItemList& conversion_queue_items) const { CHECK(transaction); if (conversion_queue_items.empty()) { diff --git a/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.h b/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.h index d3555a2bcb55..9bb3ad62bfad 100644 --- a/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.h +++ b/components/brave_ads/core/internal/conversions/queue/conversion_queue_database_table.h @@ -30,7 +30,7 @@ class ConversionQueue final : public TableInterface { ConversionQueue(); void Save(const ConversionQueueItemList& conversion_queue_items, - ResultCallback callback); + ResultCallback callback) const; void Delete(const ConversionQueueItemInfo& conversion_queue_item, ResultCallback callback) const; @@ -58,8 +58,9 @@ class ConversionQueue final : public TableInterface { void Migrate(mojom::DBTransactionInfo* transaction, int to_version) override; private: - void InsertOrUpdate(mojom::DBTransactionInfo* transaction, - const ConversionQueueItemList& conversion_queue_items); + void InsertOrUpdate( + mojom::DBTransactionInfo* transaction, + const ConversionQueueItemList& conversion_queue_items) const; std::string BuildInsertOrUpdateSql( mojom::DBCommandInfo* command, diff --git a/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_unittest_util.cc b/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_unittest_util.cc index 3ce6dc19ffab..55718f204fe7 100644 --- a/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_unittest_util.cc +++ b/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_unittest_util.cc @@ -15,7 +15,7 @@ namespace brave_ads { void SaveConversionQueueItems( const ConversionQueueItemList& conversion_queue_items) { - database::table::ConversionQueue database_table; + const database::table::ConversionQueue database_table; database_table.Save( conversion_queue_items, base::BindOnce([](const bool success) { CHECK(success); })); diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.cc b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.cc similarity index 96% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.cc rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.cc index 886e45c39dc3..c8d7c418f8bd 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.cc +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h" #include diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h similarity index 86% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h index e47809eb9695..159f90abf5c1 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_INFO_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_INFO_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_INFO_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_INFO_H_ #include @@ -38,4 +38,4 @@ bool operator!=(const VerifiableConversionEnvelopeInfo&, } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_INFO_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_INFO_H_ diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.cc b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.cc similarity index 95% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.cc rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.cc index c106d2768091..9f4849bf4c45 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.cc +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.h" #include #include @@ -11,7 +11,7 @@ #include "base/base64.h" #include "brave/components/brave_ads/core/internal/account/user_data/conversion_user_data_constants.h" #include "brave/components/brave_ads/core/internal/common/crypto/crypto_util.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h" #include "tweetnacl.h" // NOLINT namespace brave_ads { diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.h b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.h similarity index 79% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.h rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.h index 5454e2a08170..b4d29ee5426c 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.h +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UNITTEST_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UNITTEST_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UNITTEST_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UNITTEST_UTIL_H_ #include @@ -24,4 +24,4 @@ absl::optional OpenVerifiableConversionEnvelope( } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UNITTEST_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UNITTEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.cc b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.cc similarity index 93% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.cc rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.cc index c59f24134094..b09444edee0b 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.cc +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h" #include #include @@ -12,8 +12,8 @@ #include "base/check_op.h" #include "brave/components/brave_ads/core/internal/common/crypto/crypto_util.h" #include "brave/components/brave_ads/core/internal/common/crypto/key_pair_info.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_constants.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_constants.h" #include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_info.h" #include "third_party/re2/src/re2/re2.h" #include "tweetnacl.h" // NOLINT diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h similarity index 79% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h index 22cc22be5261..f5336fcb21e3 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_H_ #include @@ -23,4 +23,4 @@ SealVerifiableConversionEnvelope( } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_H_ diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_constants.h b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_constants.h similarity index 72% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_constants.h rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_constants.h index 467a868cabab..719436590cad 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_constants.h +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_constants.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_CONSTANTS_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_CONSTANTS_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_CONSTANTS_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_CONSTANTS_H_ #include @@ -15,4 +15,4 @@ constexpr size_t kMaxVerifiableConversionEnvelopeMessageLength = 30; } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_CONSTANTS_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_CONVERSIONS_TYPES_VERIFIABLE_CONVERSION_ENVELOPE_VERIFIABLE_CONVERSION_ENVELOPE_UTIL_CONSTANTS_H_ diff --git a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_unittest.cc b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_unittest.cc similarity index 91% rename from components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_unittest.cc rename to components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_unittest.cc index 2e7c684f05de..efe0559930d6 100644 --- a/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_unittest.cc +++ b/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_unittest.cc @@ -3,11 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_info.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.h" -#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_constants.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_info.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.h" +#include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_constants.h" #include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_info.h" #include "brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_unittest_constants.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util.cc b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util.cc index 17ecf3175935..0f04beed6e2e 100644 --- a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util.cc +++ b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util.cc @@ -46,6 +46,7 @@ CreativeSetConversionList FilterConvertedAndNonMatchingCreativeSetConversions( GetConvertedCreativeSets(ad_events); CreativeSetConversionList filtered_creative_set_conversions; + base::ranges::copy_if( creative_set_conversions, std::back_inserter(filtered_creative_set_conversions), diff --git a/components/brave_ads/core/test/BUILD.gn b/components/brave_ads/core/test/BUILD.gn index 3da9a1bd5a46..e7b364852128 100644 --- a/components/brave_ads/core/test/BUILD.gn +++ b/components/brave_ads/core/test/BUILD.gn @@ -313,11 +313,11 @@ source_set("brave_ads_unit_tests") { "//brave/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_unittest_util.h", "//brave/components/brave_ads/core/internal/conversions/queue/queue_item/conversion_queue_item_util_unittest.cc", "//brave/components/brave_ads/core/internal/conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util_unittest.cc", + "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.cc", + "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_unittest_util.h", + "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/envelope/verifiable_conversion_envelope_util_unittest.cc", "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_builder_unittest.cc", "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_builder_util_unittest.cc", - "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.cc", - "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_unittest_util.h", - "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_envelope_util_unittest.cc", "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_id_pattern/parsers/verifiable_conversion_id_html_meta_tag_parser_util_unittest.cc", "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_id_pattern/parsers/verifiable_conversion_id_html_parser_util_unittest.cc", "//brave/components/brave_ads/core/internal/conversions/types/verifiable_conversion/verifiable_conversion_id_pattern/parsers/verifiable_conversion_id_url_redirects_parser_util_unittest.cc", From a9151e697859c366c63d0e26497b8aa0e58c6237 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Sun, 9 Jul 2023 13:08:46 -0500 Subject: [PATCH 2/2] Remove unused Brave Ads code --- .../ads/ad_events/ad_events_database_table.cc | 19 ------------------- .../ads/ad_events/ad_events_database_table.h | 2 -- 2 files changed, 21 deletions(-) diff --git a/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.cc b/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.cc index 1e17e890d5be..10ad88eb1f3f 100644 --- a/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.cc +++ b/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.cc @@ -217,25 +217,6 @@ void AdEvents::LogEvent(const AdEventInfo& ad_event, ResultCallback callback) { RunTransaction(std::move(transaction), std::move(callback)); } -void AdEvents::GetIf(const std::string& condition, - GetAdEventsCallback callback) const { - mojom::DBTransactionInfoPtr transaction = mojom::DBTransactionInfo::New(); - mojom::DBCommandInfoPtr command = mojom::DBCommandInfo::New(); - command->type = mojom::DBCommandInfo::Type::READ; - command->sql = base::ReplaceStringPlaceholders( - "SELECT ae.placement_id, ae.type, ae.confirmation_type, ae.campaign_id, " - "ae.creative_set_id, ae.creative_instance_id, ae.advertiser_id, " - "ae.segment, ae.created_at FROM $1 AS ae WHERE $2 ORDER BY created_at " - "DESC;", - {GetTableName(), condition}, nullptr); - BindRecords(&*command); - transaction->commands.push_back(std::move(command)); - - AdsClientHelper::GetInstance()->RunDBTransaction( - std::move(transaction), - base::BindOnce(&GetCallback, std::move(callback))); -} - void AdEvents::GetAll(GetAdEventsCallback callback) const { mojom::DBTransactionInfoPtr transaction = mojom::DBTransactionInfo::New(); mojom::DBCommandInfoPtr command = mojom::DBCommandInfo::New(); diff --git a/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.h b/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.h index 1b3e72ffeff5..9ada1e896478 100644 --- a/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.h +++ b/components/brave_ads/core/internal/ads/ad_events/ad_events_database_table.h @@ -23,8 +23,6 @@ class AdEvents final : public TableInterface { public: void LogEvent(const AdEventInfo& ad_event, ResultCallback callback); - void GetIf(const std::string& condition, GetAdEventsCallback callback) const; - void GetAll(GetAdEventsCallback callback) const; void GetForType(mojom::AdType ad_type, GetAdEventsCallback callback) const;