Skip to content

Commit

Permalink
remove //brave/components/brave_ads/browser check_includes = false
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Oct 6, 2024
1 parent a235817 commit 17760b8
Show file tree
Hide file tree
Showing 26 changed files with 381 additions and 200 deletions.
135 changes: 135 additions & 0 deletions browser/brave_ads/ads_service_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* 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/. */

#include "brave/browser/brave_ads/ads_service_delegate.h"

#include <utility>

#include "brave/browser/brave_ads/ad_units/notification_ad/notification_ad_platform_bridge.h"
#include "brave/browser/brave_ads/application_state/notification_helper/notification_helper.h"
#include "brave/browser/ui/brave_ads/notification_ad.h"
#include "brave/components/brave_adaptive_captcha/brave_adaptive_captcha_service.h"
#include "build/build_config.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/profiles/profile.h"
#if BUILDFLAG(IS_ANDROID)
#include "brave/browser/notifications/brave_notification_platform_bridge_helper_android.h"
#include "chrome/browser/android/service_tab_launcher.h"
#include "content/public/browser/page_navigator.h"
#else
#include "chrome/browser/fullscreen.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#endif

namespace brave_ads {

AdsServiceDelegate::AdsServiceDelegate(
Profile* profile,
brave_adaptive_captcha::BraveAdaptiveCaptchaService*
adaptive_captcha_service,
NotificationDisplayService* notification_display_service,
std::unique_ptr<NotificationAdPlatformBridge>
notification_ad_platform_bridge)
: profile_(profile),
adaptive_captcha_service_(adaptive_captcha_service),
notification_display_service_(notification_display_service),
notification_ad_platform_bridge_(
std::move(notification_ad_platform_bridge)) {}

AdsServiceDelegate::~AdsServiceDelegate() {}

void AdsServiceDelegate::OpenNewTabWithUrl(const GURL& url) {
#if BUILDFLAG(IS_ANDROID)
// ServiceTabLauncher can currently only launch new tabs
const content::OpenURLParams params(url, content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_LINK, true);
ServiceTabLauncher::GetInstance()->LaunchTab(
profile_, params, base::BindOnce([](content::WebContents*) {}));
#else
Browser* browser = chrome::FindTabbedBrowser(profile_, false);
if (!browser) {
browser = Browser::Create(Browser::CreateParams(profile_, true));
}
NavigateParams nav_params(browser, url, ui::PAGE_TRANSITION_LINK);
nav_params.disposition = WindowOpenDisposition::SINGLETON_TAB;
nav_params.window_action = NavigateParams::SHOW_WINDOW;
nav_params.path_behavior = NavigateParams::RESPECT;
Navigate(&nav_params);
#endif
}

void AdsServiceDelegate::InitNotificationHelper() {
NotificationHelper::GetInstance()->InitForProfile(profile_);
}

bool AdsServiceDelegate::
CanShowSystemNotificationsWhileBrowserIsBackgrounded() {
return NotificationHelper::GetInstance()
->CanShowSystemNotificationsWhileBrowserIsBackgrounded();
}

bool AdsServiceDelegate::DoesSupportSystemNotifications() {
return NotificationHelper::GetInstance()->DoesSupportSystemNotifications();
}

bool AdsServiceDelegate::CanShowNotifications() {
return NotificationHelper::GetInstance()->CanShowNotifications();
}

bool AdsServiceDelegate::ShowOnboardingNotification() {
return NotificationHelper::GetInstance()->ShowOnboardingNotification();
}

void AdsServiceDelegate::ShowScheduledCaptcha(const std::string& payment_id,
const std::string& captcha_id) {
adaptive_captcha_service_->ShowScheduledCaptcha(payment_id, captcha_id);
}

void AdsServiceDelegate::ClearScheduledCaptcha() {
adaptive_captcha_service_->ClearScheduledCaptcha();
}

void AdsServiceDelegate::SnoozeScheduledCaptcha() {
adaptive_captcha_service_->SnoozeScheduledCaptcha();
}

void AdsServiceDelegate::Display(
const message_center::Notification& notification) {
notification_display_service_->Display(NotificationHandler::Type::BRAVE_ADS,
notification, nullptr);
}

void AdsServiceDelegate::Close(const std::string& notification_id) {
notification_display_service_->Close(NotificationHandler::Type::BRAVE_ADS,
notification_id);
}

void AdsServiceDelegate::ShowNotificationAd(const std::string& id,
const std::u16string& title,
const std::u16string& body) {
notification_ad_platform_bridge_->ShowNotificationAd(
NotificationAd(id, title, body, nullptr));
}

void AdsServiceDelegate::CloseNotificationAd(const std::string& id) {
notification_ad_platform_bridge_->CloseNotificationAd(id);
}

#if BUILDFLAG(IS_ANDROID)
void AdsServiceDelegate::MaybeRegenerateNotification(
const std::string& notification_id,
const GURL& service_worker_scope) {
BraveNotificationPlatformBridgeHelperAndroid::MaybeRegenerateNotification(
placement_id, url);
}
#else
bool AdsServiceDelegate::IsFullScreenMode() {
return ::IsFullScreenMode();
}
#endif
} // namespace brave_ads
78 changes: 78 additions & 0 deletions browser/brave_ads/ads_service_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* 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/. */

