Skip to content

Commit

Permalink
chrome/browser: Replace std::find with base::ContainsValue
Browse files Browse the repository at this point in the history
Use ContainsValue() instead of std::find() in chrome/browser

Bug: 561800
Change-Id: I6c2af9884029644de51bbf19507edac55b8f57b9
Reviewed-on: https://chromium-review.googlesource.com/1188723
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586168}
  • Loading branch information
haeungun authored and Commit Bot committed Aug 26, 2018
1 parent d702cf9 commit 3f61235
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 59 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ Gustav Tiger <gustav.tiger@sonymobile.com>
Gyuyoung Kim <gyuyoung.kim@navercorp.com>
Gzob Qq <gzobqq@gmail.com>
Habib Virji <habib.virji@samsung.com>
Haeun Kim <ggrace.kim93@gmail.com>
Haeun Kim <haeungun@gmail.com>
Haitao Feng <haitao.feng@intel.com>
Halley Zhao <halley.zhao@intel.com>
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/chromeos/arc/arc_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/task/post_task.h"
Expand Down Expand Up @@ -635,9 +636,7 @@ ash::mojom::AssistantAllowedState IsAssistantAllowedForProfile(

if (!pref_locale.empty()) {
base::ReplaceChars(pref_locale, "-", "_", &pref_locale);
bool disallowed = std::end(kAllowedLocales) ==
std::find(std::begin(kAllowedLocales),
std::end(kAllowedLocales), pref_locale);
bool disallowed = !base::ContainsValue(kAllowedLocales, pref_locale);

if (disallowed &&
base::CommandLine::ForCurrentProcess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_bridge_impl.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -211,8 +212,7 @@ void ArcInputMethodManagerService::OnImeInfoChanged(
// TODO(crbug.com/845079): We should keep the order of the IMEs as same as in
// chrome://settings
for (const auto& input_method_id : enabled_input_method_ids) {
if (std::find(active_ime_list.begin(), active_ime_list.end(),
input_method_id) == active_ime_list.end()) {
if (!base::ContainsValue(active_ime_list, input_method_id)) {
active_ime_list.push_back(input_method_id);
}
}
Expand Down
7 changes: 2 additions & 5 deletions chrome/browser/chromeos/locale_change_guard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -256,11 +257,7 @@ bool LocaleChangeGuard::ShouldShowLocaleChangeNotification(
if (from_lang != to_lang)
return true;

const char* const* begin = kSkipShowNotificationLanguages;
const char* const* end = kSkipShowNotificationLanguages +
arraysize(kSkipShowNotificationLanguages);

return std::find(begin, end, from_lang) == end;
return !base::ContainsValue(kSkipShowNotificationLanguages, from_lang);
}

// static
Expand Down
6 changes: 2 additions & 4 deletions chrome/browser/chromeos/locale_change_guard_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string.h>

#include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"

Expand Down Expand Up @@ -209,11 +210,8 @@ TEST(LocaleChangeGuardTest, ShowNotificationLocaleChangedList) {
const std::string language =
(dash ? std::string(locale, dash - locale) : std::string(locale));

const char* const* allowed_begin = kShowNotificationLanguages;
const char* const* allowed_end =
kShowNotificationLanguages + arraysize(kShowNotificationLanguages);
const bool notification_allowed =
(std::find(allowed_begin, allowed_end, language) != allowed_end);
base::ContainsValue(kShowNotificationLanguages, language);

const char* const* skipped_begin =
LocaleChangeGuard::GetSkipShowNotificationLanguagesForTesting();
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/settings/device_settings_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/syslog_logging.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
Expand Down Expand Up @@ -730,8 +731,7 @@ DeviceSettingsProvider::~DeviceSettingsProvider() {

// static
bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) {
const char* const* end = kKnownSettings + arraysize(kKnownSettings);
return std::find(kKnownSettings, end, name) != end;
return base::ContainsValue(kKnownSettings, name);
}

// static
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/devtools/chrome_devtools_manager_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <utility>

#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/devtools/chrome_devtools_session.h"
Expand Down Expand Up @@ -109,9 +110,7 @@ void ChromeDevToolsManagerDelegate::HandleCommand(

std::string ChromeDevToolsManagerDelegate::GetTargetType(
content::WebContents* web_contents) {
auto& all_tabs = AllTabContentses();
auto it = std::find(all_tabs.begin(), all_tabs.end(), web_contents);
if (it != all_tabs.end())
if (base::ContainsValue(AllTabContentses(), web_contents))
return DevToolsAgentHost::kTypePage;

std::string extension_name;
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/google/google_brand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/optional.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -140,9 +141,7 @@ bool IsInternetCafeBrandCode(const std::string& brand) {
"CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
"OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
};
const char* const* end = &kBrands[arraysize(kBrands)];
const char* const* found = std::find(&kBrands[0], end, brand);
return found != end;
return base::ContainsValue(kBrands, brand);
}

// BrandForTesting ------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions chrome/browser/internal_auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ bool IsVarSane(const std::string& var) {
sizeof(kAllowedChars) == 26 + 26 + 10 + 1 + 1, "some mess with chars");
// We must not allow kItemSeparator in anything used as an input to construct
// message to sign.
DCHECK(std::find(kAllowedChars, kAllowedChars + arraysize(kAllowedChars),
kItemSeparator) == kAllowedChars + arraysize(kAllowedChars));
DCHECK(std::find(kAllowedChars, kAllowedChars + arraysize(kAllowedChars),
kVarValueSeparator) == kAllowedChars + arraysize(kAllowedChars));
DCHECK(!base::ContainsValue(kAllowedChars, kItemSeparator));
DCHECK(!base::ContainsValue(kAllowedChars, kVarValueSeparator));
return !var.empty() &&
var.size() <= kStringLengthLimit &&
base::IsStringASCII(var) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>

#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/media/router/data_decoder_util.h"
Expand All @@ -27,9 +28,7 @@ static constexpr const char* kDiscoveryOnlyModelNames[3] = {
// |model_name|: device model name.
bool IsDiscoveryOnly(const std::string& model_name) {
std::string lower_model_name = base::ToLowerASCII(model_name);
return std::find(std::begin(kDiscoveryOnlyModelNames),
std::end(kDiscoveryOnlyModelNames),
lower_model_name) != std::end(kDiscoveryOnlyModelNames);
return base::ContainsValue(kDiscoveryOnlyModelNames, lower_model_name);
}

SinkAppStatus GetSinkAppStatusFromResponse(const DialAppInfoResult& result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ TEST_F(AutocompleteActionPredictorTest,
auto test = [this](const base::string16& user_text,
bool should_be_registered) {
predictor()->RegisterTransitionalMatches(user_text, AutocompleteResult());
bool registered = (std::find(transitional_matches()->begin(),
transitional_matches()->end(),
user_text) != transitional_matches()->end());
bool registered = base::ContainsValue(*transitional_matches(), user_text);
EXPECT_EQ(registered, should_be_registered);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -147,10 +148,8 @@ IN_PROC_BROWSER_TEST_P(ReporterRunnerPolicyTest, CheckComponent) {
// component installed. Otherwise it should be installed.
std::vector<std::string> component_ids =
g_browser_process->component_updater()->GetComponentIDs();
bool sw_component_registered =
std::find(component_ids.begin(), component_ids.end(),
component_updater::kSwReporterComponentId) !=
component_ids.end();
bool sw_component_registered = base::ContainsValue(
component_ids, component_updater::kSwReporterComponentId);
ASSERT_EQ(!is_managed() || is_enabled(), sw_component_registered);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ash/public/cpp/app_list/internal_app_id_constants.h"
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/window_properties.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/app_list/internal_app/internal_app_metadata.h"
#include "chrome/browser/ui/ash/launcher/app_window_base.h"
Expand Down Expand Up @@ -88,9 +89,7 @@ void InternalAppWindowShelfController::OnWindowVisibilityChanging(
return;

// Skip OnWindowVisibilityChanged for ancestors/descendants.
auto it =
std::find(observed_windows_.begin(), observed_windows_.end(), window);
if (it == observed_windows_.end())
if (!base::ContainsValue(observed_windows_, window))
return;

ash::ShelfID shelf_id =
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/debug/profiler.h"
#include "base/macros.h"
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -1225,8 +1226,7 @@ void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {

// Go through all the command ids, skip the whitelisted ones.
for (int id : command_updater->GetAllIds()) {
if (std::find(std::begin(kWhitelistedIds), std::end(kWhitelistedIds), id)
!= std::end(kWhitelistedIds)) {
if (base::ContainsValue(kWhitelistedIds, id)) {
continue;
}
DCHECK(!command_updater->IsCommandEnabled(id));
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/browser_command_controller_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -150,8 +151,7 @@ IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, LockedFullscreen) {
// Go through all the command ids and make sure all non-whitelisted commands
// are disabled.
for (int id : command_updater->GetAllIds()) {
if (std::find(std::begin(kWhitelistedIds), std::end(kWhitelistedIds), id)
!= std::end(kWhitelistedIds)) {
if (base::ContainsValue(kWhitelistedIds, id)) {
continue;
}
EXPECT_FALSE(command_updater->IsCommandEnabled(id));
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/ui/login/login_handler_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ void LoginPromptBrowserTestObserver::Observe(
}

void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) {
std::list<LoginHandler*>::iterator i =
std::find(handlers_.begin(), handlers_.end(), handler);
// Cannot use ASSERT_EQ, because gTest on Android confuses iterators with
// containers.
ASSERT_TRUE(i == handlers_.end());
ASSERT_FALSE(base::ContainsValue(handlers_, handler));
handlers_.push_back(handler);
}

Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/webui/chromeos/login/oobe_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -280,9 +281,7 @@ content::WebUIDataSource* CreateOobeUIDataSource(
std::string GetDisplayType(const GURL& url) {
std::string path = url.path().size() ? url.path().substr(1) : "";

if (std::find(kKnownDisplayTypes,
kKnownDisplayTypes + arraysize(kKnownDisplayTypes),
path) == kKnownDisplayTypes + arraysize(kKnownDisplayTypes)) {
if (!base::ContainsValue(kKnownDisplayTypes, path)) {
LOG(ERROR) << "Unknown display type '" << path << "'. Setting default.";
return OobeUI::kLoginDisplay;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/i18n/file_util_icu.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
Expand Down Expand Up @@ -93,8 +94,7 @@ std::unique_ptr<base::DictionaryValue> GetPdfCapabilities(
Media default_media("", "", default_media_size.width(),
default_media_size.height());
if (!default_media.MatchBySize() ||
std::find(kPdfMedia, kPdfMedia + arraysize(kPdfMedia),
default_media.type) == kPdfMedia + arraysize(kPdfMedia)) {
!base::ContainsValue(kPdfMedia, default_media.type)) {
default_media = Media(locale == "en-US" ? NA_LETTER : ISO_A4);
}
MediaCapability media;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "base/path_service.h"
#include "base/stl_util.h"
#include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -46,12 +47,10 @@ TEST_F(ScanDirForExternalWebAppsTest, GoodJson) {
"https://events.google.com/io2016/?utm_source=web_app_manifest",
};
for (const char* url : urls) {
EXPECT_NE(
app_infos.end(),
std::find(app_infos.begin(), app_infos.end(),
web_app::PendingAppManager::AppInfo(
GURL(url),
web_app::PendingAppManager::LaunchContainer::kWindow)));
EXPECT_TRUE(base::ContainsValue(
app_infos,
web_app::PendingAppManager::AppInfo(
GURL(url), web_app::PendingAppManager::LaunchContainer::kWindow)));
}
}

Expand Down

0 comments on commit 3f61235

Please sign in to comment.