Commit ecf1979e authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

Drag and Drop: use range-based for loops in other clipboard and drag-and-drop code

Bug: 896479
Change-Id: Iff647d3091677341f027d275884538583a56e965
Reviewed-on: https://chromium-review.googlesource.com/c/1287187Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Darwin Huang <huangdarwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601677}
parent 94e4c7f3
......@@ -497,10 +497,8 @@ void ClipboardAndroid::WriteObjects(ClipboardType type,
DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE);
g_map.Get().Clear();
for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end();
++iter) {
DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
}
for (const auto& object : objects)
DispatchObject(static_cast<ObjectType>(object.first), object.second);
g_map.Get().CommitToAndroidClipboard();
}
......
......@@ -657,10 +657,8 @@ void ClipboardAura::ReadData(const FormatType& format,
void ClipboardAura::WriteObjects(ClipboardType type, const ObjectMap& objects) {
DCHECK(CalledOnValidThread());
DCHECK(IsSupportedClipboardType(type));
for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end();
++iter) {
DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
}
for (const auto& object : objects)
DispatchObject(static_cast<ObjectType>(object.first), object.second);
ClipboardDataBuilder::CommitToClipboard();
}
......
......@@ -147,9 +147,8 @@ TargetList::TargetList(const AtomVector& target_list)
bool TargetList::ContainsText() const {
std::vector<::Atom> atoms = GetTextAtomsFrom();
for (std::vector< ::Atom>::const_iterator it = atoms.begin();
it != atoms.end(); ++it) {
if (ContainsAtom(*it))
for (const auto& atom : atoms) {
if (ContainsAtom(atom))
return true;
}
......@@ -379,8 +378,8 @@ SelectionData ClipboardAuraX11::AuraX11Details::RequestAndWaitForTypes(
// with the X server.
const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name);
for (auto it = types.begin(); it != types.end(); ++it) {
auto format_map_it = format_map.find(*it);
for (const auto& type : types) {
auto format_map_it = format_map.find(type);
if (format_map_it != format_map.end())
return SelectionData(format_map_it->first, format_map_it->second);
}
......@@ -405,9 +404,8 @@ TargetList ClipboardAuraX11::AuraX11Details::WaitAndGetTargetsList(
// We can local fastpath and return the list of local targets.
const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name);
for (auto it = format_map.begin(); it != format_map.end(); ++it) {
out.push_back(it->first);
}
for (const auto& format : format_map)
out.push_back(format.first);
} else {
scoped_refptr<base::RefCountedMemory> data;
size_t out_data_items = 0;
......@@ -431,16 +429,12 @@ TargetList ClipboardAuraX11::AuraX11Details::WaitAndGetTargetsList(
// copy the data to see if it is available, but at least this path
// shouldn't be hit for conforming programs.
std::vector< ::Atom> types = GetTextAtoms();
for (std::vector< ::Atom>::const_iterator it = types.begin();
it != types.end(); ++it) {
for (const auto& text_atom : types) {
::Atom type = x11::None;
if (selection_requestor_.PerformBlockingConvertSelection(selection_name,
*it,
NULL,
NULL,
&type) &&
type == *it) {
out.push_back(*it);
if (selection_requestor_.PerformBlockingConvertSelection(
selection_name, text_atom, NULL, NULL, &type) &&
type == text_atom) {
out.push_back(text_atom);
}
}
}
......@@ -812,9 +806,8 @@ void ClipboardAuraX11::WriteObjects(ClipboardType type,
DCHECK(IsSupportedClipboardType(type));
aurax11_details_->CreateNewClipboardData();
for (auto iter = objects.begin(); iter != objects.end(); ++iter) {
DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
}
for (const auto& object : objects)
DispatchObject(static_cast<ObjectType>(object.first), object.second);
aurax11_details_->TakeOwnershipOfSelection(type);
if (type == CLIPBOARD_TYPE_COPY_PASTE) {
......
......@@ -173,8 +173,8 @@ void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) {
void OSExchangeDataProviderAuraX11::SetFilenames(
const std::vector<FileInfo>& filenames) {
std::vector<std::string> paths;
for (auto it = filenames.begin(); it != filenames.end(); ++it) {
std::string url_spec = net::FilePathToFileURL(it->path).spec();
for (const auto& filename : filenames) {
std::string url_spec = net::FilePathToFileURL(filename.path).spec();
if (!url_spec.empty())
paths.push_back(url_spec);
}
......@@ -254,9 +254,8 @@ bool OSExchangeDataProviderAuraX11::GetURLAndTitle(
}
} else if (data.GetType() == gfx::GetAtom(Clipboard::kMimeTypeURIList)) {
std::vector<std::string> tokens = ui::ParseURIList(data);
for (std::vector<std::string>::const_iterator it = tokens.begin();
it != tokens.end(); ++it) {
GURL test_url(*it);
for (const std::string& token : tokens) {
GURL test_url(token);
if (!test_url.SchemeIsFile() ||
policy == OSExchangeData::CONVERT_FILENAMES) {
*url = test_url;
......@@ -290,9 +289,8 @@ bool OSExchangeDataProviderAuraX11::GetFilenames(
ui::SelectionData data(format_map_.GetFirstOf(requested_types));
if (data.IsValid()) {
std::vector<std::string> tokens = ui::ParseURIList(data);
for (std::vector<std::string>::const_iterator it = tokens.begin();
it != tokens.end(); ++it) {
GURL url(*it);
for (const std::string& token : tokens) {
GURL url(token);
base::FilePath file_path;
if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) {
filenames->push_back(FileInfo(file_path, base::FilePath()));
......@@ -347,9 +345,8 @@ bool OSExchangeDataProviderAuraX11::HasURL(
} else if (data.GetType() ==
gfx::GetAtom(ui::Clipboard::kMimeTypeURIList)) {
std::vector<std::string> tokens = ui::ParseURIList(data);
for (std::vector<std::string>::const_iterator it = tokens.begin();
it != tokens.end(); ++it) {
if (!GURL(*it).SchemeIsFile() ||
for (const std::string& token : tokens) {
if (!GURL(token).SchemeIsFile() ||
policy == OSExchangeData::CONVERT_FILENAMES)
return true;
}
......@@ -375,9 +372,8 @@ bool OSExchangeDataProviderAuraX11::HasFile() const {
ui::SelectionData data(format_map_.GetFirstOf(requested_types));
if (data.IsValid()) {
std::vector<std::string> tokens = ui::ParseURIList(data);
for (std::vector<std::string>::const_iterator it = tokens.begin();
it != tokens.end(); ++it) {
GURL url(*it);
for (const std::string& token : tokens) {
GURL url(token);
base::FilePath file_path;
if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path))
return true;
......
......@@ -451,9 +451,9 @@ bool OSExchangeDataProviderWin::GetFilenames(
bool success =
ClipboardUtil::GetFilenames(source_object_.Get(), &filenames_local);
if (success) {
for (size_t i = 0; i < filenames_local.size(); ++i)
for (const base::string16& filename_local : filenames_local)
filenames->push_back(
FileInfo(base::FilePath(filenames_local[i]), base::FilePath()));
FileInfo(base::FilePath(filename_local), base::FilePath()));
}
return success;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment