From c8ef420ebb3bcf85d4d9866db0352981973a4cc5 Mon Sep 17 00:00:00 2001 From: bridiver <34129+bridiver@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:34:32 -0700 Subject: [PATCH] remove check_includes = false for brave_rewards --- browser/brave_rewards/BUILD.gn | 65 +++++ .../android/brave_rewards_native_worker.cc | 18 -- ...on_rewards_notification_service_observer.h | 1 - .../brave_rewards/rewards_service_factory.cc | 37 +-- browser/brave_rewards/rewards_tab_helper.cc | 26 +- browser/brave_rewards/rewards_tab_helper.h | 34 ++- browser/brave_rewards/sources.gni | 68 ------ browser/brave_rewards/test/BUILD.gn | 1 + browser/greaselion/{sources.gni => BUILD.gn} | 21 +- browser/sources.gni | 16 +- browser/tor/test/BUILD.gn | 1 + browser/ui/BUILD.gn | 22 +- components/brave_rewards/browser/BUILD.gn | 49 ++-- components/brave_rewards/browser/DEPS | 17 -- .../brave_rewards/browser/diagnostic_log.h | 1 - .../browser/rewards_notification_service.h | 1 - .../rewards_notification_service_impl.cc | 11 +- .../rewards_notification_service_impl.h | 7 +- .../brave_rewards/browser/rewards_p3a.cc | 1 - .../brave_rewards/browser/rewards_p3a.h | 5 +- .../rewards_protocol_navigation_throttle.cc | 5 - .../rewards_protocol_navigation_throttle.h | 2 - ...s_protocol_navigation_throttle_unittest.cc | 2 +- .../brave_rewards/browser/rewards_service.cc | 4 - .../brave_rewards/browser/rewards_service.h | 3 - .../browser/rewards_service_impl.cc | 228 ++++++++---------- .../browser/rewards_service_impl.h | 28 ++- .../rewards_service_impl_jp_unittest.cc | 16 +- .../browser/rewards_service_impl_unittest.cc | 16 +- components/brave_rewards/browser/test_util.cc | 7 +- components/brave_rewards/test/BUILD.gn | 1 + test/BUILD.gn | 4 + 32 files changed, 338 insertions(+), 380 deletions(-) delete mode 100644 browser/brave_rewards/sources.gni rename browser/greaselion/{sources.gni => BUILD.gn} (50%) diff --git a/browser/brave_rewards/BUILD.gn b/browser/brave_rewards/BUILD.gn index 49319324a0d4..75815a0d3d44 100644 --- a/browser/brave_rewards/BUILD.gn +++ b/browser/brave_rewards/BUILD.gn @@ -3,8 +3,73 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. */ +import("//extensions/buildflags/buildflags.gni") import("//testing/test.gni") +source_set("brave_rewards") { + sources = [ + "//brave/browser/brave_rewards/rewards_service_factory.h", + "//brave/browser/brave_rewards/rewards_tab_helper.h", + ] + + deps = [ + "//base", + "//brave/components/brave_rewards/browser", + "//chrome/browser/profiles", + "//components/keyed_service/content", + "//components/sessions", + "//content/public/browser", + ] +} + +source_set("brave_rewards_impl") { + sources = [ + "//brave/browser/brave_rewards/rewards_prefs_util.cc", + "//brave/browser/brave_rewards/rewards_prefs_util.h", + "//brave/browser/brave_rewards/rewards_service_factory.cc", + "//brave/browser/brave_rewards/rewards_tab_helper.cc", + ] + + public_deps = [ ":brave_rewards" ] + + deps = [ + ":util", + "//base", + "//brave/browser/brave_wallet", + "//brave/browser/greaselion", + "//brave/browser/ui:brave_rewards_source", + "//brave/components/brave_rewards/browser", + "//brave/components/brave_rewards/common", + "//brave/components/greaselion/browser/buildflags", + "//chrome/browser/bitmap_fetcher", + "//chrome/browser/favicon", + "//chrome/browser/profiles", + "//chrome/browser/ui", + "//components/keyed_service/content", + "//components/prefs", + "//components/sessions", + "//extensions/buildflags", + ] + + if (is_android) { + sources += [ + "//brave/browser/brave_rewards/android/brave_rewards_native_worker.cc", + "//brave/browser/brave_rewards/android/brave_rewards_native_worker.h", + ] + } + + if (enable_extensions) { + sources += [ + "extension_rewards_notification_service_observer.cc", + "extension_rewards_notification_service_observer.h", + "extension_rewards_service_observer.cc", + "extension_rewards_service_observer.h", + ] + + deps += [ "//extensions/browser" ] + } +} + source_set("util") { sources = [ "rewards_util.cc", diff --git a/browser/brave_rewards/android/brave_rewards_native_worker.cc b/browser/brave_rewards/android/brave_rewards_native_worker.cc index 974b35295bf1..a17441b74a66 100644 --- a/browser/brave_rewards/android/brave_rewards_native_worker.cc +++ b/browser/brave_rewards/android/brave_rewards_native_worker.cc @@ -5,37 +5,19 @@ #include "brave/browser/brave_rewards/android/brave_rewards_native_worker.h" -#include -#include -#include #include -#include "base/android/jni_android.h" -#include "base/android/jni_array.h" -#include "base/android/jni_string.h" #include "base/containers/contains.h" -#include "base/containers/flat_map.h" -#include "base/feature_list.h" -#include "base/json/json_writer.h" -#include "base/strings/stringprintf.h" #include "base/time/time.h" #include "brave/browser/brave_ads/ads_service_factory.h" #include "brave/browser/brave_rewards/rewards_service_factory.h" #include "brave/build/android/jni_headers/BraveRewardsNativeWorker_jni.h" -#include "brave/components/brave_adaptive_captcha/brave_adaptive_captcha_service.h" #include "brave/components/brave_adaptive_captcha/server_util.h" -#include "brave/components/brave_ads/browser/ads_service.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" -#include "brave/components/brave_rewards/browser/rewards_p3a.h" #include "brave/components/brave_rewards/browser/rewards_service.h" -#include "brave/components/brave_rewards/common/features.h" -#include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/brave_rewards/common/rewards_util.h" #include "brave/components/brave_rewards/core/global_constants.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" -#include "components/prefs/pref_service.h" -#include "content/public/browser/url_data_source.h" #define DEFAULT_ADS_PER_HOUR 2 diff --git a/browser/brave_rewards/extension_rewards_notification_service_observer.h b/browser/brave_rewards/extension_rewards_notification_service_observer.h index a243d1a6bba9..9fc8ce200507 100644 --- a/browser/brave_rewards/extension_rewards_notification_service_observer.h +++ b/browser/brave_rewards/extension_rewards_notification_service_observer.h @@ -8,7 +8,6 @@ #include "base/memory/raw_ptr.h" #include "brave/components/brave_rewards/browser/rewards_notification_service_observer.h" -#include "brave/components/brave_rewards/common/mojom/rewards.mojom.h" class Profile; diff --git a/browser/brave_rewards/rewards_service_factory.cc b/browser/brave_rewards/rewards_service_factory.cc index c956fd438878..764184330fb6 100644 --- a/browser/brave_rewards/rewards_service_factory.cc +++ b/browser/brave_rewards/rewards_service_factory.cc @@ -11,17 +11,18 @@ #include "base/no_destructor.h" #include "brave/browser/brave_rewards/rewards_util.h" #include "brave/browser/brave_wallet/brave_wallet_service_factory.h" +#include "brave/browser/ui/webui/brave_rewards_source.h" #include "brave/components/brave_rewards/browser/rewards_notification_service_observer.h" #include "brave/components/brave_rewards/browser/rewards_service.h" #include "brave/components/brave_rewards/browser/rewards_service_impl.h" #include "brave/components/brave_rewards/browser/rewards_service_observer.h" #include "brave/components/greaselion/browser/buildflags/buildflags.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" +#include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" -#include "components/prefs/pref_service.h" +#include "content/public/browser/storage_partition.h" #include "extensions/buildflags/buildflags.h" #if BUILDFLAG(ENABLE_EXTENSIONS) @@ -32,7 +33,6 @@ #if BUILDFLAG(ENABLE_GREASELION) #include "brave/browser/greaselion/greaselion_service_factory.h" -#include "brave/components/greaselion/browser/greaselion_service.h" #endif namespace brave_rewards { @@ -77,25 +77,26 @@ KeyedService* RewardsServiceFactory::BuildServiceInstanceFor( std::unique_ptr extension_observer = nullptr; std::unique_ptr notification_observer = nullptr; + auto* profile = Profile::FromBrowserContext(context); #if BUILDFLAG(ENABLE_EXTENSIONS) - extension_observer = std::make_unique( - Profile::FromBrowserContext(context)); + extension_observer = + std::make_unique(profile); notification_observer = - std::make_unique( - Profile::FromBrowserContext(context)); + std::make_unique(profile); #endif - auto* brave_wallet_service = - brave_wallet::BraveWalletServiceFactory::GetServiceForContext(context); -#if BUILDFLAG(ENABLE_GREASELION) - greaselion::GreaselionService* greaselion_service = - greaselion::GreaselionServiceFactory::GetForBrowserContext(context); - std::unique_ptr rewards_service( - new RewardsServiceImpl(Profile::FromBrowserContext(context), - greaselion_service, brave_wallet_service)); -#else + // Set up the rewards data source + content::URLDataSource::Add(profile, + std::make_unique(profile)); std::unique_ptr rewards_service(new RewardsServiceImpl( - Profile::FromBrowserContext(context), brave_wallet_service)); + profile->GetPrefs(), profile->GetPath(), + FaviconServiceFactory::GetForProfile(profile, + ServiceAccessType::EXPLICIT_ACCESS), + BitmapFetcherServiceFactory::GetForBrowserContext(profile), + profile->GetDefaultStoragePartition(), +#if BUILDFLAG(ENABLE_GREASELION) + greaselion::GreaselionServiceFactory::GetForBrowserContext(context), #endif + brave_wallet::BraveWalletServiceFactory::GetServiceForContext(context))); rewards_service->Init(std::move(extension_observer), std::move(notification_observer)); return rewards_service.release(); diff --git a/browser/brave_rewards/rewards_tab_helper.cc b/browser/brave_rewards/rewards_tab_helper.cc index dadeecd7c0e7..be42f56f5947 100644 --- a/browser/brave_rewards/rewards_tab_helper.cc +++ b/browser/brave_rewards/rewards_tab_helper.cc @@ -21,14 +21,36 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/browser_list_observer.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #endif namespace brave_rewards { +#if !BUILDFLAG(IS_ANDROID) +class BraveBrowserListObserver : public BrowserListObserver { + public: + explicit BraveBrowserListObserver(RewardsTabHelper* tab_helper) + : tab_helper_(tab_helper) {} + ~BraveBrowserListObserver() override {} + void OnBrowserSetLastActive(Browser* browser) override { + tab_helper_->OnBrowserSetLastActive(browser); + } + void OnBrowserNoLongerActive(Browser* browser) override { + tab_helper_->OnBrowserNoLongerActive(browser); + } + + private: + raw_ptr tab_helper_; // Not owned. +}; +#endif + RewardsTabHelper::RewardsTabHelper(content::WebContents* web_contents) : content::WebContentsUserData(*web_contents), WebContentsObserver(web_contents), +#if !BUILDFLAG(IS_ANDROID) + browser_list_observer_(new BraveBrowserListObserver(this)), +#endif tab_id_(sessions::SessionTabHelper::IdForTab(web_contents)) { if (tab_id_.is_valid()) { rewards_service_ = RewardsServiceFactory::GetForProfile( @@ -40,7 +62,7 @@ RewardsTabHelper::RewardsTabHelper(content::WebContents* web_contents) } #if !BUILDFLAG(IS_ANDROID) - BrowserList::AddObserver(this); + BrowserList::AddObserver(browser_list_observer_.get()); #endif } @@ -49,7 +71,7 @@ RewardsTabHelper::~RewardsTabHelper() { rewards_service_->RemoveObserver(this); } #if !BUILDFLAG(IS_ANDROID) - BrowserList::RemoveObserver(this); + BrowserList::RemoveObserver(browser_list_observer_.get()); #endif } diff --git a/browser/brave_rewards/rewards_tab_helper.h b/browser/brave_rewards/rewards_tab_helper.h index 3a3112f25954..675a8cc6be12 100644 --- a/browser/brave_rewards/rewards_tab_helper.h +++ b/browser/brave_rewards/rewards_tab_helper.h @@ -1,11 +1,12 @@ /* Copyright (c) 2019 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef BRAVE_BROWSER_BRAVE_REWARDS_REWARDS_TAB_HELPER_H_ #define BRAVE_BROWSER_BRAVE_REWARDS_REWARDS_TAB_HELPER_H_ +#include #include #include "base/memory/raw_ptr.h" @@ -18,24 +19,18 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" -#if !BUILDFLAG(IS_ANDROID) -#include "chrome/browser/ui/browser_list_observer.h" -#endif - class Browser; +class BrowserListObserver; namespace brave_rewards { - class RewardsService; +class BraveBrowserListObserver; // A tab helper responsible for sending user-activity events to the Rewards -// engine in order to support the Auto Contribute feature, and for storing the -// publisher ID corresponding to a given tab. +// engine in order to support the Auto Contribute feature, and for storing +// the publisher ID corresponding to a given tab. class RewardsTabHelper : public content::WebContentsUserData, public content::WebContentsObserver, -#if !BUILDFLAG(IS_ANDROID) - public BrowserListObserver, -#endif public RewardsServiceObserver { public: RewardsTabHelper(const RewardsTabHelper&) = delete; @@ -52,16 +47,18 @@ class RewardsTabHelper : public content::WebContentsUserData, using Observation = base::ScopedObservation; // Returns the publisher ID associated with the web content loaded into this - // tab. The publisher ID does not necessarily refer to a registered publisher. + // tab. The publisher ID does not necessarily refer to a registered + // publisher. std::string GetPublisherIdForTab() { return publisher_id_; } - // Sets the publisher ID associated with the web content loaded into this tab. - // This method can be used to override the default publisher ID as determined - // by the current domain. + // Sets the publisher ID associated with the web content loaded into this + // tab. This method can be used to override the default publisher ID as + // determined by the current domain. void SetPublisherIdForTab(const std::string& publisher_id); private: friend class content::WebContentsUserData; + friend class brave_rewards::BraveBrowserListObserver; explicit RewardsTabHelper(content::WebContents* web_contents); @@ -78,10 +75,8 @@ class RewardsTabHelper : public content::WebContentsUserData, void WebContentsDestroyed() override; #if !BUILDFLAG(IS_ANDROID) - // BrowserListObserver: - void OnBrowserSetLastActive(Browser* browser) override; - void OnBrowserNoLongerActive(Browser* browser) override; - + void OnBrowserSetLastActive(Browser* browser); + void OnBrowserNoLongerActive(Browser* browser); bool BrowserHasWebContents(Browser* browser); #endif @@ -90,6 +85,7 @@ class RewardsTabHelper : public content::WebContentsUserData, void MaybeSavePublisherInfo(); + std::unique_ptr browser_list_observer_; SessionID tab_id_; raw_ptr rewards_service_ = nullptr; // NOT OWNED base::ObserverList observer_list_; diff --git a/browser/brave_rewards/sources.gni b/browser/brave_rewards/sources.gni deleted file mode 100644 index 3aa87b07969b..000000000000 --- a/browser/brave_rewards/sources.gni +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2021 The Brave Authors. All rights reserved. -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. - -import("//brave/components/greaselion/browser/buildflags/buildflags.gni") -import("//extensions/buildflags/buildflags.gni") - -brave_browser_brave_rewards_sources = [ - "//brave/browser/brave_rewards/rewards_prefs_util.cc", - "//brave/browser/brave_rewards/rewards_prefs_util.h", - "//brave/browser/brave_rewards/rewards_service_factory.cc", - "//brave/browser/brave_rewards/rewards_service_factory.h", - "//brave/browser/brave_rewards/rewards_tab_helper.cc", - "//brave/browser/brave_rewards/rewards_tab_helper.h", -] - -brave_browser_brave_rewards_deps = [ - "//base", - "//brave/browser/brave_rewards:util", - "//brave/components/brave_rewards/browser", - "//brave/components/brave_rewards/common", - "//brave/components/brave_rewards/core:headers", - "//chrome/browser:browser_process", - "//chrome/browser/profiles:profile", - "//chrome/browser/ui", - "//components/keyed_service/content", - "//components/prefs", - "//components/sessions", - "//extensions/buildflags", -] - -if (enable_greaselion) { - brave_browser_brave_rewards_deps += - [ "//brave/components/greaselion/browser" ] -} - -if (enable_extensions) { - brave_browser_brave_rewards_sources += [ - "//brave/browser/brave_rewards/extension_rewards_notification_service_observer.cc", - "//brave/browser/brave_rewards/extension_rewards_notification_service_observer.h", - "//brave/browser/brave_rewards/extension_rewards_service_observer.cc", - "//brave/browser/brave_rewards/extension_rewards_service_observer.h", - ] - - brave_browser_brave_rewards_deps += [ - "//brave/browser/extensions", - "//brave/common/extensions/api", - "//chrome/browser/extensions", - "//chrome/browser/profiles:profile", - "//chrome/browser/ui", - "//extensions/browser", - ] -} - -if (is_android) { - brave_browser_brave_rewards_sources += [ - "//brave/browser/brave_rewards/android/brave_rewards_native_worker.cc", - "//brave/browser/brave_rewards/android/brave_rewards_native_worker.h", - ] - - brave_browser_brave_rewards_deps += [ "//brave/components/brave_ads/browser" ] -} - -if (!is_android) { - brave_browser_brave_rewards_deps += - [ "//brave/components/brave_rewards/common:features" ] -} diff --git a/browser/brave_rewards/test/BUILD.gn b/browser/brave_rewards/test/BUILD.gn index 2394b56a1c22..09e6fc9e5f1a 100644 --- a/browser/brave_rewards/test/BUILD.gn +++ b/browser/brave_rewards/test/BUILD.gn @@ -18,6 +18,7 @@ source_set("browser_tests") { "//base/test:test_support", "//brave/app:command_ids", "//brave/browser", + "//brave/browser/brave_rewards", "//brave/browser/brave_rewards:util", "//brave/components/brave_rewards/browser", "//brave/components/brave_rewards/common", diff --git a/browser/greaselion/sources.gni b/browser/greaselion/BUILD.gn similarity index 50% rename from browser/greaselion/sources.gni rename to browser/greaselion/BUILD.gn index 15a865cd4a68..b3e0e121799b 100644 --- a/browser/greaselion/sources.gni +++ b/browser/greaselion/BUILD.gn @@ -1,23 +1,28 @@ -import("//brave/components/greaselion/browser/buildflags/buildflags.gni") +# Copyright (c) 2024 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. -brave_browser_greaselion_sources = [] -brave_browser_greaselion_deps = [] +import("//brave/components/greaselion/browser/buildflags/buildflags.gni") -if (enable_greaselion) { - brave_browser_greaselion_sources += [ +source_set("greaselion") { + sources = [ "//brave/browser/greaselion/greaselion_service_factory.cc", "//brave/browser/greaselion/greaselion_service_factory.h", "//brave/browser/greaselion/greaselion_tab_helper.cc", "//brave/browser/greaselion/greaselion_tab_helper.h", ] - brave_browser_greaselion_deps += [ + deps = [ "//base", + "//brave/browser:browser_process", "//brave/components/brave_rewards/common", "//brave/components/greaselion/browser", - "//chrome/browser/profiles:profile", - "//chrome/common", + "//chrome/browser/extensions", + "//chrome/browser/profiles", + "//chrome/common:constants", "//components/keyed_service/content", + "//components/keyed_service/core", "//extensions/browser", ] } diff --git a/browser/sources.gni b/browser/sources.gni index d0c26d927cbd..ea791eaa1901 100644 --- a/browser/sources.gni +++ b/browser/sources.gni @@ -9,7 +9,6 @@ import("//brave/browser/brave_adaptive_captcha/sources.gni") import("//brave/browser/brave_ads/sources.gni") import("//brave/browser/brave_news/sources.gni") import("//brave/browser/brave_referrals/sources.gni") -import("//brave/browser/brave_rewards/sources.gni") import("//brave/browser/brave_shields/sources.gni") import("//brave/browser/brave_stats/sources.gni") import("//brave/browser/brave_vpn/sources.gni") @@ -22,7 +21,6 @@ import("//brave/browser/download/sources.gni") import("//brave/browser/ephemeral_storage/sources.gni") import("//brave/browser/ethereum_remote_client/buildflags/buildflags.gni") import("//brave/browser/gcm_driver/sources.gni") -import("//brave/browser/greaselion/sources.gni") import("//brave/browser/importer/sources.gni") import("//brave/browser/infobars/sources.gni") import("//brave/browser/misc_metrics/sources.gni") @@ -52,6 +50,7 @@ import("//brave/components/brave_vpn/common/buildflags/buildflags.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//brave/components/commander/common/buildflags/buildflags.gni") +import("//brave/components/greaselion/browser/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") import("//extensions/buildflags/buildflags.gni") @@ -119,6 +118,8 @@ brave_chrome_browser_deps = [ "//brave/browser:browser_process", "//brave/browser:sparkle_buildflags", "//brave/browser/brave_federated", + "//brave/browser/brave_rewards:brave_rewards_impl", + "//brave/browser/brave_rewards:util", "//brave/browser/brave_wallet", "//brave/browser/brave_wallet:brave_wallet_delegate", "//brave/browser/brave_wallet:tab_helper", @@ -433,6 +434,13 @@ if (enable_brave_wayback_machine) { brave_chrome_browser_deps += [ "//brave/components/brave_wayback_machine" ] } +if (enable_greaselion) { + brave_chrome_browser_deps += [ + "//brave/browser/greaselion", + "//brave/components/greaselion/browser", + ] +} + if (enable_widevine) { brave_chrome_browser_sources += [ "//brave/browser/brave_drm_tab_helper.cc", @@ -496,7 +504,6 @@ brave_chrome_browser_sources += brave_browser_brave_adaptive_captcha_sources brave_chrome_browser_sources += brave_browser_brave_ads_sources brave_chrome_browser_sources += brave_browser_brave_news_sources brave_chrome_browser_sources += brave_browser_brave_referrals_sources -brave_chrome_browser_sources += brave_browser_brave_rewards_sources brave_chrome_browser_sources += brave_browser_brave_shields_sources brave_chrome_browser_sources += brave_browser_brave_stats_updater_sources brave_chrome_browser_sources += brave_browser_brave_vpn_sources @@ -507,7 +514,6 @@ brave_chrome_browser_sources += brave_browser_debounce_sources brave_chrome_browser_sources += brave_browser_download_sources brave_chrome_browser_sources += brave_browser_ephemeral_storage_sources brave_chrome_browser_sources += brave_browser_gcm_driver_sources -brave_chrome_browser_sources += brave_browser_greaselion_sources brave_chrome_browser_sources += brave_browser_importer_sources brave_chrome_browser_sources += brave_browser_infobar_sources brave_chrome_browser_sources += brave_browser_misc_metrics_sources @@ -533,7 +539,6 @@ brave_chrome_browser_deps += brave_browser_brave_adaptive_captcha_deps brave_chrome_browser_deps += brave_browser_brave_ads_deps brave_chrome_browser_deps += brave_browser_brave_news_deps brave_chrome_browser_deps += brave_browser_brave_referrals_deps -brave_chrome_browser_deps += brave_browser_brave_rewards_deps brave_chrome_browser_deps += brave_browser_brave_shields_deps brave_chrome_browser_deps += brave_browser_brave_stats_updater_deps brave_chrome_browser_deps += brave_browser_brave_vpn_deps @@ -544,7 +549,6 @@ brave_chrome_browser_deps += brave_browser_debounce_deps brave_chrome_browser_deps += brave_browser_download_deps brave_chrome_browser_deps += brave_browser_ephemeral_storage_deps brave_chrome_browser_deps += brave_browser_gcm_driver_deps -brave_chrome_browser_deps += brave_browser_greaselion_deps brave_chrome_browser_deps += brave_browser_importer_deps brave_chrome_browser_deps += brave_browser_infobar_deps brave_chrome_browser_deps += brave_browser_misc_metrics_deps diff --git a/browser/tor/test/BUILD.gn b/browser/tor/test/BUILD.gn index 7a12e6dcdd69..19fb899b47a2 100644 --- a/browser/tor/test/BUILD.gn +++ b/browser/tor/test/BUILD.gn @@ -53,6 +53,7 @@ source_set("browser_tests") { "//base", "//brave/app:brave_generated_resources_grit", "//brave/browser", + "//brave/browser/brave_rewards", "//brave/common", "//brave/components/brave_ads/browser", "//brave/components/brave_component_updater/browser", diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 38f52510d8a2..5e35366b09e5 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -39,9 +39,11 @@ source_set("ui") { ] public_deps = [ + ":brave_rewards_source", ":brave_tab_features", ":brave_tab_prefs", ] + sources = [ "brave_ui_features.cc", "brave_ui_features.h", @@ -61,8 +63,6 @@ source_set("ui") { "webui/brave_rewards_internals_ui.h", "webui/brave_rewards_page_ui.cc", "webui/brave_rewards_page_ui.h", - "webui/brave_rewards_source.cc", - "webui/brave_rewards_source.h", "webui/brave_wallet/line_chart/line_chart_ui.cc", "webui/brave_wallet/line_chart/line_chart_ui.h", "webui/brave_wallet/market/market_ui.cc", @@ -1137,6 +1137,7 @@ source_set("ui") { } deps += [ + "//brave/browser/brave_rewards", "//brave/browser/extensions", "//brave/components/brave_extension:generated_resources", "//brave/components/brave_extension:static_resources", @@ -1374,6 +1375,23 @@ source_set("brave_tab_features") { deps = [ "//base" ] } +source_set("brave_rewards_source") { + sources = [ + "webui/brave_rewards_source.cc", + "webui/brave_rewards_source.h", + ] + + deps = [ + "//base", + "//chrome/browser/bitmap_fetcher", + "//chrome/browser/profiles", + "//content/public/browser", + "//skia", + "//ui/gfx/codec", + "//url", + ] +} + source_set("unit_tests") { if (!is_android) { testonly = true diff --git a/components/brave_rewards/browser/BUILD.gn b/components/brave_rewards/browser/BUILD.gn index 244be753cfeb..18eec03b427b 100644 --- a/components/brave_rewards/browser/BUILD.gn +++ b/components/brave_rewards/browser/BUILD.gn @@ -4,13 +4,10 @@ # You can obtain one at https://mozilla.org/MPL/2.0/. import("//brave/components/brave_rewards/core/config.gni") +import("//brave/components/greaselion/browser/buildflags/buildflags.gni") import("//extensions/buildflags/buildflags.gni") static_library("browser") { - # Remove when https://github.com/brave/brave-browser/issues/10618 is resolved - check_includes = false - public_deps = [] - sources = [ "android_util.cc", "android_util.h", @@ -41,40 +38,47 @@ static_library("browser") { "//brave/app:brave_generated_resources_grit", "//brave/components/brave_ads/core", "//brave/components/brave_rewards/common", + "//brave/components/brave_rewards/common:features", "//brave/components/brave_rewards/common/buildflags", + "//brave/components/brave_rewards/core", + "//brave/components/brave_wallet/browser", + "//brave/components/brave_wallet/common", "//brave/components/greaselion/browser/buildflags", + "//brave/components/ntp_background_images/common", + "//brave/components/p3a_utils", "//brave/components/resources", "//brave/components/services/bat_rewards/public/interfaces", + "//brave/components/time_period_storage", + "//chrome/browser/bitmap_fetcher", # bad + "//components/country_codes", + "//components/favicon/core", + "//components/os_crypt/sync:os_crypt", + "//components/prefs", + "//components/sessions", + "//content/public/browser", "//mojo/public/cpp/bindings", "//net", "//services/data_decoder/public/cpp", "//services/network/public/cpp", "//services/service_manager/public/cpp", + "//ui/base", + "//ui/gfx", "//url", - - # for profile.h - "//components/domain_reliability", - "//components/keyed_service/content", - "//components/keyed_service/core", - "//components/sessions", - "//content/public/browser", - "//content/public/common", - "//services/network/public/mojom", ] - if (!is_android) { - # on android, one shot is part of base lib - deps += [ - # for one shot event - "//extensions/common", - ] - } - - public_deps += [ "//brave/components/brave_rewards/core:headers" ] + public_deps = [ "//brave/components/brave_rewards/core:headers" ] if (is_android) { deps += [ "//brave/components/safetynet:android" ] } + + if (enable_extensions) { + deps += [ "//extensions/buildflags" ] + } + + if (enable_greaselion) { + deps += [ "//brave/components/greaselion/browser" ] + } } source_set("testutil") { @@ -83,6 +87,7 @@ source_set("testutil") { ":browser", "//base", "//brave/browser", + "//brave/browser/brave_rewards", "//brave/components/brave_rewards/common", "//brave/components/brave_rewards/core:headers", "//chrome/browser/bitmap_fetcher:bitmap_fetcher", diff --git a/components/brave_rewards/browser/DEPS b/components/brave_rewards/browser/DEPS index c83bf3eaa583..e67730e905d0 100644 --- a/components/brave_rewards/browser/DEPS +++ b/components/brave_rewards/browser/DEPS @@ -12,23 +12,6 @@ include_rules = [ # Existing exceptions specific_include_rules = { "rewards_service_impl.cc": [ - "+brave/browser/ui/webui/brave_rewards_source.h", - "+chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h", - "+chrome/browser/browser_process_impl.h", - "+chrome/browser/favicon/favicon_service_factory.h", - "+chrome/browser/profiles/profile.h", - ], - "rewards_service_impl.h": [ "+chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h", ], - "rewards_notification_service_impl.cc": [ - "+chrome/browser/profiles/profile.h", - ], - "network_delegate_helper.cc": [ - "+brave/browser/brave_rewards/rewards_service_factory.h", - "+chrome/browser/profiles/profile.h", - ], - "network_delegate_helper.h": [ - "+brave/browser/net/url_context.h", - ], } diff --git a/components/brave_rewards/browser/diagnostic_log.h b/components/brave_rewards/browser/diagnostic_log.h index 9d7f3bd6e775..895b3ca21c75 100644 --- a/components/brave_rewards/browser/diagnostic_log.h +++ b/components/brave_rewards/browser/diagnostic_log.h @@ -8,7 +8,6 @@ #include -#include "base/files/file.h" #include "base/files/file_path.h" #include "base/sequence_checker.h" #include "base/task/sequenced_task_runner.h" diff --git a/components/brave_rewards/browser/rewards_notification_service.h b/components/brave_rewards/browser/rewards_notification_service.h index 67079ba241e5..14e0efd202cd 100644 --- a/components/brave_rewards/browser/rewards_notification_service.h +++ b/components/brave_rewards/browser/rewards_notification_service.h @@ -7,7 +7,6 @@ #define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_NOTIFICATION_SERVICE_H_ #include -#include #include #include diff --git a/components/brave_rewards/browser/rewards_notification_service_impl.cc b/components/brave_rewards/browser/rewards_notification_service_impl.cc index 8bbff6d6177a..9d0922ef5254 100644 --- a/components/brave_rewards/browser/rewards_notification_service_impl.cc +++ b/components/brave_rewards/browser/rewards_notification_service_impl.cc @@ -20,13 +20,13 @@ #include "base/values.h" #include "brave/components/brave_rewards/common/pref_names.h" #include "build/build_config.h" -#include "chrome/browser/profiles/profile.h" #include "components/prefs/pref_service.h" namespace brave_rewards { -RewardsNotificationServiceImpl::RewardsNotificationServiceImpl(Profile* profile) - : profile_(profile) { +RewardsNotificationServiceImpl::RewardsNotificationServiceImpl( + PrefService* prefs) + : prefs_(prefs) { ReadRewardsNotificationsJSON(); } @@ -141,8 +141,7 @@ RewardsNotificationServiceImpl::GenerateRewardsNotificationTimestamp() const { } void RewardsNotificationServiceImpl::ReadRewardsNotificationsJSON() { - std::string json = - profile_->GetPrefs()->GetString(prefs::kNotifications); + std::string json = prefs_->GetString(prefs::kNotifications); if (json.empty()) return; std::optional parsed = base::JSONReader::Read(json); @@ -247,7 +246,7 @@ void RewardsNotificationServiceImpl::StoreRewardsNotifications() { return; } - profile_->GetPrefs()->SetString(prefs::kNotifications, result); + prefs_->SetString(prefs::kNotifications, result); } bool RewardsNotificationServiceImpl::Exists(RewardsNotificationID id) const { diff --git a/components/brave_rewards/browser/rewards_notification_service_impl.h b/components/brave_rewards/browser/rewards_notification_service_impl.h index 66d0ccda7b5a..39df6b78e387 100644 --- a/components/brave_rewards/browser/rewards_notification_service_impl.h +++ b/components/brave_rewards/browser/rewards_notification_service_impl.h @@ -10,7 +10,6 @@ #include #include -#include "base/memory/raw_ptr.h" #include "base/values.h" #include "brave/components/brave_rewards/browser/rewards_notification_service.h" #include "brave/components/brave_rewards/browser/rewards_notification_service_observer.h" @@ -18,7 +17,7 @@ #include "brave/components/brave_rewards/common/mojom/rewards.mojom.h" #include "extensions/buildflags/buildflags.h" -class Profile; +class PrefService; namespace brave_rewards { @@ -27,7 +26,7 @@ class ExtensionRewardsNotificationServiceObserver; class RewardsNotificationServiceImpl final : public RewardsNotificationService, public RewardsServiceObserver { public: - explicit RewardsNotificationServiceImpl(Profile* profile); + explicit RewardsNotificationServiceImpl(PrefService* prefs); RewardsNotificationServiceImpl(const RewardsNotificationServiceImpl&) = delete; RewardsNotificationServiceImpl& operator=( @@ -81,7 +80,7 @@ class RewardsNotificationServiceImpl final : public RewardsNotificationService, RewardsNotificationID GenerateRewardsNotificationID() const; RewardsNotificationTimestamp GenerateRewardsNotificationTimestamp() const; - raw_ptr profile_ = nullptr; + raw_ptr prefs_ = nullptr; RewardsNotificationsMap rewards_notifications_; std::vector rewards_notifications_displayed_; std::unique_ptr extension_observer_; diff --git a/components/brave_rewards/browser/rewards_p3a.cc b/components/brave_rewards/browser/rewards_p3a.cc index c907f0a44d40..39b21f3f6712 100644 --- a/components/brave_rewards/browser/rewards_p3a.cc +++ b/components/brave_rewards/browser/rewards_p3a.cc @@ -5,7 +5,6 @@ #include "brave/components/brave_rewards/browser/rewards_p3a.h" -#include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "brave/components/brave_ads/core/public/prefs/pref_names.h" #include "brave/components/brave_rewards/common/pref_names.h" diff --git a/components/brave_rewards/browser/rewards_p3a.h b/components/brave_rewards/browser/rewards_p3a.h index 814cbc654340..1c77ce0a4058 100644 --- a/components/brave_rewards/browser/rewards_p3a.h +++ b/components/brave_rewards/browser/rewards_p3a.h @@ -1,7 +1,7 @@ -/* Copyright 2019 The Brave Authors. All rights reserved. +/* Copyright (c) 2019 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_P3A_H_ #define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_P3A_H_ @@ -10,7 +10,6 @@ #include "base/memory/raw_ptr.h" #include "base/time/time.h" -#include "base/timer/timer.h" #include "base/timer/wall_clock_timer.h" #include "brave/components/time_period_storage/weekly_storage.h" diff --git a/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc b/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc index 913b4f36748a..2347c006ce1c 100644 --- a/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc +++ b/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc @@ -6,10 +6,8 @@ #include "brave/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h" #include -#include #include #include -#include #include #include "base/ranges/algorithm.h" @@ -18,15 +16,12 @@ #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "brave/components/brave_rewards/core/buildflags.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_throttle.h" #include "content/public/browser/page_navigator.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" -#include "content/public/browser/web_contents_user_data.h" #include "content/public/common/referrer.h" #include "ui/base/page_transition_types.h" #include "url/gurl.h" diff --git a/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h b/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h index 1b36846310ae..3e9dafb456f7 100644 --- a/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h +++ b/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h @@ -9,8 +9,6 @@ #include #include "content/public/browser/navigation_throttle.h" -#include "ui/base/page_transition_types.h" -#include "url/gurl.h" namespace content { class NavigationHandle; diff --git a/components/brave_rewards/browser/rewards_protocol_navigation_throttle_unittest.cc b/components/brave_rewards/browser/rewards_protocol_navigation_throttle_unittest.cc index bb3479c8d0bf..3e4bf86a82bd 100644 --- a/components/brave_rewards/browser/rewards_protocol_navigation_throttle_unittest.cc +++ b/components/brave_rewards/browser/rewards_protocol_navigation_throttle_unittest.cc @@ -8,8 +8,8 @@ #include #include -#include "brave/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h" #include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" // clang-format off // npm run test -- brave_unit_tests --filter="*RewardsProtocolNavigationThrottleTest*" diff --git a/components/brave_rewards/browser/rewards_service.cc b/components/brave_rewards/browser/rewards_service.cc index 18d45b2dce06..3ec12be66dca 100644 --- a/components/brave_rewards/browser/rewards_service.cc +++ b/components/brave_rewards/browser/rewards_service.cc @@ -5,10 +5,6 @@ #include "brave/components/brave_rewards/browser/rewards_service.h" -#include "base/feature_list.h" -#include "base/logging.h" -#include "base/time/time.h" -#include "brave/components/brave_rewards/browser/rewards_notification_service_impl.h" #include "brave/components/brave_rewards/browser/rewards_service_observer.h" namespace brave_rewards { diff --git a/components/brave_rewards/browser/rewards_service.h b/components/brave_rewards/browser/rewards_service.h index b2d0593b8d19..0c64c46a874b 100644 --- a/components/brave_rewards/browser/rewards_service.h +++ b/components/brave_rewards/browser/rewards_service.h @@ -6,15 +6,12 @@ #ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_SERVICE_H_ -#include #include #include #include "base/containers/flat_map.h" #include "base/functional/callback_forward.h" #include "base/observer_list.h" -#include "base/types/expected.h" -#include "base/version.h" #include "brave/components/brave_rewards/browser/rewards_notification_service.h" #include "brave/components/brave_rewards/common/mojom/rewards.mojom.h" #include "build/build_config.h" diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 6ee34412fc7c..058d38228200 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -8,8 +8,6 @@ #include #include -#include -#include #include #include #include @@ -17,31 +15,24 @@ #include #include "base/barrier_closure.h" -#include "base/base64.h" #include "base/containers/contains.h" #include "base/feature_list.h" #include "base/files/file_util.h" #include "base/files/important_file_writer.h" #include "base/functional/bind.h" #include "base/i18n/time_formatting.h" -#include "base/json/json_reader.h" #include "base/json/json_string_value_serializer.h" #include "base/json/json_writer.h" #include "base/logging.h" #include "base/ranges/algorithm.h" -#include "base/strings/escape.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "base/task/sequenced_task_runner.h" #include "base/task/single_thread_task_runner.h" #include "base/task/thread_pool.h" #include "base/time/time.h" -#include "brave/browser/ui/webui/brave_rewards_source.h" #include "brave/components/api_request_helper/api_request_helper.h" #include "brave/components/brave_ads/core/public/prefs/pref_names.h" -#include "brave/components/brave_rewards/browser/android_util.h" #include "brave/components/brave_rewards/browser/diagnostic_log.h" #include "brave/components/brave_rewards/browser/logging.h" #include "brave/components/brave_rewards/browser/publisher_utils.h" @@ -57,21 +48,15 @@ #include "brave/components/brave_rewards/core/global_constants.h" #include "brave/components/brave_rewards/core/parameters/rewards_parameters_provider.h" #include "brave/components/brave_rewards/core/rewards_database.h" -#include "brave/components/brave_rewards/resources/grit/brave_rewards_resources.h" #include "brave/components/brave_wallet/browser/brave_wallet_service.h" #include "brave/components/brave_wallet/browser/json_rpc_service.h" #include "brave/components/ntp_background_images/common/pref_names.h" #include "brave/grit/brave_generated_resources.h" -#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" -#include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" #include "components/country_codes/country_codes.h" #include "components/favicon/core/favicon_service.h" -#include "components/favicon_base/favicon_types.h" -#include "components/grit/brave_components_resources.h" #include "components/os_crypt/sync/os_crypt.h" #include "components/prefs/pref_service.h" -#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/service_process_host.h" #include "content/public/browser/storage_partition.h" #include "content/public/browser/url_data_source.h" @@ -81,16 +66,12 @@ #include "net/cookies/cookie_util.h" #include "net/http/http_status_code.h" #include "services/network/public/cpp/resource_request.h" -#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/simple_url_loader.h" -#include "services/network/public/mojom/cookie_manager.mojom.h" #include "services/network/public/mojom/url_response_head.mojom.h" #include "third_party/icu/source/common/unicode/locid.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image.h" #include "url/gurl.h" -#include "url/url_canon_stdstring.h" -#include "url/url_util.h" namespace brave_rewards { @@ -269,12 +250,19 @@ const base::FilePath::StringType kPublishers_list("publishers_list"); #endif RewardsServiceImpl::RewardsServiceImpl( - Profile* profile, + PrefService* prefs, + const base::FilePath& profile_path, + favicon::FaviconService* favicon_service, + BitmapFetcherService* bitmap_fetcher_service, + content::StoragePartition* storage_partition, #if BUILDFLAG(ENABLE_GREASELION) greaselion::GreaselionService* greaselion_service, #endif brave_wallet::BraveWalletService* brave_wallet_service) - : profile_(profile), + : prefs_(prefs), + favicon_service_(favicon_service), + bitmap_fetcher_service_(bitmap_fetcher_service), + storage_partition_(storage_partition), #if BUILDFLAG(ENABLE_GREASELION) greaselion_service_(greaselion_service), #endif @@ -285,19 +273,15 @@ RewardsServiceImpl::RewardsServiceImpl( base::TaskShutdownBehavior::BLOCK_SHUTDOWN})), json_sanitizer_task_runner_(base::ThreadPool::CreateSequencedTaskRunner( {base::MayBlock(), base::TaskPriority::BEST_EFFORT})), - legacy_state_path_(profile_->GetPath().Append(kLegacy_state)), - publisher_state_path_(profile_->GetPath().Append(kPublisher_state)), - publisher_info_db_path_(profile->GetPath().Append(kPublisher_info_db)), - publisher_list_path_(profile->GetPath().Append(kPublishers_list)), - diagnostic_log_( - new DiagnosticLog(profile_->GetPath().Append(kDiagnosticLogPath), - kDiagnosticLogMaxFileSize, - kDiagnosticLogKeepNumLines)), - notification_service_(new RewardsNotificationServiceImpl(profile)), - conversion_monitor_(profile->GetPrefs()) { - // Set up the rewards data source - content::URLDataSource::Add(profile_, - std::make_unique(profile_)); + legacy_state_path_(profile_path.Append(kLegacy_state)), + publisher_state_path_(profile_path.Append(kPublisher_state)), + publisher_info_db_path_(profile_path.Append(kPublisher_info_db)), + publisher_list_path_(profile_path.Append(kPublishers_list)), + diagnostic_log_(new DiagnosticLog(profile_path.Append(kDiagnosticLogPath), + kDiagnosticLogMaxFileSize, + kDiagnosticLogKeepNumLines)), + notification_service_(new RewardsNotificationServiceImpl(prefs)), + conversion_monitor_(prefs) { ready_ = std::make_unique(); if (base::FeatureList::IsEnabled(features::kVerboseLoggingFeature)) { @@ -315,7 +299,7 @@ RewardsServiceImpl::RewardsServiceImpl( } #endif - p3a::RecordAdTypesEnabled(profile_->GetPrefs()); + p3a::RecordAdTypesEnabled(prefs_); } RewardsServiceImpl::~RewardsServiceImpl() { @@ -360,7 +344,7 @@ void RewardsServiceImpl::Init( } void RewardsServiceImpl::InitPrefChangeRegistrar() { - profile_pref_change_registrar_.Init(profile_->GetPrefs()); + profile_pref_change_registrar_.Init(prefs_); profile_pref_change_registrar_.Add( prefs::kAutoContributeEnabled, base::BindRepeating(&RewardsServiceImpl::OnPreferenceChanged, @@ -382,7 +366,7 @@ void RewardsServiceImpl::InitPrefChangeRegistrar() { void RewardsServiceImpl::OnPreferenceChanged(const std::string& key) { if (key == prefs::kAutoContributeEnabled) { - if (profile_->GetPrefs()->GetBoolean(prefs::kAutoContributeEnabled)) { + if (prefs_->GetBoolean(prefs::kAutoContributeEnabled)) { StartEngineProcessIfNecessary(); } // Must check for connected external wallet before recording @@ -394,7 +378,7 @@ void RewardsServiceImpl::OnPreferenceChanged(const std::string& key) { kNewTabPageShowSponsoredImagesBackgroundImage || key == brave_ads::prefs::kOptedInToNotificationAds || key == brave_ads::prefs::kOptedInToSearchResultAds) { - p3a::RecordAdTypesEnabled(profile_->GetPrefs()); + p3a::RecordAdTypesEnabled(prefs_); } if (key == brave_ads::prefs::kOptedInToSearchResultAds) { @@ -407,26 +391,24 @@ void RewardsServiceImpl::OnPreferenceChanged(const std::string& key) { if (key == brave_ads::prefs::kOptedInToNotificationAds) { if (greaselion_service_) { greaselion_service_->SetFeatureEnabled( - greaselion::ADS, profile_->GetPrefs()->GetBoolean( - brave_ads::prefs::kOptedInToNotificationAds)); + greaselion::ADS, + prefs_->GetBoolean(brave_ads::prefs::kOptedInToNotificationAds)); } } #endif } void RewardsServiceImpl::CheckPreferences() { - auto* prefs = profile_->GetPrefs(); - - if (prefs->GetBoolean(prefs::kAutoContributeEnabled) || - prefs->GetBoolean(brave_ads::prefs::kOptedInToNotificationAds)) { + if (prefs_->GetBoolean(prefs::kAutoContributeEnabled) || + prefs_->GetBoolean(brave_ads::prefs::kOptedInToNotificationAds)) { // If the user has enabled Ads or AC, but the "enabled" pref is missing, set // the "enabled" pref to true. - if (!prefs->GetUserPrefValue(prefs::kEnabled)) { - prefs->SetBoolean(prefs::kEnabled, true); + if (!prefs_->GetUserPrefValue(prefs::kEnabled)) { + prefs_->SetBoolean(prefs::kEnabled, true); } } - if (prefs->GetUserPrefValue(prefs::kEnabled)) { + if (prefs_->GetUserPrefValue(prefs::kEnabled)) { // If the "enabled" pref is set, then start the background Rewards // utility process. StartEngineProcessIfNecessary(); @@ -434,10 +416,10 @@ void RewardsServiceImpl::CheckPreferences() { // If Rewards is enabled and the user has a linked account, then ensure that // the "search result ads enabled" pref has the appropriate default value. - if (prefs->GetBoolean(prefs::kEnabled) && - !prefs->GetString(prefs::kExternalWalletType).empty() && - !prefs->HasPrefPath(brave_ads::prefs::kOptedInToSearchResultAds)) { - prefs->SetBoolean(brave_ads::prefs::kOptedInToSearchResultAds, false); + if (prefs_->GetBoolean(prefs::kEnabled) && + !prefs_->GetString(prefs::kExternalWalletType).empty() && + !prefs_->HasPrefPath(brave_ads::prefs::kOptedInToSearchResultAds)) { + prefs_->SetBoolean(brave_ads::prefs::kOptedInToSearchResultAds, false); } } @@ -511,16 +493,15 @@ void RewardsServiceImpl::CreateRewardsWallet( return; } - auto* prefs = self->profile_->GetPrefs(); - prefs->SetString(prefs::kDeclaredGeo, country); + self->prefs_->SetString(prefs::kDeclaredGeo, country); // Record in which environment the wallet was created (for display on the // rewards internals page). auto on_get_environment = [](base::WeakPtr self, mojom::Environment environment) { if (self) { - self->profile_->GetPrefs()->SetInteger( - prefs::kWalletCreationEnvironment, static_cast(environment)); + self->prefs_->SetInteger(prefs::kWalletCreationEnvironment, + static_cast(environment)); } }; @@ -528,14 +509,17 @@ void RewardsServiceImpl::CreateRewardsWallet( // After successfully creating a Rewards wallet for the first time, // automatically enable Ads and AC. - if (!prefs->GetBoolean(prefs::kEnabled)) { - prefs->SetBoolean(prefs::kEnabled, true); - prefs->SetString(prefs::kUserVersion, prefs::kCurrentUserVersion); - prefs->SetBoolean(brave_ads::prefs::kOptedInToNotificationAds, true); + if (!self->prefs_->GetBoolean(prefs::kEnabled)) { + self->prefs_->SetBoolean(prefs::kEnabled, true); + self->prefs_->SetString(prefs::kUserVersion, + prefs::kCurrentUserVersion); + self->prefs_->SetBoolean(brave_ads::prefs::kOptedInToNotificationAds, + true); // Set the user's current ToS version. - prefs->SetInteger(prefs::kTosVersion, - RewardsParametersFromPrefs(*prefs)->tos_version); + self->prefs_->SetInteger( + prefs::kTosVersion, + RewardsParametersFromPrefs(*(self->prefs_))->tos_version); // Fetch the user's balance before turning on AC. We don't want to // automatically turn on AC if for some reason the user has a current @@ -555,7 +539,7 @@ void RewardsServiceImpl::CreateRewardsWallet( } self->conversion_monitor_.RecordRewardsEnable(); - p3a::RecordAdTypesEnabled(prefs); + p3a::RecordAdTypesEnabled(self->prefs_); std::move(callback).Run(CreateRewardsWalletResult::kSuccess); }; @@ -588,20 +572,18 @@ void RewardsServiceImpl::GetUserType( } bool RewardsServiceImpl::IsTermsOfServiceUpdateRequired() { - auto* prefs = profile_->GetPrefs(); - if (!prefs->GetBoolean(prefs::kEnabled)) { + if (!prefs_->GetBoolean(prefs::kEnabled)) { return false; } - int params_version = RewardsParametersFromPrefs(*prefs)->tos_version; - int user_version = prefs->GetInteger(prefs::kTosVersion); + int params_version = RewardsParametersFromPrefs(*prefs_)->tos_version; + int user_version = prefs_->GetInteger(prefs::kTosVersion); return user_version < params_version; } void RewardsServiceImpl::AcceptTermsOfServiceUpdate() { if (IsTermsOfServiceUpdateRequired()) { - auto* prefs = profile_->GetPrefs(); - int params_version = RewardsParametersFromPrefs(*prefs)->tos_version; - prefs->SetInteger(prefs::kTosVersion, params_version); + int params_version = RewardsParametersFromPrefs(*prefs_)->tos_version; + prefs_->SetInteger(prefs::kTosVersion, params_version); for (auto& observer : observers_) { observer.OnTermsOfServiceUpdateAccepted(); } @@ -609,12 +591,11 @@ void RewardsServiceImpl::AcceptTermsOfServiceUpdate() { } std::string RewardsServiceImpl::GetCountryCode() const { - auto* prefs = profile_->GetPrefs(); - std::string declared_geo = prefs->GetString(prefs::kDeclaredGeo); + std::string declared_geo = prefs_->GetString(prefs::kDeclaredGeo); return !declared_geo.empty() ? declared_geo : country_codes::CountryIDToCountryString( - country_codes::GetCountryIDFromPrefs(prefs)); + country_codes::GetCountryIDFromPrefs(prefs_)); } void RewardsServiceImpl::GetAvailableCountries( @@ -840,11 +821,9 @@ void RewardsServiceImpl::Shutdown() { RemoveObserver(extension_observer_.get()); } - BitmapFetcherService* image_service = - BitmapFetcherServiceFactory::GetForBrowserContext(profile_); - if (image_service) { + if (bitmap_fetcher_service_) { for (auto mapping : current_media_fetchers_) { - image_service->CancelRequest(mapping.second); + bitmap_fetcher_service_->CancelRequest(mapping.second); } } @@ -1025,9 +1004,7 @@ void RewardsServiceImpl::LoadURL(mojom::UrlRequestPtr request, auto loader_it = url_loaders_.insert(url_loaders_.begin(), std::move(loader)); loader_it->get()->DownloadToStringOfUnboundedSizeUntilCrashAndDie( - profile_->GetDefaultStoragePartition() - ->GetURLLoaderFactoryForBrowserProcess() - .get(), + storage_partition_->GetURLLoaderFactoryForBrowserProcess().get(), base::BindOnce(&RewardsServiceImpl::OnURLLoaderComplete, base::Unretained(this), loader_it, std::move(callback))); } @@ -1190,8 +1167,7 @@ std::vector RewardsServiceImpl::GetExternalWalletProviders() if (base::FeatureList::IsEnabled( features::kAllowSelfCustodyProvidersFeature)) { - auto& self_custody_dict = - profile_->GetPrefs()->GetDict(prefs::kSelfCustodyAvailable); + auto& self_custody_dict = prefs_->GetDict(prefs::kSelfCustodyAvailable); if (auto solana_entry = self_custody_dict.FindBool(internal::constant::kWalletSolana); @@ -1220,10 +1196,10 @@ void RewardsServiceImpl::EnableGreaselion() { greaselion_service_->SetFeatureEnabled(greaselion::REWARDS, true); greaselion_service_->SetFeatureEnabled( greaselion::AUTO_CONTRIBUTION, - profile_->GetPrefs()->GetBoolean(prefs::kAutoContributeEnabled)); + prefs_->GetBoolean(prefs::kAutoContributeEnabled)); greaselion_service_->SetFeatureEnabled( - greaselion::ADS, profile_->GetPrefs()->GetBoolean( - brave_ads::prefs::kOptedInToNotificationAds)); + greaselion::ADS, + prefs_->GetBoolean(brave_ads::prefs::kOptedInToNotificationAds)); greaselion_enabled_ = true; } @@ -1263,12 +1239,12 @@ void RewardsServiceImpl::OnStopEngineForCompleteReset( SuccessCallback callback, const mojom::Result result) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - profile_->GetPrefs()->ClearPrefsWithPrefixSilently(pref_prefix); + prefs_->ClearPrefsWithPrefixSilently(pref_prefix); diagnostic_log_->Delete(base::BindOnce( &RewardsServiceImpl::OnDiagnosticLogDeletedForCompleteReset, AsWeakPtr(), std::move(callback))); - p3a::RecordAdTypesEnabled(profile_->GetPrefs()); + p3a::RecordAdTypesEnabled(prefs_); } void RewardsServiceImpl::OnDiagnosticLogDeletedForCompleteReset( @@ -1290,11 +1266,9 @@ void RewardsServiceImpl::OnDiagnosticLogDeletedForCompleteReset( void RewardsServiceImpl::Reset() { url_loaders_.clear(); - BitmapFetcherService* image_service = - BitmapFetcherServiceFactory::GetForBrowserContext(profile_); - if (image_service) { + if (bitmap_fetcher_service_) { for (auto mapping : current_media_fetchers_) { - image_service->CancelRequest(mapping.second); + bitmap_fetcher_service_->CancelRequest(mapping.second); } } @@ -1310,103 +1284,102 @@ void RewardsServiceImpl::Reset() { void RewardsServiceImpl::SetBooleanState(const std::string& name, bool value, SetBooleanStateCallback callback) { - profile_->GetPrefs()->SetBoolean(GetPrefPath(name), value); + prefs_->SetBoolean(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetBooleanState(const std::string& name, GetBooleanStateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetBoolean(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetBoolean(GetPrefPath(name))); } void RewardsServiceImpl::SetIntegerState(const std::string& name, int32_t value, SetIntegerStateCallback callback) { - profile_->GetPrefs()->SetInteger(GetPrefPath(name), value); + prefs_->SetInteger(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetIntegerState(const std::string& name, GetIntegerStateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetInteger(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetInteger(GetPrefPath(name))); } void RewardsServiceImpl::SetDoubleState(const std::string& name, double value, SetDoubleStateCallback callback) { - profile_->GetPrefs()->SetDouble(GetPrefPath(name), value); + prefs_->SetDouble(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetDoubleState(const std::string& name, GetDoubleStateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetDouble(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetDouble(GetPrefPath(name))); } void RewardsServiceImpl::SetStringState(const std::string& name, const std::string& value, SetStringStateCallback callback) { - profile_->GetPrefs()->SetString(GetPrefPath(name), value); + prefs_->SetString(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetStringState(const std::string& name, GetStringStateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetString(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetString(GetPrefPath(name))); } void RewardsServiceImpl::SetInt64State(const std::string& name, int64_t value, SetInt64StateCallback callback) { - profile_->GetPrefs()->SetInt64(GetPrefPath(name), value); + prefs_->SetInt64(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetInt64State(const std::string& name, GetInt64StateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetInt64(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetInt64(GetPrefPath(name))); } void RewardsServiceImpl::SetUint64State(const std::string& name, uint64_t value, SetUint64StateCallback callback) { - profile_->GetPrefs()->SetUint64(GetPrefPath(name), value); + prefs_->SetUint64(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetUint64State(const std::string& name, GetUint64StateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetUint64(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetUint64(GetPrefPath(name))); } void RewardsServiceImpl::SetValueState(const std::string& name, base::Value value, SetValueStateCallback callback) { - profile_->GetPrefs()->Set(GetPrefPath(name), std::move(value)); + prefs_->Set(GetPrefPath(name), std::move(value)); std::move(callback).Run(); } void RewardsServiceImpl::GetValueState(const std::string& name, GetValueStateCallback callback) { - std::move(callback).Run( - profile_->GetPrefs()->GetValue(GetPrefPath(name)).Clone()); + std::move(callback).Run(prefs_->GetValue(GetPrefPath(name)).Clone()); } void RewardsServiceImpl::SetTimeState(const std::string& name, base::Time value, SetTimeStateCallback callback) { - profile_->GetPrefs()->SetTime(GetPrefPath(name), value); + prefs_->SetTime(GetPrefPath(name), value); std::move(callback).Run(); } void RewardsServiceImpl::GetTimeState(const std::string& name, GetTimeStateCallback callback) { - std::move(callback).Run(profile_->GetPrefs()->GetTime(GetPrefPath(name))); + std::move(callback).Run(prefs_->GetTime(GetPrefPath(name))); } void RewardsServiceImpl::ClearState(const std::string& name, ClearStateCallback callback) { - profile_->GetPrefs()->ClearPref(GetPrefPath(name)); + prefs_->ClearPref(GetPrefPath(name)); std::move(callback).Run(); } @@ -1572,10 +1545,8 @@ void RewardsServiceImpl::FetchFavIcon(const std::string& url, return std::move(callback).Run(false, ""); } - BitmapFetcherService* image_service = - BitmapFetcherServiceFactory::GetForBrowserContext(profile_); - if (image_service) { - current_media_fetchers_[url] = image_service->RequestImage( + if (bitmap_fetcher_service_) { + current_media_fetchers_[url] = bitmap_fetcher_service_->RequestImage( parsedUrl, base::BindOnce( &RewardsServiceImpl::OnFetchFavIconCompleted, AsWeakPtr(), @@ -1601,10 +1572,8 @@ void RewardsServiceImpl::OnFetchFavIconCompleted(FetchFavIconCallback callback, const SkBitmap& image) { GURL favicon_url(favicon_key); gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(image); - favicon::FaviconService* favicon_service = - FaviconServiceFactory::GetForProfile(profile_, - ServiceAccessType::EXPLICIT_ACCESS); - favicon_service->SetOnDemandFavicons( + + favicon_service_->SetOnDemandFavicons( favicon_url, url, favicon_base::IconType::kFavicon, gfx_image, base::BindOnce(&RewardsServiceImpl::OnSetOnDemandFaviconComplete, AsWeakPtr(), favicon_url.spec(), std::move(callback))); @@ -1983,7 +1952,7 @@ void RewardsServiceImpl::PrepareEngineEnvForTesting( engine_state_target_version_for_testing_; options.retry_interval = 1; - profile_->GetPrefs()->SetInteger(prefs::kMinVisitTime, 1); + prefs_->SetInteger(prefs::kMinVisitTime, 1); } void RewardsServiceImpl::StartContributionsForTesting() { @@ -2007,7 +1976,7 @@ p3a::ConversionMonitor* RewardsServiceImpl::GetP3AConversionMonitor() { } void RewardsServiceImpl::OnRewardsPageShown() { - p3a::RecordRewardsPageViews(profile_->GetPrefs(), true); + p3a::RecordRewardsPageViews(prefs_, true); } void RewardsServiceImpl::PublisherListNormalized( @@ -2078,7 +2047,7 @@ void RewardsServiceImpl::FetchBalance(FetchBalanceCallback callback) { } void RewardsServiceImpl::GetLegacyWallet(GetLegacyWalletCallback callback) { - const auto& dict = profile_->GetPrefs()->GetDict(prefs::kExternalWallets); + const auto& dict = prefs_->GetDict(prefs::kExternalWallets); std::string json; for (auto it = dict.begin(); it != dict.end(); ++it) { @@ -2132,8 +2101,8 @@ void RewardsServiceImpl::OnExternalWalletLoginStarted( set_cookie_callback.Run(); }; - auto* cookie_manager = profile_->GetDefaultStoragePartition() - ->GetCookieManagerForBrowserProcess(); + auto* cookie_manager = + storage_partition_->GetCookieManagerForBrowserProcess(); net::CookieOptions options; options.set_include_httponly(); @@ -2225,7 +2194,7 @@ void RewardsServiceImpl::RecordBackendP3AStats(bool delay_report) { return; } - p3a::RecordRewardsPageViews(profile_->GetPrefs(), false); + p3a::RecordRewardsPageViews(prefs_, false); GetExternalWallet( base::BindOnce(&RewardsServiceImpl::OnRecordBackendP3AExternalWallet, @@ -2255,7 +2224,7 @@ void RewardsServiceImpl::OnRecordBackendP3AExternalWallet( } if (search_result_optin_changed) { - p3a::RecordSearchResultAdsOptinChange(profile_->GetPrefs()); + p3a::RecordSearchResultAdsOptinChange(prefs_); } else if (delay_report) { // Use delay to ensure tips are confirmed when counting. p3a_tip_report_timer_.Start( @@ -2322,9 +2291,8 @@ mojom::Environment RewardsServiceImpl::GetDefaultServerEnvironment() { mojom::Environment RewardsServiceImpl::GetDefaultServerEnvironmentForAndroid() { auto result = mojom::Environment::kProduction; bool use_staging = false; - if (profile_ && profile_->GetPrefs()) { - use_staging = - profile_->GetPrefs()->GetBoolean(prefs::kUseRewardsStagingServer); + if (profile_ && prefs_) { + use_staging = prefs_->GetBoolean(prefs::kUseRewardsStagingServer); } if (use_staging) { @@ -2425,8 +2393,7 @@ void RewardsServiceImpl::OnFilesDeletedForCompleteReset( void RewardsServiceImpl::ExternalWalletConnected() { // When the user connects an external wallet, turn off search result ads since // users cannot earn BAT for them yet. The user can turn them on manually. - profile_->GetPrefs()->SetBoolean(brave_ads::prefs::kOptedInToSearchResultAds, - false); + prefs_->SetBoolean(brave_ads::prefs::kOptedInToSearchResultAds, false); for (auto& observer : observers_) { observer.OnExternalWalletConnected(); } @@ -2521,8 +2488,7 @@ std::string RewardsServiceImpl::GetExternalWalletType() const { return internal::constant::kWalletBitflyer; } - const std::string type = - profile_->GetPrefs()->GetString(prefs::kExternalWalletType); + const std::string type = prefs_->GetString(prefs::kExternalWalletType); if (IsValidWalletType(type)) { return type; diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index f907d68c32bb..338a1d3622e6 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -6,7 +6,6 @@ #ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_SERVICE_IMPL_H_ #define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_REWARDS_SERVICE_IMPL_H_ -#include #include #include #include @@ -15,11 +14,9 @@ #include #include "base/containers/flat_map.h" -#include "base/files/file.h" #include "base/files/file_path.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/observer_list.h" #include "base/one_shot_event.h" #include "base/sequence_checker.h" #include "base/threading/sequence_bound.h" @@ -38,7 +35,7 @@ #include "build/build_config.h" #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" #include "components/prefs/pref_change_registrar.h" -#include "content/public/browser/browser_thread.h" +#include "content/public/browser/storage_partition.h" #include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/remote.h" @@ -52,21 +49,20 @@ #include "brave/components/greaselion/browser/greaselion_service.h" #endif +class BitmapFetcherService; + namespace base { class OneShotTimer; class SequencedTaskRunner; } // namespace base -namespace leveldb { -class DB; -} // namespace leveldb - +namespace favicon { +class FaviconService; +} // namespace favicon namespace network { class SimpleURLLoader; } // namespace network -class Profile; - namespace brave_wallet { class BraveWalletService; } @@ -100,7 +96,11 @@ class RewardsServiceImpl final : public RewardsService, #endif public mojom::RewardsEngineClient { public: - RewardsServiceImpl(Profile* profile, + RewardsServiceImpl(PrefService* prefs, + const base::FilePath& profile_path, + favicon::FaviconService* favicon_service, + BitmapFetcherService* bitmap_fetcher_service, + content::StoragePartition* storage_partition, #if BUILDFLAG(ENABLE_GREASELION) greaselion::GreaselionService* greaselion_service, #endif @@ -547,8 +547,10 @@ class RewardsServiceImpl final : public RewardsService, mojom::Environment GetDefaultServerEnvironmentForAndroid(); safetynet_check::SafetyNetCheckRunner safetynet_check_runner_; #endif - - raw_ptr profile_ = nullptr; // NOT OWNED + raw_ptr prefs_; // NOT OWNED + raw_ptr favicon_service_; // NOT OWNED + raw_ptr bitmap_fetcher_service_; // NOT OWNED + raw_ptr storage_partition_; // NOT OWNED #if BUILDFLAG(ENABLE_GREASELION) raw_ptr greaselion_service_ = nullptr; // NOT OWNED diff --git a/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc b/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc index c456cce55ef7..31f01419128b 100644 --- a/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc +++ b/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc @@ -3,20 +3,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include - #include "base/files/scoped_temp_dir.h" -#include "base/memory/ptr_util.h" -#include "base/memory/raw_ptr.h" #include "base/test/scoped_feature_list.h" #include "brave/browser/brave_rewards/rewards_service_factory.h" #include "brave/components/brave_rewards/browser/rewards_service_impl.h" -#include "brave/components/brave_rewards/browser/rewards_service_observer.h" #include "brave/components/brave_rewards/browser/test_util.h" #include "brave/components/brave_rewards/common/features.h" -#include "brave/components/brave_rewards/common/mojom/rewards.mojom.h" #include "brave/components/brave_rewards/common/pref_names.h" -#include "brave/components/brave_rewards/common/rewards_flags.h" #include "brave/components/brave_rewards/core/global_constants.h" #include "brave/components/greaselion/browser/buildflags/buildflags.h" #include "brave/components/l10n/common/test/scoped_default_locale.h" @@ -46,12 +39,13 @@ class RewardsServiceJPTest : public testing::Test { std::make_unique("ja_JP"); profile_ = CreateBraveRewardsProfile(temp_dir_.GetPath()); ASSERT_TRUE(profile_); + rewards_service_ = std::make_unique( + profile()->GetPrefs(), profile()->GetPath(), nullptr, nullptr, + profile()->GetDefaultStoragePartition(), #if BUILDFLAG(ENABLE_GREASELION) - rewards_service_ = - std::make_unique(profile(), nullptr, nullptr); -#else - rewards_service_ = std::make_unique(profile(), nullptr); + nullptr, #endif + nullptr); ASSERT_TRUE(rewards_service()); profile()->GetPrefs()->SetString(prefs::kDeclaredGeo, "JP"); diff --git a/components/brave_rewards/browser/rewards_service_impl_unittest.cc b/components/brave_rewards/browser/rewards_service_impl_unittest.cc index feb5526f77ea..a8bbd91b47c2 100644 --- a/components/brave_rewards/browser/rewards_service_impl_unittest.cc +++ b/components/brave_rewards/browser/rewards_service_impl_unittest.cc @@ -3,15 +3,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include +#include "brave/components/brave_rewards/browser/rewards_service_impl.h" + #include #include "base/files/scoped_temp_dir.h" -#include "base/memory/ptr_util.h" -#include "base/memory/raw_ptr.h" #include "base/test/scoped_feature_list.h" #include "brave/browser/brave_rewards/rewards_service_factory.h" -#include "brave/components/brave_rewards/browser/rewards_service_impl.h" #include "brave/components/brave_rewards/browser/rewards_service_observer.h" #include "brave/components/brave_rewards/browser/test_util.h" #include "brave/components/brave_rewards/common/features.h" @@ -67,12 +65,14 @@ class RewardsServiceTest : public testing::Test { std::make_unique("en_US"); profile_ = CreateBraveRewardsProfile(temp_dir_.GetPath()); ASSERT_TRUE(profile_.get()); + + rewards_service_ = std::make_unique( + profile()->GetPrefs(), profile()->GetPath(), nullptr, nullptr, + profile()->GetDefaultStoragePartition(), #if BUILDFLAG(ENABLE_GREASELION) - rewards_service_ = - std::make_unique(profile(), nullptr, nullptr); -#else - rewards_service_ = std::make_unique(profile(), nullptr); + nullptr, #endif + nullptr); ASSERT_TRUE(rewards_service()); observer_ = std::make_unique(); rewards_service_->AddObserver(observer_.get()); diff --git a/components/brave_rewards/browser/test_util.cc b/components/brave_rewards/browser/test_util.cc index 88ed8d0658d2..3df413288843 100644 --- a/components/brave_rewards/browser/test_util.cc +++ b/components/brave_rewards/browser/test_util.cc @@ -3,14 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include - #include "brave/components/brave_rewards/browser/test_util.h" -#include "base/files/file_util.h" -#include "base/strings/utf_string_conversions.h" +#include + #include "brave/browser/brave_rewards/rewards_service_factory.h" -#include "brave/components/brave_rewards/common/pref_registry.h" #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/test/base/testing_profile.h" diff --git a/components/brave_rewards/test/BUILD.gn b/components/brave_rewards/test/BUILD.gn index 582f7619b988..9c342cbf4fdb 100644 --- a/components/brave_rewards/test/BUILD.gn +++ b/components/brave_rewards/test/BUILD.gn @@ -19,6 +19,7 @@ source_set("brave_rewards_unit_tests") { deps = [ "//base/test:test_support", + "//brave/browser/brave_rewards", "//brave/components/brave_rewards/browser:browser", "//brave/components/brave_rewards/browser:testutil", "//brave/components/brave_rewards/common:common", diff --git a/test/BUILD.gn b/test/BUILD.gn index 65553c6d962e..ac956cab18c4 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -686,6 +686,7 @@ if (!is_android) { deps = [ "//base", "//brave/base/test:test_vendor_is_brave", + "//brave/browser/brave_rewards", "//brave/components/brave_ads/core/public:headers", "//brave/components/brave_rewards/browser", "//chrome/browser", @@ -837,6 +838,7 @@ test("brave_browser_tests") { "//brave/browser/autoplay:browser_tests", "//brave/browser/brave_ads:browser_tests", "//brave/browser/brave_news:browser_tests", + "//brave/browser/brave_rewards", "//brave/browser/brave_rewards/test:browser_tests", "//brave/browser/brave_wallet", "//brave/browser/brave_wallet:browser_tests", @@ -1037,6 +1039,8 @@ test("brave_browser_tests") { sources += [ "//brave/browser/greaselion/greaselion_browsertest.cc" ] deps += [ + "//brave/browser/brave_rewards", + "//brave/browser/greaselion", "//brave/components/greaselion/browser", "//chrome/browser", ]