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

Unify AdsService with iOS #26639

Merged
merged 5 commits into from
Nov 19, 2024
Merged

Unify AdsService with iOS #26639

merged 5 commits into from
Nov 19, 2024

Conversation

aseren
Copy link
Collaborator

@aseren aseren commented Nov 19, 2024

This is a prerequisite for the Ads-Internals page task brave/brave-browser#40952, as we now need to access AdsService from various parts of the Brave iOS codebase.

This is also a step in Unification of Service Layer for iOS: brave/brave-browser#33868.

Resolves brave/brave-browser#42349

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:

No manual testing is required.

@aseren aseren requested review from a team as code owners November 19, 2024 17:48
@aseren aseren requested a review from tmancey November 19, 2024 17:49
Copy link
Contributor

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

Description

This PR refactors and updates the Brave Ads service implementation, moving some functionality from the browser layer to the core layer and updating interfaces and implementations accordingly. The changes aim to improve code organization, reduce dependencies, and potentially enhance maintainability.

Changes

Changes

  1. browser/brave_ads/BUILD.gn:

    • Added dependency on "//ui/message_center/public/cpp"
  2. browser/brave_ads/ad_units/notification_ad/notification_ad_platform_bridge.cc:

    • Updated import path for ads_service.h
  3. browser/brave_ads/ads_service_delegate.cc:

    • Refactored notification ad display logic
    • Updated method signatures for ShowNotificationAd and CloseNotificationAd
    • Removed Display and Close methods
    • Updated IsFullScreenMode implementation
  4. browser/brave_ads/ads_service_delegate.h:

    • Updated method signatures to match changes in ads_service_delegate.cc
  5. browser/brave_ads/ads_service_factory.cc:

    • Updated import path for ads_service.h
  6. browser/brave_ads/android/brave_ads_native_helper.cc:

    • Updated import path for ads_service.h
    • Updated ClearData call to include a callback
  7. browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper.cc:

    • Updated import path for ads_service.h
  8. browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper_browsertest.cc:

    • Updated import paths for ads_service.h and ads_service_mock.h
  9. browser/brave_ads/tabs/ads_tab_helper.cc:

    • Updated import path for ads_service.h
  10. browser/brave_ads/test_ads_service_waiter.cc and test_ads_service_waiter.h:

    • Updated import paths for ads_service.h and ads_service_observer.h
  11. browser/brave_rewards/android/brave_rewards_native_worker.cc:

    • Updated import path for ads_service.h
  12. browser/extensions/api/brave_rewards_api.cc:

    • Updated import path for ads_service.h
  13. browser/notifications/ads_notification_handler.cc:

    • Updated import path for ads_service.h
  14. browser/ntp_background/view_counter_service_factory.cc:

    • Updated import path for ads_service.h
  15. browser/ui/webui/brave_rewards/rewards_page_handler.cc:

    • Updated import path for ads_service.h
  16. browser/ui/webui/brave_rewards_internals_ui.cc:

    • Updated import path for ads_service.h
  17. browser/ui/webui/brave_rewards_page_ui.cc:

    • Updated import path for ads_service.h
  18. browser/ui/webui/new_tab_page/brave_new_tab_message_handler.h:

    • Updated import path for ads_service.h
  19. browser/ui/webui/settings/brave_clear_browsing_data_handler.cc:

    • Updated import path for ads_service.h
    • Updated ClearData call to include a callback
  20. components/brave_ads/browser/BUILD.gn:

    • Removed ads_service.cc, ads_service.h, and ads_service_observer.h
  21. components/brave_ads/browser/ads_service_impl.cc:

    • Updated implementation to match new interface
    • Refactored notification ad display logic
  22. components/brave_ads/browser/ads_service_impl.h:

    • Updated method signatures to match new interface
  23. components/brave_ads/browser/ads_service_mock.h:

    • Updated import paths and method signatures
  24. components/brave_ads/content/browser/creatives/search_result_ad/creative_search_result_ad_handler.cc:

    • Updated import path for ads_service.h
  25. components/brave_ads/core/BUILD.gn:

    • Added public dependency on "//brave/components/brave_ads/core/browser"
  26. New file: components/brave_ads/core/browser/BUILD.gn:

    • Added new build file for core browser components
  27. Moved and updated files:

    • components/brave_ads/browser/ads_service.cccomponents/brave_ads/core/browser/service/ads_service.cc
    • components/brave_ads/browser/ads_service.hcomponents/brave_ads/core/browser/service/ads_service.h
    • components/brave_ads/browser/ads_service_observer.hcomponents/brave_ads/core/browser/service/ads_service_observer.h
    • components/brave_ads/browser/ads_service_callback.hcomponents/brave_ads/core/public/service/ads_service_callback.h
  28. components/brave_news/browser/brave_news_controller.cc:

    • Updated import paths and method calls for inline content ads
  29. components/ntp_background_images/browser/view_counter_service.cc:

    • Updated import path for ads_service.h
  30. ios/browser/brave_ads/ads_service_impl_ios.h and ads_service_impl_ios.mm:

    • Updated to implement the new AdsService interface
    • Added new methods and implementations to match the updated interface

Possible Issues

  • Some functionality is marked as NOTIMPLEMENTED() in the iOS implementation, which may need to be addressed in future updates.
  • The refactoring may require updates to other parts of the codebase that are not included in this PR.

Security Hotspots

None identified.

graph TD
    A[AdsService] --> B[AdsServiceImpl]
    A --> C[AdsServiceImplIOS]
    B --> D[NotificationAdPlatformBridge]
    B --> E[AdsServiceDelegate]
    F[BraveAdsNativeHelper] --> A
    G[BraveRewardsNativeWorker] --> A
    H[BraveNewsController] --> A
    I[ViewCounterService] --> A
Loading
sequenceDiagram
    participant User
    participant Browser
    participant AdsService
    participant AdsServiceDelegate
    participant NotificationAdPlatformBridge

    User->>Browser: Interacts with browser
    Browser->>AdsService: Triggers ad-related event
    AdsService->>AdsServiceDelegate: Requests to show/close ad
    AdsServiceDelegate->>NotificationAdPlatformBridge: Shows/closes notification ad
    NotificationAdPlatformBridge-->>AdsServiceDelegate: Confirms action
    AdsServiceDelegate-->>AdsService: Reports result
    AdsService-->>Browser: Updates ad state
    Browser-->>User: Displays/removes ad
Loading

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 (see comments). Thanks

Copy link
Collaborator

@zenparsing zenparsing left a comment

Choose a reason for hiding this comment

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

Rewards 👍

@aseren aseren merged commit a633545 into master Nov 19, 2024
19 checks passed
@aseren aseren deleted the issues/42349 branch November 19, 2024 23:12
@github-actions github-actions bot added this to the 1.75.x - Nightly milestone Nov 19, 2024
@brave-builds
Copy link
Collaborator

Released in v1.75.35

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.

Unify AdsService with iOS
5 participants