#ifndef BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_DELEGATE_H_
#define BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_DELEGATE_H_

#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"
#include "brave/components/brave_ads/browser/ads_service.h"

class Profile;

namespace brave_adaptive_captcha {
class BraveAdaptiveCaptchaService;
}

class NotificationDisplayService;

namespace brave_ads {

class NotificationAdPlatformBridge;

// Singleton that owns all AdsService and associates them with Profiles.
class AdsServiceDelegate : public AdsService::Delegate {
public:
explicit AdsServiceDelegate(
Profile* profile,
brave_adaptive_captcha::BraveAdaptiveCaptchaService*
adaptive_captcha_service,
NotificationDisplayService* notification_display_service,
std::unique_ptr<NotificationAdPlatformBridge>
notification_ad_platform_bridge);
~AdsServiceDelegate() override;
AdsServiceDelegate(const AdsServiceDelegate&) = delete;
AdsServiceDelegate& operator=(const AdsServiceDelegate&) = delete;

AdsServiceDelegate(AdsServiceDelegate&&) noexcept = delete;
AdsServiceDelegate& operator=(AdsServiceDelegate&&) noexcept = delete;

// AdsService::Delegate implementation
void InitNotificationHelper() override;
bool CanShowSystemNotificationsWhileBrowserIsBackgrounded() override;
bool DoesSupportSystemNotifications() override;
bool CanShowNotifications() override;
bool ShowOnboardingNotification() override;
void ShowScheduledCaptcha(const std::string& payment_id,
const std::string& captcha_id) override;
void ClearScheduledCaptcha() override;
void SnoozeScheduledCaptcha() override;
void Display(const message_center::Notification& notification) override;
void Close(const std::string& notification_id) override;
void ShowNotificationAd(const std::string& id,
const std::u16string& title,
const std::u16string& body) override;
void CloseNotificationAd(const std::string& id) override;
void OpenNewTabWithUrl(const GURL& url) override;
#if BUILDFLAG(IS_ANDROID)
void MaybeRegenerateNotification(const std::string& notification_id,
const GURL& service_worker_scope) override;
#else
bool IsFullScreenMode() override;
#endif
private:
raw_ptr<Profile> profile_;
raw_ptr<brave_adaptive_captcha::BraveAdaptiveCaptchaService>
adaptive_captcha_service_;
raw_ptr<NotificationDisplayService> notification_display_service_;
std::unique_ptr<NotificationAdPlatformBridge>
notification_ad_platform_bridge_;
};

} // namespace brave_ads

#endif // BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_DELEGATE_H_
15 changes: 12 additions & 3 deletions browser/brave_ads/ads_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "base/no_destructor.h"
#include "brave/browser/brave_adaptive_captcha/brave_adaptive_captcha_service_factory.h"
#include "brave/browser/brave_ads/ad_units/notification_ad/notification_ad_platform_bridge.h"
#include "brave/browser/brave_ads/ads_service_delegate.h"
#include "brave/browser/brave_ads/device_id/device_id_impl.h"
#include "brave/browser/brave_ads/services/bat_ads_service_factory_impl.h"
#include "brave/browser/brave_ads/tooltips/ads_tooltips_delegate_impl.h"
Expand All @@ -17,9 +19,11 @@
#include "brave/components/brave_ads/browser/ads_service_impl.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/storage_partition.h"

