[CodeHealth][cr146] `base::Contains` dissallowed when `.contains` suffices it This is being enforced by the compiler through a concept, and it only applies for cases where `base::Contains` is used without a projection. This change also carries out IWYU for `base::Contains`. Chromium changes: https://chromium.googlesource.com/chromium/src/+/4a17af8403373b7f7e7546ef61f30dfbe883d617 ``` commit 4a17af8403373b7f7e7546ef61f30dfbe883d617 Author: Victor Hugo Vianna Silva <victorvianna@google.com> Date: Tue Jan 13 07:30:34 2026 -0800 Disallow base::Contains() when contains() or find() methods available This is a temporary step towards deleting base::Contains(). Trying to call base::Contains(foo, bar) will now cause a static assertion failure if foo has contains() or find() methods. This effectively makes base::Contains() an alias to std::ranges::contains(). The result is we can replace instances of 'base::Contains' with 'std::ranges::contains' in upcoming CLs while being sure to not regress performance. Bug: 470391351 Change-Id: I8778f435ff8f5b52fb3bf336724f2dfef388907a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7415207 Commit-Queue: Francois Pierre Doray <fdoray@chromium.org> Reviewed-by: Francois Pierre Doray <fdoray@chromium.org> Cr-Commit-Position: refs/heads/main@{#1568392} ``` Bug: https://github.com/brave/brave-browser/issues/42557
60 lines
2.2 KiB
C++
60 lines
2.2 KiB
C++
// Copyright (c) 2023 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/components/webui/about_ui.h"
|
|
|
|
#include <string_view>
|
|
|
|
#include "base/containers/fixed_flat_set.h"
|
|
#include "base/strings/string_split.h"
|
|
#include "base/strings/string_util.h"
|
|
#include "third_party/re2/src/re2/re2.h"
|
|
|
|
namespace brave {
|
|
|
|
std::string ReplaceAboutUIChromeURLs(std::string chrome_urls) {
|
|
// Replace Chrome -> Brave.
|
|
constexpr std::string_view kChromeHeader = "Chrome URLs";
|
|
constexpr std::string_view kBraveHeader = "Brave URLs";
|
|
constexpr std::string_view kChromePagesHeader = "List of Chrome URLs";
|
|
constexpr std::string_view kBravePagesHeader = "List of Brave URLs";
|
|
constexpr std::string_view kChromeInternalPagesHeader =
|
|
"List of chrome://internals pages";
|
|
constexpr std::string_view kBraveInternalPagesHeader =
|
|
"List of brave://internals pages";
|
|
constexpr std::string_view kChromeURLList = ">chrome://";
|
|
constexpr std::string_view kBraveURLList = ">brave://";
|
|
|
|
RE2::GlobalReplace(&chrome_urls, kChromeHeader, kBraveHeader);
|
|
RE2::GlobalReplace(&chrome_urls, kChromePagesHeader, kBravePagesHeader);
|
|
RE2::GlobalReplace(&chrome_urls, kChromeInternalPagesHeader,
|
|
kBraveInternalPagesHeader);
|
|
RE2::GlobalReplace(&chrome_urls, kChromeURLList, kBraveURLList);
|
|
|
|
// Remove some URLs.
|
|
auto html_lines = base::SplitStringPiece(
|
|
chrome_urls, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
|
|
constexpr auto kURLsToRemove = base::MakeFixedFlatSet<std::string_view>({
|
|
"brave://memories",
|
|
});
|
|
// URLs in html should be sorted so it's okay to iterate over sorted
|
|
// kURLsToRemove.
|
|
auto html_line_it = html_lines.begin();
|
|
auto url_to_remove_it = kURLsToRemove.begin();
|
|
while (html_line_it != html_lines.end() &&
|
|
url_to_remove_it != kURLsToRemove.end()) {
|
|
if (html_line_it->contains(*url_to_remove_it)) {
|
|
html_line_it = html_lines.erase(html_line_it);
|
|
++url_to_remove_it;
|
|
} else {
|
|
++html_line_it;
|
|
}
|
|
}
|
|
|
|
return base::JoinString(html_lines, "\n");
|
|
}
|
|
|
|
} // namespace brave
|