Skip to content

Commit

Permalink
build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Sep 22, 2024
1 parent ccfda84 commit 02d6a87
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 54 deletions.
1 change: 1 addition & 0 deletions browser/brave_rewards/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ source_set("brave_rewards_impl") {
"//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",
Expand Down
5 changes: 4 additions & 1 deletion browser/brave_rewards/rewards_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#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/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"
Expand Down Expand Up @@ -86,14 +87,16 @@ KeyedService* RewardsServiceFactory::BuildServiceInstanceFor(
auto* brave_wallet_service =
brave_wallet::BraveWalletServiceFactory::GetServiceForContext(context);
auto* storage_partition = profile->GetDefaultStoragePartition();
auto* bitmap_fetcher_service =
BitmapFetcherServiceFactory::GetForBrowserContext(profile);
// Set up the rewards data source
content::URLDataSource::Add(profile,
std::make_unique<BraveRewardsSource>(profile));
std::unique_ptr<RewardsServiceImpl> rewards_service(new RewardsServiceImpl(
profile->GetPrefs(), profile->GetPath(),
FaviconServiceFactory::GetForProfile(profile,
ServiceAccessType::EXPLICIT_ACCESS),
storage_partition,
bitmap_fetcher_service, storage_partition,
#if BUILDFLAG(ENABLE_GREASELION)
greaselion::GreaselionServiceFactory::GetForBrowserContext(context),
#endif
Expand Down
22 changes: 8 additions & 14 deletions browser/brave_rewards/rewards_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,28 @@
namespace brave_rewards {

#if !BUILDFLAG(IS_ANDROID)
namespace {
class BrowserListObserver : public BrowserListObserver {
class BraveBrowserListObserver : public BrowserListObserver {
public:
explicit BrowserListObserver(RewardsTabHelper* tab_helper)
explicit BraveBrowserListObserver(RewardsTabHelper* tab_helper)
: tab_helper_(tab_helper) {}
~BrowserListObserver() = default;
~BraveBrowserListObserver();
void OnBrowserSetLastActive(Browser* browser) override {
tab_helper->OnBrowserSetLastActive(browser);
tab_helper_->OnBrowserSetLastActive(browser);
}
void OnBrowserNoLongerActive(Browser* browser) override {
tab_helper->OnBrowserNoLongerActive(browser);
}

bool BrowserHasWebContents(Browser* browser) {
tab_helper->BrowserHasWebContents(browser);
tab_helper_->OnBrowserNoLongerActive(browser);
}

private:
RewardsTabHelper* tab_helper_;
}
} // namespace
raw_ptr<RewardsTabHelper> tab_helper_; // Not owned.
};
#endif

RewardsTabHelper::RewardsTabHelper(content::WebContents* web_contents)
: content::WebContentsUserData<RewardsTabHelper>(*web_contents),
WebContentsObserver(web_contents),
#if !BUILDFLAG(IS_ANDROID)
browser_list_observer_(new BrowserListObserver(this)),
browser_list_observer_(new BraveBrowserListObserver(this)),
#endif
tab_id_(sessions::SessionTabHelper::IdForTab(web_contents)) {
if (tab_id_.is_valid()) {
Expand Down
6 changes: 4 additions & 2 deletions browser/brave_rewards/rewards_tab_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ 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<RewardsTabHelper>,
public content::WebContentsObserver,
public RewardsServiceObserver {
Expand Down Expand Up @@ -57,6 +58,7 @@ class RewardsTabHelper : public content::WebContentsUserData<RewardsTabHelper>,

private:
friend class content::WebContentsUserData<RewardsTabHelper>;
friend class brave_rewards::BraveBrowserListObserver;

explicit RewardsTabHelper(content::WebContents* web_contents);

Expand Down
17 changes: 0 additions & 17 deletions components/brave_rewards/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}
39 changes: 19 additions & 20 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#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/bitmap_fetcher/bitmap_fetcher_service.h"
#include "components/country_codes/country_codes.h"
#include "components/favicon/core/favicon_service.h"
#include "components/os_crypt/sync/os_crypt.h"
Expand Down Expand Up @@ -252,13 +252,15 @@ RewardsServiceImpl::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
brave_wallet::BraveWalletService* brave_wallet_service)
: prefs_(prefs),
favicon_service_(favicon_service),
bitmap_fetcher_service_(bitmap_fetcher_service),
storage_partition_(storage_partition),
#if BUILDFLAG(ENABLE_GREASELION)
greaselion_service_(greaselion_service),
Expand Down Expand Up @@ -506,14 +508,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
Expand All @@ -533,7 +538,7 @@ void RewardsServiceImpl::CreateRewardsWallet(
}

self->conversion_monitor_.RecordRewardsEnable();
p3a::RecordAdTypesEnabled(prefs);
p3a::RecordAdTypesEnabled(self->prefs_);

std::move(callback).Run(CreateRewardsWalletResult::kSuccess);
};
Expand Down Expand Up @@ -815,11 +820,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);
}
}

Expand Down Expand Up @@ -1262,11 +1265,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);
}
}

Expand Down Expand Up @@ -1543,10 +1544,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(),
Expand Down
4 changes: 4 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#include "brave/components/greaselion/browser/greaselion_service.h"
#endif

class BitmapFetcherService;

namespace base {
class OneShotTimer;
class SequencedTaskRunner;
Expand Down Expand Up @@ -97,6 +99,7 @@ class RewardsServiceImpl final : public RewardsService,
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,
Expand Down Expand Up @@ -546,6 +549,7 @@ class RewardsServiceImpl final : public RewardsService,
#endif
raw_ptr<PrefService> prefs_; // NOT OWNED
raw_ptr<favicon::FaviconService> favicon_service_; // NOT OWNED
raw_ptr<BitmapFetcherService> bitmap_fetcher_service_; // NOT OWNED
raw_ptr<content::StoragePartition> storage_partition_; // NOT OWNED
#if BUILDFLAG(ENABLE_GREASELION)
raw_ptr<greaselion::GreaselionService> greaselion_service_ =
Expand Down

0 comments on commit 02d6a87

Please sign in to comment.