8 Commits
Author SHA1 Message Date
cdesouza-chromium 4e7fcd376f [CodeHealth] Use std::string::[starts|ends]_with (#26306)
For cases where the comparison is case sensitive, we should use the
methods provided by the common std string types provided since cxx20.
2024-10-31 13:44:30 +00:00
Brian Johnson 3313ad628b remove include rules that no longer apply (#25911)
remove include rules that no longer apply and fix existing include rules
2024-10-10 16:19:48 -07:00
cdesouza-chromium e1f8a28431 [CodeHealth] Use constexpr strings (#25810)
Use `constexpr` strings

This PR changes moves away from uses of `const char` with two
approaches. For `.cc` files, these types are turned into constexpr ones,
which gives the compiler more leeway for optimisations.

For the constants on header files, we are converting these instances to
`inline constexpr`, in order to also reduce string duplication across
the binary.

This change was generated with a tool.
2024-10-04 10:01:05 -07:00
cdesouza-chromium 028205bab9 [CodeHealth] Avoid accidental const-copies - Part I (#25774)
[CodeHealth] Avoid accidental const-copies I

This is of concern when passing vectors and strings, as unintended
(and often expensive) copies occur under the covers.

-- Make non-const and move in callee where appropriate.
-- Convert to string_view where appropriate.
-- Avoid stray const in a few places

Additionally, in a few places this cahnge removes things like
`std::function`, and unnecessary code like JSON parsing testing utils.
2024-10-03 15:18:37 +01:00
Claudio DeSouza 76faa1624e IWYU fixes 2024-04-08 17:33:57 -04: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
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
Claudio DeSouza 3f6af44ea5 SXG-banning browser tests
Singed exchange is an undesirable feature, which should not be allowed
in brave. This feature is guarded behind the feature flag
SignedHTTPExchange.

This change adds browser tests to the codebase to make sure that this
feature doesn't come to creep in into our codebase.

For reference:

https://github.com/brave/brave-browser/issues/24227
2022-10-13 23:52:13 +01:00