35 Commits
Author SHA1 Message Date
Aleksei Seren b302d127d2 [CodeHealth] Use ScopedObservation in NTP Background Images code (#36726)
Replaces manual `AddObserver/RemoveObserver` pairs in `ViewCounterService`,
`NTPBackgroundImagesBridge`, and `NTPBackgroundImagesServiceWaiter` with
base::ScopedObservation so observer cleanup is automatic and the
lifecycle is consistent with the rest of the codebase.
2026-05-26 13:18:18 -05:00
Terry ManceyandAleksei Seren 40526ffca3 [ads] Serve new-tab takeover ads on demand instead of prefetching (#34771)
[Ads] Serve new-tab takeover ads on demand instead of prefetching

Removing prefetching reduces unnecessary complexity.
Ads will instead be served on demand, ensuring they are
only delivered within the campaign’s configured start and
end dates.

Co-authored-by: Aleksei Seren <aseren@brave.com>
2026-03-27 17:59:52 -05:00
cdesouza-chromium c69126a894 [CodeHealth] Use base::DictValue/base::ListValue - Part X (#33715)
These classes were hoisted and renamed. This has been replaced in
Chromium as well. This is a mechanical change for Brave, done with the
following script.

```
git grep -lw 'Value::List' | xargs sed -i 's/\bValue::List\b/ListValue/g'
git grep -lw 'Value::Dict' | xargs sed -i 's/\bValue::Dict\b/DictValue/g'
git cl format
```

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/6bc468d481835992696083e99e556516fb7f5f80

```
commit 6bc468d481835992696083e99e556516fb7f5f80
Author: Avi Drissman <avi@chromium.org>
Date:   Thu Jan 29 22:14:50 2026 -0800

    Remove aliases for base::DictValue and base::ListValue

    This removes a few last stragglers as well.

    Fixed: 478100525
    Cq-Include-Trybots: luci.chromium.try:win-official,mac-official,linux-official,android-official,android-desktop-x64-official
    Change-Id: If92142b8ab0562a82c609b71c6b2a7665cea6ec6
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7513889
    Auto-Submit: Avi Drissman <avi@chromium.org>
    Commit-Queue: Daniel Cheng <dcheng@chromium.org>
    Owners-Override: Daniel Cheng <dcheng@chromium.org>
    Reviewed-by: Daniel Cheng <dcheng@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1577038}
```

Issue: https://github.com/brave/brave-browser/issues/52435
2026-02-06 12:16:42 -03:00
Artem Samoilenko 79cb1bbb57 [cr145][Android] Replace JavaParamRef -> JavaRef
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/0d6ec7e0f328e9ddd6f5174f61676ff85c777af6

commit 0d6ec7e0f328e9ddd6f5174f61676ff85c777af6
Author: Andrew Grieve <agrieve@chromium.org>
Date:   Tue Dec 2 12:37:02 2025 -0800

    Android: Replace JavaParamRef -> JavaRef (part 5)

    JavaParamRef used to be different, but now is an alias for JavaRef.

    Bug: 40173007
    Change-Id: I9bfa2fcdd012fc90859886ee2e747cb360733421
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7217772
    Commit-Queue: Andrew Grieve <agrieve@chromium.org>
    Owners-Override: Andrew Grieve <agrieve@chromium.org>
    Reviewed-by: Martin Kong <martinkong@google.com>
    Cr-Commit-Position: refs/heads/main@{#1553033}
2026-01-29 13:40:24 -05:00
Artem Samoilenko a79268cd0e [cr145][Android] Add DEFINE_JNI macro to the end of every file (part 1)
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/37865ec47270489182e954bb9a6dc32c04fd51d7

commit 37865ec47270489182e954bb9a6dc32c04fd51d7
Author: Martin Kong <martinkong@google.com>
Date:   Mon Dec 1 08:47:18 2025 -0800

    Add DEFINE_JNI macro to the end of every file (part 1)

    This CL adds DEFINE_JNI(ClassName) macro to the end of every file
    that includes ClassName_jni.h. Currently the macro expands to nothing.

    Bug: 346596940
    Change-Id: I61da4d1cc46f71d8ede30f74b267237a5f8cf14f
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7206009
    Commit-Queue: Andrew Grieve <agrieve@chromium.org>
    Auto-Submit: Martin Kong <martinkong@google.com>
    Reviewed-by: Andrew Grieve <agrieve@chromium.org>
    Owners-Override: Andrew Grieve <agrieve@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1552186}
2026-01-29 13:40:19 -05:00
Serg 86a4887089 Android new tab page ab test (#32464)
* [Android] Fresh NTP after idle experiment.

Introduces 4 different variants whether to show NTP or not when Brave
is foregrounded.
Resolves: https://github.com/brave/brave-browser/issues/50989
2025-11-21 17:32:50 -05:00
cdesouza-chromium 46e6b835c4 [CodeHealth] namespace pollution clean up for NTPBackgroundImagesBridge (#32469)
This PR is a namespace pollution clean up, following the style guide
recommendation that `using` namespace inclusions should not be done in
header files, or in the global namespace.

https://google.github.io/styleguide/cppguide.html#Namespaces

Bug: https://github.com/brave/brave-browser/issues/50970
2025-11-21 09:57:05 +00:00
cdesouza-chromium 6272401ed9 [IWYU] base/files/file_util.h (#32385)
This PR corrects several inclusions of `base/files/file_util.h`,
specially in headers where it is absolutely not supposed to occur.

Bug: https://github.com/brave/brave-browser/issues/42212
2025-11-20 18:41:41 +00:00
Terry Mancey 6a2ea02465 [ads] Fixes NTPBackgroundImagesBridge::CreateBrandedWallpaper crash when opening SNTP (#32440) 2025-11-20 06:26:26 -05:00
Terry Mancey 55bb54e876 [ads][CodeHealth] Remove unused campaign id (#32393)
This field is no longer needed now that P3A metric reporting has been
removed.
2025-11-18 18:26:04 +01:00
Terry Mancey 75a2652d65 [ads] Remove Android super referrals (#32158)
Remove Android Super Referrals. The feature is no longer supported or
used, and this cleanup helps reduce unused code and simplify the overall
system as part of https://github.com/brave/brave-browser/issues/44403.
2025-11-17 15:23:55 -05:00
Terry Mancey da86a7631c [ads] Invalid view_counter_service_ (#31969)
As part of brave/brave-browser#50267, we added a `DumpWithoutCrashing`
call to help identify issues with new tab takeovers. Investigating https://brave.sp.backtrace.io/p/brave/explore?time=all&filters=JTVCJTVCJTIySXNzdWU1MDI2Ny1mYWlsdXJlX3JlYXNvbiUyMiUyQyUyMmVxdWFsJTIyJTJDJTIySW52YWxpZCUyMHZpZXdfY291bnRlcl9zZXJ2aWNlXyUyMiU1RCU1RA%3D%3D&sort=(ver%2Crange%2Cmax%2Cdesc)&aggregations=((ver%2Crange)%2C(plat%2Cdistribution)%2C(ver%2Cdistribution)%2C(callstack%2Chead))&
as part of this issue.

While reviewing reports on Backtrace, we determined that the
view_counter_service_ can legitimately be null in incognito mode. This
PR removes the DumpWithoutCrashing call since it results in false
positives and that the conditional logic made no sense.
2025-10-23 16:35:00 +01:00
Terry Mancey d0537fab55 [ads] new tab takeover ad code health (#31894)
Rename to a generic name since clicked events are no longer limited to
logos.
2025-10-22 21:28:14 +01:00
Terry Mancey d4f6f7b4d2 [ads] Add DumpWithoutCrashing calls to help identify potential NTT-related issues (#31878)
This change adds DumpWithoutCrashing calls in key New Tab Takeover (NTT)
code paths to help diagnose potential issues affecting ad performance.

We have observed a noticeable drop in Android metrics since May 2025.
These dumps will help capture additional diagnostic data without causing
crashes, allowing us to better understand and correlate client-side
issues with the recent metric decline.
2025-10-17 23:17:13 +01:00
Terry Mancey 99ed05b5b8 [ads] Convert bool to enum and rename related variables (#31787)
Replace P3A boolean flag with an enum (Confirmation/P3A)
for clarity and rename related variables to match.
2025-10-14 11:41:06 -05:00
Aleksei Seren 87ba6f1985 Fix NTP view counter on Android (#31168)
Changed RegisterPageView() to be called after
GetCurrentWallpaperForDisplay()
2025-09-13 01:11:31 +09:00
Terry Mancey eacb87dca6 [ads] Fix should_metrics_fallback_to_p3a (#28379) 2025-03-30 01:00:04 -05:00
Terry Mancey f1545f26f0 [ads] NTT metric reporting (#28080)
* [ads] Report new tab page ad metrics via confirmation with an optional fallback to P3A

* [ads] Always serve new tab page ads through the component

* [ads] Do not frequency cap last served new tab page ad

* [ads] Deprecate redundant conditon matcher code

* [ads] Transition to v4 confirmation endpoint

* [ads] Include firstTime in the confirmation payload if it is the first impression for the campaign

* [ads] Deprecate HTTP_IM_A_TEAPOT

* [ads] Do not load unnecessary resources

* [ads] Migrate P3A opted-in status

* [ads] Deprecate AdInfoMatchesSponsoredImage

* [ads] Add ad events to brave://ads-internals

* [ads] Optimize firstTime database query

* [ads] Purge ad events when opting out

* [ads] Add grace period

* [ads] General code health

* [ads] Purge Brave News ads for all users when opting out
2025-03-21 17:01:23 +01:00
Artem Samoilenko 8ad41286d0 [Android] Remove duplicate jni headers generation 2025-03-06 15:49:32 -05:00
Terry Mancey 4f26062417 [ads] Suppress RichNTT if brave://settings/content/javascript is disabled (#27783) 2025-03-03 15:27:47 -05:00
Aleksei Seren 424ad890b2 [ads] RichNTT: Android 2025-02-27 12:12:59 -05:00
Terry Mancey 7d67928485 [ads] General code health (#27602) 2025-02-11 16:22:05 +01:00
Terry Mancey 8de249afef [ads] General code health (#27452) 2025-02-01 19:45:49 -05:00
Brian Johnson afd4e0239d fix overly permissive DEPS (#27193)
Fix overly permissive deps
2025-01-12 21:43:04 -07:00
zenparsing d90520fbca Modularize browser/ntp_background 2024-11-15 09:05:00 -05:00
Darnell Andries 3e404e7414 Add NTT reach metrics 2024-11-04 17:38:19 -08:00
cdesouza-chromium cbc844a561 BuildServiceInstanceFor => BuildServiceInstanceForBrowserContext (#25833)
This PR replaces the use of `BuildServiceInstanceFor` across brave, as
it has been deprecated, in favour of
`BuildServiceInstanceForBrowserContext`, which return a `unique_ptr`
rather than a naked pointer allocation.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/6121e052e0373a9a0cc84a718ef73e68e3b8a628

commit 6121e052e0373a9a0cc84a718ef73e68e3b8a628
Author: Tom Sepez <tsepez@chromium.org>
Date:   Wed Dec 14 21:38:26 2022 +0000

    Rework BrowserContextKeyedServiceFactory::BuildServiceInstanceFor().

    Avoid releasing an unique_ptr<> only to re-insert the raw value back
    into a different one. Instead, maintain ownership at all times.

    This is done by overriding the form of BuildServiceInstanceFor() as declared by KeyedServiceFactory, rather than the form of declared by BrowserContextKeyedServiceFactory.

    Demonstrate one usage in page_colors_factor.cc as an example, before
    taking on the hundreds that remain.

    Bug: 1396138
2024-10-08 11:57:01 +01:00
Artem Samoilenko e5d34071ef [Android] Remove remnants of ProfileAndroid
Chromium change:
https://source.chromium.org/chromium/chromium/src/+/8d32d8bc17cad5c37c8e5869501e1e8e3283bc47

Android: Remove remnants of ProfileAndroid

ProfileAndroid was merged with Profile, so just use Profile directly
everywhere.

Bug: b/339851174
2024-06-25 13:13:07 +01:00
cdesouza-chromium d1384a7872 [CodeHealth] Replace absl::optional with std::* (#21156)
This change replaces all uses of `absl::optional` with `std::*` variants
for optional. This is in line with upstream recent changes making
`absl::optional` a `typedef` to the `std` type.

This change has been done using an automated script:

    #!/bin/bash

    function replace {
      echo "Replacing $1 by $2"
      git grep -l "$1" \
        | cut -f1 -d: \
        | sort \
        | uniq \
        | grep \
          -e "\.h" \
          -e "\.cc" \
          -e "\.mm" \
          -e "\.py" \
        | xargs sed -i "s/$1/$2/g"
    }

    function delete_line_with {
      echo "Deleting lines with $1"
      git grep -l "$1" \
        | cut -f1 -d: \
        | sort \
        | uniq \
        | grep \
          -e "\.h" \
          -e "\.cc" \
          -e "\.mm" \
          -e "\.py" \
        | xargs sed -i "/$1/d"
    }

    function add_header {
      echo "Adding header $1"
      git diff --name-only HEAD \
        | xargs ../tools/add_header.py --header "$1"
    }

    replace "absl::make_optional" "std::make_optional"
    replace "absl::optional" "std::optional"
    replace "absl::nullopt" "std::nullopt"
    replace "absl::in_place" "std::in_place"
    replace "absl::in_place_t" "std::in_place_t"
    add_header "<optional>"
    delete_line_with "\"third_party\/abseil-cpp\/absl\/types\/optional.h\""
    git cl format

Chromium change:
https://chromium.googlesource.com/chromium/src/+/d9d21aa16829a7d471a4f3b3a493a31170ed8271

commit d9d21aa16829a7d471a4f3b3a493a31170ed8271
Author: David Benjamin <davidben@chromium.org>
Date:   Mon Oct 2 23:29:57 2023 +0000

    Make absl::optional a typedef for std::optional

    This only changes the types around. It doesn't rewrite existing uses
    to std::optional, which we can do incrementally.

    absl::optional to std::optional seems to have two visible impacts.
    First, the field order is different (bool first vs bool last).
    std::optional's order (bool last) seems to be better overall, decreasing
    binary size. Second, absl::optional's assertions crash with
    __builtin_trap, while std::optional calls __libcpp_verbose_abort which
    calls base::ImmediateCrash. __builtin_trap permits the compiler to
    combine crash sites within a function but leads to worse crash
    debugging. In base::ImmediateCrash, we'd made a conscious decision to
    prefer debuggability and pay some binary size for it. The net size
    increase brings our optional type in line with that preference.

    For more details see the discussion and document below:
    https://groups.google.com/a/chromium.org/g/cxx/c/XG3G85_ZF1k/m/_QN8adIJBQAJ
    https://docs.google.com/document/d/1AW7q9HCLOk738OCj8Z2U_AKVUC0YIFZWuyRvv09XTHk/edit

    Binary-Size: See discussion above.
    Fuchsia-Binary-Size: See discussion above.
    Bug: 1373619
2023-12-01 10:16:12 +00:00
cdesouza-chromium b94efd40d1 Use base::NoDestructor rather than Singleton (#18846)
This change replaces all uses of `base::Singleton` across the codebase,
in favor of `base::NoDestructor`. This is following the a direction
taken upstream, in getting `base::Singleton` deleted.

LSC doc:
https://docs.google.com/document/d/1x1LqRQyfBOmpMkNQBYs7QBPSxLtuiImvmgcJYI_kaS4/edit?usp=sharing
2023-06-13 03:00:07 +01:00
cdesouza-chromium cbcdb547e0 Replace base::GUID with base::Uuid (#18854)
Upstream has renamed `base::GUID` to `base::Uuid` to avoid name
collisions with some constants in Windows headers. Therefore, all
instances of the `base/guid.h` header, as well as anything using the
former name, must be changed to use `base::Uuid`, in preparation of the
deletion of the legacy name from upstream.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/f800d299bb9374ca8d401c1d326339833cb4280e

commit f800d299bb9374ca8d401c1d326339833cb4280e
Author: Claudio DeSouza <cdesouza@igalia.com>
Date:   Thu Jun 8 03:11:20 2023 +0000

    Delete base/guid.h

    This CL deletes `base/guid.h` from the codebase, as all uses of
    `base::GUID` have been replaced with `base::Uuid`. Additionally, all
    deprecated functions are also getting deleted, as all uses have been
    corrected.

    Bug: 1428566, 1195446
2023-06-12 19:42:06 +01:00
Emerick Rogul 7d7bca1cef bind.h, callback{,_forward,_helpers}.h now located in //base/functionality
Chromium change:

https://source.chromium.org/chromium/chromium/src/+/cd23b8b9d212daf06dde638488dbaa355d6651fa

commit cd23b8b9d212daf06dde638488dbaa355d6651fa
Author: Daniel Cheng <dcheng@chromium.org>
Date:   Fri Sep 16 17:16:24 2022 +0000

    Move bind.h, callback{,_forward,_helpers}.h into //base/functional

    Forwarding headers remain in the old locations to ease migration.
    Include paths for files in //base/functional/ are also fixed up to the
    new canonical path; remaining fixups are deferred until followups to
    minimize the risk of conflicts.

    Bug: 1364441
2023-02-22 06:29:17 -05:00
Terry Mancey b7728bf807 Refactor Brave Ads served events 2023-02-01 13:20:27 -05:00
Claudio DeSouza bdd3261c4f [CodeHealth] base::Value modernisation around New Tab Page
This change updates the use of base::Value, removing all deprecated
methods around the NTP code. Methods that were using base::Value null
type to signify nothing at return are now using optional, as that more
consisely expresses the interface.
2022-08-25 16:38:20 +01:00
sangwoo.ko 1cba5b76c3 Introduce NTPBackgroundPref
* Mark `kNTPCustomBGEnabled` pref as deprecated
* NTPBackgroundPref is responsble for managing pref related to NTP
  background.
* Migrate old pref with new pref

https://docs.google.com/document/d/1uYp_NPk93r36LHpTqn1_7yJ5M3h3uOq238_6PbjwBnI/edit?usp=sharing

TEST=NTPBackgroundPrefTest*, BravePrefsBrowserTest
2022-08-19 17:47:30 +09:00