Hide Brave Rewards toggle doesn't work after launching private window

This commit is contained in:
Emerick Rogul
2021-03-24 22:01:17 -04:00
parent f6ec503a1f
commit 553b9d48a5
3 changed files with 7 additions and 37 deletions
@@ -43,19 +43,6 @@
#include "brave/components/brave_rewards/browser/rewards_service_impl.h"
#endif
namespace {
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
void OverridePrefsForPrivateProfileUserPrefs(Profile* profile) {
if (brave::IsRegularProfile(profile))
return;
// rewards button should be hidden on guest and tor profile.
PrefService* pref_service = profile->GetPrefs();
pref_service->SetBoolean(brave_rewards::prefs::kHideButton, true);
}
#endif
} // namespace
namespace brave_rewards {
RewardsService* testing_service_;
@@ -90,18 +77,6 @@ RewardsServiceFactory::RewardsServiceFactory()
#if BUILDFLAG(ENABLE_GREASELION)
DependsOn(greaselion::GreaselionServiceFactory::GetInstance());
#endif
#if BUILDFLAG(BRAVE_REWARDS_ENABLED) && !defined(OS_ANDROID)
if (g_browser_process && g_browser_process->profile_manager())
g_browser_process->profile_manager()->AddObserver(this);
#endif
}
RewardsServiceFactory::~RewardsServiceFactory() {
#if BUILDFLAG(BRAVE_REWARDS_ENABLED) && !defined(OS_ANDROID)
if (g_browser_process && g_browser_process->profile_manager())
g_browser_process->profile_manager()->RemoveObserver(this);
#endif
}
KeyedService* RewardsServiceFactory::BuildServiceInstanceFor(
@@ -147,10 +122,4 @@ bool RewardsServiceFactory::ServiceIsNULLWhileTesting() const {
return false;
}
void RewardsServiceFactory::OnProfileAdded(Profile* profile) {
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
OverridePrefsForPrivateProfileUserPrefs(profile);
#endif
}
} // namespace brave_rewards
@@ -17,8 +17,7 @@ namespace brave_rewards {
class RewardsService;
// Singleton that owns all RewardsService and associates them with Profiles.
class RewardsServiceFactory : public BrowserContextKeyedServiceFactory,
public ProfileManagerObserver {
class RewardsServiceFactory : public BrowserContextKeyedServiceFactory {
public:
RewardsServiceFactory(const RewardsServiceFactory&) = delete;
RewardsServiceFactory& operator=(const RewardsServiceFactory&) = delete;
@@ -33,15 +32,12 @@ class RewardsServiceFactory : public BrowserContextKeyedServiceFactory,
friend struct base::DefaultSingletonTraits<RewardsServiceFactory>;
RewardsServiceFactory();
~RewardsServiceFactory() override;
~RewardsServiceFactory() override = default;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
bool ServiceIsNULLWhileTesting() const override;
// ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override;
};
} // namespace brave_rewards
@@ -13,6 +13,7 @@
#include "base/one_shot_event.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/extensions/brave_component_loader.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/ui/brave_actions/brave_action_view_controller.h"
#include "brave/browser/ui/views/brave_actions/brave_action_view.h"
#include "brave/browser/ui/views/brave_actions/brave_rewards_action_stub_view.h"
@@ -187,6 +188,10 @@ bool BraveActionsContainer::ShouldAddBraveRewardsAction() const {
return false;
}
if (!brave::IsRegularProfile(browser_->profile())) {
return false;
}
const PrefService* prefs = browser_->profile()->GetPrefs();
return !prefs->GetBoolean(brave_rewards::prefs::kHideButton);
}