diff --git a/include/bat/confirmations/confirmations.h b/include/bat/confirmations/confirmations.h index 47b39c3ee3df..d8f94a512e6a 100644 --- a/include/bat/confirmations/confirmations.h +++ b/include/bat/confirmations/confirmations.h @@ -32,9 +32,6 @@ class CONFIRMATIONS_EXPORT Confirmations { // Should be called when a new catalog has been downloaded in Brave Ads virtual void SetCatalogIssuers(std::unique_ptr info) = 0; - // Should be called to determine if Confirmations is ready to show ads - virtual bool IsReadyToShowAds() = 0; - // Should be called when an ad is sustained in Brave Ads virtual void AdSustained(std::unique_ptr info) = 0; diff --git a/include/bat/confirmations/confirmations_client.h b/include/bat/confirmations/confirmations_client.h index df0b674aa714..94a70b0b96c1 100644 --- a/include/bat/confirmations/confirmations_client.h +++ b/include/bat/confirmations/confirmations_client.h @@ -84,6 +84,9 @@ class CONFIRMATIONS_EXPORT ConfirmationsClient { // storage virtual void Reset(const std::string& name, OnResetCallback callback) = 0; + // Should be called to inform ads if confirmations is ready + virtual void SetConfirmationsIsReady(const bool is_ready) = 0; + // Should log diagnostic information virtual std::unique_ptr Log( const char* file, diff --git a/src/confirmations_impl.cc b/src/confirmations_impl.cc index cdad902a6069..007d31805472 100644 --- a/src/confirmations_impl.cc +++ b/src/confirmations_impl.cc @@ -86,12 +86,9 @@ std::vector ConfirmationsImpl::Unmunge(base::Value* value) { return v; } -bool ConfirmationsImpl::IsReadyToShowAds() { - // Whatever thread/service calls this in brave-core-client must also be the - // one that triggers ad showing, or we'll have a race condition - bool ready = (signed_blinded_confirmation_tokens.size() > 0); - - return ready; +void ConfirmationsImpl::SetConfirmationsStatus() { + bool is_ready = signed_blinded_confirmation_tokens.size() > 0 ? true : false; + confirmations_client_->SetConfirmationsIsReady(is_ready); } std::string ConfirmationsImpl::GetServerUrl() { @@ -433,10 +430,13 @@ void ConfirmationsImpl::Step2cRefillConfirmationsIfNecessary( VectorConcat(&this->signed_blinded_confirmation_tokens, &server_signed_blinded_confirmations); + SetConfirmationsStatus(); + this->SaveState(); OnStep2RefillConfirmationsIfNecessary(SUCCESS); } + void ConfirmationsImpl::OnStep2RefillConfirmationsIfNecessary( const Result result) { if (result != SUCCESS) { @@ -484,6 +484,7 @@ void ConfirmationsImpl::Step3RedeemConfirmation( // success/failure since it's cheaper development wise. but optimization wise, // it "wastes" a (free) confirmation token on failure this->PopFrontConfirmation(); + SetConfirmationsStatus(); // persist this->SaveState(); @@ -1376,6 +1377,8 @@ void ConfirmationsImpl::OnStateLoaded( BLOG(INFO) << "Successfully loaded confirmations state"; + SetConfirmationsStatus(); + RefillConfirmations(); RetrievePaymentIOUs(); CashInPaymentIOUs(); diff --git a/src/confirmations_impl.h b/src/confirmations_impl.h index ce9dcb1fc886..28e6fc6489ed 100644 --- a/src/confirmations_impl.h +++ b/src/confirmations_impl.h @@ -29,7 +29,6 @@ class ConfirmationsImpl : public Confirmations { void SetWalletInfo(std::unique_ptr info) override; void SetCatalogIssuers(std::unique_ptr info) override; - bool IsReadyToShowAds() override; void AdSustained(std::unique_ptr info) override; void OnTimer(const uint32_t timer_id) override; @@ -105,6 +104,8 @@ class ConfirmationsImpl : public Confirmations { ///////////////////////////////////////////////////////////////////////////// + void SetConfirmationsStatus(); + std::string GetServerUrl(); int GetServerPort(); diff --git a/src/mock_confirmations_client.cc b/src/mock_confirmations_client.cc index 8fd8ecdeaf5b..0067b7194166 100644 --- a/src/mock_confirmations_client.cc +++ b/src/mock_confirmations_client.cc @@ -122,6 +122,10 @@ void MockConfirmationsClient::Reset( callback(FAILED); } +void MockConfirmationsClient::SetConfirmationsIsReady(const bool is_ready) { + (void)is_ready; +} + std::unique_ptr MockConfirmationsClient::Log( const char* file, const int line, diff --git a/src/mock_confirmations_client.h b/src/mock_confirmations_client.h index 719ec488a6d3..a81d9a60a7f9 100644 --- a/src/mock_confirmations_client.h +++ b/src/mock_confirmations_client.h @@ -45,6 +45,8 @@ class MockConfirmationsClient : public ConfirmationsClient { void Reset(const std::string& name, OnResetCallback callback) override; + void SetConfirmationsIsReady(const bool is_ready) override; + std::unique_ptr Log( const char* file, const int line, diff --git a/test/confirmations_client_mock.h b/test/confirmations_client_mock.h index 2b89b4d50be7..a4955638f7d1 100644 --- a/test/confirmations_client_mock.h +++ b/test/confirmations_client_mock.h @@ -59,6 +59,9 @@ class MockConfirmationsClient : public ConfirmationsClient { const std::string& name, OnResetCallback callback)); + MOCK_METHOD1(SetConfirmationsIsReady, void( + const bool is_ready)); + std::unique_ptr Log( const char* file, const int line,