diff --git a/browser/brave_ads/ads_service_delegate.cc b/browser/brave_ads/ads_service_delegate.cc index 85571cb0fa51..a0d5b5284e5e 100644 --- a/browser/brave_ads/ads_service_delegate.cc +++ b/browser/brave_ads/ads_service_delegate.cc @@ -271,7 +271,7 @@ void AdsServiceDelegate::CloseNotificationAd(const std::string& id, const GURL url = GURL(brave_ads_url_prefix.substr(0, brave_ads_url_prefix.size() - 1)); BraveNotificationPlatformBridgeHelperAndroid::MaybeRegenerateNotification( - placement_id, url); + id, url); #endif // We cannot store a raw_ptr to NotificationDisplayService due to upstream diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index bd57946b24fd..9b9bc08efd2d 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -232,18 +232,6 @@ AdsServiceImpl::AdsServiceImpl( AdsServiceImpl::~AdsServiceImpl() = default; -void AdsServiceImpl::AddObserver(AdsServiceObserver* const observer) { - CHECK(observer); - - observers_.AddObserver(observer); -} - -void AdsServiceImpl::RemoveObserver(AdsServiceObserver* const observer) { - CHECK(observer); - - observers_.RemoveObserver(observer); -} - /////////////////////////////////////////////////////////////////////////////// bool AdsServiceImpl::IsBatAdsServiceBound() const { diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index 8cebae9b7cd7..03baa06d6a45 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -94,9 +94,6 @@ class AdsServiceImpl final : public AdsService, ~AdsServiceImpl() override; - void AddObserver(AdsServiceObserver* observer) override; - void RemoveObserver(AdsServiceObserver* observer) override; - private: using SimpleURLLoaderList = std::list>; diff --git a/components/brave_ads/browser/ads_service_mock.h b/components/brave_ads/browser/ads_service_mock.h index 039d4d486c07..5bca5da4d1f3 100644 --- a/components/brave_ads/browser/ads_service_mock.h +++ b/components/brave_ads/browser/ads_service_mock.h @@ -32,9 +32,6 @@ class AdsServiceMock : public AdsService { ~AdsServiceMock() override; - MOCK_METHOD(void, AddObserver, (AdsServiceObserver * observer)); - MOCK_METHOD(void, RemoveObserver, (AdsServiceObserver * observer)); - MOCK_METHOD(void, AddBatAdsObserver, (mojo::PendingRemote diff --git a/components/brave_ads/core/browser/service/ads_service.cc b/components/brave_ads/core/browser/service/ads_service.cc index 0e4b6cd1ba3b..d16c94aa5499 100644 --- a/components/brave_ads/core/browser/service/ads_service.cc +++ b/components/brave_ads/core/browser/service/ads_service.cc @@ -7,6 +7,8 @@ #include +#include "base/check.h" + namespace brave_ads { AdsService::AdsService(std::unique_ptr delegate) @@ -14,4 +16,16 @@ AdsService::AdsService(std::unique_ptr delegate) AdsService::~AdsService() = default; +void AdsService::AddObserver(AdsServiceObserver* const observer) { + CHECK(observer); + + observers_.AddObserver(observer); +} + +void AdsService::RemoveObserver(AdsServiceObserver* const observer) { + CHECK(observer); + + observers_.RemoveObserver(observer); +} + } // namespace brave_ads diff --git a/components/brave_ads/core/browser/service/ads_service.h b/components/brave_ads/core/browser/service/ads_service.h index 3d7fedf06fea..ec52b2700a67 100644 --- a/components/brave_ads/core/browser/service/ads_service.h +++ b/components/brave_ads/core/browser/service/ads_service.h @@ -12,6 +12,7 @@ #include #include +#include "base/observer_list.h" #include "base/time/time.h" #include "brave/components/brave_ads/core/browser/service/ads_service_observer.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" @@ -64,8 +65,8 @@ class AdsService : public KeyedService { AdsService::Delegate* delegate() { return delegate_.get(); } - virtual void AddObserver(AdsServiceObserver* observer) = 0; - virtual void RemoveObserver(AdsServiceObserver* observer) = 0; + void AddObserver(AdsServiceObserver* observer); + void RemoveObserver(AdsServiceObserver* observer); // Returns true if a browser upgrade is required to serve ads. virtual bool IsBrowserUpgradeRequiredToServeAds() const = 0; @@ -297,6 +298,8 @@ class AdsService : public KeyedService { protected: std::unique_ptr delegate_; + + base::ObserverList observers_; }; } // namespace brave_ads diff --git a/ios/browser/api/ads/brave_ads.mm b/ios/browser/api/ads/brave_ads.mm index 3cbb627f440d..299e148d4af0 100644 --- a/ios/browser/api/ads/brave_ads.mm +++ b/ios/browser/api/ads/brave_ads.mm @@ -185,7 +185,7 @@ + (BOOL)isSupportedRegion { - (BOOL)isServiceRunning { return adsClientNotifier != nil && adsService != nil && - adsService->IsRunning(); + adsService->IsInitialized(); } + (BOOL)shouldAlwaysRunService { diff --git a/ios/browser/brave_ads/ads_service_impl_ios.h b/ios/browser/brave_ads/ads_service_impl_ios.h index 16280a9c35b1..de06c0a939a5 100644 --- a/ios/browser/brave_ads/ads_service_impl_ios.h +++ b/ios/browser/brave_ads/ads_service_impl_ios.h @@ -8,14 +8,15 @@ #include #include +#include #include "base/functional/callback_forward.h" #include "base/memory/weak_ptr.h" #include "base/threading/sequence_bound.h" +#include "brave/components/brave_ads/core/browser/service/ads_service.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_client/ads_client_callback.h" -#include "components/keyed_service/core/keyed_service.h" class PrefService; @@ -29,7 +30,7 @@ class Ads; class AdsClient; class Database; -class AdsServiceImplIOS : public KeyedService { +class AdsServiceImplIOS : public AdsService { public: explicit AdsServiceImplIOS(PrefService* prefs); @@ -41,7 +42,7 @@ class AdsServiceImplIOS : public KeyedService { ~AdsServiceImplIOS() override; - bool IsRunning() const; + bool IsInitialized() const; void InitializeAds(const std::string& storage_path, std::unique_ptr ads_client, @@ -51,50 +52,111 @@ class AdsServiceImplIOS : public KeyedService { InitializeCallback callback); void ShutdownAds(ShutdownCallback callback); - void ClearData(base::OnceClosure callback); - void RunDBTransaction(mojom::DBTransactionInfoPtr mojom_db_transaction, RunDBTransactionCallback callback); + void MaybeGetNotificationAd(const std::string& placement_id, + MaybeGetNotificationAdCallback callback); + void TriggerNotificationAdEvent( + const std::string& placement_id, + mojom::NotificationAdEventType mojom_ad_event_type, + TriggerAdEventCallback callback); + + // AdsService: + bool IsBrowserUpgradeRequiredToServeAds() const override; + + int64_t GetMaximumNotificationAdsPerHour() const override; + + void OnNotificationAdShown(const std::string& placement_id) override; + void OnNotificationAdClosed(const std::string& placement_id, + bool by_user) override; + void OnNotificationAdClicked(const std::string& placement_id) override; + + void ClearData(base::OnceClosure callback) override; + + void AddBatAdsObserver(mojo::PendingRemote + bat_ads_observer_pending_remote) override; + + void GetDiagnostics(GetDiagnosticsCallback callback) override; - void GetStatementOfAccounts(GetStatementOfAccountsCallback callback); + void GetStatementOfAccounts(GetStatementOfAccountsCallback callback) override; - void MaybeServeInlineContentAd(const std::string& dimensions, - MaybeServeInlineContentAdCallback callback); + void MaybeServeInlineContentAd( + const std::string& dimensions, + MaybeServeInlineContentAdCallback callback) override; void TriggerInlineContentAdEvent( const std::string& placement_id, const std::string& creative_instance_id, mojom::InlineContentAdEventType mojom_ad_event_type, - TriggerAdEventCallback callback); + TriggerAdEventCallback callback) override; + std::optional MaybeGetPrefetchedNewTabPageAdForDisplay() + override; + void PrefetchNewTabPageAd() override; + void OnFailedToPrefetchNewTabPageAd( + const std::string& placement_id, + const std::string& creative_instance_id) override; void TriggerNewTabPageAdEvent( const std::string& placement_id, const std::string& creative_instance_id, mojom::NewTabPageAdEventType mojom_ad_event_type, - TriggerAdEventCallback callback); - - void MaybeGetNotificationAd(const std::string& placement_id, - MaybeGetNotificationAdCallback callback); - void TriggerNotificationAdEvent( - const std::string& placement_id, - mojom::NotificationAdEventType mojom_ad_event_type, - TriggerAdEventCallback callback); + TriggerAdEventCallback callback) override; void TriggerPromotedContentAdEvent( const std::string& placement_id, const std::string& creative_instance_id, mojom::PromotedContentAdEventType mojom_ad_event_type, - TriggerAdEventCallback callback); + TriggerAdEventCallback callback) override; void MaybeGetSearchResultAd(const std::string& placement_id, - MaybeGetSearchResultAdCallback callback); + MaybeGetSearchResultAdCallback callback) override; void TriggerSearchResultAdEvent( mojom::CreativeSearchResultAdInfoPtr mojom_creative_ad, mojom::SearchResultAdEventType mojom_ad_event_type, - TriggerAdEventCallback callback); + TriggerAdEventCallback callback) override; void PurgeOrphanedAdEventsForType( mojom::AdType mojom_ad_type, - PurgeOrphanedAdEventsForTypeCallback callback); + PurgeOrphanedAdEventsForTypeCallback callback) override; + + void GetAdHistory(base::Time from_time, + base::Time to_time, + GetAdHistoryForUICallback callback) override; + + void ToggleLikeAd(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) override; + void ToggleDislikeAd(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) override; + void ToggleLikeSegment(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) override; + void ToggleDislikeSegment(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) override; + void ToggleSaveAd(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) override; + void ToggleMarkAdAsInappropriate(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) override; + + void NotifyTabTextContentDidChange(int32_t tab_id, + const std::vector& redirect_chain, + const std::string& text) override; + void NotifyTabHtmlContentDidChange(int32_t tab_id, + const std::vector& redirect_chain, + const std::string& html) override; + void NotifyTabDidStartPlayingMedia(int32_t tab_id) override; + void NotifyTabDidStopPlayingMedia(int32_t tab_id) override; + void NotifyTabDidChange(int32_t tab_id, + const std::vector& redirect_chain, + bool is_new_navigation, + bool is_restoring, + bool is_visible) override; + void NotifyTabDidLoad(int32_t tab_id, int http_status_code) override; + void NotifyDidCloseTab(int32_t tab_id) override; + + void NotifyUserGestureEventTriggered(int32_t page_transition_type) override; + + void NotifyBrowserDidBecomeActive() override; + void NotifyBrowserDidResignActive() override; + + void NotifyDidSolveAdaptiveCaptcha() override; private: // KeyedService: diff --git a/ios/browser/brave_ads/ads_service_impl_ios.mm b/ios/browser/brave_ads/ads_service_impl_ios.mm index c653fab57003..955cb6c78cb1 100644 --- a/ios/browser/brave_ads/ads_service_impl_ios.mm +++ b/ios/browser/brave_ads/ads_service_impl_ios.mm @@ -15,6 +15,7 @@ #include "base/functional/callback.h" #include "base/functional/callback_helpers.h" #include "base/metrics/histogram_macros.h" +#include "base/notimplemented.h" #include "base/task/sequenced_task_runner.h" #include "base/task/thread_pool.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" @@ -36,7 +37,8 @@ } // namespace AdsServiceImplIOS::AdsServiceImplIOS(PrefService* prefs) - : prefs_(prefs), + : AdsService(/*delegate=*/nullptr), + prefs_(prefs), database_queue_(base::ThreadPool::CreateSequencedTaskRunner( {base::MayBlock(), base::TaskPriority::USER_VISIBLE, base::TaskShutdownBehavior::BLOCK_SHUTDOWN})) { @@ -45,7 +47,7 @@ AdsServiceImplIOS::~AdsServiceImplIOS() = default; -bool AdsServiceImplIOS::IsRunning() const { +bool AdsServiceImplIOS::IsInitialized() const { return !!ads_; } @@ -56,7 +58,9 @@ mojom::BuildChannelInfoPtr mojom_build_channel, mojom::WalletInfoPtr mojom_wallet, InitializeCallback callback) { - CHECK(!IsRunning()); + if (IsInitialized()) { + return std::move(callback).Run(/*success=*/false); + } storage_path_ = base::FilePath(storage_path); ads_client_ = std::move(ads_client); @@ -68,13 +72,70 @@ } void AdsServiceImplIOS::ShutdownAds(ShutdownCallback callback) { - CHECK(IsRunning()); + if (!IsInitialized()) { + return std::move(callback).Run(/*success=*/false); + } ads_->Shutdown(base::BindOnce(&AdsServiceImplIOS::ShutdownAdsCallback, weak_ptr_factory_.GetWeakPtr(), std::move(callback))); } +void AdsServiceImplIOS::RunDBTransaction( + mojom::DBTransactionInfoPtr mojom_db_transaction, + RunDBTransactionCallback callback) { + database_.AsyncCall(&brave_ads::Database::RunDBTransaction) + .WithArgs(std::move(mojom_db_transaction)) + .Then(std::move(callback)); +} + +void AdsServiceImplIOS::MaybeGetNotificationAd( + const std::string& placement_id, + MaybeGetNotificationAdCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*ad*/ std::nullopt); + } + + ads_->MaybeGetNotificationAd(placement_id, std::move(callback)); +} + +void AdsServiceImplIOS::TriggerNotificationAdEvent( + const std::string& placement_id, + mojom::NotificationAdEventType mojom_ad_event_type, + TriggerAdEventCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->TriggerNotificationAdEvent(placement_id, mojom_ad_event_type, + std::move(callback)); +} + +bool AdsServiceImplIOS::IsBrowserUpgradeRequiredToServeAds() const { + return false; +} + +int64_t AdsServiceImplIOS::GetMaximumNotificationAdsPerHour() const { + NOTIMPLEMENTED() << "Not used on iOS."; + return 0; +} + +void AdsServiceImplIOS::OnNotificationAdShown( + const std::string& /*placement_id*/) { + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::OnNotificationAdClosed( + const std::string& /*placement_id*/, + const bool /*by_user*/) { + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::OnNotificationAdClicked( + const std::string& /*placement_id*/) { + NOTIMPLEMENTED() << "Not used on iOS."; +} + void AdsServiceImplIOS::ClearData(base::OnceClosure callback) { UMA_HISTOGRAM_BOOLEAN(kClearDataHistogramName, true); prefs_->ClearPrefsWithPrefixSilently("brave.brave_ads"); @@ -84,17 +145,25 @@ std::move(callback))); } -void AdsServiceImplIOS::RunDBTransaction( - mojom::DBTransactionInfoPtr mojom_db_transaction, - RunDBTransactionCallback callback) { - database_.AsyncCall(&brave_ads::Database::RunDBTransaction) - .WithArgs(std::move(mojom_db_transaction)) - .Then(std::move(callback)); +void AdsServiceImplIOS::AddBatAdsObserver( + mojo::PendingRemote + /*bat_ads_observer_pending_remote*/) { + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::GetDiagnostics(GetDiagnosticsCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*diagnostics*/ std::nullopt); + } + + ads_->GetDiagnostics(std::move(callback)); } void AdsServiceImplIOS::GetStatementOfAccounts( GetStatementOfAccountsCallback callback) { - CHECK(IsRunning()); + if (!IsInitialized()) { + return std::move(callback).Run(/*statement*/ nullptr); + } ads_->GetStatementOfAccounts(std::move(callback)); } @@ -102,7 +171,10 @@ void AdsServiceImplIOS::MaybeServeInlineContentAd( const std::string& dimensions, MaybeServeInlineContentAdCallback callback) { - CHECK(IsRunning()); + if (!IsInitialized()) { + return std::move(callback).Run(dimensions, + /*inline_content_ad*/ std::nullopt); + } ads_->MaybeServeInlineContentAd(dimensions, std::move(callback)); } @@ -110,49 +182,65 @@ void AdsServiceImplIOS::TriggerInlineContentAdEvent( const std::string& placement_id, const std::string& creative_instance_id, - mojom::InlineContentAdEventType mojom_ad_event_type, + const mojom::InlineContentAdEventType mojom_ad_event_type, TriggerAdEventCallback callback) { - CHECK(IsRunning()); + CHECK(mojom::IsKnownEnumValue(mojom_ad_event_type)); + + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } ads_->TriggerInlineContentAdEvent(placement_id, creative_instance_id, mojom_ad_event_type, std::move(callback)); } -void AdsServiceImplIOS::TriggerNewTabPageAdEvent( - const std::string& placement_id, - const std::string& creative_instance_id, - mojom::NewTabPageAdEventType mojom_ad_event_type, - TriggerAdEventCallback callback) { - CHECK(IsRunning()); - - ads_->TriggerNewTabPageAdEvent(placement_id, creative_instance_id, - mojom_ad_event_type, std::move(callback)); +void AdsServiceImplIOS::PrefetchNewTabPageAd() { + // TODO(https://github.com/brave/brave-browser/issues/39703): Unify iOS new + // tab takeover ad serving + NOTIMPLEMENTED() << "Not used on iOS."; } -void AdsServiceImplIOS::MaybeGetNotificationAd( - const std::string& placement_id, - MaybeGetNotificationAdCallback callback) { - CHECK(IsRunning()); +std::optional +AdsServiceImplIOS::MaybeGetPrefetchedNewTabPageAdForDisplay() { + // TODO(https://github.com/brave/brave-browser/issues/39703): Unify iOS new + // tab takeover ad serving + NOTIMPLEMENTED() << "Not used on iOS."; + return std::nullopt; +} - ads_->MaybeGetNotificationAd(placement_id, std::move(callback)); +void AdsServiceImplIOS::OnFailedToPrefetchNewTabPageAd( + const std::string& /*placement_id*/, + const std::string& /*creative_instance_id*/) { + // TODO(https://github.com/brave/brave-browser/issues/39703): Unify iOS new + // tab takeover ad serving + NOTIMPLEMENTED() << "Not used on iOS."; } -void AdsServiceImplIOS::TriggerNotificationAdEvent( +void AdsServiceImplIOS::TriggerNewTabPageAdEvent( const std::string& placement_id, - mojom::NotificationAdEventType mojom_ad_event_type, + const std::string& creative_instance_id, + const mojom::NewTabPageAdEventType mojom_ad_event_type, TriggerAdEventCallback callback) { - CHECK(IsRunning()); + CHECK(mojom::IsKnownEnumValue(mojom_ad_event_type)); - ads_->TriggerNotificationAdEvent(placement_id, mojom_ad_event_type, - std::move(callback)); + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->TriggerNewTabPageAdEvent(placement_id, creative_instance_id, + mojom_ad_event_type, std::move(callback)); } void AdsServiceImplIOS::TriggerPromotedContentAdEvent( const std::string& placement_id, const std::string& creative_instance_id, - mojom::PromotedContentAdEventType mojom_ad_event_type, + const mojom::PromotedContentAdEventType mojom_ad_event_type, TriggerAdEventCallback callback) { - CHECK(IsRunning()); + CHECK(mojom::IsKnownEnumValue(mojom_ad_event_type)); + + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } ads_->TriggerPromotedContentAdEvent(placement_id, creative_instance_id, mojom_ad_event_type, std::move(callback)); @@ -161,29 +249,186 @@ void AdsServiceImplIOS::MaybeGetSearchResultAd( const std::string& placement_id, MaybeGetSearchResultAdCallback callback) { - CHECK(IsRunning()); + if (!IsInitialized()) { + return std::move(callback).Run(/*mojom_creative_ad*/ {}); + } ads_->MaybeGetSearchResultAd(placement_id, std::move(callback)); } void AdsServiceImplIOS::TriggerSearchResultAdEvent( mojom::CreativeSearchResultAdInfoPtr mojom_creative_ad, - mojom::SearchResultAdEventType mojom_ad_event_type, + const mojom::SearchResultAdEventType mojom_ad_event_type, TriggerAdEventCallback callback) { - CHECK(IsRunning()); + CHECK(mojom::IsKnownEnumValue(mojom_ad_event_type)); + + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } ads_->TriggerSearchResultAdEvent(std::move(mojom_creative_ad), mojom_ad_event_type, std::move(callback)); } void AdsServiceImplIOS::PurgeOrphanedAdEventsForType( - mojom::AdType mojom_ad_type, + const mojom::AdType mojom_ad_type, PurgeOrphanedAdEventsForTypeCallback callback) { - CHECK(IsRunning()); + CHECK(mojom::IsKnownEnumValue(mojom_ad_type)); + + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } ads_->PurgeOrphanedAdEventsForType(mojom_ad_type, std::move(callback)); } +void AdsServiceImplIOS::GetAdHistory(const base::Time from_time, + const base::Time to_time, + GetAdHistoryForUICallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*ad_history*/ std::nullopt); + } + + ads_->GetAdHistory(from_time, to_time, std::move(callback)); +} + +void AdsServiceImplIOS::ToggleLikeAd(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->ToggleLikeAd(std::move(mojom_reaction), std::move(callback)); +} + +void AdsServiceImplIOS::ToggleDislikeAd(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->ToggleDislikeAd(std::move(mojom_reaction), std::move(callback)); +} + +void AdsServiceImplIOS::ToggleLikeSegment(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->ToggleLikeSegment(std::move(mojom_reaction), std::move(callback)); +} + +void AdsServiceImplIOS::ToggleDislikeSegment( + mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->ToggleDislikeSegment(std::move(mojom_reaction), std::move(callback)); +} + +void AdsServiceImplIOS::ToggleSaveAd(mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->ToggleSaveAd(std::move(mojom_reaction), std::move(callback)); +} + +void AdsServiceImplIOS::ToggleMarkAdAsInappropriate( + mojom::ReactionInfoPtr mojom_reaction, + ToggleReactionCallback callback) { + if (!IsInitialized()) { + return std::move(callback).Run(/*success*/ false); + } + + ads_->ToggleMarkAdAsInappropriate(std::move(mojom_reaction), + std::move(callback)); +} + +void AdsServiceImplIOS::NotifyTabTextContentDidChange( + const int32_t /*tab_id*/, + const std::vector& /*redirect_chain*/, + const std::string& /*text*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyTabHtmlContentDidChange( + const int32_t /*tab_id*/, + const std::vector& /*redirect_chain*/, + const std::string& /*html*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyTabDidStartPlayingMedia( + const int32_t /*tab_id*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyTabDidStopPlayingMedia(const int32_t /*tab_id*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyTabDidChange( + const int32_t /*tab_id*/, + const std::vector& /*redirect_chain*/, + const bool /*is_new_navigation*/, + const bool /*is_restoring*/, + const bool /*is_visible*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyTabDidLoad(const int32_t /*tab_id*/, + const int /*http_status_code*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyDidCloseTab(const int32_t /*tab_id*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyUserGestureEventTriggered( + const int32_t /*page_transition_type*/) { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyBrowserDidBecomeActive() { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyBrowserDidResignActive() { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + +void AdsServiceImplIOS::NotifyDidSolveAdaptiveCaptcha() { + // TODO(https://github.com/brave/brave-browser/issues/42373): Utilize + // AdsClientNotifier in AdsServiceImplIOS + NOTIMPLEMENTED() << "Not used on iOS."; +} + /////////////////////////////////////////////////////////////////////////////// void AdsServiceImplIOS::Shutdown() { @@ -192,7 +437,7 @@ } void AdsServiceImplIOS::InitializeAds(InitializeCallback callback) { - CHECK(!IsRunning()); + CHECK(!IsInitialized()); InitializeDatabase(); @@ -237,7 +482,7 @@ } // Ensure the Brave Ads service is stopped before clearing data. - CHECK(!IsRunning()); + CHECK(!IsInitialized()); database_queue_->PostTaskAndReply( FROM_HERE,