Skip to content

Commit

Permalink
Resolves initiating profile DCHECK failure (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey authored Jan 25, 2019
1 parent 4c2242a commit c125900
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -201,11 +207,6 @@ void ShowNotification(std::unique_ptr<NotificationInfo> info)
void SetCatalogIssuers(std::unique_ptr<IssuersInfo> 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<NotificationInfo> info)
Expand Down
3 changes: 3 additions & 0 deletions include/bat/ads/ads.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions include/bat/ads/ads_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ class ADS_EXPORT AdsClient {
// Should notify that the catalog issuers have changed
virtual void SetCatalogIssuers(std::unique_ptr<IssuersInfo> 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<NotificationInfo> info) = 0;

Expand Down
9 changes: 7 additions & 2 deletions src/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ AdsImpl::AdsImpl(AdsClient* ads_client) :
ads_serve_(std::make_unique<AdsServe>(this, ads_client, bundle_.get())),
user_model_(nullptr),
is_initialized_(false),
is_confirmations_ready_(false),
ads_client_(ads_client) {
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/ads_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/bat_native_ads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ int main() {

ads.ChangeLocale("fr");

ads.SetConfirmationsIsReady(true);

ads.OnIdle();

ads.TabUpdated(1, "https://brave.com", true, false);
Expand Down
4 changes: 0 additions & 4 deletions src/mock_ads_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ void MockAdsClient::SetCatalogIssuers(std::unique_ptr<IssuersInfo> info) {
(void)info;
}

bool MockAdsClient::IsConfirmationsReadyToShowAds() {
return true;
}

void MockAdsClient::AdSustained(std::unique_ptr<NotificationInfo> info) {
(void)info;
}
Expand Down
1 change: 0 additions & 1 deletion src/mock_ads_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class MockAdsClient : public AdsClient {
void ShowNotification(std::unique_ptr<NotificationInfo> info) override;

void SetCatalogIssuers(std::unique_ptr<IssuersInfo> info) override;
bool IsConfirmationsReadyToShowAds() override;
void AdSustained(std::unique_ptr<NotificationInfo> info) override;

uint32_t SetTimer(const uint64_t time_offset) override;
Expand Down
2 changes: 0 additions & 2 deletions test/mock_ads_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class MockAdsClient : public AdsClient {
MOCK_METHOD1(SetCatalogIssuers, void(
std::unique_ptr<IssuersInfo> info));

MOCK_METHOD0(IsConfirmationsReadyToShowAds, bool());

MOCK_METHOD1(AdSustained, void(
std::unique_ptr<NotificationInfo> info));

Expand Down

0 comments on commit c125900

Please sign in to comment.