Skip to content

Commit

Permalink
[clang-tidy] Apply modernize-use-auto in /ui
Browse files Browse the repository at this point in the history
This change applies clang-tidy's modernize-use-auto [1] in /ui.
This change does not rewrite new and cast expressions.

Reproduction steps:
- run clang-tidy's modernize-use-auto
- run git cl format
- manually remove unused typedefs due to -Wunused-local-typedef error

[1] https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-auto.html

This CL was uploaded by git cl split.

R=sadrul@chromium.org

Bug: 890902
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I0eb0b9aa6d22bb039c9c2510dd1ad4f814f66aa7
Reviewed-on: https://chromium-review.googlesource.com/c/1257854
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598284}
  • Loading branch information
jdoerrie authored and Commit Bot committed Oct 10, 2018
1 parent f935aff commit dcef4b1
Show file tree
Hide file tree
Showing 77 changed files with 190 additions and 281 deletions.
3 changes: 1 addition & 2 deletions ui/aura/mus/os_exchange_data_provider_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ void OSExchangeDataProviderMus::SetFilename(const base::FilePath& path) {
void OSExchangeDataProviderMus::SetFilenames(
const std::vector<ui::FileInfo>& file_names) {
std::vector<std::string> paths;
for (std::vector<ui::FileInfo>::const_iterator it = file_names.begin();
it != file_names.end(); ++it) {
for (auto it = file_names.begin(); it != file_names.end(); ++it) {
std::string url_spec = net::FilePathToFileURL(it->path).spec();
if (!url_spec.empty())
paths.push_back(url_spec);
Expand Down
4 changes: 2 additions & 2 deletions ui/aura/test/test_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ bool LayerIsAbove(Window* upper, Window* lower) {

std::string ChildWindowIDsAsString(aura::Window* parent) {
std::string result;
for (Window::Windows::const_iterator i = parent->children().begin();
i != parent->children().end(); ++i) {
for (auto i = parent->children().begin(); i != parent->children().end();
++i) {
if (!result.empty())
result += " ";
result += base::IntToString((*i)->id());
Expand Down
6 changes: 2 additions & 4 deletions ui/aura/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ void Window::RemoveChildImpl(Window* child, Window* new_parent) {
if (child->OwnsLayer())
layer()->Remove(child->layer());
child->parent_ = NULL;
Windows::iterator i = std::find(children_.begin(), children_.end(), child);
auto i = std::find(children_.begin(), children_.end(), child);
DCHECK(i != children_.end());
children_.erase(i);
child->OnParentChanged();
Expand Down Expand Up @@ -1078,9 +1078,7 @@ bool Window::CleanupGestureState() {
bool state_modified = false;
state_modified |= env_->gesture_recognizer()->CancelActiveTouches(this);
state_modified |= env_->gesture_recognizer()->CleanupStateForConsumer(this);
for (Window::Windows::iterator iter = children_.begin();
iter != children_.end();
++iter) {
for (auto iter = children_.begin(); iter != children_.end(); ++iter) {
state_modified |= (*iter)->CleanupGestureState();
}
return state_modified;
Expand Down
16 changes: 7 additions & 9 deletions ui/base/accelerators/accelerator_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void AcceleratorManager::Register(

void AcceleratorManager::Unregister(const Accelerator& accelerator,
AcceleratorTarget* target) {
AcceleratorMap::iterator map_iter = accelerators_.find(accelerator);
auto map_iter = accelerators_.find(accelerator);
if (map_iter == accelerators_.end()) {
NOTREACHED() << "Unregistering non-existing accelerator";
return;
Expand All @@ -58,7 +58,7 @@ void AcceleratorManager::Unregister(const Accelerator& accelerator,
}

void AcceleratorManager::UnregisterAll(AcceleratorTarget* target) {
for (AcceleratorMap::iterator map_iter = accelerators_.begin();
for (auto map_iter = accelerators_.begin();
map_iter != accelerators_.end();) {
AcceleratorTargetList* targets = &map_iter->second.second;
if (!base::ContainsValue(*targets, target)) {
Expand All @@ -72,20 +72,19 @@ void AcceleratorManager::UnregisterAll(AcceleratorTarget* target) {
}

bool AcceleratorManager::IsRegistered(const Accelerator& accelerator) const {
AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator);
auto map_iter = accelerators_.find(accelerator);
return map_iter != accelerators_.end() && !map_iter->second.second.empty();
}

bool AcceleratorManager::Process(const Accelerator& accelerator) {
AcceleratorMap::iterator map_iter = accelerators_.find(accelerator);
auto map_iter = accelerators_.find(accelerator);
if (map_iter == accelerators_.end())
return false;

// We have to copy the target list here, because an AcceleratorPressed
// event handler may modify the list.
AcceleratorTargetList targets(map_iter->second.second);
for (AcceleratorTargetList::iterator iter = targets.begin();
iter != targets.end(); ++iter) {
for (auto iter = targets.begin(); iter != targets.end(); ++iter) {
if ((*iter)->CanHandleAccelerators() &&
(*iter)->AcceleratorPressed(accelerator)) {
return true;
Expand All @@ -97,7 +96,7 @@ bool AcceleratorManager::Process(const Accelerator& accelerator) {

bool AcceleratorManager::HasPriorityHandler(
const Accelerator& accelerator) const {
AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator);
auto map_iter = accelerators_.find(accelerator);
if (map_iter == accelerators_.end() || map_iter->second.second.empty())
return false;

Expand All @@ -113,8 +112,7 @@ bool AcceleratorManager::HasPriorityHandler(
void AcceleratorManager::UnregisterImpl(AcceleratorMap::iterator map_iter,
AcceleratorTarget* target) {
AcceleratorTargetList* targets = &map_iter->second.second;
AcceleratorTargetList::iterator target_iter =
std::find(targets->begin(), targets->end(), target);
auto target_iter = std::find(targets->begin(), targets->end(), target);
if (target_iter == targets->end()) {
NOTREACHED() << "Unregistering accelerator for wrong target";
return;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/class_property.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void PropertyHandler::ClearProperties() {

int64_t PropertyHandler::GetPropertyInternal(const void* key,
int64_t default_value) const {
std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
auto iter = prop_map_.find(key);
if (iter == prop_map_.end())
return default_value;
return iter->second.value;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/clipboard/clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void Clipboard::DestroyClipboardForCurrentThread() {

ClipboardMap* clipboard_map = clipboard_map_.Pointer();
base::PlatformThreadId id = base::PlatformThread::CurrentId();
ClipboardMap::iterator it = clipboard_map->find(id);
auto it = clipboard_map->find(id);
if (it != clipboard_map->end())
clipboard_map->erase(it);
}
Expand Down
13 changes: 5 additions & 8 deletions ui/base/clipboard/clipboard_aurax11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,8 @@ SelectionData ClipboardAuraX11::AuraX11Details::RequestAndWaitForTypes(
// with the X server.
const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name);

for (std::vector< ::Atom>::const_iterator it = types.begin();
it != types.end(); ++it) {
SelectionFormatMap::const_iterator format_map_it = format_map.find(*it);
for (auto it = types.begin(); it != types.end(); ++it) {
auto format_map_it = format_map.find(*it);
if (format_map_it != format_map.end())
return SelectionData(format_map_it->first, format_map_it->second);
}
Expand All @@ -406,8 +405,7 @@ TargetList ClipboardAuraX11::AuraX11Details::WaitAndGetTargetsList(
// We can local fastpath and return the list of local targets.
const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name);

for (SelectionFormatMap::const_iterator it = format_map.begin();
it != format_map.end(); ++it) {
for (auto it = format_map.begin(); it != format_map.end(); ++it) {
out.push_back(it->first);
}
} else {
Expand Down Expand Up @@ -814,14 +812,13 @@ void ClipboardAuraX11::WriteObjects(ClipboardType type,
DCHECK(IsSupportedClipboardType(type));

aurax11_details_->CreateNewClipboardData();
for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end();
++iter) {
for (auto iter = objects.begin(); iter != objects.end(); ++iter) {
DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
}
aurax11_details_->TakeOwnershipOfSelection(type);

if (type == CLIPBOARD_TYPE_COPY_PASTE) {
ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT);
auto text_iter = objects.find(CBF_TEXT);
if (text_iter != objects.end()) {
aurax11_details_->CreateNewClipboardData();
const ObjectMapParams& params_vector = text_iter->second;
Expand Down
4 changes: 1 addition & 3 deletions ui/base/dragdrop/os_exchange_data_provider_aurax11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) {
void OSExchangeDataProviderAuraX11::SetFilenames(
const std::vector<FileInfo>& filenames) {
std::vector<std::string> paths;
for (std::vector<FileInfo>::const_iterator it = filenames.begin();
it != filenames.end();
++it) {
for (auto it = filenames.begin(); it != filenames.end(); ++it) {
std::string url_spec = net::FilePathToFileURL(it->path).spec();
if (!url_spec.empty())
paths.push_back(url_spec);
Expand Down
9 changes: 3 additions & 6 deletions ui/base/models/list_selection_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ bool ListSelectionModel::operator!=(const ListSelectionModel& other) const {

void ListSelectionModel::IncrementFrom(int index) {
// Shift the selection to account for a newly inserted item at |index|.
for (SelectedIndices::iterator i = selected_indices_.begin();
i != selected_indices_.end(); ++i) {
for (auto i = selected_indices_.begin(); i != selected_indices_.end(); ++i) {
IncrementFromImpl(index, &(*i));
}
IncrementFromImpl(index, &anchor_);
IncrementFromImpl(index, &active_);
}

void ListSelectionModel::DecrementFrom(int index) {
for (SelectedIndices::iterator i = selected_indices_.begin();
i != selected_indices_.end(); ) {
for (auto i = selected_indices_.begin(); i != selected_indices_.end();) {
if (DecrementFromImpl(index, &(*i)))
i = selected_indices_.erase(i);
else
Expand Down Expand Up @@ -115,8 +113,7 @@ void ListSelectionModel::AddIndexToSelection(int index) {
}

void ListSelectionModel::RemoveIndexFromSelection(int index) {
SelectedIndices::iterator i = std::find(selected_indices_.begin(),
selected_indices_.end(), index);
auto i = std::find(selected_indices_.begin(), selected_indices_.end(), index);
if (i != selected_indices_.end())
selected_indices_.erase(i);
}
Expand Down
4 changes: 2 additions & 2 deletions ui/base/models/simple_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void SimpleMenuModel::Clear() {
}

int SimpleMenuModel::GetIndexOfCommandId(int command_id) const {
for (ItemVector::const_iterator i = items_.begin(); i != items_.end(); ++i) {
for (auto i = items_.begin(); i != items_.end(); ++i) {
if (i->command_id == command_id)
return static_cast<int>(std::distance(items_.begin(), i));
}
Expand All @@ -306,7 +306,7 @@ int SimpleMenuModel::GetIndexOfCommandId(int command_id) const {
// SimpleMenuModel, MenuModel implementation:

bool SimpleMenuModel::HasIcons() const {
for (ItemVector::const_iterator i = items_.begin(); i != items_.end(); ++i) {
for (auto i = items_.begin(); i != items_.end(); ++i) {
if (!i->icon.IsEmpty())
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions ui/base/resource/resource_bundle_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ void AddCustomChunk(const base::StringPiece& custom_chunk,
bitmap_data->begin(),
bitmap_data->begin() + arraysize(kPngMagic),
kPngMagic));
std::vector<unsigned char>::iterator ihdr_start =
bitmap_data->begin() + arraysize(kPngMagic);
auto ihdr_start = bitmap_data->begin() + arraysize(kPngMagic);
char ihdr_length_data[sizeof(uint32_t)];
for (size_t i = 0; i < sizeof(uint32_t); ++i)
ihdr_length_data[i] = *(ihdr_start + i);
Expand Down
2 changes: 1 addition & 1 deletion ui/base/template_expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ std::string ReplaceTemplateExpressions(
source.substr(current_pos, key_end - current_pos).as_string();
CHECK(!key.empty());

TemplateReplacements::const_iterator value = replacements.find(key);
auto value = replacements.find(key);
CHECK(value != replacements.end()) << "$i18n replacement key \"" << key
<< "\" not found";

Expand Down
4 changes: 2 additions & 2 deletions ui/base/view_prop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ViewProp::Data : public base::RefCounted<ViewProp::Data> {
if (!data_set_)
data_set_ = new DataSet;
scoped_refptr<Data> new_data(new Data(view, key));
DataSet::const_iterator i = data_set_->find(new_data.get());
auto i = data_set_->find(new_data.get());
if (i != data_set_->end()) {
*data = *i;
return;
Expand Down Expand Up @@ -58,7 +58,7 @@ class ViewProp::Data : public base::RefCounted<ViewProp::Data> {
data_(NULL) {}

~Data() {
DataSet::iterator i = data_set_->find(this);
auto i = data_set_->find(this);
// Also check for equality using == as |Get| creates dummy values in order
// to look up a value.
if (i != data_set_->end() && *i == this)
Expand Down
14 changes: 5 additions & 9 deletions ui/base/x/selection_owner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ SelectionOwner::~SelectionOwner() {
}

void SelectionOwner::RetrieveTargets(std::vector<XAtom>* targets) {
for (SelectionFormatMap::const_iterator it = format_map_.begin();
it != format_map_.end(); ++it) {
for (auto it = format_map_.begin(); it != format_map_.end(); ++it) {
targets->push_back(it->first);
}
}
Expand Down Expand Up @@ -187,8 +186,7 @@ bool SelectionOwner::CanDispatchPropertyEvent(const XEvent& event) {
}

void SelectionOwner::OnPropertyEvent(const XEvent& event) {
std::vector<IncrementalTransfer>::iterator it =
FindIncrementalTransferForEvent(event);
auto it = FindIncrementalTransferForEvent(event);
if (it == incremental_transfers_.end())
return;

Expand Down Expand Up @@ -233,7 +231,7 @@ bool SelectionOwner::ProcessTarget(XAtom target,
}

// Try to find the data type in map.
SelectionFormatMap::const_iterator it = format_map_.find(target);
auto it = format_map_.find(target);
if (it != format_map_.end()) {
if (it->second->size() > max_request_size_) {
// We must send the data back in several chunks due to a limitation in
Expand Down Expand Up @@ -326,10 +324,8 @@ void SelectionOwner::CompleteIncrementalTransfer(

std::vector<SelectionOwner::IncrementalTransfer>::iterator
SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) {
for (std::vector<IncrementalTransfer>::iterator it =
incremental_transfers_.begin();
it != incremental_transfers_.end();
++it) {
for (auto it = incremental_transfers_.begin();
it != incremental_transfers_.end(); ++it) {
if (it->window == event.xproperty.window &&
it->property == event.xproperty.atom) {
return it;
Expand Down
6 changes: 2 additions & 4 deletions ui/base/x/selection_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ bool SelectionRequestor::PerformBlockingConvertSelection(
ConvertSelectionForCurrentRequest();
BlockTillSelectionNotifyForRequest(&request);

std::vector<Request*>::iterator request_it = std::find(
requests_.begin(), requests_.end(), &request);
auto request_it = std::find(requests_.begin(), requests_.end(), &request);
CHECK(request_it != requests_.end());
if (static_cast<int>(current_request_index_) >
request_it - requests_.begin()) {
Expand Down Expand Up @@ -116,8 +115,7 @@ void SelectionRequestor::PerformBlockingConvertSelectionWithParameter(
SelectionData SelectionRequestor::RequestAndWaitForTypes(
XAtom selection,
const std::vector<XAtom>& types) {
for (std::vector<XAtom>::const_iterator it = types.begin();
it != types.end(); ++it) {
for (auto it = types.begin(); it != types.end(); ++it) {
scoped_refptr<base::RefCountedMemory> data;
XAtom type = x11::None;
if (PerformBlockingConvertSelection(selection,
Expand Down
10 changes: 4 additions & 6 deletions ui/base/x/selection_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ std::vector<::Atom> GetURIListAtomsFrom() {
void GetAtomIntersection(const std::vector< ::Atom>& desired,
const std::vector< ::Atom>& offered,
std::vector< ::Atom>* output) {
for (std::vector< ::Atom>::const_iterator it = desired.begin();
it != desired.end(); ++it) {
for (auto it = desired.begin(); it != desired.end(); ++it) {
if (base::ContainsValue(offered, *it))
output->push_back(*it);
}
Expand Down Expand Up @@ -121,9 +120,8 @@ void SelectionFormatMap::Insert(

ui::SelectionData SelectionFormatMap::GetFirstOf(
const std::vector< ::Atom>& requested_types) const {
for (std::vector< ::Atom>::const_iterator it = requested_types.begin();
it != requested_types.end(); ++it) {
const_iterator data_it = data_.find(*it);
for (auto it = requested_types.begin(); it != requested_types.end(); ++it) {
auto data_it = data_.find(*it);
if (data_it != data_.end()) {
return SelectionData(data_it->first, data_it->second);
}
Expand All @@ -134,7 +132,7 @@ ui::SelectionData SelectionFormatMap::GetFirstOf(

std::vector< ::Atom> SelectionFormatMap::GetTypes() const {
std::vector< ::Atom> atoms;
for (const_iterator it = data_.begin(); it != data_.end(); ++it)
for (auto it = data_.begin(); it != data_.end(); ++it)
atoms.push_back(it->first);

return atoms;
Expand Down
3 changes: 1 addition & 2 deletions ui/base/x/x11_menu_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ void XMenuList::MaybeRegisterMenu(XID menu) {
}

void XMenuList::MaybeUnregisterMenu(XID menu) {
std::vector<XID>::iterator iter = std::find(menus_.begin(), menus_.end(),
menu);
auto iter = std::find(menus_.begin(), menus_.end(), menu);
if (iter == menus_.end())
return;
menus_.erase(iter);
Expand Down
3 changes: 1 addition & 2 deletions ui/compositor/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ void Layer::Remove(Layer* child) {
if (compositor)
child->ResetCompositorForAnimatorsInTree(compositor);

std::vector<Layer*>::iterator i =
std::find(children_.begin(), children_.end(), child);
auto i = std::find(children_.begin(), children_.end(), child);
DCHECK(i != children_.end());
children_.erase(i);
child->parent_ = nullptr;
Expand Down
3 changes: 1 addition & 2 deletions ui/compositor/layer_animation_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ void ImplicitAnimationObserver::UpdatePropertyAnimationStatus(
ImplicitAnimationObserver::AnimationStatus
ImplicitAnimationObserver::AnimationStatusForProperty(
LayerAnimationElement::AnimatableProperty property) const {
PropertyAnimationStatusMap::const_iterator iter =
property_animation_status_.find(property);
auto iter = property_animation_status_.find(property);
return iter == property_animation_status_.end() ? ANIMATION_STATUS_UNKNOWN :
iter->second;
}
Expand Down
Loading

0 comments on commit dcef4b1

Please sign in to comment.