Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix brave ads check includes #25828

Merged
merged 1 commit into from
Oct 6, 2024
Merged

Fix brave ads check includes #25828

merged 1 commit into from
Oct 6, 2024

Conversation

bridiver
Copy link
Collaborator

@bridiver bridiver commented Oct 5, 2024

Resolves brave/brave-browser#24163

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Copy link
Collaborator

@tmancey tmancey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from fix-extensions-check-includes to master October 5, 2024 23:37
@bridiver bridiver requested review from a team and iefremov as code owners October 5, 2024 23:37
@bridiver bridiver force-pushed the fix-brave-ads-check-includes branch from 2ed4e48 to 906a60f Compare October 5, 2024 23:39
@bridiver bridiver changed the base branch from master to rewards-page-gn-check-fix October 6, 2024 00:33
@bridiver bridiver changed the base branch from rewards-page-gn-check-fix to master October 6, 2024 00:35
Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browser/widevine ++

@@ -1530,17 +1482,13 @@ void AdsServiceImpl::CanShowNotificationAds(
void AdsServiceImpl::CanShowNotificationAdsWhileBrowserIsBackgrounded(
CanShowNotificationAdsWhileBrowserIsBackgroundedCallback callback) {
std::move(callback).Run(
NotificationHelper::GetInstance()
->CanShowSystemNotificationsWhileBrowserIsBackgrounded());
delegate_->CanShowSystemNotificationsWhileBrowserIsBackgrounded());
}

void AdsServiceImpl::ShowNotificationAd(base::Value::Dict dict) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move this function to AdsServiceDelegate and pass ShouldShowCustomNotificationAds() value as a parameter? Declaration can look something like:

virtual void ShowNotificationAd(
                                    bool should_show_custom_notification_ads,
                                    const std::string& id,
                                    const std::u16string& title,
                                    const std::u16string& body);

If so, we will get rid of ui/message_center dependency in header because the new function will replace following functions in AdsService::Delegate:

    virtual void Display(const message_center::Notification& notification) = 0;
    virtual void ShowNotificationAd(const std::string& id,
                                    const std::u16string& title,
                                    const std::u16string& body);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's still quite a bit of refactoring that needs to be done here, but for this first pass my goal is just to remove check_includes = false

@@ -1584,28 +1531,23 @@ void AdsServiceImpl::ShowNotificationAd(base::Value::Dict dict) {
notification->set_never_timeout(true);
#endif

display_service_->Display(NotificationHandler::Type::BRAVE_ADS,
*notification, /*metadata=*/nullptr);
delegate_->Display(*notification);
}

StartNotificationAdTimeOutTimer(ad.placement_id);
}

void AdsServiceImpl::CloseNotificationAd(const std::string& placement_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move this function to AdsServiceDelegate and pass ShouldShowCustomNotificationAds() value as a parameter? Declaration can look something like:

virtual void CloseNotificationAd(
                                    bool should_show_custom_notification_ads,
                                    const std::string& placement_id);

If so, the new function will replace following functions in AdsService::Delegate:

    virtual void Close(const std::string& notification_id) = 0;
    virtual void CloseNotificationAd(const std::string& id) = 0;

Copy link
Collaborator

@aseren aseren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change! left few comments, thanks!

components/brave_ads/browser/BUILD.gn Show resolved Hide resolved
@bridiver bridiver force-pushed the fix-brave-ads-check-includes branch 2 times, most recently from ca85ed1 to a75c474 Compare October 6, 2024 18:02
Copy link
Contributor

github-actions bot commented Oct 6, 2024

[puLL-Merge] - brave/brave-core@25828

Description

This PR introduces a new AdsServiceDelegate class and refactors the AdsService and AdsServiceImpl classes to use this delegate. The main motivation appears to be improving the separation of concerns and reducing direct dependencies on platform-specific implementations within the ads service.

Changes

Changes

  1. browser/brave_ads/ads_service_delegate.cc and ads_service_delegate.h:

    • New files introducing the AdsServiceDelegate class.
    • This class acts as an intermediary between the AdsService and platform-specific implementations.
    • Implements methods for handling notifications, opening new tabs, and other platform-specific operations.
  2. browser/brave_ads/ads_service_factory.cc:

    • Updated to use the new AdsServiceDelegate.
    • Creates an instance of AdsServiceDelegate and passes it to AdsServiceImpl.
  3. components/brave_ads/browser/ads_service.h:

    • Added a Delegate nested class to AdsService.
    • Modified the constructor to take a Delegate* parameter.
  4. components/brave_ads/browser/ads_service_impl.cc and ads_service_impl.h:

    • Refactored to use the new AdsServiceDelegate.
    • Removed direct dependencies on Profile, NotificationDisplayService, and other platform-specific classes.
    • Updated method implementations to use the delegate for platform-specific operations.
  5. components/brave_ads/browser/ads_service_mock.cc and ads_service_mock.h:

    • Updated to take a Delegate* in the constructor.
  6. components/brave_ads/browser/application_state/background_helper.h:

    • Moved from browser/brave_ads/application_state/background_helper/background_helper.h to components/brave_ads/browser/application_state/background_helper.h.
  7. Various test files:

    • Updated to use the new AdsServiceMock constructor with a null delegate.

Possible Issues

  • The PR introduces a new layer of abstraction, which might slightly increase the complexity of the codebase.
  • Some platform-specific code still remains in AdsServiceImpl, which might be further refactored in the future.

Security Hotspots

None identified. The changes primarily focus on architectural improvements and don't introduce new security risks.

@bridiver bridiver force-pushed the fix-brave-ads-check-includes branch from a75c474 to 17760b8 Compare October 6, 2024 18:15
@bridiver bridiver force-pushed the fix-brave-ads-check-includes branch from 17760b8 to 892cdad Compare October 6, 2024 18:46
@bridiver
Copy link
Collaborator Author

bridiver commented Oct 6, 2024

unrelated test failure on macos

@bridiver bridiver merged commit 1ac1d51 into master Oct 6, 2024
18 of 19 checks passed
@bridiver bridiver deleted the fix-brave-ads-check-includes branch October 6, 2024 20:24
@github-actions github-actions bot added this to the 1.72.x - Nightly milestone Oct 6, 2024
@brave-builds
Copy link
Collaborator

Released in v1.72.65

virtual void Close(const std::string& notification_id) = 0;
virtual void ShowNotificationAd(const std::string& id,
const std::u16string& title,
const std::u16string& body);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed = 0? I've got 'undefined symbol' referenced by 'const brave_ads::AdsService::Delegate::`vftable'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I wonder why it wasn't caught in CI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdesouza-chromium says he is creating a PR for it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boocmp what build were you running when you saw that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already merged a fix. I should have linked to it #25847

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it may have been debug builds only. At least, that's what it seemed like when I encountered it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it only fails when optimization is turned off

@cdesouza-chromium
Copy link
Collaborator

This PR has broken the ubsan build for me:

ld.lld: error: undefined symbol: typeinfo for brave_ads::AdsService::Delegate
>>> referenced by ads_service_impl.cc
>>>               browser/ads_service_impl.o:(.data+0x18) in archive obj/brave/components/brave_ads/browser/libbrowser.a
>>> referenced by ads_service_impl.cc
>>>               browser/ads_service_impl.o:(.data+0x18) in archive obj/brave/components/brave_ads/browser/libbrowser.a
>>> referenced by ads_service_impl.cc
>>>               browser/ads_service_impl.o:(.data+0x18) in archive obj/brave/components/brave_ads/browser/libbrowser.a
>>> referenced 13 more times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Brave Ads layering violations
8 participants