Skip to content

Commit

Permalink
[ads] SmartNTT code health
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Oct 29, 2024
1 parent a0c201c commit af84212
Show file tree
Hide file tree
Showing 41 changed files with 1,569 additions and 1,316 deletions.
19 changes: 11 additions & 8 deletions browser/brave_ads/ads_service_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ AdsServiceDelegate::AdsServiceDelegate(

AdsServiceDelegate::~AdsServiceDelegate() {}

std::string AdsServiceDelegate::GetDefaultSearchEngineName() {
const auto template_url_data =
TemplateURLPrepopulateData::GetPrepopulatedFallbackSearch(
profile_->GetPrefs(), &search_engine_choice_service_);

const std::u16string& default_search_engine_name =
template_url_data ? template_url_data->short_name() : u"";
return base::UTF16ToUTF8(default_search_engine_name);
}

void AdsServiceDelegate::OpenNewTabWithUrl(const GURL& url) {
#if BUILDFLAG(IS_ANDROID)
// ServiceTabLauncher can currently only launch new tabs
Expand Down Expand Up @@ -146,20 +156,13 @@ bool AdsServiceDelegate::IsFullScreenMode() {
#endif

base::Value::Dict AdsServiceDelegate::GetVirtualPrefs() {
const auto template_url_data =
TemplateURLPrepopulateData::GetPrepopulatedFallbackSearch(
profile_->GetPrefs(), &search_engine_choice_service_);
if (!template_url_data) {
return {};
}

return base::Value::Dict()
.Set("[virtual]:operating_system.name", version_info::GetOSType())
.Set("[virtual]:build_channel.name",
version_info::GetChannelString(chrome::GetChannel()))
.Set("[virtual]:browser_version", version_info::GetVersionNumber())
.Set("[virtual]:default_search_engine.name",
base::UTF16ToUTF8(template_url_data->short_name()));
GetDefaultSearchEngineName());
}

} // namespace brave_ads
2 changes: 2 additions & 0 deletions browser/brave_ads/ads_service_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AdsServiceDelegate : public AdsService::Delegate {

~AdsServiceDelegate() override;

std::string GetDefaultSearchEngineName();

// AdsService::Delegate implementation
void InitNotificationHelper() override;
bool CanShowSystemNotificationsWhileBrowserIsBackgrounded() override;
Expand Down
16 changes: 13 additions & 3 deletions components/brave_ads/core/internal/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,6 @@ static_library("internal") {
"serving/inline_content_ad_serving_feature.h",
"serving/new_tab_page_ad_serving.cc",
"serving/new_tab_page_ad_serving.h",
"serving/new_tab_page_ad_serving_condition_matcher_util.cc",
"serving/new_tab_page_ad_serving_condition_matcher_util_internal.cc",
"serving/new_tab_page_ad_serving_condition_matcher_util_internal.h",
"serving/new_tab_page_ad_serving_delegate.h",
"serving/new_tab_page_ad_serving_feature.cc",
"serving/new_tab_page_ad_serving_feature.h",
Expand Down Expand Up @@ -942,6 +939,19 @@ static_library("internal") {
"serving/prediction/model_based/weight/creative_notification_ad_model_based_predictor_weights_builder.cc",
"serving/prediction/model_based/weight/creative_notification_ad_model_based_predictor_weights_builder.h",
"serving/prediction/model_based/weight/segment/creative_ad_model_based_predictor_segment_weight_info.h",
"serving/targeting/condition_matcher/condition_matcher_util.cc",
"serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc",
"serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.h",
"serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.cc",
"serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.h",
"serving/targeting/condition_matcher/matchers/pattern_condition_matcher_util.cc",
"serving/targeting/condition_matcher/matchers/pattern_condition_matcher_util.h",
"serving/targeting/condition_matcher/matchers/regex_condition_matcher_util.cc",
"serving/targeting/condition_matcher/matchers/regex_condition_matcher_util.h",
"serving/targeting/condition_matcher/prefs/condition_matcher_pref_util.cc",
"serving/targeting/condition_matcher/prefs/condition_matcher_pref_util.h",
"serving/targeting/condition_matcher/prefs/internal/condition_matcher_pref_util_internal.cc",
"serving/targeting/condition_matcher/prefs/internal/condition_matcher_pref_util_internal.h",
"serving/targeting/segments/top_segments.cc",
"serving/targeting/segments/top_segments.h",
"serving/targeting/segments/top_user_model_segments.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>

#include "brave/components/brave_ads/core/internal/catalog/campaign/creative_set/creative/new_tab_page_ad/catalog_new_tab_page_ad_wallpaper_focal_point_info.h"
#include "brave/components/brave_ads/core/public/serving/new_tab_page_ad_serving_condition_matcher_util.h"
#include "brave/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h"
#include "url/gurl.h"

namespace brave_ads {
Expand All @@ -31,7 +31,7 @@ struct CatalogNewTabPageAdWallpaperInfo final {

GURL image_url;
CatalogNewTabPageAdWallpaperFocalPointInfo focal_point;
NewTabPageAdConditionMatcherMap condition_matchers;
ConditionMatcherMap condition_matchers;
};

using CatalogNewTabPageAdWallpaperList =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>

#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpaper_focal_point_info.h"
#include "brave/components/brave_ads/core/public/serving/new_tab_page_ad_serving_condition_matcher_util.h"
#include "brave/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h"
#include "url/gurl.h"

namespace brave_ads {
Expand All @@ -32,7 +32,7 @@ struct CreativeNewTabPageAdWallpaperInfo final {

GURL image_url;
CreativeNewTabPageAdWallpaperFocalPointInfo focal_point;
NewTabPageAdConditionMatcherMap condition_matchers;
ConditionMatcherMap condition_matchers;
};

using CreativeNewTabPageAdWallpaperList =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
constexpr char kTableName[] = "creative_new_tab_page_ad_wallpapers";

std::string ConditionMatchersToString(
const NewTabPageAdConditionMatcherMap& condition_matchers) {
const ConditionMatcherMap& condition_matchers) {
std::vector<std::string> condition_matchers_as_string;
condition_matchers_as_string.reserve(condition_matchers.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "brave/components/brave_ads/core/internal/segments/segment_util.h"
#include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h"
#include "brave/components/brave_ads/core/public/ads_client/ads_client.h"
#include "brave/components/brave_ads/core/public/serving/new_tab_page_ad_serving_condition_matcher_util.h"
#include "brave/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h"
#include "url/gurl.h"

namespace brave_ads::database::table {
Expand All @@ -41,13 +41,12 @@ constexpr char kTableName[] = "creative_new_tab_page_ads";

constexpr int kDefaultBatchSize = 50;

NewTabPageAdConditionMatcherMap StringToConditionMatchers(
const std::string& value) {
ConditionMatcherMap StringToConditionMatchers(const std::string& value) {
const std::vector<std::string> condition_matchers_as_string =
base::SplitString(value, ";", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);

NewTabPageAdConditionMatcherMap condition_matchers;
ConditionMatcherMap condition_matchers;
for (const auto& condition_matcher_as_string : condition_matchers_as_string) {
const std::vector<std::string> condition_matcher =
base::SplitString(condition_matcher_as_string, "|",
Expand Down

This file was deleted.

Loading

0 comments on commit af84212

Please sign in to comment.