Skip to content

Commit

Permalink
Change std::find() to use base:: functions: chrome/browser/ui/
Browse files Browse the repository at this point in the history
Simplifies code slightly.

Bug: 1368812
Change-Id: I1c4c3e6338041ca54f4877d087d23a2de742dd6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3923837
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Trent Apted <tapted@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052151}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Sep 28, 2022
1 parent 11fac0f commit dbb1c29
Show file tree
Hide file tree
Showing 35 changed files with 81 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#include <stddef.h>

#include <algorithm>
#include <utility>

#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/android/chrome_jni_headers/UsbChooserDialog_jni.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -139,7 +139,7 @@ void UsbChooserDialogAndroid::OnItemSelected(
const base::android::JavaParamRef<jstring>& item_id_jstring) {
std::string item_id =
base::android::ConvertJavaStringToUTF8(env, item_id_jstring);
auto it = std::find(item_id_map_.begin(), item_id_map_.end(), item_id);
auto it = base::ranges::find(item_id_map_, item_id);
DCHECK(it != item_id_map_.end());
controller_->Select(
{static_cast<size_t>(std::distance(item_id_map_.begin(), it))});
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ui/android/tab_model/tab_model_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <jni.h>

#include "base/android/jni_android.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/android/tab_model/tab_model.h"
Expand Down Expand Up @@ -35,7 +36,7 @@ void TabModelList::RemoveTabModel(TabModel* tab_model) {
auto& tab_models = tab_model_list_.Get().models_;

TabModelList::iterator remove_tab_model =
std::find(tab_models.begin(), tab_models.end(), tab_model);
base::ranges::find(tab_models, tab_model);

if (remove_tab_model != tab_models.end())
tab_models.erase(remove_tab_model);
Expand Down
8 changes: 3 additions & 5 deletions chrome/browser/ui/app_list/arc/arc_app_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <map>
#include <memory>
#include <string>
Expand All @@ -29,6 +28,7 @@
#include "base/files/file_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/task/task_runner_util.h"
Expand Down Expand Up @@ -683,8 +683,7 @@ class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase,
// Process requested apps.
for (auto& app : apps) {
const std::string id = ArcAppTest::GetAppId(*app);
std::vector<std::string>::iterator it_id =
std::find(ids.begin(), ids.end(), id);
std::vector<std::string>::iterator it_id = base::ranges::find(ids, id);
ASSERT_NE(it_id, ids.end());
ids.erase(it_id);

Expand Down Expand Up @@ -713,8 +712,7 @@ class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase,
// Process requested apps.
for (auto& shortcut : shortcuts) {
const std::string id = ArcAppTest::GetAppId(shortcut);
std::vector<std::string>::iterator it_id =
std::find(ids.begin(), ids.end(), id);
std::vector<std::string>::iterator it_id = base::ranges::find(ids, id);
ASSERT_NE(it_id, ids.end());
ids.erase(it_id);

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

#include "chrome/browser/ui/app_list/chrome_app_list_item_manager.h"

#include "base/ranges/algorithm.h"
#include "chrome/browser/ui/app_list/chrome_app_list_item.h"

ChromeAppListItemManager::ChromeAppListItemManager() = default;
Expand Down Expand Up @@ -170,8 +171,8 @@ void ChromeAppListItemManager::RemoveChildFromFolderItemMapping(
std::vector<ChromeAppListItem*>* sorted_children_ptr =
&folder_item_mappings_iter->second;

auto children_array_iter = std::find(sorted_children_ptr->cbegin(),
sorted_children_ptr->cend(), child_item);
auto children_array_iter =
base::ranges::find(*sorted_children_ptr, child_item);
DCHECK(children_array_iter != sorted_children_ptr->cend());

// Delete `child_item` from `src_folder`'s children list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ash/public/cpp/window_properties.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/ash/arc/arc_util.h"
Expand Down Expand Up @@ -389,8 +390,7 @@ void AppServiceAppWindowShelfController::OnInstanceUpdate(
// then removed. Since it is not registered we don't need to do anything
// anyways. As such, all which is left to do here is to get rid of our own
// reference.
WindowList::iterator it =
std::find(window_list_.begin(), window_list_.end(), update.Window());
WindowList::iterator it = base::ranges::find(window_list_, update.Window());
if (it != window_list_.end())
window_list_.erase(it);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#include <stddef.h>

#include <algorithm>
#include <memory>
#include <utility>

#include "base/callback_helpers.h"
#include "base/containers/contains.h"
#include "base/memory/ptr_util.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
Expand Down Expand Up @@ -103,7 +103,7 @@ absl::optional<ash::ShelfAction> AdvanceApp(
size_t index = 0;
if (active_item) {
DCHECK(base::Contains(items, active_item));
auto it = std::find(items.cbegin(), items.cend(), active_item);
auto it = base::ranges::find(items, active_item);
index = (it - items.cbegin() + 1) % items.size();
}
std::move(activate_callback).Run(items[index]);
Expand Down Expand Up @@ -424,8 +424,7 @@ void AppShortcutShelfItemController::OnBrowserClosing(Browser* browser) {
if (!app_menu_cached_by_browsers_)
return;
// Reset pointers to the closed browser, but leave menu indices intact.
auto it =
std::find(app_menu_browsers_.begin(), app_menu_browsers_.end(), browser);
auto it = base::ranges::find(app_menu_browsers_, browser);
if (it != app_menu_browsers_.end())
*it = nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ash/wm/desks/desks_util.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ash/app_restore/full_restore_service.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -297,8 +298,7 @@ BrowserShortcutShelfItemController::ActivateOrAdvanceToNextBrowser() {
// If there is more than one suitable browser, we advance to the next if
// |browser| is already active - or - check the last used browser if it can
// be used.
std::vector<Browser*>::iterator i =
std::find(items.begin(), items.end(), browser);
std::vector<Browser*>::iterator i = base::ranges::find(items, browser);
if (i != items.end()) {
if (browser->window()->IsActive())
browser = (++i == items.end()) ? items[0] : *i;
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/ash/shelf/chrome_shelf_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "chrome/browser/ui/ash/shelf/chrome_shelf_controller.h"

#include <algorithm>
#include <memory>
#include <set>
#include <utility>
Expand All @@ -27,6 +26,7 @@
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/pattern.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -192,8 +192,7 @@ void ChromeShelfControllerUserSwitchObserver::OnUserProfileReadyToSwitch(
std::string user_id =
multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail();
std::set<std::string>::iterator it =
std::find(added_user_ids_waiting_for_profiles_.begin(),
added_user_ids_waiting_for_profiles_.end(), user_id);
base::ranges::find(added_user_ids_waiting_for_profiles_, user_id);
if (it != added_user_ids_waiting_for_profiles_.end()) {
added_user_ids_waiting_for_profiles_.erase(it);
AddUser(profile->GetOriginalProfile());
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/ui/ash/shelf/chrome_shelf_prefs_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "base/containers/contains.h"
#include "base/ranges/algorithm.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
Expand Down Expand Up @@ -290,8 +291,8 @@ TEST_F(ChromeShelfPrefsTest, TransformationForStandaloneBrowserChromeApps) {

// The three items should come in order. Other items might be added by
// migration. That's OK.
auto it = std::find(pinned_apps_strs.begin(), pinned_apps_strs.end(),
kAshChromeAppIdWithUsualPrefix);
auto it =
base::ranges::find(pinned_apps_strs, kAshChromeAppIdWithUsualPrefix);
size_t index = it - pinned_apps_strs.begin();

ASSERT_EQ(pinned_apps_strs[index + 1], kLacrosChromeAppIdWithUsualPrefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/ui/ash/wallpaper_controller_client_impl.h"

#include "ash/webui/personalization_app/mojom/personalization_app.mojom.h"
#include "base/containers/contains.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
Expand Down Expand Up @@ -103,8 +104,7 @@ TEST_F(WallpaperControllerClientImplTest, DailyGooglePhotosDoNotRepeat) {
auto handle_photo = [&last_ten](GooglePhotosPhotoPtr photo, bool success) {
ASSERT_TRUE(success);

auto it = std::find(last_ten.begin(), last_ten.end(), photo->id);
EXPECT_TRUE(it == last_ten.end());
EXPECT_FALSE(base::Contains(last_ten, photo->id));

last_ten.push_back(photo->id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/metrics/user_metrics.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "chrome/grit/generated_resources.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
Expand Down Expand Up @@ -125,8 +126,7 @@ absl::optional<size_t> RecentlyUsedFoldersComboModel::GetDefaultIndex() const {
// that we don't remove `parent_node_`.
// TODO(pbos): Look at returning -1 here if there's no default index. Right
// now a lot of code in Combobox assumes an index within `items_` bounds.
auto it = std::find(items_.begin(), items_.end(),
Item(parent_node_, Item::TYPE_NODE));
auto it = base::ranges::find(items_, Item(parent_node_, Item::TYPE_NODE));
return it == items_.end() ? 0 : static_cast<int>(it - items_.begin());
}

Expand Down Expand Up @@ -233,8 +233,7 @@ const BookmarkNode* RecentlyUsedFoldersComboModel::GetNodeAt(size_t index) {
}

void RecentlyUsedFoldersComboModel::RemoveNode(const BookmarkNode* node) {
auto it =
std::find(items_.begin(), items_.end(), Item(node, Item::TYPE_NODE));
auto it = base::ranges::find(items_, Item(node, Item::TYPE_NODE));
if (it != items_.end())
items_.erase(it);
}
5 changes: 2 additions & 3 deletions chrome/browser/ui/browser_finder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include <stdint.h>

#include <algorithm>

#include "base/ranges/algorithm.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -241,7 +240,7 @@ Browser* FindBrowserWithActiveWindow() {
Browser* FindBrowserWithWebContents(const WebContents* web_contents) {
DCHECK(web_contents);
auto& all_tabs = AllTabContentses();
auto it = std::find(all_tabs.begin(), all_tabs.end(), web_contents);
auto it = base::ranges::find(all_tabs, web_contents);

return (it == all_tabs.end()) ? nullptr : it.browser();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/extensions/scripting_permissions_modifier.h"
#include "chrome/browser/extensions/site_permissions_helper.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ size_t ExtensionSiteAccessComboboxModel::GetCurrentSiteAccessIndex() const {
extensions::SitePermissionsHelper::SiteAccess current_access =
extensions::SitePermissionsHelper(browser_->profile())
.GetSiteAccess(*extension_, web_contents->GetLastCommittedURL());
auto item_it = std::find(items_.begin(), items_.end(), current_access);
auto item_it = base::ranges::find(items_, current_access);
DCHECK(item_it != items_.end());

return static_cast<size_t>(item_it - items_.begin());
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/global_error/global_error_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

#include <stddef.h>

#include <algorithm>

#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_bubble_view_base.h"
Expand Down Expand Up @@ -48,7 +47,7 @@ std::unique_ptr<GlobalError> GlobalErrorService::RemoveGlobalError(

void GlobalErrorService::RemoveUnownedGlobalError(GlobalError* error) {
DCHECK(owned_errors_.find(error) == owned_errors_.end());
all_errors_.erase(std::find(all_errors_.begin(), all_errors_.end(), error));
all_errors_.erase(base::ranges::find(all_errors_, error));
GlobalErrorBubbleViewBase* bubble = error->GetBubbleView();
if (bubble)
bubble->CloseBubbleView();
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/hung_renderer/hung_renderer_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#include "chrome/browser/ui/hung_renderer/hung_renderer_core.h"

#include <algorithm>

#include "base/i18n/rtl.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
Expand Down Expand Up @@ -86,7 +85,7 @@ std::vector<content::WebContents*> GetHungWebContentsList(
// Move |hung_web_contents| to the front. It might be missing from the
// initial |results| when it hasn't yet committed a navigation into the hung
// process.
auto first = std::find(result.begin(), result.end(), hung_web_contents);
auto first = base::ranges::find(result, hung_web_contents);
if (first != result.end())
std::rotate(result.begin(), first, std::next(first));
else
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ui/login/login_handler_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/ui/login/login_handler_test_utils.h"

#include "base/containers/contains.h"
#include "base/ranges/algorithm.h"
#include "chrome/browser/ui/login/login_handler.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -39,7 +40,7 @@ void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) {
}

void LoginPromptBrowserTestObserver::RemoveHandler(LoginHandler* handler) {
auto i = std::find(handlers_.begin(), handlers_.end(), handler);
auto i = base::ranges::find(handlers_, handler);
// Cannot use ASSERT_NE, because gTest on Android confuses iterators with
// containers.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/ui/media_router/media_route_starter.h"

#include "base/json/json_reader.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "chrome/browser/media/router/chrome_media_router_factory.h"
#include "chrome/browser/media/router/test/provider_test_helpers.h"
Expand Down Expand Up @@ -185,8 +186,7 @@ class MediaRouteStarterTest : public ChromeRenderViewHostTestHarness {
// this to occur).
ON_CALL(*media_router(), UnregisterMediaSinksObserver(_))
.WillByDefault([this](MediaSinksObserver* observer) {
auto it = std::find(media_sinks_observers_.begin(),
media_sinks_observers_.end(), observer);
auto it = base::ranges::find(media_sinks_observers_, observer);
if (it != media_sinks_observers_.end()) {
media_sinks_observers_.erase(it);
}
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/tabs/tab_strip_model_stats_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include "chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h"

#include <algorithm>
#include <utility>

#include "base/check.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/supports_user_data.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
Expand Down Expand Up @@ -115,8 +115,7 @@ void TabStripModelStatsRecorder::OnActiveTabChanged(
// A UMA Histogram must be bounded by some number.
// We chose 64 as our bound as 99.5% of the users open <64 tabs.
const int kMaxTabHistory = 64;
auto it = std::find(active_tab_history_.cbegin(), active_tab_history_.cend(),
new_contents);
auto it = base::ranges::find(active_tab_history_, new_contents);
int age = (it != active_tab_history_.cend()) ?
(it - active_tab_history_.cbegin()) : (kMaxTabHistory - 1);
if (was_inactive) {
Expand Down

0 comments on commit dbb1c29

Please sign in to comment.