diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index e7ebeacb384..00548ea40e5 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -24,7 +24,6 @@ #include "brave/browser/profiles/brave_profile_manager.h" #include "brave/common/brave_channel_info.h" #include "brave/components/ai_chat/core/common/buildflags/buildflags.h" -#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_component_updater/browser/brave_component_updater_delegate.h" #include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_origin/brave_origin_policy_manager.h" diff --git a/browser/brave_browser_process_impl.h b/browser/brave_browser_process_impl.h index d662a59508a..a041a302dca 100644 --- a/browser/brave_browser_process_impl.h +++ b/browser/brave_browser_process_impl.h @@ -12,6 +12,7 @@ #include "base/sequence_checker.h" #include "brave/browser/brave_browser_process.h" #include "brave/components/ai_chat/core/common/buildflags/buildflags.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_component_updater/browser/brave_component.h" #include "brave/components/brave_vpn/common/buildflags/buildflags.h" #include "brave/components/speedreader/common/buildflags/buildflags.h" @@ -74,10 +75,12 @@ namespace speedreader { class SpeedreaderRewriterService; } +#if BUILDFLAG(ENABLE_BRAVE_ADS) namespace brave_ads { class BraveStatsHelper; class ResourceComponent; } // namespace brave_ads +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) namespace ai_chat { #if BUILDFLAG(ENABLE_BRAVE_AI_CHAT_AGENT_PROFILE) @@ -125,10 +128,12 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, p3a::P3AService* p3a_service() override; brave::BraveReferralsService* brave_referrals_service() override; brave_stats::BraveStatsUpdater* brave_stats_updater() override; +#if BUILDFLAG(ENABLE_BRAVE_ADS) brave_ads::BraveStatsHelper* ads_brave_stats_helper() override; + brave_ads::ResourceComponent* resource_component() override; +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) ntp_background_images::NTPBackgroundImagesService* ntp_background_images_service() override; - brave_ads::ResourceComponent* resource_component() override; #if BUILDFLAG(ENABLE_SPEEDREADER) speedreader::SpeedreaderRewriterService* speedreader_rewriter_service() override; @@ -194,7 +199,11 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, scoped_refptr histogram_braveizer_; std::unique_ptr ntp_background_images_service_; + +#if BUILDFLAG(ENABLE_BRAVE_ADS) std::unique_ptr resource_component_; + std::unique_ptr brave_stats_helper_; +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) #if BUILDFLAG(ENABLE_SPEEDREADER) std::unique_ptr @@ -207,7 +216,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, #endif std::unique_ptr process_misc_metrics_; - std::unique_ptr brave_stats_helper_; #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) std::unique_ptr diff --git a/browser/brave_news/brave_news_controller_factory.cc b/browser/brave_news/brave_news_controller_factory.cc index 78ac7d878b0..ac1af7e0f5f 100644 --- a/browser/brave_news/brave_news_controller_factory.cc +++ b/browser/brave_news/brave_news_controller_factory.cc @@ -8,7 +8,6 @@ #include #include "base/no_destructor.h" -#include "brave/browser/brave_ads/ads_service_factory.h" #include "brave/browser/brave_news/direct_feed_fetcher_delegate_impl.h" #include "brave/components/brave_news/browser/brave_news_controller.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" @@ -51,7 +50,6 @@ BraveNewsControllerFactory::BraveNewsControllerFactory() : BrowserContextKeyedServiceFactory( "BraveNewsControllerFactory", BrowserContextDependencyManager::GetInstance()) { - DependsOn(brave_ads::AdsServiceFactory::GetInstance()); DependsOn(HistoryServiceFactory::GetInstance()); DependsOn(HostContentSettingsMapFactory::GetInstance()); } @@ -72,14 +70,12 @@ BraveNewsControllerFactory::BuildServiceInstanceForBrowserContext( if (!profile) { return nullptr; } - auto* ads_service = brave_ads::AdsServiceFactory::GetForProfile(profile); auto* history_service = HistoryServiceFactory::GetForProfile( profile, ServiceAccessType::EXPLICIT_ACCESS); auto* host_content_settings_map = HostContentSettingsMapFactory::GetForProfile(profile); return std::make_unique( - profile->GetPrefs(), ads_service, history_service, - profile->GetURLLoaderFactory(), + profile->GetPrefs(), history_service, profile->GetURLLoaderFactory(), std::make_unique( host_content_settings_map)); } diff --git a/browser/brave_search/BUILD.gn b/browser/brave_search/BUILD.gn index 161413ebccb..0089b2f689e 100644 --- a/browser/brave_search/BUILD.gn +++ b/browser/brave_search/BUILD.gn @@ -3,6 +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/. +import("//brave/components/brave_ads/buildflags/buildflags.gni") + source_set("brave_search") { sources = [ "backup_results_navigation_throttle.cc", @@ -43,7 +45,7 @@ if (!is_android) { deps = [ ":brave_search", "//base/test:test_support", - "//brave/components/brave_ads/core/public:headers", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_rewards/core", "//brave/components/brave_search/browser", "//brave/components/brave_search/common", @@ -56,6 +58,10 @@ if (!is_android) { "//net:test_support", ] + if (enable_brave_ads) { + deps += [ "//brave/components/brave_ads/core/public:headers" ] + } + defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] } } diff --git a/browser/brave_search/brave_search_browsertest.cc b/browser/brave_search/brave_search_browsertest.cc index 1f5d6b84667..2b02be9f8ad 100644 --- a/browser/brave_search/brave_search_browsertest.cc +++ b/browser/brave_search/brave_search_browsertest.cc @@ -10,8 +10,7 @@ #include "base/strings/strcat.h" #include "base/test/scoped_feature_list.h" #include "base/test/thread_test_helper.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" -#include "brave/components/brave_rewards/core/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_search/browser/brave_search_fallback_host.h" #include "brave/components/brave_search/common/features.h" #include "brave/components/constants/brave_paths.h" @@ -36,6 +35,11 @@ #include "net/test/embedded_test_server/http_response.h" #include "third_party/abseil-cpp/absl/strings/str_format.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_rewards/core/pref_names.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + using extensions::ExtensionBrowserTest; using RequestExpectationsCallback = base::RepeatingCallback; @@ -49,8 +53,6 @@ constexpr char kNotAllowedDomain[] = "brave.com"; constexpr char kBraveSearchPath[] = "/bravesearch.html"; constexpr char kPageWithCookie[] = "/simple_page_with_cookie.html"; constexpr char kPageWithoutCookie[] = "/simple_page_without_cookie.html"; -constexpr char kSearchAdsHeader[] = "Brave-Search-Ads"; -constexpr char kSearchAdsDisabledValue[] = "?0"; constexpr char kBackupSearchRedirectContent[] = R"( @@ -84,6 +86,11 @@ constexpr char kScriptDefaultAPIGetValue[] = R"( }); )"; +#if BUILDFLAG(ENABLE_BRAVE_ADS) +constexpr char kSearchAdsHeader[] = "Brave-Search-Ads"; +constexpr char kSearchAdsDisabledValue[] = "?0"; +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + std::string GetChromeFetchBackupResultsAvailScript() { return absl::StrFormat(R"( new Promise(resolve => { @@ -344,6 +351,7 @@ IN_PROC_BROWSER_TEST_F(BraveSearchTestDisabled, DefaultAPIInvisibleKnownHost) { EXPECT_EQ(false, content::EvalJs(contents, kScriptDefaultAPIExists)); } +#if BUILDFLAG(ENABLE_BRAVE_ADS) IN_PROC_BROWSER_TEST_F(BraveSearchTest, SearchAdsHeader) { base::RunLoop run_loop; SetRequestExpectationsCallback(base::BindRepeating( @@ -518,6 +526,7 @@ IN_PROC_BROWSER_TEST_F(BraveSearchTest, SearchAdsHeaderIncognitoBrowser) { run_loop.Run(); } +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) IN_PROC_BROWSER_TEST_F(BraveSearchTest, CheckNoCookieForFallback) { // Sets cookie for the search backup provider domain diff --git a/browser/brave_stats/BUILD.gn b/browser/brave_stats/BUILD.gn index 532ad6b83b1..875b2e7cc41 100644 --- a/browser/brave_stats/BUILD.gn +++ b/browser/brave_stats/BUILD.gn @@ -4,6 +4,7 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. */ import("//brave/browser/brave_stats/buildflags.gni") +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/brave_wallet/common/buildflags/buildflags.gni") import("//build/buildflag_header.gni") @@ -30,7 +31,7 @@ source_set("brave_stats") { "//brave/browser:browser_process", "//brave/browser/brave_stats:buildflags", "//brave/common", - "//brave/components/brave_ads/core", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_referrals/common", "//brave/components/brave_stats/browser", "//brave/components/brave_wallet/common/buildflags", @@ -48,6 +49,10 @@ source_set("brave_stats") { "//services/network/public/cpp", ] + if (enable_brave_ads) { + deps += [ "//brave/components/brave_ads/core" ] + } + if (enable_brave_wallet) { deps += [ "//brave/components/brave_wallet/browser", @@ -80,9 +85,8 @@ source_set("unit_tests") { ] deps = [ - "//brave/browser/brave_ads", "//brave/browser/brave_stats", - "//brave/components/brave_ads/core", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_referrals/browser", "//brave/components/brave_rewards/content", "//brave/components/brave_stats/browser", @@ -94,6 +98,13 @@ source_set("unit_tests") { "//components/prefs", ] + if (enable_brave_ads) { + deps += [ + "//brave/browser/brave_ads", + "//brave/components/brave_ads/core", + ] + } + if (enable_brave_wallet) { deps += [ "//brave/components/brave_wallet/browser", diff --git a/browser/brave_stats/brave_stats_updater.cc b/browser/brave_stats/brave_stats_updater.cc index dbabbd1671f..bed5c4baa02 100644 --- a/browser/brave_stats/brave_stats_updater.cc +++ b/browser/brave_stats/brave_stats_updater.cc @@ -23,7 +23,7 @@ #include "brave/browser/brave_stats/first_run_util.h" #include "brave/browser/brave_stats/switches.h" #include "brave/common/brave_channel_info.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_referrals/common/pref_names.h" #include "brave/components/brave_stats/browser/brave_stats_updater_util.h" #include "brave/components/brave_wallet/common/buildflags/buildflags.h" @@ -49,6 +49,10 @@ #include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/mojom/fetch_api.mojom-shared.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif + #if BUILDFLAG(ENABLE_BRAVE_WALLET) #include "brave/components/brave_wallet/browser/pref_names.h" #endif @@ -248,7 +252,11 @@ bool BraveStatsUpdater::IsReferralInitialized() { } bool BraveStatsUpdater::IsAdsEnabled() { +#if BUILDFLAG(ENABLE_BRAVE_ADS) return pref_service_->GetBoolean(brave_ads::prefs::kEnabledForLastProfile); +#else + return false; +#endif } void BraveStatsUpdater::OnProfileAdded(Profile* profile) { diff --git a/browser/brave_stats/brave_stats_updater_params.cc b/browser/brave_stats/brave_stats_updater_params.cc index 46fffab5f80..d688740d946 100644 --- a/browser/brave_stats/brave_stats_updater_params.cc +++ b/browser/brave_stats/brave_stats_updater_params.cc @@ -14,7 +14,7 @@ #include "base/time/time.h" #include "brave/browser/brave_stats/features.h" #include "brave/browser/brave_stats/first_run_util.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_referrals/common/pref_names.h" #include "brave/components/brave_stats/browser/brave_stats_updater_util.h" #include "brave/components/constants/pref_names.h" @@ -25,6 +25,10 @@ #include "net/base/url_util.h" #include "url/gurl.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif + namespace brave_stats { base::Time BraveStatsUpdaterParams::g_current_time; @@ -98,10 +102,12 @@ std::string BraveStatsUpdaterParams::GetReferralCodeParam() const { return referral_promo_code_.empty() ? "none" : referral_promo_code_; } +#if BUILDFLAG(ENABLE_BRAVE_ADS) std::string BraveStatsUpdaterParams::GetAdsEnabledParam() const { return BooleanToString(stats_pref_service_->GetBoolean( brave_ads::prefs::kEnabledForLastProfile)); } +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) std::string BraveStatsUpdaterParams::GetProcessArchParam() const { if (arch_ == ProcessArch::kArchSkip) { @@ -201,8 +207,10 @@ GURL BraveStatsUpdaterParams::GetUpdateURL( GetDateOfInstallationParam()); update_url = net::AppendQueryParameter(update_url, "ref", GetReferralCodeParam()); +#if BUILDFLAG(ENABLE_BRAVE_ADS) update_url = net::AppendQueryParameter(update_url, "adsEnabled", GetAdsEnabledParam()); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) update_url = net::AppendQueryParameter(update_url, "arch", GetProcessArchParam()); return update_url; diff --git a/browser/brave_stats/brave_stats_updater_params.h b/browser/brave_stats/brave_stats_updater_params.h index 5b8da0138c2..cbf9246529b 100644 --- a/browser/brave_stats/brave_stats_updater_params.h +++ b/browser/brave_stats/brave_stats_updater_params.h @@ -13,6 +13,7 @@ #include "base/gtest_prod_util.h" #include "base/memory/raw_ptr.h" #include "base/time/time.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_stats/browser/brave_stats_updater_util.h" class BraveStatsUpdaterTest; @@ -45,7 +46,9 @@ class BraveStatsUpdaterParams { std::string GetWeekOfInstallationParam() const; std::string GetDateOfInstallationParam() const; std::string GetReferralCodeParam() const; +#if BUILDFLAG(ENABLE_BRAVE_ADS) std::string GetAdsEnabledParam() const; +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) std::string GetProcessArchParam() const; GURL GetUpdateURL(const GURL& base_update_url, std::string_view platform_id, diff --git a/browser/brave_stats/brave_stats_updater_unittest.cc b/browser/brave_stats/brave_stats_updater_unittest.cc index 8edf0a91877..a485d992b8f 100644 --- a/browser/brave_stats/brave_stats_updater_unittest.cc +++ b/browser/brave_stats/brave_stats_updater_unittest.cc @@ -17,10 +17,9 @@ #include "base/test/metrics/histogram_tester.h" #include "base/test/scoped_feature_list.h" #include "base/time/time.h" -#include "brave/browser/brave_ads/analytics/p3a/brave_stats_helper.h" #include "brave/browser/brave_stats/brave_stats_updater_params.h" #include "brave/browser/brave_stats/features.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_referrals/browser/brave_referrals_service.h" #include "brave/components/brave_referrals/common/pref_names.h" #include "brave/components/brave_rewards/content/rewards_service.h" @@ -39,6 +38,11 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/switches.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/browser/brave_ads/analytics/p3a/brave_stats_helper.h" +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + using testing::HasSubstr; // npm run test -- brave_unit_tests --filter=BraveStatsUpdaterTest.* @@ -80,8 +84,11 @@ class BraveStatsUpdaterTest : public testing::Test { testing_local_state_.registry()); brave::RegisterPrefsForBraveReferralsService( testing_local_state_.registry()); +#if BUILDFLAG(ENABLE_BRAVE_ADS) brave_ads::BraveStatsHelper::RegisterLocalStatePrefs( testing_local_state_.registry()); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + SetCurrentTimeForTest(base::Time()); brave_stats::BraveStatsUpdaterParams::SetFirstRunForTest(true); } @@ -93,10 +100,13 @@ class BraveStatsUpdaterTest : public testing::Test { return std::make_unique( GetLocalState(), brave_stats::ProcessArch::kArchSkip); } + +#if BUILDFLAG(ENABLE_BRAVE_ADS) void SetEnableAds(bool ads_enabled) { GetLocalState()->SetBoolean(brave_ads::prefs::kEnabledForLastProfile, ads_enabled); } +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) void SetCurrentTimeForTest(const base::Time& current_time) { brave_stats::BraveStatsUpdaterParams::SetCurrentTimeForTest(current_time); @@ -240,6 +250,7 @@ TEST_F(BraveStatsUpdaterTest, IsMonthlyUpdateNeededLastCheckedNextMonth) { EXPECT_EQ(GetLocalState()->GetInteger(kLastCheckMonth), kThisMonth); } +#if BUILDFLAG(ENABLE_BRAVE_ADS) TEST_F(BraveStatsUpdaterTest, HasAdsDisabled) { brave_stats::BraveStatsUpdaterParams brave_stats_updater_params( GetLocalState(), brave_stats::ProcessArch::kArchSkip, kToday, kThisWeek, @@ -255,6 +266,7 @@ TEST_F(BraveStatsUpdaterTest, HasAdsEnabled) { SetEnableAds(true); EXPECT_EQ(brave_stats_updater_params.GetAdsEnabledParam(), "true"); } +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) TEST_F(BraveStatsUpdaterTest, HasArchSkip) { brave_stats::BraveStatsUpdaterParams brave_stats_updater_params( diff --git a/browser/net/BUILD.gn b/browser/net/BUILD.gn index 7f31f732d6b..4cb001e5206 100644 --- a/browser/net/BUILD.gn +++ b/browser/net/BUILD.gn @@ -3,6 +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/. +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -71,12 +72,10 @@ source_set("unit_tests") { "brave_static_redirect_network_delegate_helper_unittest.cc", "brave_system_request_handler_unittest.cc", "brave_user_agent_network_delegate_helper_unittest.cc", - "search_ads_header_network_delegate_helper_unittest.cc", ] deps = [ - "//brave/components/brave_ads/core", - "//brave/components/brave_ads/core/browser/service:test_support", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_component_updater/browser", "//brave/components/brave_rewards/core", "//brave/components/brave_rewards/core:features", @@ -99,4 +98,9 @@ source_set("unit_tests") { "//testing/gtest", "//third_party/abseil-cpp:absl", ] + + if (enable_brave_ads) { + sources += [ "search_ads_header_network_delegate_helper_unittest.cc" ] + deps += [ "//brave/components/brave_ads/core" ] + } } diff --git a/browser/net/brave_request_handler.cc b/browser/net/brave_request_handler.cc index f010789974f..1ec9ef9181b 100644 --- a/browser/net/brave_request_handler.cc +++ b/browser/net/brave_request_handler.cc @@ -20,7 +20,7 @@ #include "brave/browser/net/brave_stp_util.h" #include "brave/browser/net/brave_user_agent_network_delegate_helper.h" #include "brave/browser/net/global_privacy_control_network_delegate_helper.h" -#include "brave/browser/net/search_ads_header_network_delegate_helper.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_shields/core/common/features.h" #include "brave/components/brave_user_agent/common/features.h" #include "brave/components/brave_wallet/common/buildflags/buildflags.h" @@ -35,6 +35,10 @@ #include "net/base/net_errors.h" #include "third_party/blink/public/common/features.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/browser/net/search_ads_header_network_delegate_helper.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + #if BUILDFLAG(ENABLE_BRAVE_WALLET) #include "brave/browser/net/decentralized_dns_network_delegate_helper.h" #endif @@ -103,9 +107,11 @@ void BraveRequestHandler::SetupCallbacks() { before_start_transaction_callbacks_.push_back(start_transaction_callback); } +#if BUILDFLAG(ENABLE_BRAVE_ADS) start_transaction_callback = base::BindRepeating(brave::OnBeforeStartTransaction_SearchAdsHeader); before_start_transaction_callbacks_.push_back(start_transaction_callback); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) if (base::FeatureList::IsEnabled( ::brave_shields::features::kBraveAdblockCspRules)) { diff --git a/browser/net/sources.gni b/browser/net/sources.gni index e89723a1b1d..604756ed12c 100644 --- a/browser/net/sources.gni +++ b/browser/net/sources.gni @@ -3,6 +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/. +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/brave_wallet/common/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -43,8 +44,6 @@ brave_browser_net_sources = [ "//brave/browser/net/global_privacy_control_network_delegate_helper.h", "//brave/browser/net/resource_context_data.cc", "//brave/browser/net/resource_context_data.h", - "//brave/browser/net/search_ads_header_network_delegate_helper.cc", - "//brave/browser/net/search_ads_header_network_delegate_helper.h", "//brave/browser/net/url_context.cc", "//brave/browser/net/url_context.h", ] @@ -62,7 +61,7 @@ brave_browser_net_deps = [ "//brave/browser:browser_process", "//brave/browser/profiles:util", "//brave/common", - "//brave/components/brave_ads/browser", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_component_updater/browser", "//brave/components/brave_referrals/browser", "//brave/components/brave_rewards/core", @@ -116,3 +115,12 @@ if (enable_brave_wallet) { if (enable_extensions) { brave_browser_net_deps += [ "//extensions/common:common_constants" ] } + +if (enable_brave_ads) { + brave_browser_net_sources += [ + "//brave/browser/net/search_ads_header_network_delegate_helper.cc", + "//brave/browser/net/search_ads_header_network_delegate_helper.h", + ] + + brave_browser_net_deps += [ "//brave/components/brave_ads/core" ] +} diff --git a/browser/notifications/sources.gni b/browser/notifications/sources.gni index 57207d61794..73e6c0671fd 100644 --- a/browser/notifications/sources.gni +++ b/browser/notifications/sources.gni @@ -3,18 +3,24 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. -brave_browser_notifications_sources = [ - "//brave/browser/notifications/ads_notification_handler.cc", - "//brave/browser/notifications/ads_notification_handler.h", -] +import("//brave/components/brave_ads/buildflags/buildflags.gni") +brave_browser_notifications_sources = [] brave_browser_notifications_deps = [ "//base", + "//brave/components/brave_ads/buildflags", "//chrome/browser/notifications", "//third_party/abseil-cpp:absl", "//url", ] +if (enable_brave_ads) { + brave_browser_notifications_sources += [ + "//brave/browser/notifications/ads_notification_handler.cc", + "//brave/browser/notifications/ads_notification_handler.h", + ] +} + if (is_android) { brave_browser_notifications_sources += [ "//brave/browser/notifications/brave_notification_platform_bridge_helper_android.cc", diff --git a/browser/perf/brave_perf_features_processor.cc b/browser/perf/brave_perf_features_processor.cc index 30b22fb5c94..940ee254893 100644 --- a/browser/perf/brave_perf_features_processor.cc +++ b/browser/perf/brave_perf_features_processor.cc @@ -11,7 +11,7 @@ #include "brave/browser/brave_rewards/rewards_service_factory.h" #include "brave/browser/perf/brave_perf_switches.h" #include "brave/components/ai_chat/core/common/buildflags/buildflags.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_news/common/buildflags/buildflags.h" #include "brave/components/brave_rewards/content/rewards_service.h" #include "brave/components/brave_shields/content/browser/ad_block_service.h" @@ -25,6 +25,10 @@ #include "brave/components/ai_chat/core/common/pref_names.h" #endif +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif + #if BUILDFLAG(ENABLE_BRAVE_NEWS) #include "brave/components/brave_news/common/pref_names.h" #endif @@ -68,9 +72,11 @@ void MaybeEnableBraveFeaturesPrefsForPerfTesting(Profile* profile) { return; } +#if BUILDFLAG(ENABLE_BRAVE_ADS) // Notification Ads profile->GetPrefs()->SetBoolean(brave_ads::prefs::kOptedInToNotificationAds, true); +#endif #if BUILDFLAG(ENABLE_BRAVE_NEWS) // Brave news diff --git a/browser/perf/brave_perf_features_processor_browsertest.cc b/browser/perf/brave_perf_features_processor_browsertest.cc index 893fd985ed0..2e53c85dcb0 100644 --- a/browser/perf/brave_perf_features_processor_browsertest.cc +++ b/browser/perf/brave_perf_features_processor_browsertest.cc @@ -7,7 +7,7 @@ #include "brave/browser/brave_rewards/rewards_service_factory.h" #include "brave/browser/perf/brave_perf_switches.h" #include "brave/components/ai_chat/core/common/buildflags/buildflags.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_news/common/buildflags/buildflags.h" #include "brave/components/brave_rewards/content/rewards_service.h" #include "brave/components/brave_rewards/content/rewards_service_observer.h" @@ -23,6 +23,10 @@ #include "brave/components/ai_chat/core/browser/utils.h" #endif +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + #if BUILDFLAG(ENABLE_SPEEDREADER) #include "brave/browser/speedreader/speedreader_service_factory.h" #include "brave/components/speedreader/speedreader_service.h" @@ -80,10 +84,12 @@ class BraveSpeedFeatureProcessorBrowserTest : public InProcessBrowserTest { } #endif +#if BUILDFLAG(ENABLE_BRAVE_ADS) bool HasOptedInToNotificationAds() { return browser()->profile()->GetPrefs()->GetBoolean( brave_ads::prefs::kOptedInToNotificationAds); } +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) void WaitForRewardsServiceInitialized() { auto* rewards_service = brave_rewards::RewardsServiceFactory::GetForProfile( @@ -101,7 +107,9 @@ IN_PROC_BROWSER_TEST_F(BraveSpeedFeatureProcessorBrowserTest, Default) { #if BUILDFLAG(ENABLE_SPEEDREADER) EXPECT_TRUE(SpeedreaderIsEnabled()); #endif +#if BUILDFLAG(ENABLE_BRAVE_ADS) EXPECT_TRUE(HasOptedInToNotificationAds()); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) #if BUILDFLAG(ENABLE_BRAVE_NEWS) EXPECT_TRUE(BraveNewsAreEnabled()); #endif diff --git a/browser/perf/sources.gni b/browser/perf/sources.gni index 6e318059fa4..aea96c4d302 100644 --- a/browser/perf/sources.gni +++ b/browser/perf/sources.gni @@ -3,6 +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/. +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/brave_news/common/buildflags/buildflags.gni") import("//brave/components/speedreader/common/buildflags/buildflags.gni") @@ -14,7 +15,7 @@ brave_browser_perf_sources = [ brave_browser_perf_deps = [ "//base", - "//brave/components/brave_ads/core", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_news/common/buildflags", "//brave/components/brave_rewards/content", "//brave/components/brave_shields/content/browser", @@ -23,6 +24,10 @@ brave_browser_perf_deps = [ "//components/prefs", ] +if (enable_brave_ads) { + brave_browser_perf_deps += [ "//brave/components/brave_ads/core" ] +} + if (enable_speedreader) { brave_browser_perf_deps += [ "//brave/components/speedreader" ] } diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index d4382e22ab7..707d583a5ef 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -11,7 +11,6 @@ #include "base/check.h" #include "base/path_service.h" -#include "brave/browser/brave_ads/ads_service_factory.h" #include "brave/browser/brave_rewards/rewards_service_factory.h" #include "brave/browser/misc_metrics/profile_misc_metrics_service_factory.h" #include "brave/browser/perf/brave_perf_features_processor.h" @@ -19,6 +18,7 @@ #include "brave/browser/request_otr/request_otr_service_factory.h" #include "brave/browser/url_sanitizer/url_sanitizer_service_factory.h" #include "brave/components/ai_chat/core/common/buildflags/buildflags.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_shields/content/browser/brave_shields_util.h" #include "brave/components/brave_shields/core/browser/brave_shields_p3a.h" #include "brave/components/brave_shields/core/browser/brave_shields_utils.h" @@ -53,6 +53,10 @@ #include "chrome/browser/user_education/user_education_service_factory.h" #endif +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/browser/brave_ads/ads_service_factory.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + #if BUILDFLAG(ENABLE_BRAVE_WALLET) #include "brave/browser/brave_wallet/brave_wallet_service_factory.h" #endif @@ -201,7 +205,9 @@ void BraveProfileManager::DoFinalInitForServices(Profile* profile, #endif perf::MaybeEnableBraveFeaturesServicesAndComponentsForPerfTesting(profile); +#if BUILDFLAG(ENABLE_BRAVE_ADS) brave_ads::AdsServiceFactory::GetForProfile(profile); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) brave_rewards::RewardsServiceFactory::GetForProfile(profile); #if BUILDFLAG(ENABLE_BRAVE_WALLET) brave_wallet::BraveWalletServiceFactory::GetServiceForContext(profile); diff --git a/browser/profiles/brave_profile_manager_browsertest.cc b/browser/profiles/brave_profile_manager_browsertest.cc index b8a3575a1e5..77861a86243 100644 --- a/browser/profiles/brave_profile_manager_browsertest.cc +++ b/browser/profiles/brave_profile_manager_browsertest.cc @@ -6,8 +6,8 @@ #include #include "base/functional/callback_helpers.h" -#include "brave/browser/brave_ads/ads_service_factory.h" #include "brave/browser/brave_rewards/rewards_service_factory.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/constants/pref_names.h" #include "brave/components/tor/buildflags/buildflags.h" #include "brave/components/tor/tor_constants.h" @@ -30,6 +30,9 @@ #include "chrome/test/base/ui_test_utils.h" #endif +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/browser/brave_ads/ads_service_factory.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) class BraveProfileManagerTest : public PlatformBrowserTest { }; @@ -56,8 +59,10 @@ IN_PROC_BROWSER_TEST_F(BraveProfileManagerTest, EXPECT_EQ(brave_rewards::RewardsServiceFactory::GetForProfile(guest_profile), nullptr); +#if BUILDFLAG(ENABLE_BRAVE_ADS) EXPECT_EQ(brave_ads::AdsServiceFactory::GetForProfile(guest_profile), nullptr); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) ASSERT_TRUE(otr_profile->IsOffTheRecord()); @@ -66,8 +71,10 @@ IN_PROC_BROWSER_TEST_F(BraveProfileManagerTest, EXPECT_EQ(brave_rewards::RewardsServiceFactory::GetForProfile(otr_profile), nullptr); +#if BUILDFLAG(ENABLE_BRAVE_ADS) EXPECT_NE(brave_ads::AdsServiceFactory::GetForProfile(profile), nullptr); EXPECT_EQ(brave_ads::AdsServiceFactory::GetForProfile(otr_profile), nullptr); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) } #endif diff --git a/browser/resources/settings/BUILD.gn b/browser/resources/settings/BUILD.gn index faf82e5d254..4190dd9549d 100644 --- a/browser/resources/settings/BUILD.gn +++ b/browser/resources/settings/BUILD.gn @@ -6,6 +6,7 @@ import("//brave/browser/shell_integrations/buildflags/buildflags.gni") import("//brave/build/config.gni") import("//brave/components/ai_chat/core/common/buildflags/buildflags.gni") +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/brave_vpn/common/buildflags/buildflags.gni") import("//brave/components/brave_wallet/common/buildflags/buildflags.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") @@ -86,6 +87,7 @@ generate_grd("build_grd") { preprocess_if_expr("preprocess") { defines = [ "enable_ai_chat=$enable_ai_chat", + "enable_brave_ads=$enable_brave_ads", "enable_tor=$enable_tor", "enable_brave_wayback_machine=$enable_brave_wayback_machine", "enable_brave_vpn=$enable_brave_vpn", diff --git a/browser/resources/settings/br/clear_browsing_data_dialog.ts b/browser/resources/settings/br/clear_browsing_data_dialog.ts index 737c7f7b5bc..59069adc087 100644 --- a/browser/resources/settings/br/clear_browsing_data_dialog.ts +++ b/browser/resources/settings/br/clear_browsing_data_dialog.ts @@ -79,13 +79,15 @@ RegisterPolymerTemplateModifications({ saveButton.textContent = loadTimeData.getString('save') } - // Append clear Brave Ads data link const body = templateContent.querySelector('[slot="body"]') if (!body) { console.error( '[Settings] missing \'slot="body"\' in clear-browsing-data-dialog') return } + +// + // Append clear Brave Ads data link body.insertAdjacentHTML( 'beforeend', getTrustedHTML` @@ -103,6 +105,7 @@ RegisterPolymerTemplateModifications({ clearBraveAdsLink.textContent = loadTimeData.getString('clearBraveAdsData') } +// // Append reset Brave Rewards data link body.insertAdjacentHTML( diff --git a/browser/search_engines/search_engine_tracker.cc b/browser/search_engines/search_engine_tracker.cc index 8d3144505ca..22290ce4645 100644 --- a/browser/search_engines/search_engine_tracker.cc +++ b/browser/search_engines/search_engine_tracker.cc @@ -14,7 +14,7 @@ #include "base/no_destructor.h" #include "base/strings/string_util.h" #include "base/time/time.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_rewards/core/pref_names.h" #include "brave/components/brave_search_conversion/p3a.h" #include "brave/components/brave_search_conversion/utils.h" @@ -25,6 +25,10 @@ #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/pref_registry/pref_registry_syncable.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif + namespace { // Preference name for last switch report timestamp (new location in local @@ -219,11 +223,14 @@ SearchEngineTracker::SearchEngineTracker( kWebDiscoveryEnabled, base::BindRepeating(&SearchEngineTracker::RecordWebDiscoveryEnabledP3A, base::Unretained(this))); +#if BUILDFLAG(ENABLE_BRAVE_ADS) pref_change_registrar_.Add( brave_ads::prefs::kOptedInToNotificationAds, base::BindRepeating(&SearchEngineTracker::RecordWebDiscoveryEnabledP3A, base::Unretained(this))); -#endif +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) +#endif // BUILDFLAG(ENABLE_EXTENSIONS) || + // BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE) } SearchEngineTracker::~SearchEngineTracker() = default; @@ -269,10 +276,12 @@ void SearchEngineTracker::OnTemplateURLServiceChanged() { void SearchEngineTracker::RecordWebDiscoveryEnabledP3A() { bool enabled = profile_prefs_->GetBoolean(kWebDiscoveryEnabled); UMA_HISTOGRAM_BOOLEAN(kWebDiscoveryEnabledMetric, enabled); +#if BUILDFLAG(ENABLE_BRAVE_ADS) UMA_HISTOGRAM_BOOLEAN( kWebDiscoveryAndAdsMetric, enabled && profile_prefs_->GetBoolean( brave_ads::prefs::kOptedInToNotificationAds)); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) // Record web discovery default engine metric int answer = INT_MAX - 1; diff --git a/browser/search_engines/search_engine_tracker.h b/browser/search_engines/search_engine_tracker.h index 179a638b237..3270f41e42d 100644 --- a/browser/search_engines/search_engine_tracker.h +++ b/browser/search_engines/search_engine_tracker.h @@ -11,6 +11,7 @@ #include "base/memory/raw_ptr.h" #include "base/scoped_observation.h" #include "base/timer/wall_clock_timer.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/web_discovery/buildflags/buildflags.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/core/keyed_service.h" @@ -35,8 +36,10 @@ inline constexpr char kSwitchSearchEngineMetric[] = "Brave.Search.SwitchEngine.2"; inline constexpr char kWebDiscoveryEnabledMetric[] = "Brave.Search.WebDiscoveryEnabled"; +#if BUILDFLAG(ENABLE_BRAVE_ADS) inline constexpr char kWebDiscoveryAndAdsMetric[] = "Brave.Search.WebDiscoveryAndAds"; +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) inline constexpr char kWebDiscoveryDefaultEngineMetric[] = "Brave.Search.WebDiscoveryDefaultEngine"; inline constexpr char kRewardsDefaultEngineMetric[] = diff --git a/browser/search_engines/search_engine_tracker_browsertest.cc b/browser/search_engines/search_engine_tracker_browsertest.cc index 91dbc185de9..e01b55a5e4f 100644 --- a/browser/search_engines/search_engine_tracker_browsertest.cc +++ b/browser/search_engines/search_engine_tracker_browsertest.cc @@ -9,7 +9,7 @@ #include "base/test/metrics/histogram_tester.h" #include "brave/browser/ui/browser_commands.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_rewards/core/pref_names.h" #include "brave/components/constants/pref_names.h" #include "brave/components/search_engines/brave_prepopulated_engines.h" @@ -29,6 +29,10 @@ #include "content/public/test/browser_test.h" #include "extensions/buildflags/buildflags.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_ads/core/public/prefs/pref_names.h" +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + class SearchEngineProviderP3ATest : public InProcessBrowserTest { public: SearchEngineProviderP3ATest() { @@ -256,19 +260,25 @@ IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest, WebDiscoveryEnabledP3A) { histogram_tester_->ExpectBucketCount(kWebDiscoveryDefaultEngineMetric, SearchEngineP3A::kDuckDuckGo, 1); +#if BUILDFLAG(ENABLE_BRAVE_ADS) histogram_tester_->ExpectUniqueSample(kWebDiscoveryAndAdsMetric, 0, 3); prefs->SetBoolean(brave_ads::prefs::kOptedInToNotificationAds, true); histogram_tester_->ExpectBucketCount(kWebDiscoveryAndAdsMetric, 1, 1); histogram_tester_->ExpectBucketCount(kWebDiscoveryDefaultEngineMetric, SearchEngineP3A::kDuckDuckGo, 2); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) prefs->SetBoolean(kWebDiscoveryEnabled, false); histogram_tester_->ExpectBucketCount(kWebDiscoveryEnabledMetric, 0, 2); histogram_tester_->ExpectBucketCount(kWebDiscoveryDefaultEngineMetric, INT_MAX - 1, 2); +#if BUILDFLAG(ENABLE_BRAVE_ADS) histogram_tester_->ExpectBucketCount(kWebDiscoveryAndAdsMetric, 0, 4); histogram_tester_->ExpectTotalCount(kWebDiscoveryAndAdsMetric, 5); histogram_tester_->ExpectTotalCount(kWebDiscoveryDefaultEngineMetric, 5); +#else + histogram_tester_->ExpectTotalCount(kWebDiscoveryDefaultEngineMetric, 4); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) } #endif diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 157b3d68856..cb0beca9cc9 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -816,7 +816,6 @@ source_set("ui") { "//brave/browser/brave_rewards:util", "//brave/browser/misc_metrics", "//brave/browser/shell_integrations/buildflags", - "//brave/browser/ui/brave_ads", "//brave/browser/ui/brave_tooltips", # //chrome/browser/ui depends on //brave/browser/ui, add this target here @@ -1009,11 +1008,14 @@ source_set("ui") { ] deps += [ - "//brave/browser/ui/views/brave_ads", "//brave/browser/ui/views/brave_tooltips", "//brave/browser/ui/views/page_info", "//ui/views/controls/webview", ] + + if (enable_brave_ads) { + deps += [ "//brave/browser/ui/views/brave_ads" ] + } } if (enable_text_recognition) { diff --git a/browser/ui/config.gni b/browser/ui/config.gni index db54526ae9f..827f35824bd 100644 --- a/browser/ui/config.gni +++ b/browser/ui/config.gni @@ -4,13 +4,14 @@ # You can obtain one at https://mozilla.org/MPL/2.0/. import("//brave/components/ai_chat/core/common/buildflags/buildflags.gni") +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/brave_news/common/buildflags/buildflags.gni") import("//brave/components/containers/buildflags/buildflags.gni") import("//brave/components/speedreader/common/buildflags/buildflags.gni") import("//build/config/ui.gni") -brave_ui_allow_circular_includes_from = - [ "//brave/browser/ui/webui/ads_internals" ] +brave_ui_allow_circular_includes_from = [] + if (enable_ai_chat) { brave_ui_allow_circular_includes_from += [ "//brave/browser/ui/webui/ai_chat" ] @@ -63,6 +64,11 @@ if (toolkit_views) { } } +if (enable_brave_ads) { + brave_ui_allow_circular_includes_from += + [ "//brave/browser/ui/webui/ads_internals" ] +} + if (enable_speedreader) { brave_ui_allow_circular_includes_from += [ "//brave/browser/ui/speedreader" ] } diff --git a/browser/ui/webui/brave_rewards/rewards_page_handler.cc b/browser/ui/webui/brave_rewards/rewards_page_handler.cc index 913953fb6a4..622bda4b872 100644 --- a/browser/ui/webui/brave_rewards/rewards_page_handler.cc +++ b/browser/ui/webui/brave_rewards/rewards_page_handler.cc @@ -21,6 +21,7 @@ #include "brave/components/brave_adaptive_captcha/brave_adaptive_captcha_service.h" #include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/browser/service/ads_service.h" +#include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "brave/components/brave_rewards/content/rewards_p3a.h" #include "brave/components/brave_rewards/content/rewards_service.h" #include "brave/components/brave_rewards/content/rewards_service_observer.h" diff --git a/browser/ui/webui/brave_rewards/rewards_page_handler.h b/browser/ui/webui/brave_rewards/rewards_page_handler.h index fd3520baca2..ec3b78d01db 100644 --- a/browser/ui/webui/brave_rewards/rewards_page_handler.h +++ b/browser/ui/webui/brave_rewards/rewards_page_handler.h @@ -10,6 +10,7 @@ #include #include "base/memory/raw_ptr.h" +#include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_rewards/core/mojom/rewards_page.mojom.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index 3405546b9e9..c53e25bc56d 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -15,7 +15,6 @@ #include "brave/browser/brave_browser_features.h" #include "brave/browser/brave_rewards/rewards_util.h" #include "brave/browser/ntp_background/view_counter_service_factory.h" -#include "brave/browser/ui/webui/ads_internals/ads_internals_ui.h" #include "brave/browser/ui/webui/brave_rewards/rewards_page_ui.h" #include "brave/browser/ui/webui/brave_rewards/rewards_web_ui_utils.h" #include "brave/browser/ui/webui/brave_rewards_internals_ui.h" @@ -77,6 +76,7 @@ #if BUILDFLAG(ENABLE_BRAVE_ADS) #include "brave/browser/brave_ads/ads_service_factory.h" +#include "brave/browser/ui/webui/ads_internals/ads_internals_ui.h" #endif #if BUILDFLAG(ENABLE_BRAVE_WALLET) @@ -110,13 +110,15 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { Profile* profile = Profile::FromBrowserContext( web_ui->GetWebContents()->GetBrowserContext()); CHECK(profile); - if (host == kAdsInternalsHost) { + if (host == kSkusInternalsHost) { + return new SkusInternalsUI(web_ui, url.host()); +#if BUILDFLAG(ENABLE_BRAVE_ADS) + } else if (host == kAdsInternalsHost) { return new AdsInternalsUI( web_ui, url.host(), brave_ads::AdsServiceFactory::GetForProfile(profile), *profile->GetPrefs()); - } else if (host == kSkusInternalsHost) { - return new SkusInternalsUI(web_ui, url.host()); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) } else if (host == kRewardsPageHost && // We don't want to check for supported profile type here because // we want private windows to redirect to the regular profile. @@ -232,8 +234,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, (url.host() == kRewriterUIHost && ai_rewriter::features::IsAIRewriterEnabled()) || #endif - url.host() == kRewardsPageHost || url.host() == kRewardsInternalsHost || - (url.host() == kAdsInternalsHost && !profile->IsIncognitoProfile())) { + url.host() == kRewardsPageHost || url.host() == kRewardsInternalsHost +#if BUILDFLAG(ENABLE_BRAVE_ADS) + || (url.host() == kAdsInternalsHost && !profile->IsIncognitoProfile()) +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) + ) { return &NewWebUI; } diff --git a/browser/ui/webui/settings/brave_clear_browsing_data_handler.cc b/browser/ui/webui/settings/brave_clear_browsing_data_handler.cc index a0f64f866a1..6d5bac875d0 100644 --- a/browser/ui/webui/settings/brave_clear_browsing_data_handler.cc +++ b/browser/ui/webui/settings/brave_clear_browsing_data_handler.cc @@ -9,12 +9,15 @@ #include "base/check_op.h" #include "base/functional/bind.h" #include "base/functional/callback_helpers.h" -#include "brave/browser/brave_ads/ads_service_factory.h" -#include "brave/components/brave_ads/core/browser/service/ads_service.h" #include "brave/components/brave_rewards/core/pref_names.h" #include "chrome/browser/profiles/profile.h" #include "components/prefs/pref_service.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/browser/brave_ads/ads_service_factory.h" +#include "brave/components/brave_ads/core/browser/service/ads_service.h" +#endif + namespace settings { BraveClearBrowsingDataHandler::BraveClearBrowsingDataHandler( @@ -41,11 +44,13 @@ void BraveClearBrowsingDataHandler::RegisterMessages() { base::BindRepeating( &BraveClearBrowsingDataHandler::HandleGetBraveRewardsEnabled, base::Unretained(this))); +#if BUILDFLAG(ENABLE_BRAVE_ADS) web_ui()->RegisterMessageCallback( "clearBraveAdsData", base::BindRepeating( &BraveClearBrowsingDataHandler::HandleClearBraveAdsData, base::Unretained(this))); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) } void BraveClearBrowsingDataHandler::HandleGetBraveRewardsEnabled( @@ -59,6 +64,7 @@ void BraveClearBrowsingDataHandler::HandleGetBraveRewardsEnabled( ResolveJavascriptCallback(args[0], rewards_enabled); } +#if BUILDFLAG(ENABLE_BRAVE_ADS) void BraveClearBrowsingDataHandler::HandleClearBraveAdsData( const base::Value::List& /*args*/) { if (auto* ads_service = @@ -66,6 +72,7 @@ void BraveClearBrowsingDataHandler::HandleClearBraveAdsData( ads_service->ClearData(/*intentional*/ base::DoNothing()); } } +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) void BraveClearBrowsingDataHandler::OnRewardsEnabledPreferenceChanged() { if (!IsJavascriptAllowed()) { diff --git a/browser/ui/webui/settings/brave_clear_browsing_data_handler.h b/browser/ui/webui/settings/brave_clear_browsing_data_handler.h index c0e38f3413f..84cf622e68c 100644 --- a/browser/ui/webui/settings/brave_clear_browsing_data_handler.h +++ b/browser/ui/webui/settings/brave_clear_browsing_data_handler.h @@ -7,6 +7,7 @@ #define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_CLEAR_BROWSING_DATA_HANDLER_H_ #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.h" #include "components/prefs/pref_change_registrar.h" @@ -28,7 +29,9 @@ class BraveClearBrowsingDataHandler : public ClearBrowsingDataHandler { void HandleGetBraveRewardsEnabled(const base::Value::List& args); +#if BUILDFLAG(ENABLE_BRAVE_ADS) void HandleClearBraveAdsData(const base::Value::List& args); +#endif // BUILDFLAG(ENABLE_BRAVE_ADS) void OnRewardsEnabledPreferenceChanged(); diff --git a/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_feature.h b/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_feature.h index db8ba9a1eee..4f8fa13241c 100644 --- a/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_feature.h +++ b/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_feature.h @@ -11,8 +11,11 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" #include "brave/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_constants.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "build/build_config.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { BASE_DECLARE_FEATURE(kCustomNotificationAdFeature); diff --git a/components/brave_ads/browser/component_updater/resource_component.h b/components/brave_ads/browser/component_updater/resource_component.h index 30f614e9f36..6d2b06f325d 100644 --- a/components/brave_ads/browser/component_updater/resource_component.h +++ b/components/brave_ads/browser/component_updater/resource_component.h @@ -17,8 +17,11 @@ #include "brave/components/brave_ads/browser/component_updater/resource_component_registrar.h" #include "brave/components/brave_ads/browser/component_updater/resource_component_registrar_delegate.h" #include "brave/components/brave_ads/browser/component_updater/resource_info.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_component_updater/browser/brave_component.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { class ResourceComponent final : public ResourceComponentRegistrarDelegate { diff --git a/components/brave_ads/buildflags/buildflags.gni b/components/brave_ads/buildflags/buildflags.gni index ed728717adf..c5b2a60936f 100644 --- a/components/brave_ads/buildflags/buildflags.gni +++ b/components/brave_ads/buildflags/buildflags.gni @@ -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/. +import("//brave/components/brave_origin/buildflags/buildflags.gni") + declare_args() { - # Set `enable_brave_ads=!is_brave_origin_branded` once all PRs migrating - # Brave Ads code under ENABLE_BRAVE_ADS build flag have landed. - enable_brave_ads = true + enable_brave_ads = !is_brave_origin_branded } diff --git a/components/brave_ads/core/browser/internals/BUILD.gn b/components/brave_ads/core/browser/internals/BUILD.gn index 2906bc4020a..5fe7c6652e3 100644 --- a/components/brave_ads/core/browser/internals/BUILD.gn +++ b/components/brave_ads/core/browser/internals/BUILD.gn @@ -17,6 +17,7 @@ source_set("internals") { public_deps = [ "//base", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_rewards/core", "//brave/components/services/bat_ads/public/interfaces", "//components/prefs", diff --git a/components/brave_ads/core/browser/internals/ads_internals_handler.h b/components/brave_ads/core/browser/internals/ads_internals_handler.h index 15c0ad40908..246ad6bf049 100644 --- a/components/brave_ads/core/browser/internals/ads_internals_handler.h +++ b/components/brave_ads/core/browser/internals/ads_internals_handler.h @@ -11,12 +11,15 @@ #include "base/memory/weak_ptr.h" #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/browser/service/ads_service_callback.h" #include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h" #include "components/prefs/pref_change_registrar.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class PrefService; namespace brave_ads { diff --git a/components/brave_ads/core/browser/network/BUILD.gn b/components/brave_ads/core/browser/network/BUILD.gn index 19d6e3a06f0..0d786a0410c 100644 --- a/components/brave_ads/core/browser/network/BUILD.gn +++ b/components/brave_ads/core/browser/network/BUILD.gn @@ -30,6 +30,7 @@ source_set("network") { ] deps = [ + "//brave/components/brave_ads/buildflags", "//brave/components/brave_ads/core/public:headers", "//components/prefs", "//mojo/public/cpp/bindings", diff --git a/components/brave_ads/core/browser/network/network_client.h b/components/brave_ads/core/browser/network/network_client.h index b0960b0d16b..9b05381fe3e 100644 --- a/components/brave_ads/core/browser/network/network_client.h +++ b/components/brave_ads/core/browser/network/network_client.h @@ -13,11 +13,14 @@ #include "base/memory/raw_ref.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/browser/network/network_client_callback.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "services/network/public/cpp/network_context_getter.h" #include "url/gurl.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class PrefService; namespace network { diff --git a/components/brave_ads/core/browser/service/BUILD.gn b/components/brave_ads/core/browser/service/BUILD.gn index 8f8716bcc0a..8002e25de97 100644 --- a/components/brave_ads/core/browser/service/BUILD.gn +++ b/components/brave_ads/core/browser/service/BUILD.gn @@ -3,6 +3,9 @@ # 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/. +# The target provides the AdsService interface and related types without +# depending on Brave Ads implementation targets, allowing it to be used even +# when Brave Ads is disabled by build flag. source_set("service") { sources = [ "ads_service.cc", diff --git a/components/brave_ads/core/browser/service/ads_service.h b/components/brave_ads/core/browser/service/ads_service.h index 895ca83450e..b332a5b6c1d 100644 --- a/components/brave_ads/core/browser/service/ads_service.h +++ b/components/brave_ads/core/browser/service/ads_service.h @@ -25,6 +25,12 @@ class GURL; namespace brave_ads { +// AdsService is the key interface for the Brave Ads component, managing ad +// serving, user interactions, and ad-related events. It handles all ad types +// including notification ads, new tab page ads, and search result ads. +// Note: This header can be included even when Brave Ads is disabled by build +// flag. When Brave Ads is disabled, the pointer to AdsService should be +// nullptr and no ads functionality should be available. class AdsService : public KeyedService { public: class Delegate { diff --git a/components/brave_ads/core/browser/virtual_pref/BUILD.gn b/components/brave_ads/core/browser/virtual_pref/BUILD.gn index 8add820c4d1..d9f22228cdf 100644 --- a/components/brave_ads/core/browser/virtual_pref/BUILD.gn +++ b/components/brave_ads/core/browser/virtual_pref/BUILD.gn @@ -19,6 +19,7 @@ source_set("virtual_pref") { deps = [ "//base/version_info", + "//brave/components/brave_ads/buildflags", "//brave/components/brave_ads/core/public:headers", "//brave/components/ntp_background_images/common", "//brave/components/skus/browser", diff --git a/components/brave_ads/core/browser/virtual_pref/virtual_pref_provider.h b/components/brave_ads/core/browser/virtual_pref/virtual_pref_provider.h index 5a2d8ed1c8d..bd6b0d154d4 100644 --- a/components/brave_ads/core/browser/virtual_pref/virtual_pref_provider.h +++ b/components/brave_ads/core/browser/virtual_pref/virtual_pref_provider.h @@ -12,6 +12,9 @@ #include "base/memory/raw_ptr.h" #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); class PrefService; diff --git a/components/brave_ads/core/public/BUILD.gn b/components/brave_ads/core/public/BUILD.gn index 3304e965bbb..ce184ad5530 100644 --- a/components/brave_ads/core/public/BUILD.gn +++ b/components/brave_ads/core/public/BUILD.gn @@ -55,11 +55,16 @@ source_set("headers") { "//url", ] - public_deps = [ "//brave/components/brave_ads/core/mojom" ] + public_deps = [ + "//brave/components/brave_ads/buildflags", + "//brave/components/brave_ads/core/mojom", + ] } source_set("test_support") { testonly = true sources = [ "common/locale/scoped_locale_for_testing.h" ] + + deps = [ "//brave/components/brave_ads/buildflags" ] } diff --git a/components/brave_ads/core/public/account/confirmations/confirmation_type.h b/components/brave_ads/core/public/account/confirmations/confirmation_type.h index f7646d0ed4c..8fc3530a4e6 100644 --- a/components/brave_ads/core/public/account/confirmations/confirmation_type.h +++ b/components/brave_ads/core/public/account/confirmations/confirmation_type.h @@ -8,8 +8,11 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { // Returns a `mojom::ConfirmationType` value based on the string input. diff --git a/components/brave_ads/core/public/ad_units/ad_info.h b/components/brave_ads/core/public/ad_units/ad_info.h index 6d83d04c729..b9a4e7b1fbd 100644 --- a/components/brave_ads/core/public/ad_units/ad_info.h +++ b/components/brave_ads/core/public/ad_units/ad_info.h @@ -8,9 +8,12 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "url/gurl.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { struct AdInfo { diff --git a/components/brave_ads/core/public/ad_units/ad_type.h b/components/brave_ads/core/public/ad_units/ad_type.h index 8d878f998cc..1399adfc1a9 100644 --- a/components/brave_ads/core/public/ad_units/ad_type.h +++ b/components/brave_ads/core/public/ad_units/ad_type.h @@ -8,8 +8,11 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { // Returns a `mojom::AdType` value based on the string input. diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_constants.h b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_constants.h index ac0717f53ed..97dd5b63bfb 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_constants.h +++ b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_constants.h @@ -6,6 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_CONSTANTS_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_CONSTANTS_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { inline constexpr char kNewTabPageAdTypeKey[] = "type"; diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.h b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.h index bcd2d5b6a66..bed42e22cdf 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.h +++ b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.h @@ -9,8 +9,11 @@ #include #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { std::optional ToMojomNewTabPageAdEventType( diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h index a250f80d9a6..edef89b41a3 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h +++ b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h @@ -8,6 +8,9 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace base { class TimeDelta; diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h index 43a1d29a864..6824527eb28 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h +++ b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h @@ -8,8 +8,11 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/public/ad_units/ad_info.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { struct NewTabPageAdInfo final : AdInfo { diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_prefetcher.h b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_prefetcher.h index 102c31c746d..2e807f84abc 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_prefetcher.h +++ b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_prefetcher.h @@ -8,8 +8,11 @@ #include "base/memory/raw_ref.h" #include "base/memory/weak_ptr.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { class AdsService; diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_util.h b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_util.h index 292652ee366..7c25b2ad25b 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_util.h +++ b/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_util.h @@ -9,8 +9,11 @@ #include #include "base/types/optional_ref.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { struct NewTabPageAdInfo; diff --git a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_constants.h b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_constants.h index d7dbb259cde..8b739404b24 100644 --- a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_constants.h +++ b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_constants.h @@ -9,8 +9,11 @@ #include #include "base/time/time.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "build/build_config.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { inline constexpr char kNotificationAdTypeKey[] = "type"; diff --git a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h index 8341406691d..78b74d94b44 100644 --- a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h +++ b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h @@ -9,8 +9,11 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" #include "base/time/time.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_constants.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { BASE_DECLARE_FEATURE(kNotificationAdFeature); diff --git a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h index 826b4df27a3..65b432cbe57 100644 --- a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h +++ b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h @@ -8,8 +8,11 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/public/ad_units/ad_info.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { struct NotificationAdInfo final : AdInfo { diff --git a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_value_util.h b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_value_util.h index bc560fc40ad..bdcbc9913ea 100644 --- a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_value_util.h +++ b/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_value_util.h @@ -8,6 +8,9 @@ #include "base/containers/circular_deque.h" #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace brave_ads { diff --git a/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_feature.h b/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_feature.h index 5e1dd4cb8c3..186ccff8d25 100644 --- a/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_feature.h +++ b/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_feature.h @@ -8,6 +8,9 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace brave_ads { diff --git a/components/brave_ads/core/public/ads.h b/components/brave_ads/core/public/ads.h index dfdf34380f5..fc0c1dbb62e 100644 --- a/components/brave_ads/core/public/ads.h +++ b/components/brave_ads/core/public/ads.h @@ -10,10 +10,13 @@ #include #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_ads/core/public/ads_callback.h" #include "brave/components/brave_ads/core/public/ads_observer.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace base { class Time; } // namespace base diff --git a/components/brave_ads/core/public/ads_callback.h b/components/brave_ads/core/public/ads_callback.h index 2a1ef124d29..c7fa3478f70 100644 --- a/components/brave_ads/core/public/ads_callback.h +++ b/components/brave_ads/core/public/ads_callback.h @@ -11,11 +11,14 @@ #include "base/functional/callback.h" #include "base/types/optional_ref.h" #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" #include "brave/components/brave_ads/core/public/history/ad_history_item_info.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { using ResultCallback = base::OnceCallback; diff --git a/components/brave_ads/core/public/ads_client/ads_client.h b/components/brave_ads/core/public/ads_client/ads_client.h index fbfdb2c2972..149f2332b1d 100644 --- a/components/brave_ads/core/public/ads_client/ads_client.h +++ b/components/brave_ads/core/public/ads_client/ads_client.h @@ -10,9 +10,12 @@ #include #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.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" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { class AdsClientNotifierObserver; diff --git a/components/brave_ads/core/public/ads_client/ads_client_callback.h b/components/brave_ads/core/public/ads_client/ads_client_callback.h index 04452f2a0ba..6aa9a642fed 100644 --- a/components/brave_ads/core/public/ads_client/ads_client_callback.h +++ b/components/brave_ads/core/public/ads_client/ads_client_callback.h @@ -11,9 +11,12 @@ #include "base/files/file.h" #include "base/functional/callback.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_ads/core/public/history/site_history.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { using SaveCallback = base::OnceCallback; diff --git a/components/brave_ads/core/public/ads_client/ads_client_notifier.h b/components/brave_ads/core/public/ads_client/ads_client_notifier.h index a3b48e3cb5f..c1c69b27531 100644 --- a/components/brave_ads/core/public/ads_client/ads_client_notifier.h +++ b/components/brave_ads/core/public/ads_client/ads_client_notifier.h @@ -13,9 +13,12 @@ #include "base/memory/weak_ptr.h" #include "base/observer_list.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client_notifier_interface.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client_notifier_observer.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class GURL; namespace brave_ads { diff --git a/components/brave_ads/core/public/ads_client/ads_client_notifier_interface.h b/components/brave_ads/core/public/ads_client/ads_client_notifier_interface.h index 26e034d902f..2e25c97c91d 100644 --- a/components/brave_ads/core/public/ads_client/ads_client_notifier_interface.h +++ b/components/brave_ads/core/public/ads_client/ads_client_notifier_interface.h @@ -10,6 +10,10 @@ #include #include +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class GURL; namespace base { diff --git a/components/brave_ads/core/public/ads_client/ads_client_notifier_observer.h b/components/brave_ads/core/public/ads_client/ads_client_notifier_observer.h index 3affe50b97a..3f423d428eb 100644 --- a/components/brave_ads/core/public/ads_client/ads_client_notifier_observer.h +++ b/components/brave_ads/core/public/ads_client/ads_client_notifier_observer.h @@ -12,8 +12,11 @@ #include "base/observer_list_types.h" #include "base/time/time.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "url/gurl.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { class AdsClientNotifierObserver : public base::CheckedObserver { diff --git a/components/brave_ads/core/public/ads_constants.h b/components/brave_ads/core/public/ads_constants.h index 3450da7cba1..4f0b84d9842 100644 --- a/components/brave_ads/core/public/ads_constants.h +++ b/components/brave_ads/core/public/ads_constants.h @@ -6,6 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_CONSTANTS_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_CONSTANTS_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { inline constexpr char kTraceEventCategory[] = "brave.ads"; diff --git a/components/brave_ads/core/public/ads_observer.h b/components/brave_ads/core/public/ads_observer.h index 5f8947c4995..7f07ac18e18 100644 --- a/components/brave_ads/core/public/ads_observer.h +++ b/components/brave_ads/core/public/ads_observer.h @@ -6,8 +6,11 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_OBSERVER_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_OBSERVER_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { class AdsObserver { diff --git a/components/brave_ads/core/public/ads_util.h b/components/brave_ads/core/public/ads_util.h index b1ac44e21f4..d68082cc103 100644 --- a/components/brave_ads/core/public/ads_util.h +++ b/components/brave_ads/core/public/ads_util.h @@ -6,6 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_UTIL_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { // Determines whether ads are supported in the user's region, returning `true` diff --git a/components/brave_ads/core/public/common/functional/once_closure_task_queue.h b/components/brave_ads/core/public/common/functional/once_closure_task_queue.h index 52f29f70524..c905a86abca 100644 --- a/components/brave_ads/core/public/common/functional/once_closure_task_queue.h +++ b/components/brave_ads/core/public/common/functional/once_closure_task_queue.h @@ -8,6 +8,9 @@ #include "base/containers/queue.h" #include "base/functional/callback.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace brave_ads { diff --git a/components/brave_ads/core/public/common/locale/locale_util.h b/components/brave_ads/core/public/common/locale/locale_util.h index e61e88f2387..15fce5a8cab 100644 --- a/components/brave_ads/core/public/common/locale/locale_util.h +++ b/components/brave_ads/core/public/common/locale/locale_util.h @@ -8,6 +8,10 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { inline constexpr char kDefaultLanguageCode[] = "en"; diff --git a/components/brave_ads/core/public/common/locale/scoped_locale_for_testing.h b/components/brave_ads/core/public/common/locale/scoped_locale_for_testing.h index 5349d3f00e5..6c9eacfa82a 100644 --- a/components/brave_ads/core/public/common/locale/scoped_locale_for_testing.h +++ b/components/brave_ads/core/public/common/locale/scoped_locale_for_testing.h @@ -8,6 +8,10 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads::test { // Set the current language code for testing, restoring the original language diff --git a/components/brave_ads/core/public/common/url/url_util.h b/components/brave_ads/core/public/common/url/url_util.h index a77b4bc32ec..383b3807480 100644 --- a/components/brave_ads/core/public/common/url/url_util.h +++ b/components/brave_ads/core/public/common/url/url_util.h @@ -9,6 +9,10 @@ #include #include +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class GURL; namespace brave_ads { diff --git a/components/brave_ads/core/public/flags/flags_util.h b/components/brave_ads/core/public/flags/flags_util.h index 6566e106780..939e762fe2f 100644 --- a/components/brave_ads/core/public/flags/flags_util.h +++ b/components/brave_ads/core/public/flags/flags_util.h @@ -6,8 +6,11 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_FLAGS_FLAGS_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_FLAGS_FLAGS_UTIL_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { // Builds Flags basing on command line arguments and environment. diff --git a/components/brave_ads/core/public/history/ad_history_feature.h b/components/brave_ads/core/public/history/ad_history_feature.h index a285cfb4d53..7a2aafe729c 100644 --- a/components/brave_ads/core/public/history/ad_history_feature.h +++ b/components/brave_ads/core/public/history/ad_history_feature.h @@ -9,6 +9,9 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" #include "base/time/time.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace brave_ads { diff --git a/components/brave_ads/core/public/history/ad_history_item_info.h b/components/brave_ads/core/public/history/ad_history_item_info.h index 3fc3c423572..89ccdc1cdf9 100644 --- a/components/brave_ads/core/public/history/ad_history_item_info.h +++ b/components/brave_ads/core/public/history/ad_history_item_info.h @@ -10,9 +10,12 @@ #include #include "base/time/time.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "url/gurl.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { struct AdHistoryItemInfo final { diff --git a/components/brave_ads/core/public/history/ad_history_item_value_util.h b/components/brave_ads/core/public/history/ad_history_item_value_util.h index de317ca4c32..be14f055b86 100644 --- a/components/brave_ads/core/public/history/ad_history_item_value_util.h +++ b/components/brave_ads/core/public/history/ad_history_item_value_util.h @@ -7,6 +7,9 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_HISTORY_AD_HISTORY_ITEM_VALUE_UTIL_H_ #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace brave_ads { diff --git a/components/brave_ads/core/public/history/site_history.h b/components/brave_ads/core/public/history/site_history.h index 0466e415621..b7a2894f18f 100644 --- a/components/brave_ads/core/public/history/site_history.h +++ b/components/brave_ads/core/public/history/site_history.h @@ -8,8 +8,11 @@ #include +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "url/gurl.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { using SiteHistoryList = std::vector; diff --git a/components/brave_ads/core/public/prefs/obsolete_pref_util.h b/components/brave_ads/core/public/prefs/obsolete_pref_util.h index d9903162ba6..57304210b35 100644 --- a/components/brave_ads/core/public/prefs/obsolete_pref_util.h +++ b/components/brave_ads/core/public/prefs/obsolete_pref_util.h @@ -6,6 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_OBSOLETE_PREF_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_OBSOLETE_PREF_UTIL_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class PrefRegistrySimple; class PrefService; diff --git a/components/brave_ads/core/public/prefs/pref_names.h b/components/brave_ads/core/public/prefs/pref_names.h index 757f58c867f..7acb968e798 100644 --- a/components/brave_ads/core/public/prefs/pref_names.h +++ b/components/brave_ads/core/public/prefs/pref_names.h @@ -6,6 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_PREF_NAMES_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_PREF_NAMES_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads::prefs { // IMPORTANT: Prefs that need clearing should be prefixed with diff --git a/components/brave_ads/core/public/prefs/pref_registry.h b/components/brave_ads/core/public/prefs/pref_registry.h index c438cfdc9fa..0e7dfa89136 100644 --- a/components/brave_ads/core/public/prefs/pref_registry.h +++ b/components/brave_ads/core/public/prefs/pref_registry.h @@ -6,6 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_PREF_REGISTRY_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_PREF_REGISTRY_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + class PrefRegistrySimple; namespace brave_ads { diff --git a/components/brave_ads/core/public/targeting/geographical/subdivision/supported_subdivisions.h b/components/brave_ads/core/public/targeting/geographical/subdivision/supported_subdivisions.h index a65baaa345b..0fdfbcd8e45 100644 --- a/components/brave_ads/core/public/targeting/geographical/subdivision/supported_subdivisions.h +++ b/components/brave_ads/core/public/targeting/geographical/subdivision/supported_subdivisions.h @@ -11,6 +11,9 @@ #include "base/containers/flat_map.h" #include "base/values.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace brave_ads { diff --git a/components/brave_ads/core/public/user_attention/user_idle_detection/user_idle_detection_feature.h b/components/brave_ads/core/public/user_attention/user_idle_detection/user_idle_detection_feature.h index 5154285e93f..3c67c514bab 100644 --- a/components/brave_ads/core/public/user_attention/user_idle_detection/user_idle_detection_feature.h +++ b/components/brave_ads/core/public/user_attention/user_idle_detection/user_idle_detection_feature.h @@ -8,6 +8,9 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace base { class TimeDelta; diff --git a/components/brave_ads/core/public/user_engagement/reactions/reactions_util.h b/components/brave_ads/core/public/user_engagement/reactions/reactions_util.h index 7c90746edd7..7b5c03d774c 100644 --- a/components/brave_ads/core/public/user_engagement/reactions/reactions_util.h +++ b/components/brave_ads/core/public/user_engagement/reactions/reactions_util.h @@ -6,9 +6,12 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_USER_ENGAGEMENT_REACTIONS_REACTIONS_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_USER_ENGAGEMENT_REACTIONS_REACTIONS_UTIL_H_ +#include "brave/components/brave_ads/buildflags/buildflags.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_ads/core/public/history/ad_history_item_info.h" +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); + namespace brave_ads { struct AdHistoryItemInfo; diff --git a/components/brave_ads/core/public/user_engagement/site_visit/site_visit_feature.h b/components/brave_ads/core/public/user_engagement/site_visit/site_visit_feature.h index 144f6c0dcf7..62e4bdcd9fe 100644 --- a/components/brave_ads/core/public/user_engagement/site_visit/site_visit_feature.h +++ b/components/brave_ads/core/public/user_engagement/site_visit/site_visit_feature.h @@ -8,6 +8,9 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" + +static_assert(BUILDFLAG(ENABLE_BRAVE_ADS)); namespace base { class TimeDelta; diff --git a/components/brave_news/browser/BUILD.gn b/components/brave_news/browser/BUILD.gn index d34c6e6490c..95c5c8d80e9 100644 --- a/components/brave_news/browser/BUILD.gn +++ b/components/brave_news/browser/BUILD.gn @@ -73,7 +73,6 @@ static_library("browser") { "//base", "//brave/brave_domains", "//brave/components/api_request_helper", - "//brave/components/brave_ads/browser", "//brave/components/brave_news/api", "//brave/components/brave_private_cdn", "//brave/components/brave_rewards/core", diff --git a/components/brave_news/browser/brave_news_controller.cc b/components/brave_news/browser/brave_news_controller.cc index 0f8f5646b19..59043233926 100644 --- a/components/brave_news/browser/brave_news_controller.cc +++ b/components/brave_news/browser/brave_news_controller.cc @@ -30,7 +30,6 @@ #include "base/task/thread_pool.h" #include "base/time/time.h" #include "base/values.h" -#include "brave/components/brave_ads/core/browser/service/ads_service.h" #include "brave/components/brave_news/browser/background_history_querier.h" #include "brave/components/brave_news/browser/brave_news_engine.h" #include "brave/components/brave_news/browser/brave_news_p3a.h" @@ -97,11 +96,10 @@ mojo::StructPtr CreateChangeEvent( BraveNewsController::BraveNewsController( PrefService* prefs, - brave_ads::AdsService* ads_service, history::HistoryService* history_service, scoped_refptr url_loader_factory, std::unique_ptr direct_feed_fetcher_delegate) - : ads_service_(ads_service), + : #if BUILDFLAG(IS_ANDROID) private_cdn_request_helper_(GetNetworkTrafficAnnotationTag(), url_loader_factory), diff --git a/components/brave_news/browser/brave_news_controller.h b/components/brave_news/browser/brave_news_controller.h index eac088f5635..44beaaf116e 100644 --- a/components/brave_news/browser/brave_news_controller.h +++ b/components/brave_news/browser/brave_news_controller.h @@ -40,10 +40,6 @@ static_assert(BUILDFLAG(ENABLE_BRAVE_NEWS)); class PrefService; -namespace brave_ads { -class AdsService; -} // namespace brave_ads - namespace history { class HistoryService; } // namespace history @@ -63,7 +59,6 @@ class BraveNewsController public: BraveNewsController( PrefService* prefs, - brave_ads::AdsService* ads_service, history::HistoryService* history_service, scoped_refptr url_loader_factory, std::unique_ptr @@ -173,8 +168,6 @@ class BraveNewsController BackgroundHistoryQuerier MakeHistoryQuerier(); - raw_ptr ads_service_ = nullptr; - #if BUILDFLAG(IS_ANDROID) // Note: This is only used by Android, to load padded images from the Private // CDN. diff --git a/components/resources/BUILD.gn b/components/resources/BUILD.gn index 169413cd2f0..534634ae92a 100644 --- a/components/resources/BUILD.gn +++ b/components/resources/BUILD.gn @@ -5,6 +5,7 @@ import("//brave/components/ai_chat/core/common/buildflags/buildflags.gni") import("//brave/components/ai_rewriter/common/buildflags/buildflags.gni") +import("//brave/components/brave_ads/buildflags/buildflags.gni") import("//brave/components/brave_news/common/buildflags/buildflags.gni") import("//brave/components/brave_vpn/common/buildflags/buildflags.gni") import("//brave/components/brave_wallet/common/buildflags/buildflags.gni") @@ -68,18 +69,22 @@ repack("resources") { ":static_resources", "//brave/components/ai_rewriter/common/buildflags", "//brave/components/brave_account/resources", - "//brave/components/brave_ads/browser/resources:generated_resources", "//brave/components/cosmetic_filters/resources/data:generated_resources", "//brave/components/skus/browser/resources:generated_resources", ] sources = [ "$root_gen_dir/brave/components/brave_account/resources/brave_account_resources.pak", - "$root_gen_dir/brave/components/brave_ads/browser/resources/ads_internals_generated.pak", "$root_gen_dir/brave/components/cosmetic_filters/resources/cosmetic_filters_generated.pak", "$root_gen_dir/brave/components/skus/browser/resources/skus_internals_generated.pak", "$root_gen_dir/components/brave_components_static.pak", ] + if (enable_brave_ads) { + deps += + [ "//brave/components/brave_ads/browser/resources:generated_resources" ] + sources += [ "$root_gen_dir/brave/components/brave_ads/browser/resources/ads_internals_generated.pak" ] + } + if (enable_brave_wallet) { deps += [ "//brave/components/brave_wallet_ui:resources" ] sources += [ diff --git a/test/BUILD.gn b/test/BUILD.gn index 476e4b29145..712843b402f 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -134,13 +134,11 @@ test("brave_unit_tests") { "//brave/components/ntp_background_images/browser/ntp_background_images_source_unittest.cc", "//brave/components/ntp_background_images/browser/ntp_sponsored_image_source_unittest.cc", "//brave/components/ntp_background_images/browser/ntp_sponsored_images_data_unittest.cc", - "//brave/components/ntp_background_images/browser/ntp_sponsored_rich_media_ad_event_handler_unittest.cc", "//brave/components/ntp_background_images/browser/ntp_sponsored_rich_media_source_unittest.cc", "//brave/components/ntp_background_images/browser/ntp_sponsored_source_test_util.cc", "//brave/components/ntp_background_images/browser/ntp_sponsored_source_test_util.h", "//brave/components/ntp_background_images/browser/ntp_sponsored_source_util_unittest.cc", "//brave/components/ntp_background_images/browser/view_counter_model_unittest.cc", - "//brave/components/ntp_background_images/browser/view_counter_service_unittest.cc", "//brave/components/time_period_storage/daily_storage_unittest.cc", "//brave/components/time_period_storage/time_period_storage_unittest.cc", "//brave/components/time_period_storage/weekly_event_storage_unittest.cc", @@ -383,6 +381,11 @@ test("brave_unit_tests") { } if (enable_brave_ads) { + sources += [ + "//brave/components/ntp_background_images/browser/ntp_sponsored_rich_media_ad_event_handler_unittest.cc", + "//brave/components/ntp_background_images/browser/view_counter_service_unittest.cc", + ] + deps += [ "//brave/browser/brave_ads", "//brave/browser/brave_ads/device_id:unit_tests", @@ -918,6 +921,7 @@ test("brave_browser_tests") { "//brave/components/brave_perf_predictor/browser", "//brave/components/brave_perf_predictor/common", "//brave/components/brave_referrals/browser", + "//brave/components/brave_rewards/core", ] if (enable_brave_news) { diff --git a/utility/DEPS b/utility/DEPS index 002d0f33ef7..073bc2ab0a4 100644 --- a/utility/DEPS +++ b/utility/DEPS @@ -10,8 +10,6 @@ include_rules += [ "+brave/grit", "+chrome/utility", "+brave/components/constants", - "+brave/components/constants", - "+brave/components/services/bat_ads", "+brave/components/services/bat_rewards", "+brave/components/services/brave_wallet", "+brave/components/brave_wallet/common/buildflags", diff --git a/utility/brave_content_utility_client.cc b/utility/brave_content_utility_client.cc index 96ca511ab6e..cf96692672b 100644 --- a/utility/brave_content_utility_client.cc +++ b/utility/brave_content_utility_client.cc @@ -9,8 +9,6 @@ #include #include "brave/components/brave_wallet/common/buildflags/buildflags.h" -#include "brave/components/services/bat_ads/bat_ads_service_impl.h" -#include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h" #include "brave/components/services/bat_rewards/public/interfaces/rewards_engine_factory.mojom.h" #include "brave/components/services/bat_rewards/rewards_engine_factory.h" #include "brave/components/tor/buildflags/buildflags.h" @@ -52,11 +50,6 @@ auto RunRewardsEngineFactory( std::move(receiver)); } -auto RunBatAdsService( - mojo::PendingReceiver receiver) { - return std::make_unique(std::move(receiver)); -} - #if BUILDFLAG(ENABLE_BRAVE_WALLET) auto RunBraveWalletUtilsService( mojo::PendingReceiver @@ -83,8 +76,6 @@ void BraveContentUtilityClient::RegisterMainThreadServices( services.Add(RunRewardsEngineFactory); - services.Add(RunBatAdsService); - #if BUILDFLAG(ENABLE_BRAVE_WALLET) services.Add(RunBraveWalletUtilsService); #endif diff --git a/utility/importer/sources.gni b/utility/importer/sources.gni index cda707624ae..6fc1d686b3f 100644 --- a/utility/importer/sources.gni +++ b/utility/importer/sources.gni @@ -7,10 +7,8 @@ import("//brave/components/tor/buildflags/buildflags.gni") brave_utility_importer_sources = [] brave_utility_importer_deps = [] -brave_utility_importer_public_deps = [ - "//brave/components/services/bat_ads:lib", - "//brave/components/services/bat_rewards:lib", -] +brave_utility_importer_public_deps = + [ "//brave/components/services/bat_rewards:lib" ] if (!is_android) { brave_utility_importer_sources += [ diff --git a/utility/sources.gni b/utility/sources.gni index c80fc3fa16f..dd1bcfe5a68 100644 --- a/utility/sources.gni +++ b/utility/sources.gni @@ -16,8 +16,6 @@ brave_utility_sources += brave_utility_importer_sources brave_utility_deps = [ "//brave/components/brave_wallet/common/buildflags", - "//brave/components/services/bat_ads:lib", - "//brave/components/services/bat_ads/public/interfaces", "//brave/components/services/bat_rewards:lib", "//brave/components/services/bat_rewards/public/interfaces", "//brave/components/tor/buildflags",