namespace brave_ads {

Expand Down Expand Up @@ -64,10 +68,13 @@ AdsServiceFactory::CreateAdsTooltipsDelegate(Profile* profile) const {
KeyedService* AdsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
auto* profile = Profile::FromBrowserContext(context);

auto* brave_adaptive_captcha_service =
brave_adaptive_captcha::BraveAdaptiveCaptchaServiceFactory::GetInstance()
->GetForProfile(profile);
auto* display_service = NotificationDisplayService::GetForProfile(profile);
auto* delegate = new AdsServiceDelegate(
profile, brave_adaptive_captcha_service, display_service,
std::make_unique<NotificationAdPlatformBridge>(*profile));

auto* history_service = HistoryServiceFactory::GetInstance()->GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
Expand All @@ -78,8 +85,10 @@ KeyedService* AdsServiceFactory::BuildServiceInstanceFor(

std::unique_ptr<AdsServiceImpl> ads_service =
std::make_unique<AdsServiceImpl>(
profile, g_browser_process->local_state(),
brave_adaptive_captcha_service, CreateAdsTooltipsDelegate(profile),
delegate, profile->GetPrefs(), g_browser_process->local_state(),
profile->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess(),
profile->GetPath(), CreateAdsTooltipsDelegate(profile),
std::make_unique<DeviceIdImpl>(),
std::make_unique<BatAdsServiceFactoryImpl>(),
g_brave_browser_process->resource_component(), history_service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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 "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"

#include "brave/browser/brave_ads/application_state/background_helper/background_helper_holder.h"
#include "build/build_config.h" // IWYU pragma: keep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "base/android/application_status_listener.h"
#include "base/memory/weak_ptr.h"
#include "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"

namespace brave_ads {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "brave/browser/brave_ads/application_state/background_helper/background_helper_holder.h"

#include "base/no_destructor.h"
#include "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"
#include "build/build_config.h" // IWYU pragma: keep

#if BUILDFLAG(IS_ANDROID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define BRAVE_BROWSER_BRAVE_ADS_APPLICATION_STATE_BACKGROUND_HELPER_BACKGROUND_HELPER_LINUX_H_

#include "base/memory/weak_ptr.h"
#include "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"
#include "chrome/browser/ui/browser_list_observer.h"

namespace brave_ads {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <memory>

#include "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"

namespace brave_ads {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <memory>

#include "base/win/windows_types.h"
#include "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"
#include "ui/gfx/win/singleton_hwnd_observer.h"

namespace brave_ads {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "base/system/sys_info.h"
#include "brave/browser/brave_ads/android/jni_headers/BraveAdsSignupDialog_jni.h"
#include "brave/browser/brave_ads/android/jni_headers/BraveAds_jni.h"
#include "brave/browser/brave_ads/application_state/background_helper/background_helper.h"
#include "brave/build/android/jni_headers/BraveSiteChannelsManagerBridge_jni.h"
#include "brave/components/brave_ads/browser/ad_units/notification_ad/custom_notification_ad_feature.h"
#include "brave/components/brave_ads/browser/application_state/background_helper.h"
#include "chrome/browser/notifications/jni_headers/NotificationSystemStatusUtil_jni.h"
#include "chrome/browser/notifications/notification_channels_provider_android.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class BraveAdsCreativeSearchResultAdTabHelperTest
base::test::ScopedFeatureList scoped_feature_list_;
net::EmbeddedTestServer https_server_{
net::test_server::EmbeddedTestServer::TYPE_HTTPS};
AdsServiceMock ads_service_mock_;
AdsServiceMock ads_service_mock_{nullptr};
};

IN_PROC_BROWSER_TEST_F(BraveAdsCreativeSearchResultAdTabHelperTest,
Expand Down
3 changes: 2 additions & 1 deletion browser/brave_ads/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

brave_browser_brave_ads_sources = [
"//brave/browser/brave_ads/ad_units/notification_ad/notification_ad_platform_bridge.h",
"//brave/browser/brave_ads/ads_service_delegate.cc",
"//brave/browser/brave_ads/ads_service_delegate.h",
"//brave/browser/brave_ads/ads_service_factory.cc",
"//brave/browser/brave_ads/ads_service_factory.h",
"//brave/browser/brave_ads/analytics/p3a/brave_stats_helper.cc",
"//brave/browser/brave_ads/analytics/p3a/brave_stats_helper.h",
"//brave/browser/brave_ads/application_state/background_helper/background_helper.cc",
"//brave/browser/brave_ads/application_state/background_helper/background_helper.h",
"//brave/browser/brave_ads/application_state/background_helper/background_helper_holder.cc",
"//brave/browser/brave_ads/application_state/background_helper/background_helper_holder.h",
"//brave/browser/brave_ads/application_state/notification_helper/notification_helper.cc",
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_ads/tabs/ads_tab_helper_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AdsTabHelperTest : public CertVerifierBrowserTest {
private:
net::EmbeddedTestServer https_server_{
net::test_server::EmbeddedTestServer::TYPE_HTTPS};
AdsServiceMock ads_service_mock_;
AdsServiceMock ads_service_mock_{nullptr};
};

IN_PROC_BROWSER_TEST_F(AdsTabHelperTest, UserHasNotJoinedBraveRewards) {
Expand Down
9 changes: 8 additions & 1 deletion browser/widevine/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ source_set("widevine") {
deps = [
"//base",
"//brave/app:brave_generated_resources_grit",
"//brave/components/brave_component_updater/browser",
"//brave/components/constants",
"//brave/components/l10n/common",
"//brave/components/widevine:constants",
"//chrome/browser:browser_process",
"//chrome/browser/profiles:profile",
"//chrome/common",
"//components/component_updater/",
"//components/content_settings/core/common",
"//components/permissions",
"//components/pref_registry",
"//components/prefs",
"//components/subresource_filter/content/browser",
Expand All @@ -32,6 +35,10 @@ source_set("widevine") {
"//third_party/widevine/cdm:buildflags",
"//third_party/widevine/cdm:headers",
"//ui/base",
]

public_deps = [
"//components/permissions",
"//url",
]

Expand Down
Loading

0 comments on commit 17760b8

Please sign in to comment.