diff --git a/browser/brave_ads/analytics/p3a/brave_stats_helper_browsertest.cc b/browser/brave_ads/analytics/p3a/brave_stats_helper_browsertest.cc index 02aa8028f477..514acbaa4592 100644 --- a/browser/brave_ads/analytics/p3a/brave_stats_helper_browsertest.cc +++ b/browser/brave_ads/analytics/p3a/brave_stats_helper_browsertest.cc @@ -10,7 +10,7 @@ #include "base/test/metrics/histogram_tester.h" #include "brave/browser/brave_browser_process.h" #include "brave/components/brave_ads/core/public/prefs/pref_names.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" diff --git a/browser/brave_ads/application_state/background_helper/background_helper.cc b/browser/brave_ads/application_state/background_helper/background_helper.cc index 8802acc949c2..e0d76540afc2 100644 --- a/browser/brave_ads/application_state/background_helper/background_helper.cc +++ b/browser/brave_ads/application_state/background_helper/background_helper.cc @@ -6,7 +6,7 @@ #include "brave/components/brave_ads/browser/application_state/background_helper.h" #include "brave/browser/brave_ads/application_state/background_helper/background_helper_holder.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" namespace brave_ads { diff --git a/browser/brave_ads/application_state/background_helper/background_helper_holder.cc b/browser/brave_ads/application_state/background_helper/background_helper_holder.cc index 300a7d2ad7af..c5cb6e909682 100644 --- a/browser/brave_ads/application_state/background_helper/background_helper_holder.cc +++ b/browser/brave_ads/application_state/background_helper/background_helper_holder.cc @@ -7,7 +7,7 @@ #include "base/no_destructor.h" #include "brave/components/brave_ads/browser/application_state/background_helper.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #if BUILDFLAG(IS_ANDROID) #include "brave/browser/brave_ads/application_state/background_helper/background_helper_android.h" diff --git a/browser/brave_ads/application_state/notification_helper/notification_helper.cc b/browser/brave_ads/application_state/notification_helper/notification_helper.cc index 39e75efac64b..fe50782a1036 100644 --- a/browser/brave_ads/application_state/notification_helper/notification_helper.cc +++ b/browser/brave_ads/application_state/notification_helper/notification_helper.cc @@ -8,7 +8,7 @@ #include "base/functional/bind.h" #include "base/no_destructor.h" #include "brave/browser/brave_ads/application_state/notification_helper/notification_helper_impl.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/notifications/notification_platform_bridge.h" #include "chrome/browser/profiles/profile.h" diff --git a/browser/brave_ads/tabs/ads_tab_helper.cc b/browser/brave_ads/tabs/ads_tab_helper.cc index 0cb19c41d28e..e0dd6953228a 100644 --- a/browser/brave_ads/tabs/ads_tab_helper.cc +++ b/browser/brave_ads/tabs/ads_tab_helper.cc @@ -18,6 +18,7 @@ #include "components/prefs/pref_service.h" #include "components/sessions/content/session_tab_helper.h" #include "components/sessions/core/session_id.h" +#include "content/public/browser/media_player_id.h" #include "content/public/browser/navigation_handle.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" @@ -51,12 +52,11 @@ std::string MediaPlayerUuid(const content::MediaPlayerId& id) { } // namespace -AdsTabHelper::AdsTabHelper(content::WebContents* web_contents) +AdsTabHelper::AdsTabHelper(content::WebContents* const web_contents) : content::WebContentsObserver(web_contents), content::WebContentsUserData(*web_contents), session_id_(sessions::SessionTabHelper::IdForTab(web_contents)) { if (!session_id_.is_valid()) { - // Invalid session id instance. return; } @@ -64,7 +64,6 @@ AdsTabHelper::AdsTabHelper(content::WebContents* web_contents) Profile::FromBrowserContext(web_contents->GetBrowserContext()); ads_service_ = AdsServiceFactory::GetForProfile(profile); if (!ads_service_) { - // No-op if the ads service is unavailable. return; } @@ -84,7 +83,7 @@ AdsTabHelper::~AdsTabHelper() { #endif } -void AdsTabHelper::SetAdsServiceForTesting(AdsService* ads_service) { +void AdsTabHelper::SetAdsServiceForTesting(AdsService* const ads_service) { CHECK_IS_TEST(); ads_service_ = ads_service; @@ -108,6 +107,7 @@ bool AdsTabHelper::UserHasOptedInToNotificationAds() const { } bool AdsTabHelper::IsVisible() const { + // The web contents must be visible and the browser must be active. return is_web_contents_visible_ && is_browser_active_.value_or(false); } @@ -142,7 +142,7 @@ void AdsTabHelper::MaybeSetBrowserIsNoLongerActive() { } bool AdsTabHelper::IsNewNavigation( - content::NavigationHandle* navigation_handle) { + content::NavigationHandle* const navigation_handle) { CHECK(navigation_handle); return ui::PageTransitionIsNewNavigation( @@ -150,7 +150,7 @@ bool AdsTabHelper::IsNewNavigation( } std::optional AdsTabHelper::HttpStatusCode( - content::NavigationHandle* navigation_handle) { + content::NavigationHandle* const navigation_handle) { CHECK(navigation_handle); if (const net::HttpResponseHeaders* const response_headers = @@ -198,11 +198,10 @@ void AdsTabHelper::MaybeNotifyBrowserDidResignActive() { } void AdsTabHelper::MaybeNotifyUserGestureEventTriggered( - content::NavigationHandle* navigation_handle) { + content::NavigationHandle* const navigation_handle) { CHECK(navigation_handle); if (!ads_service_) { - // No-op if the ads service is unavailable. return; } @@ -225,7 +224,6 @@ void AdsTabHelper::MaybeNotifyUserGestureEventTriggered( void AdsTabHelper::MaybeNotifyTabDidChange() { if (!ads_service_) { - // No-op if the ads service is unavailable. return; } @@ -273,8 +271,7 @@ void AdsTabHelper::MaybeNotifyTabHtmlContentDidChange() { // for Brave Rewards users. However, we must notify that the tab content has // changed with empty HTML to ensure that regular conversions are processed. return ads_service_->NotifyTabHtmlContentDidChange( - /*tab_id=*/session_id_.id(), redirect_chain_, - /*html=*/""); + /*tab_id=*/session_id_.id(), redirect_chain_, /*html=*/""); } // Only utilized for verifiable conversions, which requires the user to have @@ -342,7 +339,12 @@ void AdsTabHelper::MaybeNotifyTabdidClose() { void AdsTabHelper::DidStartNavigation( content::NavigationHandle* navigation_handle) { - if (!ads_service_ || !navigation_handle->IsInPrimaryMainFrame()) { + if (!ads_service_) { + // No-op if the ads service is unavailable. + return; + } + + if (!navigation_handle->IsInPrimaryMainFrame()) { return; } @@ -360,7 +362,6 @@ void AdsTabHelper::DidStartNavigation( void AdsTabHelper::DidFinishNavigation( content::NavigationHandle* navigation_handle) { if (!ads_service_) { - // No-op if the ads service is unavailable. return; } @@ -400,7 +401,6 @@ void AdsTabHelper::DidFinishNavigation( // have finished loading. void AdsTabHelper::DocumentOnLoadCompletedInPrimaryMainFrame() { if (!ads_service_) { - // No-op if the ads service is unavailable. return; } diff --git a/browser/brave_ads/tabs/ads_tab_helper.h b/browser/brave_ads/tabs/ads_tab_helper.h index 2da062be5632..b3e053b1a79a 100644 --- a/browser/brave_ads/tabs/ads_tab_helper.h +++ b/browser/brave_ads/tabs/ads_tab_helper.h @@ -14,9 +14,8 @@ #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/values.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #include "components/sessions/core/session_id.h" -#include "content/public/browser/media_player_id.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" @@ -27,6 +26,10 @@ class Browser; class GURL; +namespace content { +struct MediaPlayerId; +} // namespace content + namespace brave_ads { class AdsService; @@ -37,7 +40,7 @@ class AdsTabHelper : public content::WebContentsObserver, #endif public content::WebContentsUserData { public: - explicit AdsTabHelper(content::WebContents*); + explicit AdsTabHelper(content::WebContents* const); ~AdsTabHelper() override; AdsTabHelper(const AdsTabHelper&) = delete; @@ -45,7 +48,7 @@ class AdsTabHelper : public content::WebContentsObserver, AdsService* ads_service() { return ads_service_; } - void SetAdsServiceForTesting(AdsService* ads_service); + void SetAdsServiceForTesting(AdsService* const ads_service); private: friend class content::WebContentsUserData; @@ -60,12 +63,12 @@ class AdsTabHelper : public content::WebContentsObserver, // Returns 'false' if the navigation was a back/forward navigation or a // reload, otherwise 'true'. - bool IsNewNavigation(content::NavigationHandle* navigation_handle); + bool IsNewNavigation(content::NavigationHandle* const navigation_handle); // NOTE: DO NOT use this method before the navigation commit as it will return // null. It is safe to use from `WebContentsObserver::DidFinishNavigation()`. std::optional HttpStatusCode( - content::NavigationHandle* navigation_handle); + content::NavigationHandle* const navigation_handle); bool IsErrorPage(int http_status_code) const; @@ -77,7 +80,7 @@ class AdsTabHelper : public content::WebContentsObserver, void MaybeNotifyBrowserDidResignActive(); void MaybeNotifyUserGestureEventTriggered( - content::NavigationHandle* navigation_handle); + content::NavigationHandle* const navigation_handle); void MaybeNotifyTabDidChange(); diff --git a/browser/ui/views/brave_ads/notification_ad_popup_widget.cc b/browser/ui/views/brave_ads/notification_ad_popup_widget.cc index c7be3d9143cf..9a09e68598b4 100644 --- a/browser/ui/views/brave_ads/notification_ad_popup_widget.cc +++ b/browser/ui/views/brave_ads/notification_ad_popup_widget.cc @@ -8,7 +8,7 @@ #include #include "brave/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_feature.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #include "ui/gfx/geometry/rect.h" #include "ui/native_theme/native_theme.h" #include "ui/views/widget/widget_delegate.h" diff --git a/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_constants.h b/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_constants.h index 6dd427fa9066..f06ea6efd07f 100644 --- a/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_constants.h +++ b/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_constants.h @@ -6,7 +6,7 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_UNITS_NOTIFICATION_AD_CUSTOM_NOTIFICATION_AD_CONSTANTS_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_UNITS_NOTIFICATION_AD_CUSTOM_NOTIFICATION_AD_CONSTANTS_H_ -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" namespace brave_ads { 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 4dff1d60d8ca..db8ba9a1eeeb 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,7 +11,7 @@ #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 "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" namespace brave_ads { diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 43c2128d6ace..5d44688eee3d 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -59,7 +59,7 @@ #include "brave/components/l10n/common/prefs.h" #include "brave/components/ntp_background_images/common/pref_names.h" #include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_context.h" #include "mojo/public/cpp/bindings/callback_helpers.h" diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index 756519b7ab06..7b1a7167f8f7 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -62,8 +62,8 @@ class AdsTooltipsDelegate; class BatAdsServiceFactory; class Database; class DeviceId; -struct NewTabPageAdInfo; class ResourceComponent; +struct NewTabPageAdInfo; class AdsServiceImpl final : public AdsService, public bat_ads::mojom::BatAdsClient, @@ -480,7 +480,6 @@ class AdsServiceImpl final : public AdsService, mojo::Receiver bat_ads_observer_receiver_{ this}; - mojo::Remote bat_ads_service_remote_; mojo::AssociatedReceiver bat_ads_client_associated_receiver_; diff --git a/components/brave_ads/core/internal/common/platform/platform_helper.cc b/components/brave_ads/core/internal/common/platform/platform_helper.cc index 610254fdf639..565133504378 100644 --- a/components/brave_ads/core/internal/common/platform/platform_helper.cc +++ b/components/brave_ads/core/internal/common/platform/platform_helper.cc @@ -6,7 +6,7 @@ #include "brave/components/brave_ads/core/internal/common/platform/platform_helper.h" #include "base/check_is_test.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #if BUILDFLAG(IS_ANDROID) #include "brave/components/brave_ads/core/internal/common/platform/platform_helper_android.h" #elif BUILDFLAG(IS_IOS) diff --git a/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.cc b/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.cc index 6d8e1e1727c7..2403c80c5706 100644 --- a/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.cc +++ b/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.cc @@ -15,7 +15,7 @@ #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_value_util.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client.h" #include "brave/components/brave_ads/core/public/prefs/pref_names.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" #if BUILDFLAG(IS_ANDROID) #include "brave/components/brave_ads/core/internal/application_state/browser_util.h" diff --git a/components/brave_ads/core/internal/flags/flag_constants.h b/components/brave_ads/core/internal/flags/flag_constants.h index 79085fd7b591..bb7cd7a9e3ba 100644 --- a/components/brave_ads/core/internal/flags/flag_constants.h +++ b/components/brave_ads/core/internal/flags/flag_constants.h @@ -7,7 +7,7 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_FLAGS_FLAG_CONSTANTS_H_ #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" namespace brave_ads { 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 0f3b004c5385..d7dbb259cde9 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,7 +9,7 @@ #include #include "base/time/time.h" -#include "build/build_config.h" // IWYU pragma: keep +#include "build/build_config.h" namespace brave_ads { diff --git a/ios/browser/api/ads/brave_ads.mm b/ios/browser/api/ads/brave_ads.mm index 5d53baf59b77..4f9780fd8169 100644 --- a/ios/browser/api/ads/brave_ads.mm +++ b/ios/browser/api/ads/brave_ads.mm @@ -1738,7 +1738,7 @@ - (void)notifyTabTextContentDidChange:(NSInteger)tabId const std::vector urls = [self GURLsWithNSURLs:redirectChain]; adsClientNotifier->NotifyTabTextContentDidChange( - (int32_t)tabId, urls, base::SysNSStringToUTF8(text)); + static_cast(tabId), urls, base::SysNSStringToUTF8(text)); } - (void)notifyTabHtmlContentDidChange:(NSInteger)tabId @@ -1751,18 +1751,20 @@ - (void)notifyTabHtmlContentDidChange:(NSInteger)tabId const std::vector urls = [self GURLsWithNSURLs:redirectChain]; adsClientNotifier->NotifyTabHtmlContentDidChange( - (int32_t)tabId, urls, base::SysNSStringToUTF8(html)); + static_cast(tabId), urls, base::SysNSStringToUTF8(html)); } - (void)notifyTabDidStartPlayingMedia:(NSInteger)tabId { if (adsClientNotifier != nil) { - adsClientNotifier->NotifyTabDidStartPlayingMedia((int32_t)tabId); + adsClientNotifier->NotifyTabDidStartPlayingMedia( + static_cast(tabId)); } } - (void)notifyTabDidStopPlayingMedia:(NSInteger)tabId { if (adsClientNotifier != nil) { - adsClientNotifier->NotifyTabDidStopPlayingMedia((int32_t)tabId); + adsClientNotifier->NotifyTabDidStopPlayingMedia( + static_cast(tabId)); } } @@ -1779,8 +1781,9 @@ - (void)notifyTabDidChange:(NSInteger)tabId const bool isVisible = isSelected && [self isBrowserActive]; - adsClientNotifier->NotifyTabDidChange((int32_t)tabId, urls, isNewNavigation, - isRestoring, isVisible); + adsClientNotifier->NotifyTabDidChange(static_cast(tabId), urls, + isNewNavigation, isRestoring, + isVisible); } - (void)notifyTabDidLoad:(NSInteger)tabId @@ -1789,12 +1792,13 @@ - (void)notifyTabDidLoad:(NSInteger)tabId return; } - adsClientNotifier->NotifyTabDidLoad((int32_t)tabId, (int32_t)httpStatusCode); + adsClientNotifier->NotifyTabDidLoad(static_cast(tabId), + static_cast(httpStatusCode)); } - (void)notifyDidCloseTab:(NSInteger)tabId { if (adsClientNotifier != nil) { - adsClientNotifier->NotifyDidCloseTab((int32_t)tabId); + adsClientNotifier->NotifyDidCloseTab(static_cast(tabId)); } }