Skip to content

Commit

Permalink
Resolves initiating profile DCHECK failure (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey authored Jan 25, 2019
1 parent 0ef7164 commit ef08bed
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
3 changes: 0 additions & 3 deletions include/bat/confirmations/confirmations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<IssuersInfo> 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<NotificationInfo> info) = 0;

Expand Down
3 changes: 3 additions & 0 deletions include/bat/confirmations/confirmations_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogStream> Log(
const char* file,
Expand Down
15 changes: 9 additions & 6 deletions src/confirmations_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ std::vector<std::string> 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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1376,6 +1377,8 @@ void ConfirmationsImpl::OnStateLoaded(

BLOG(INFO) << "Successfully loaded confirmations state";

SetConfirmationsStatus();

RefillConfirmations();
RetrievePaymentIOUs();
CashInPaymentIOUs();
Expand Down
3 changes: 2 additions & 1 deletion src/confirmations_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ConfirmationsImpl : public Confirmations {

void SetWalletInfo(std::unique_ptr<WalletInfo> info) override;
void SetCatalogIssuers(std::unique_ptr<IssuersInfo> info) override;
bool IsReadyToShowAds() override;
void AdSustained(std::unique_ptr<NotificationInfo> info) override;
void OnTimer(const uint32_t timer_id) override;

Expand Down Expand Up @@ -105,6 +104,8 @@ class ConfirmationsImpl : public Confirmations {

/////////////////////////////////////////////////////////////////////////////

void SetConfirmationsStatus();

std::string GetServerUrl();
int GetServerPort();

Expand Down
4 changes: 4 additions & 0 deletions src/mock_confirmations_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ void MockConfirmationsClient::Reset(
callback(FAILED);
}

void MockConfirmationsClient::SetConfirmationsIsReady(const bool is_ready) {
(void)is_ready;
}

std::unique_ptr<LogStream> MockConfirmationsClient::Log(
const char* file,
const int line,
Expand Down
2 changes: 2 additions & 0 deletions src/mock_confirmations_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogStream> Log(
const char* file,
const int line,
Expand Down
3 changes: 3 additions & 0 deletions test/confirmations_client_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogStream> Log(
const char* file,
const int line,
Expand Down

0 comments on commit ef08bed

Please sign in to comment.