Deprecate and replace Brave Ads SetEnabled with SetBoolean pref

This commit is contained in:
Terry Mancey
2023-06-08 09:59:42 -05:00
committed by Aleksey Seren
parent 87ba11ac86
commit 92b9aaf221
7 changed files with 8 additions and 21 deletions
@@ -10,8 +10,10 @@
#include "base/android/jni_string.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_ads/android/jni_headers/BraveAdsNativeHelper_jni.h"
#include "brave/components/brave_ads/common/pref_names.h"
#include "brave/components/brave_ads/core/ads_util.h"
#include "chrome/browser/profiles/profile_android.h"
#include "components/prefs/pref_service.h"
namespace brave_ads {
@@ -34,12 +36,8 @@ void JNI_BraveAdsNativeHelper_SetAdsEnabled(
const base::android::JavaParamRef<jobject>& j_profile_android,
jboolean should_enable_ads) {
Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile_android);
AdsService* ads_service = AdsServiceFactory::GetForProfile(profile);
if (!ads_service) {
return;
}
ads_service->SetEnabled(should_enable_ads);
profile->GetPrefs()->SetBoolean(brave_ads::prefs::kEnabled,
should_enable_ads);
}
// static
@@ -7,11 +7,10 @@
#include "base/command_line.h"
#include "base/task/sequenced_task_runner.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/perf/brave_perf_switches.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/common/pref_names.h"
#include "brave/components/brave_news/common/pref_names.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
@@ -61,8 +60,7 @@ void MaybeEnableBraveFeatureForPerfTesting(Profile* profile) {
}
// Ads
auto* ads_service = brave_ads::AdsServiceFactory::GetForProfile(profile);
ads_service->SetEnabled(true);
profile->GetPrefs()->SetBoolean(brave_ads::prefs::kEnabled, true);
// Rewards
auto* rewards_service =
+1 -1
View File
@@ -14,7 +14,7 @@ brave_browser_perf_sources = [
brave_browser_perf_deps = [
"//base",
"//brave/components/brave_ads/browser",
"//brave/components/brave_ads/common",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser",
"//brave/components/brave_shields/common/",
@@ -49,9 +49,6 @@ class AdsService : public KeyedService {
// Returns |true| if ads are enabled.
virtual bool IsEnabled() const = 0;
// Called to enable or disable ads.
virtual void SetEnabled(bool is_enabled) = 0;
// Returns the maximum number of notification ads that can be served per hour.
virtual int64_t GetMaximumNotificationAdsPerHour() const = 0;
@@ -1017,7 +1017,7 @@ const PrefService* AdsServiceImpl::GetPrefService() const {
void AdsServiceImpl::DisableAdsIfUnsupportedRegion() {
if (!IsSupportedRegion() && IsEnabled()) {
SetEnabled(false);
SetBooleanPref(prefs::kEnabled, false);
}
}
@@ -1070,10 +1070,6 @@ bool AdsServiceImpl::IsEnabled() const {
return GetPrefService()->GetBoolean(prefs::kEnabled);
}
void AdsServiceImpl::SetEnabled(const bool is_enabled) {
SetBooleanPref(prefs::kEnabled, is_enabled);
}
int64_t AdsServiceImpl::GetMaximumNotificationAdsPerHour() const {
int64_t ads_per_hour =
GetPrefService()->GetInt64(prefs::kMaximumNotificationAdsPerHour);
@@ -197,7 +197,6 @@ class AdsServiceImpl : public AdsService,
// AdsService:
bool IsEnabled() const override;
void SetEnabled(bool is_enabled) override;
int64_t GetMaximumNotificationAdsPerHour() const override;
void SetMaximumNotificationAdsPerHour(int64_t ads_per_hour) override;
@@ -28,7 +28,6 @@ class AdsServiceMock : public AdsService {
~AdsServiceMock() override;
MOCK_CONST_METHOD0(IsEnabled, bool());
MOCK_METHOD1(SetEnabled, void(bool));
MOCK_CONST_METHOD0(GetMaximumNotificationAdsPerHour, int64_t());
MOCK_METHOD1(SetMaximumNotificationAdsPerHour, void(int64_t));