diff --git a/browser/greaselion/greaselion_browsertest.cc b/browser/greaselion/greaselion_browsertest.cc index ba7ca78d2f64..90d3e92aeed1 100644 --- a/browser/greaselion/greaselion_browsertest.cc +++ b/browser/greaselion/greaselion_browsertest.cc @@ -129,6 +129,7 @@ class GreaselionServiceTest : public BaseLocalDataFilesBrowserTest { BaseLocalDataFilesBrowserTest::SetUpOnMainThread(); base::ScopedAllowBlockingForTesting allow_blocking; response_->LoadMocks(); + profile()->GetPrefs()->SetBoolean(brave_rewards::prefs::kEnabled, true); } // BaseLocalDataFilesBrowserTest overrides diff --git a/browser/greaselion/greaselion_service_factory.cc b/browser/greaselion/greaselion_service_factory.cc index 0b6ba14300b5..b0f470879028 100644 --- a/browser/greaselion/greaselion_service_factory.cc +++ b/browser/greaselion/greaselion_service_factory.cc @@ -12,9 +12,11 @@ #include "base/no_destructor.h" #include "base/path_service.h" #include "brave/browser/brave_browser_process.h" +#include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/greaselion/browser/greaselion_service.h" #include "brave/components/greaselion/browser/greaselion_service_impl.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_paths.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/core/keyed_service.h" @@ -36,6 +38,19 @@ class GreaselionServiceDelegateImpl content::BrowserContext* browser_context) : browser_context_(browser_context) { DCHECK(browser_context_); + pref_change_registrar_.Init( + Profile::FromBrowserContext(browser_context)->GetPrefs()); + pref_change_registrar_.Add( + brave_rewards::prefs::kEnabled, + base::BindRepeating( + &GreaselionServiceDelegateImpl::UpdateGreaselionExtensions, + base::Unretained(this))); + } + + bool IsEnabled() const override { + return Profile::FromBrowserContext(browser_context_) + ->GetPrefs() + ->GetBoolean(brave_rewards::prefs::kEnabled); } void AddExtension(extensions::Extension* extension) override { @@ -56,7 +71,16 @@ class GreaselionServiceDelegateImpl } private: + void UpdateGreaselionExtensions() { + auto* service = + GreaselionServiceFactory::GetForBrowserContext(browser_context_); + if (service) { + service->UpdateInstalledExtensions(); + } + } + raw_ptr browser_context_; // Not owned + PrefChangeRegistrar pref_change_registrar_; }; } // namespace diff --git a/browser/greaselion/sources.gni b/browser/greaselion/sources.gni index 4dc7b7242621..15a865cd4a68 100644 --- a/browser/greaselion/sources.gni +++ b/browser/greaselion/sources.gni @@ -13,7 +13,9 @@ if (enable_greaselion) { brave_browser_greaselion_deps += [ "//base", + "//brave/components/brave_rewards/common", "//brave/components/greaselion/browser", + "//chrome/browser/profiles:profile", "//chrome/common", "//components/keyed_service/content", "//extensions/browser", diff --git a/components/greaselion/browser/greaselion_service.h b/components/greaselion/browser/greaselion_service.h index 9f3372179cd1..c031ea5cfab0 100644 --- a/components/greaselion/browser/greaselion_service.h +++ b/components/greaselion/browser/greaselion_service.h @@ -42,6 +42,7 @@ class GreaselionService : public KeyedService, class Delegate { public: virtual ~Delegate() = default; + virtual bool IsEnabled() const = 0; virtual void AddExtension(extensions::Extension* extension) = 0; virtual void UnloadExtension(const std::string& extension_id) = 0; }; diff --git a/components/greaselion/browser/greaselion_service_impl.cc b/components/greaselion/browser/greaselion_service_impl.cc index 781645461d16..1564ae2b2bc7 100644 --- a/components/greaselion/browser/greaselion_service_impl.cc +++ b/components/greaselion/browser/greaselion_service_impl.cc @@ -270,6 +270,9 @@ GreaselionServiceImpl::GetExtensionIdsForTesting() { } void GreaselionServiceImpl::UpdateInstalledExtensions() { + if (!delegate_->IsEnabled()) { + return; + } if (update_in_progress_) { update_pending_ = true; return;