diff --git a/README.md b/README.md index 53fee1313cc0..056e42c5fa27 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,12 @@ void TabClosed( void RemoveAllHistory() ``` +`SetConfirmationsIsReady` should be called to inform ads if confirmations is ready +``` +void SetConfirmationsIsReady( + const bool is_ready) +``` + `ChangeLocale` should be called when the user changes the operating system's locale, i.e. `en`, `en_US` or `en_GB.UTF-8`. This call is not required if the operating system restarts the app when the user changes their locale ``` void ChangeLocale( @@ -201,11 +207,6 @@ void ShowNotification(std::unique_ptr info) void SetCatalogIssuers(std::unique_ptr info) ``` -`IsConfirmationsReadyToShowAds` should return `true` if Confirmations is ready to show ads otherwise returns `false` -``` -bool IsConfirmationsReadyToShowAds() -``` - `AdSustained` should be called to inform Confirmations that an ad was sustained ``` void AdSustained(std::unique_ptr info) diff --git a/include/bat/ads/ads.h b/include/bat/ads/ads.h index c56c3b42cc25..db121892608f 100644 --- a/include/bat/ads/ads.h +++ b/include/bat/ads/ads.h @@ -78,6 +78,9 @@ class ADS_EXPORT Ads { // Should be called to determine if the operating system's region is supported virtual bool IsSupportedRegion() = 0; + // Should be called to inform ads if confirmations is ready + virtual void SetConfirmationsIsReady(const bool is_ready) = 0; + // Should be called when the user changes the operating system's locale, i.e. // en, en_US or en_GB.UTF-8 unless the operating system restarts the app virtual void ChangeLocale(const std::string& locale) = 0; diff --git a/include/bat/ads/ads_client.h b/include/bat/ads/ads_client.h index d4f53ab76d52..5916cec6e06b 100644 --- a/include/bat/ads/ads_client.h +++ b/include/bat/ads/ads_client.h @@ -109,10 +109,6 @@ class ADS_EXPORT AdsClient { // Should notify that the catalog issuers have changed virtual void SetCatalogIssuers(std::unique_ptr info) = 0; - // Should return true if Confirmations is ready to show ad otherwise returns - // false - virtual bool IsConfirmationsReadyToShowAds() = 0; - // Should be called to inform Confirmations that an ad was sustained virtual void AdSustained(std::unique_ptr info) = 0; diff --git a/src/ads_impl.cc b/src/ads_impl.cc index 35b6571535d4..5ddc2fc9d280 100644 --- a/src/ads_impl.cc +++ b/src/ads_impl.cc @@ -45,6 +45,7 @@ AdsImpl::AdsImpl(AdsClient* ads_client) : ads_serve_(std::make_unique(this, ads_client, bundle_.get())), user_model_(nullptr), is_initialized_(false), + is_confirmations_ready_(false), ads_client_(ads_client) { } @@ -136,7 +137,7 @@ void AdsImpl::LoadUserModel() { auto locale = client_->GetLocale(); auto callback = std::bind(&AdsImpl::OnUserModelLoaded, this, _1, _2); ads_client_->LoadUserModelForLocale(locale, callback); -} +} void AdsImpl::OnUserModelLoaded(const Result result, const std::string& json) { if (result != SUCCESS) { @@ -323,6 +324,10 @@ bool AdsImpl::IsSupportedRegion() { return true; } +void AdsImpl::SetConfirmationsIsReady(const bool is_ready) { + is_confirmations_ready_ = is_ready; +} + void AdsImpl::ChangeLocale(const std::string& locale) { if (!IsInitialized()) { return; @@ -592,7 +597,7 @@ void AdsImpl::CheckReadyAdServe(const bool forced) { } if (!forced) { - if (!ads_client_->IsConfirmationsReadyToShowAds()) { + if (!is_confirmations_ready_) { LOG(INFO) << "Notification not made: Confirmations not ready"; return; diff --git a/src/ads_impl.h b/src/ads_impl.h index f5e4c6145e24..29d93c1766bb 100644 --- a/src/ads_impl.h +++ b/src/ads_impl.h @@ -77,6 +77,8 @@ class AdsImpl : public Ads { bool IsSupportedRegion() override; + void SetConfirmationsIsReady(const bool is_ready) override; + void ChangeLocale(const std::string& locale) override; void ClassifyPage(const std::string& url, const std::string& html) override; @@ -166,6 +168,8 @@ class AdsImpl : public Ads { private: bool is_initialized_; + bool is_confirmations_ready_; + AdsClient* ads_client_; // NOT OWNED // Not copyable, not assignable diff --git a/src/bat_native_ads.cc b/src/bat_native_ads.cc index c08b0885d82a..6cba51c57a29 100644 --- a/src/bat_native_ads.cc +++ b/src/bat_native_ads.cc @@ -15,6 +15,8 @@ int main() { ads.ChangeLocale("fr"); + ads.SetConfirmationsIsReady(true); + ads.OnIdle(); ads.TabUpdated(1, "https://brave.com", true, false); diff --git a/src/mock_ads_client.cc b/src/mock_ads_client.cc index c52028deac5c..32c9fc18967b 100644 --- a/src/mock_ads_client.cc +++ b/src/mock_ads_client.cc @@ -155,10 +155,6 @@ void MockAdsClient::SetCatalogIssuers(std::unique_ptr info) { (void)info; } -bool MockAdsClient::IsConfirmationsReadyToShowAds() { - return true; -} - void MockAdsClient::AdSustained(std::unique_ptr info) { (void)info; } diff --git a/src/mock_ads_client.h b/src/mock_ads_client.h index b4cde90a8fd9..b90fd6e320c0 100644 --- a/src/mock_ads_client.h +++ b/src/mock_ads_client.h @@ -54,7 +54,6 @@ class MockAdsClient : public AdsClient { void ShowNotification(std::unique_ptr info) override; void SetCatalogIssuers(std::unique_ptr info) override; - bool IsConfirmationsReadyToShowAds() override; void AdSustained(std::unique_ptr info) override; uint32_t SetTimer(const uint64_t time_offset) override; diff --git a/test/mock_ads_client.h b/test/mock_ads_client.h index 4bc445df771b..f362b25d3751 100644 --- a/test/mock_ads_client.h +++ b/test/mock_ads_client.h @@ -92,8 +92,6 @@ class MockAdsClient : public AdsClient { MOCK_METHOD1(SetCatalogIssuers, void( std::unique_ptr info)); - MOCK_METHOD0(IsConfirmationsReadyToShowAds, bool()); - MOCK_METHOD1(AdSustained, void( std::unique_ptr info));