Skip to content

Commit

Permalink
Revert "[CodeHealth] Use cxx20's T::contains pt.2 (#27709)"
Browse files Browse the repository at this point in the history
This reverts commit b54f97e.
  • Loading branch information
cdesouza-chromium committed Feb 20, 2025
1 parent 0614a2f commit cece9e1
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <utility>

#include "base/containers/contains.h"
#include "brave/browser/ephemeral_storage/ephemeral_storage_service_factory.h"
#include "brave/components/brave_wallet/browser/permission_utils.h"
#include "brave/components/ephemeral_storage/ephemeral_storage_service.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ PermissionOriginLifetimeMonitorImpl::SubscribeToPermissionOriginDestruction(
}
std::string storage_domain = net::URLToEphemeralStorageDomain(
is_sub_request_origin ? sub_request_origin.GetURL() : requesting_origin);
if (!active_subscriptions_.contains(storage_domain)) {
if (!base::Contains(active_subscriptions_, storage_domain)) {
active_subscriptions_.insert(storage_domain);
}
return storage_domain;
Expand Down
7 changes: 4 additions & 3 deletions browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include "brave/browser/ui/brave_browser_command_controller.h"

#include <optional>
#include <vector>

#include "base/containers/fixed_flat_set.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/types/to_address.h"
#include "brave/app/brave_command_ids.h"
Expand Down Expand Up @@ -75,11 +76,11 @@ bool IsBraveCommands(int id) {
}

bool IsBraveOverrideCommands(int id) {
static constexpr auto kOverrideCommands = base::MakeFixedFlatSet<int>({
static std::vector<int> override_commands({
IDC_NEW_WINDOW,
IDC_NEW_INCOGNITO_WINDOW,
});
return kOverrideCommands.contains(id);
return base::Contains(override_commands, id);
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <string>

#include "base/containers/fixed_flat_set.h"
#include "base/containers/contains.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "content/public/common/url_constants.h"

Expand All @@ -18,22 +18,18 @@

namespace sessions {

namespace {

// Extension can override below three chrome urls.
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/extensions/api/chrome_url_overrides.idl
constexpr auto kAllowedChromeUrlsOverridingHostList =
base::MakeFixedFlatSet<std::string_view>(
{"newtab", "history", "bookmarks"});

} // namespace

std::string ContentSerializedNavigationDriver::GetSanitizedPageStateForPickle(
const sessions::SerializedNavigationEntry* navigation) const {
// Extension can override below three chrome urls.
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/extensions/api/chrome_url_overrides.idl
constexpr std::array<const char*, 3> kAllowedChromeUrlsOverridingHostList = {
"newtab", "history", "bookmarks"};

const auto& virtual_url = navigation->virtual_url();
if (virtual_url.SchemeIs(content::kChromeUIScheme)) {
// If empty string is returned, chrome url overriding is ignored.
if (kAllowedChromeUrlsOverridingHostList.contains(virtual_url.host())) {
if (base::Contains(kAllowedChromeUrlsOverridingHostList,
virtual_url.host())) {
// chrome url can be re-written when it's restored during the tab but
// re-written url is ignored when encoded page state is empty.
// In ContentSerializedNavigationBuilder::ToNavigationEntry(), re-written
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void DeviceInfoSyncBridge::RefreshLocalDeviceInfoIfNeeded() {
return;
}

if (!all_data_.contains(current_info->guid())) {
if (!base::Contains(all_data_, current_info->guid())) {
// After initiating leave the sync chain `DeleteSpecifics` cleans
// `all_data_` map.
// It is possible that user close sync settings page or change the data type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 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 "base/containers/contains.h"
#include "brave/components/constants/webui_url_constants.h"

// Include password_manager constants before override so we don't override the
Expand All @@ -12,7 +13,7 @@
// Add some extra items to WebUI hosts considered valid for PWAs
#define kChromeUIPasswordManagerHost \
kChromeUIPasswordManagerHost && \
!kInstallablePWAWebUIHosts.contains(url.host_piece())
!base::Contains(kInstallablePWAWebUIHosts, url.host_piece())

#include "src/components/webapps/browser/banners/app_banner_manager.cc"
#undef kChromeUIPasswordManagerHost
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <string_view>

#include "base/containers/fixed_flat_set.h"
#include "base/containers/contains.h"

namespace blink::origin_trials {
bool IsTrialValid_ChromiumImpl(std::string_view trial_name);
Expand All @@ -19,33 +19,21 @@ bool IsTrialValid_ChromiumImpl(std::string_view trial_name);

namespace blink::origin_trials {

namespace {

// When updating also update the array in the overload below.
constexpr auto kBraveDisabledTrialNames =
base::MakeFixedFlatSet<std::string_view>({
"AdInterestGroupAPI",
"DeviceAttributes",
"DigitalGoodsV2",
"InterestCohortAPI",
"FencedFrames",
"Fledge",
"Parakeet",
"SignedExchangeSubresourcePrefetch",
"SubresourceWebBundles",
});

constexpr auto kBraveDisabledTrialFeatures =
base::MakeFixedFlatSet<blink::mojom::OriginTrialFeature>({
blink::mojom::OriginTrialFeature::kAdInterestGroupAPI,
blink::mojom::OriginTrialFeature::kDigitalGoods,
blink::mojom::OriginTrialFeature::kParakeet,
});

} // namespace

bool IsTrialDisabledInBrave(std::string_view trial_name) {
if (kBraveDisabledTrialNames.contains(trial_name)) {
// When updating also update the array in the overload below.
static const char* const kBraveDisabledTrialNames[] = {
"AdInterestGroupAPI",
"DeviceAttributes",
"DigitalGoodsV2",
"InterestCohortAPI",
"FencedFrames",
"Fledge",
"Parakeet",
"SignedExchangeSubresourcePrefetch",
"SubresourceWebBundles",
};

if (base::Contains(kBraveDisabledTrialNames, trial_name)) {
// Check if this is still a valid trial name in Chromium. If not, it needs
// to be changed as in Chromium or removed.
DCHECK(IsTrialValid_ChromiumImpl(trial_name));
Expand All @@ -57,7 +45,14 @@ bool IsTrialDisabledInBrave(std::string_view trial_name) {

bool IsTrialDisabledInBrave(blink::mojom::OriginTrialFeature feature) {
// When updating also update the array in the overload above.
return kBraveDisabledTrialFeatures.contains(feature);
static const blink::mojom::OriginTrialFeature kBraveDisabledTrialFeatures[] =
{
blink::mojom::OriginTrialFeature::kAdInterestGroupAPI,
blink::mojom::OriginTrialFeature::kDigitalGoods,
blink::mojom::OriginTrialFeature::kParakeet,
};

return base::Contains(kBraveDisabledTrialFeatures, feature);
}

bool IsTrialValid(std::string_view trial_name) {
Expand Down
5 changes: 3 additions & 2 deletions components/ai_chat/content/browser/page_content_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "base/check.h"
#include "base/containers/checked_iterators.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
Expand Down Expand Up @@ -202,7 +203,7 @@ class PageContentFetcherInternal {
return;
}
DVLOG(1) << "OnTabContentResult: " << data.get();
const bool is_video = kVideoPageContentTypes.contains(data->type);
const bool is_video = base::Contains(kVideoPageContentTypes, data->type);
DVLOG(1) << "Is video? " << is_video;
// Handle text mode response
if (!is_video) {
Expand Down Expand Up @@ -455,7 +456,7 @@ void PageContentFetcher::FetchPageContent(std::string_view invalidation_token,

auto url = web_contents_->GetLastCommittedURL();
#if BUILDFLAG(ENABLE_TEXT_RECOGNITION)
if (kScreenshotRetrievalHosts.contains(url.host_piece())) {
if (base::Contains(kScreenshotRetrievalHosts, url.host_piece())) {
content::RenderWidgetHostView* view =
web_contents_->GetRenderWidgetHostView();
if (view) {
Expand Down
2 changes: 1 addition & 1 deletion components/ai_chat/core/browser/tab_tracker_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void TabTrackerService::Bind(

void TabTrackerService::UpdateTab(int32_t tab_id, mojom::TabDataPtr tab) {
auto allowed_scheme =
tab && kAllowedContentSchemes.contains(tab->url.scheme());
tab && base::Contains(kAllowedContentSchemes, tab->url.scheme());

auto it = std::ranges::find_if(
tabs_, [tab_id](const auto& tab) { return tab->id == tab_id; });
Expand Down
4 changes: 3 additions & 1 deletion components/ai_chat/renderer/ai_chat_resource_sniffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <utility>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/functional/callback.h"
#include "base/macros/if.h"
Expand Down Expand Up @@ -50,7 +51,8 @@ std::unique_ptr<AIChatResourceSniffer> AIChatResourceSniffer::MaybeCreate(
// TODO(petemill): Allow some kind of config to be passed in to determine
// which hosts and paths to sniff, and how to parse it to a
// |mojom::PageContent|.
if (url.SchemeIsHTTPOrHTTPS() && kYouTubeHosts.contains(url.host_piece()) &&
if (url.SchemeIsHTTPOrHTTPS() &&
base::Contains(kYouTubeHosts, url.host_piece()) &&
base::EqualsCaseInsensitiveASCII(url.path_piece(),
kYouTubePlayerAPIPath)) {
return base::WrapUnique(new AIChatResourceSniffer(std::move(delegate)));
Expand Down
5 changes: 3 additions & 2 deletions components/ai_chat/renderer/page_content_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/containers/flat_tree.h"
#include "base/containers/span.h"
Expand Down Expand Up @@ -172,7 +173,7 @@ void PageContentExtractor::ExtractPageContent(

if (origin.is_valid()) {
std::string host = origin.host();
if (kYouTubeHosts.contains(host)) {
if (base::Contains(kYouTubeHosts, host)) {
VLOG(1) << "YouTube transcript type";
// Do Youtube extraction
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
Expand All @@ -192,7 +193,7 @@ void PageContentExtractor::ExtractPageContent(
blink::mojom::WantResultOption::kWantResult,
blink::mojom::PromiseResultOption::kAwait);
return;
} else if (kVideoTrackHosts.contains(host)) {
} else if (base::Contains(kVideoTrackHosts, host)) {
VLOG(1) << "Video track transcript type";
// Video <track> extraction
// TODO(petemill): Use heuristics to determine if page's main focus is
Expand Down
22 changes: 11 additions & 11 deletions components/ai_chat/renderer/page_text_distilling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <vector>

#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/fixed_flat_set.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
Expand Down Expand Up @@ -50,18 +50,18 @@ namespace ai_chat {

namespace {

constexpr auto kContentParentRoles = base::MakeFixedFlatSet<ax::mojom::Role>({
static const ax::mojom::Role kContentParentRoles[]{
ax::mojom::Role::kMain,
ax::mojom::Role::kArticle,
});
};

constexpr auto kContentRoles = base::MakeFixedFlatSet<ax::mojom::Role>({
static const ax::mojom::Role kContentRoles[]{
ax::mojom::Role::kHeading,
ax::mojom::Role::kParagraph,
ax::mojom::Role::kNote,
});
};

constexpr auto kRolesToSkip = base::MakeFixedFlatSet<ax::mojom::Role>({
static const ax::mojom::Role kRolesToSkip[]{
ax::mojom::Role::kAudio,
ax::mojom::Role::kBanner,
ax::mojom::Role::kButton,
Expand All @@ -83,7 +83,7 @@ constexpr auto kRolesToSkip = base::MakeFixedFlatSet<ax::mojom::Role>({
ax::mojom::Role::kSlider,
ax::mojom::Role::kSpinButton,
ax::mojom::Role::kSearchBox,
});
};

void GetContentRootNodes(const ui::AXNode* root,
std::vector<const ui::AXNode*>* content_root_nodes) {
Expand All @@ -94,7 +94,7 @@ void GetContentRootNodes(const ui::AXNode* root,
queue.pop();
// If a main or article node is found, add it to the list of content root
// nodes and continue. Do not explore children for nested article nodes.
if (kContentParentRoles.contains(node->GetRole())) {
if (base::Contains(kContentParentRoles, node->GetRole())) {
content_root_nodes->push_back(node);
continue;
}
Expand All @@ -107,11 +107,11 @@ void GetContentRootNodes(const ui::AXNode* root,

void AddContentNodesToVector(const ui::AXNode* node,
std::vector<const ui::AXNode*>* content_nodes) {
if (kContentRoles.contains(node->GetRole())) {
if (base::Contains(kContentRoles, node->GetRole())) {
content_nodes->emplace_back(node);
return;
}
if (kRolesToSkip.contains(node->GetRole())) {
if (base::Contains(kRolesToSkip, node->GetRole())) {
return;
}
for (auto iter = node->UnignoredChildrenBegin();
Expand All @@ -124,7 +124,7 @@ void AddTextNodesToVector(const ui::AXNode* node,
std::vector<std::u16string>* strings) {
const ui::AXNodeData& node_data = node->data();

if (kRolesToSkip.contains(node_data.role)) {
if (base::Contains(kRolesToSkip, node_data.role)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <utility>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/containers/flat_set.h"
#include "base/logging.h"
Expand Down Expand Up @@ -260,7 +261,8 @@ mojom::CreativeSearchResultAdInfoPtr ExtractMojomEntity(
return {};
}

if (kRequiredCreativeAdPropertyNames.contains(mojom_property->name)) {
if (base::Contains(kRequiredCreativeAdPropertyNames,
mojom_property->name)) {
if (!ExtractCreativeAdMojomProperty(mojom_property,
mojom_creative_ad.get())) {
VLOG(6) << "Failed to extract creative search result ad property "
Expand All @@ -269,8 +271,8 @@ mojom::CreativeSearchResultAdInfoPtr ExtractMojomEntity(
}

creative_ad_property_names.insert(mojom_property->name);
} else if (kCreativeSetConversionPropertyNames.contains(
mojom_property->name)) {
} else if (base::Contains(kCreativeSetConversionPropertyNames,
mojom_property->name)) {
if (!ExtractCreativeSetConversionMojomProperty(
mojom_property, mojom_creative_set_conversion.get())) {
VLOG(6) << "Failed to extract creative set conversion property "
Expand Down
Loading

0 comments on commit cece9e1

Please sign in to comment.