Skip to content

Commit

Permalink
Fixes issue with ads per day incorrectly limited to ads per hour and …
Browse files Browse the repository at this point in the history
…increases ads per day from 20 to 40
  • Loading branch information
tmancey committed Dec 16, 2020
1 parent 61efb6a commit 45188c2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/brave_ads/browser/ads_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void AdsService::RegisterProfilePrefs(
registry->RegisterUint64Pref(
ads::prefs::kAdsPerHour, 2);
registry->RegisterUint64Pref(
ads::prefs::kAdsPerDay, 20);
ads::prefs::kAdsPerDay, 40);

registry->RegisterIntegerPref(
ads::prefs::kIdleThreshold, 15);
Expand Down
12 changes: 10 additions & 2 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ uint64_t AdsServiceImpl::GetAdsPerHour() const {

uint64_t AdsServiceImpl::GetAdsPerDay() const {
return base::ClampToRange(GetUint64Pref(ads::prefs::kAdsPerDay),
static_cast<uint64_t>(1), static_cast<uint64_t>(20));
static_cast<uint64_t>(1), static_cast<uint64_t>(40));
}

bool AdsServiceImpl::ShouldAllowAdsSubdivisionTargeting() const {
Expand Down Expand Up @@ -1342,7 +1342,8 @@ bool AdsServiceImpl::MigratePrefs(
{{4, 5}, &AdsServiceImpl::MigratePrefsVersion4To5},
{{5, 6}, &AdsServiceImpl::MigratePrefsVersion5To6},
{{6, 7}, &AdsServiceImpl::MigratePrefsVersion6To7},
{{7, 8}, &AdsServiceImpl::MigratePrefsVersion7To8}
{{7, 8}, &AdsServiceImpl::MigratePrefsVersion7To8},
{{8, 9}, &AdsServiceImpl::MigratePrefsVersion8To9}
};

// Cycle through migration paths, i.e. if upgrading from version 2 to 5 we
Expand Down Expand Up @@ -1553,6 +1554,13 @@ void AdsServiceImpl::MigratePrefsVersion7To8() {
}
}

void AdsServiceImpl::MigratePrefsVersion8To9() {
// Unlike Muon, ads per day are not configurable in the UI so we can safely
// migrate to the new value

SetUint64Pref(ads::prefs::kAdsPerDay, 40);
}

int AdsServiceImpl::GetPrefsVersion() const {
return GetIntegerPref(prefs::kVersion);
}
Expand Down
1 change: 1 addition & 0 deletions components/brave_ads/browser/ads_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class AdsServiceImpl : public AdsService,
void MigratePrefsVersion5To6();
void MigratePrefsVersion6To7();
void MigratePrefsVersion7To8();
void MigratePrefsVersion8To9();
int GetPrefsVersion() const;

bool IsUpgradingFromPreBraveAdsBuild();
Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const int kSupportedCountryCodesSchemaVersionNumber = 9;
// Stores the preferences version number
const char kVersion[] = "brave.brave_ads.prefs.version";

const int kCurrentVersionNumber = 8;
const int kCurrentVersionNumber = 9;

} // namespace prefs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool AdsPerDayFrequencyCap::DoesRespectCap(
base::Time::kHoursPerDay;

const uint64_t cap =
AdsClientHelper::Get()->GetUint64Pref(prefs::kAdsPerHour);
AdsClientHelper::Get()->GetUint64Pref(prefs::kAdsPerDay);

return DoesHistoryRespectCapForRollingTimeConstraint(
history, time_constraint, cap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void MockDefaultPrefs(
mock->SetBooleanPref(prefs::kEnabled, true);

mock->SetUint64Pref(prefs::kAdsPerHour, 2);
mock->SetUint64Pref(prefs::kAdsPerDay, 20);
mock->SetUint64Pref(prefs::kAdsPerDay, 40);

mock->SetIntegerPref(prefs::kIdleThreshold, 15);

Expand Down
2 changes: 1 addition & 1 deletion vendor/brave-ios/Ads/BATBraveAds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
+ (__type)__objc_getter { return ads::__cpp_var; } \
+ (void)__objc_setter:(__type)newValue { ads::__cpp_var = newValue; }

static const NSInteger kDefaultNumberOfAdsPerDay = 20;
static const NSInteger kDefaultNumberOfAdsPerDay = 40;
static const NSInteger kDefaultNumberOfAdsPerHour = 2;

static const int kCurrentUserModelManifestSchemaVersion = 1;
Expand Down

0 comments on commit 45188c2

Please sign in to comment.