Modernize to C++11: Use for-range loop.

This commit is contained in:
Haojian Wu 2016-07-10 13:32:40 +02:00
parent 3bdeac98bf
commit 55b3f1936f
17 changed files with 66 additions and 71 deletions

View file

@ -241,10 +241,10 @@ void OnGetBackend(disk_cache::Backend** backend_ptr,
} else if (action == Session::CacheAction::STATS) { } else if (action == Session::CacheAction::STATS) {
base::StringPairs stats; base::StringPairs stats;
(*backend_ptr)->GetStats(&stats); (*backend_ptr)->GetStats(&stats);
for (size_t i = 0; i < stats.size(); ++i) { for (auto& stat : stats) {
if (stats[i].first == "Current size") { if (stat.first == "Current size") {
int current_size; int current_size;
base::StringToInt(stats[i].second, &current_size); base::StringToInt(stat.second, &current_size);
RunCallbackInUI(callback, current_size); RunCallbackInUI(callback, current_size);
break; break;
} }

View file

@ -685,10 +685,10 @@ void WebContents::TitleWasSet(content::NavigationEntry* entry,
void WebContents::DidUpdateFaviconURL( void WebContents::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& urls) { const std::vector<content::FaviconURL>& urls) {
std::set<GURL> unique_urls; std::set<GURL> unique_urls;
for (auto iter = urls.begin(); iter != urls.end(); ++iter) { for (const auto& iter : urls) {
if (iter->icon_type != content::FaviconURL::FAVICON) if (iter.icon_type != content::FaviconURL::FAVICON)
continue; continue;
const GURL& url = iter->icon_url; const GURL& url = iter.icon_url;
if (url.is_valid()) if (url.is_valid())
unique_urls.insert(url); unique_urls.insert(url);
} }

View file

@ -435,8 +435,8 @@ void CommonWebContentsDelegate::DevToolsRequestFileSystems() {
} }
base::ListValue file_system_value; base::ListValue file_system_value;
for (size_t i = 0; i < file_systems.size(); ++i) for (auto& file_system : file_systems)
file_system_value.Append(CreateFileSystemValue(file_systems[i])); file_system_value.Append(CreateFileSystemValue(file_system));
web_contents_->CallClientFunction("DevToolsAPI.fileSystemsLoaded", web_contents_->CallClientFunction("DevToolsAPI.fileSystemsLoaded",
&file_system_value, nullptr, nullptr); &file_system_value, nullptr, nullptr);
} }
@ -610,8 +610,8 @@ void CommonWebContentsDelegate::OnDevToolsSearchCompleted(
const std::string& file_system_path, const std::string& file_system_path,
const std::vector<std::string>& file_paths) { const std::vector<std::string>& file_paths) {
base::ListValue file_paths_value; base::ListValue file_paths_value;
for (auto it(file_paths.begin()); it != file_paths.end(); ++it) { for (const auto& file_path : file_paths) {
file_paths_value.AppendString(*it); file_paths_value.AppendString(file_path);
} }
base::FundamentalValue request_id_value(request_id); base::FundamentalValue request_id_value(request_id);
base::StringValue file_system_path_value(file_system_path); base::StringValue file_system_path_value(file_system_path);

View file

@ -30,9 +30,9 @@ bool StringToAccelerator(const std::string& shortcut,
// Now, parse it into an accelerator. // Now, parse it into an accelerator.
int modifiers = ui::EF_NONE; int modifiers = ui::EF_NONE;
ui::KeyboardCode key = ui::VKEY_UNKNOWN; ui::KeyboardCode key = ui::VKEY_UNKNOWN;
for (size_t i = 0; i < tokens.size(); i++) { for (auto& token : tokens) {
bool shifted = false; bool shifted = false;
ui::KeyboardCode code = atom::KeyboardCodeFromStr(tokens[i], &shifted); ui::KeyboardCode code = atom::KeyboardCodeFromStr(token, &shifted);
if (shifted) if (shifted)
modifiers |= ui::EF_SHIFT_DOWN; modifiers |= ui::EF_SHIFT_DOWN;
switch (code) { switch (code) {

View file

@ -70,8 +70,8 @@ void WindowList::RemoveObserver(WindowListObserver* observer) {
// static // static
void WindowList::CloseAllWindows() { void WindowList::CloseAllWindows() {
WindowVector windows = GetInstance()->windows_; WindowVector windows = GetInstance()->windows_;
for (size_t i = 0; i < windows.size(); ++i) for (auto& window : windows)
windows[i]->Close(); window->Close();
} }
WindowList::WindowList() { WindowList::WindowList() {

View file

@ -63,10 +63,10 @@ float GetScaleFactorFromPath(const base::FilePath& path) {
// We don't try to convert string to float here because it is very very // We don't try to convert string to float here because it is very very
// expensive. // expensive.
for (unsigned i = 0; i < node::arraysize(kScaleFactorPairs); ++i) { for (auto& kScaleFactorPair : kScaleFactorPairs) {
if (base::EndsWith(filename, kScaleFactorPairs[i].name, if (base::EndsWith(filename, kScaleFactorPair.name,
base::CompareCase::INSENSITIVE_ASCII)) base::CompareCase::INSENSITIVE_ASCII))
return kScaleFactorPairs[i].scale; return kScaleFactorPair.scale;
} }
return 1.0f; return 1.0f;

View file

@ -132,10 +132,10 @@ void AtomRenderViewObserver::DraggableRegionsChanged(blink::WebFrame* frame) {
blink::WebVector<blink::WebDraggableRegion> webregions = blink::WebVector<blink::WebDraggableRegion> webregions =
frame->document().draggableRegions(); frame->document().draggableRegions();
std::vector<DraggableRegion> regions; std::vector<DraggableRegion> regions;
for (size_t i = 0; i < webregions.size(); ++i) { for (auto& webregion : webregions) {
DraggableRegion region; DraggableRegion region;
region.bounds = webregions[i].bounds; region.bounds = webregion.bounds;
region.draggable = webregions[i].draggable; region.draggable = webregion.draggable;
regions.push_back(region); regions.push_back(region);
} }
Send(new AtomViewHostMsg_UpdateDraggableRegions(routing_id(), regions)); Send(new AtomViewHostMsg_UpdateDraggableRegions(routing_id(), regions));

View file

@ -87,16 +87,16 @@ void GlobalShortcutListener::SetShortcutHandlingSuspended(bool suspended) {
return; return;
shortcut_handling_suspended_ = suspended; shortcut_handling_suspended_ = suspended;
for (auto it = accelerator_map_.begin(); it != accelerator_map_.end(); ++it) { for (auto& it : accelerator_map_) {
// On Linux, when shortcut handling is suspended we cannot simply early // On Linux, when shortcut handling is suspended we cannot simply early
// return in NotifyKeyPressed (similar to what we do for non-global // return in NotifyKeyPressed (similar to what we do for non-global
// shortcuts) because we'd eat the keyboard event thereby preventing the // shortcuts) because we'd eat the keyboard event thereby preventing the
// user from setting the shortcut. Therefore we must unregister while // user from setting the shortcut. Therefore we must unregister while
// handling is suspended and register when handling resumes. // handling is suspended and register when handling resumes.
if (shortcut_handling_suspended_) if (shortcut_handling_suspended_)
UnregisterAcceleratorImpl(it->first); UnregisterAcceleratorImpl(it.first);
else else
RegisterAcceleratorImpl(it->first); RegisterAcceleratorImpl(it.first);
} }
} }

View file

@ -152,12 +152,12 @@ void NativeDesktopMediaList::Worker::Refresh(
if (window_capturer_) { if (window_capturer_) {
webrtc::WindowCapturer::WindowList windows; webrtc::WindowCapturer::WindowList windows;
if (window_capturer_->GetWindowList(&windows)) { if (window_capturer_->GetWindowList(&windows)) {
for (auto it = windows.begin(); it != windows.end(); ++it) { for (auto& window : windows) {
// Skip the picker dialog window. // Skip the picker dialog window.
if (it->id != view_dialog_id) { if (window.id != view_dialog_id) {
sources.push_back(SourceDescription( sources.push_back(SourceDescription(
DesktopMediaID(DesktopMediaID::TYPE_WINDOW, it->id), DesktopMediaID(DesktopMediaID::TYPE_WINDOW, window.id),
base::UTF8ToUTF16(it->title))); base::UTF8ToUTF16(window.title)));
} }
} }
} }
@ -296,8 +296,8 @@ void NativeDesktopMediaList::OnSourcesList(
const std::vector<SourceDescription>& new_sources) { const std::vector<SourceDescription>& new_sources) {
typedef std::set<content::DesktopMediaID> SourceSet; typedef std::set<content::DesktopMediaID> SourceSet;
SourceSet new_source_set; SourceSet new_source_set;
for (size_t i = 0; i < new_sources.size(); ++i) { for (const auto& new_source : new_sources) {
new_source_set.insert(new_sources[i].id); new_source_set.insert(new_source.id);
} }
// Iterate through the old sources to find the removed sources. // Iterate through the old sources to find the removed sources.
for (size_t i = 0; i < sources_.size(); ++i) { for (size_t i = 0; i < sources_.size(); ++i) {
@ -310,8 +310,8 @@ void NativeDesktopMediaList::OnSourcesList(
// Iterate through the new sources to find the added sources. // Iterate through the new sources to find the added sources.
if (new_sources.size() > sources_.size()) { if (new_sources.size() > sources_.size()) {
SourceSet old_source_set; SourceSet old_source_set;
for (size_t i = 0; i < sources_.size(); ++i) { for (auto& source : sources_) {
old_source_set.insert(sources_[i].id); old_source_set.insert(source.id);
} }
for (size_t i = 0; i < new_sources.size(); ++i) { for (size_t i = 0; i < new_sources.size(); ++i) {

View file

@ -61,9 +61,8 @@ void PrintQueriesQueue::Shutdown() {
// Stop all pending queries, requests to generate print preview do not have // Stop all pending queries, requests to generate print preview do not have
// corresponding PrintJob, so any pending preview requests are not covered // corresponding PrintJob, so any pending preview requests are not covered
// by PrintJobManager::StopJobs and should be stopped explicitly. // by PrintJobManager::StopJobs and should be stopped explicitly.
for (auto itr = queries_to_stop.begin(); itr != queries_to_stop.end(); for (auto& itr : queries_to_stop) {
++itr) { itr->PostTask(FROM_HERE, base::Bind(&PrinterQuery::StopWorker, itr));
(*itr)->PostTask(FROM_HERE, base::Bind(&PrinterQuery::StopWorker, *itr));
} }
} }
@ -99,11 +98,11 @@ void PrintJobManager::StopJobs(bool wait_for_finish) {
PrintJobs to_stop; PrintJobs to_stop;
to_stop.swap(current_jobs_); to_stop.swap(current_jobs_);
for (auto job = to_stop.begin(); job != to_stop.end(); ++job) { for (const auto& job : to_stop) {
// Wait for two minutes for the print job to be spooled. // Wait for two minutes for the print job to be spooled.
if (wait_for_finish) if (wait_for_finish)
(*job)->FlushJob(base::TimeDelta::FromMinutes(2)); job->FlushJob(base::TimeDelta::FromMinutes(2));
(*job)->Stop(); job->Stop();
} }
} }

View file

@ -820,9 +820,9 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout(
to_send.append(current_dir.value()); to_send.append(current_dir.value());
const std::vector<std::string>& argv = atom::AtomCommandLine::argv(); const std::vector<std::string>& argv = atom::AtomCommandLine::argv();
for (auto it = argv.begin(); it != argv.end(); ++it) { for (const auto& it : argv) {
to_send.push_back(kTokenDelimiter); to_send.push_back(kTokenDelimiter);
to_send.append(*it); to_send.append(it);
} }
// Send the message // Send the message

View file

@ -86,10 +86,10 @@ std::string ReadDataFromPickle(const base::string16& format,
bool WriteDataToPickle(const std::map<base::string16, std::string>& data, bool WriteDataToPickle(const std::map<base::string16, std::string>& data,
base::Pickle* pickle) { base::Pickle* pickle) {
pickle->WriteUInt32(data.size()); pickle->WriteUInt32(data.size());
for (auto it = data.begin(); it != data.end(); ++it) { for (const auto& it : data) {
if (!pickle->WriteString16(it->first)) if (!pickle->WriteString16(it.first))
return false; return false;
if (!pickle->WriteString(it->second)) if (!pickle->WriteString(it.second))
return false; return false;
} }
return true; return true;

View file

@ -43,16 +43,14 @@ void WidevineCdmMessageFilter::OnIsInternalPluginAvailableForMimeType(
std::vector<WebPluginInfo> plugins; std::vector<WebPluginInfo> plugins;
PluginService::GetInstance()->GetInternalPlugins(&plugins); PluginService::GetInstance()->GetInternalPlugins(&plugins);
for (size_t i = 0; i < plugins.size(); ++i) { for (auto& plugin : plugins) {
const WebPluginInfo& plugin = plugins[i];
const std::vector<content::WebPluginMimeType>& mime_types = const std::vector<content::WebPluginMimeType>& mime_types =
plugin.mime_types; plugin.mime_types;
for (size_t j = 0; j < mime_types.size(); ++j) { for (const auto& j : mime_types) {
if (j.mime_type == mime_type) {
if (mime_types[j].mime_type == mime_type) {
*is_available = true; *is_available = true;
*additional_param_names = mime_types[j].additional_param_names; *additional_param_names = j.additional_param_names;
*additional_param_values = mime_types[j].additional_param_values; *additional_param_values = j.additional_param_values;
return; return;
} }
} }

View file

@ -415,9 +415,8 @@ int TtsControllerImpl::GetMatchingVoice(
if (utterance->required_event_types().size() > 0) { if (utterance->required_event_types().size() > 0) {
bool has_all_required_event_types = true; bool has_all_required_event_types = true;
for (auto iter = utterance->required_event_types().begin(); for (auto iter : utterance->required_event_types()) {
iter != utterance->required_event_types().end(); ++iter) { if (voice.events.find(iter) == voice.events.end()) {
if (voice.events.find(*iter) == voice.events.end()) {
has_all_required_event_types = false; has_all_required_event_types = false;
break; break;
} }
@ -434,9 +433,8 @@ int TtsControllerImpl::GetMatchingVoice(
} }
void TtsControllerImpl::VoicesChanged() { void TtsControllerImpl::VoicesChanged() {
for (auto iter = voices_changed_delegates_.begin(); for (auto voices_changed_delegate : voices_changed_delegates_) {
iter != voices_changed_delegates_.end(); ++iter) { voices_changed_delegate->OnVoicesChanged();
(*iter)->OnVoicesChanged();
} }
} }

View file

@ -112,13 +112,13 @@ static void AddPepperBasedWidevine(
supported_codecs |= media::EME_CODEC_MP4_AAC; supported_codecs |= media::EME_CODEC_MP4_AAC;
#endif // defined(USE_PROPRIETARY_CODECS) #endif // defined(USE_PROPRIETARY_CODECS)
for (size_t i = 0; i < codecs.size(); ++i) { for (auto& codec : codecs) {
if (codecs[i] == kCdmSupportedCodecVp8) if (codec == kCdmSupportedCodecVp8)
supported_codecs |= media::EME_CODEC_WEBM_VP8; supported_codecs |= media::EME_CODEC_WEBM_VP8;
if (codecs[i] == kCdmSupportedCodecVp9) if (codec == kCdmSupportedCodecVp9)
supported_codecs |= media::EME_CODEC_WEBM_VP9; supported_codecs |= media::EME_CODEC_WEBM_VP9;
#if defined(USE_PROPRIETARY_CODECS) #if defined(USE_PROPRIETARY_CODECS)
if (codecs[i] == kCdmSupportedCodecAvc1) if (codec == kCdmSupportedCodecAvc1)
supported_codecs |= media::EME_CODEC_MP4_AVC1; supported_codecs |= media::EME_CODEC_MP4_AVC1;
#endif // defined(USE_PROPRIETARY_CODECS) #endif // defined(USE_PROPRIETARY_CODECS)
} }

View file

@ -980,10 +980,10 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
PrintPageInternal(page_params, frame); PrintPageInternal(page_params, frame);
} }
} else { } else {
for (size_t i = 0; i < params.pages.size(); ++i) { for (int page : params.pages) {
if (params.pages[i] >= page_count) if (page >= page_count)
break; break;
page_params.page_number = params.pages[i]; page_params.page_number = page;
PrintPageInternal(page_params, frame); PrintPageInternal(page_params, frame);
} }
} }

View file

@ -118,8 +118,8 @@ std::string StripTrailingWildcard(const std::string& path) {
namespace extensions { namespace extensions {
// static // static
bool URLPattern::IsValidSchemeForExtensions(const std::string& scheme) { bool URLPattern::IsValidSchemeForExtensions(const std::string& scheme) {
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { for (auto& kValidScheme : kValidSchemes) {
if (scheme == kValidSchemes[i]) if (scheme == kValidScheme)
return true; return true;
} }
return false; return false;
@ -543,8 +543,8 @@ bool URLPattern::Contains(const URLPattern& other) const {
bool URLPattern::MatchesAnyScheme( bool URLPattern::MatchesAnyScheme(
const std::vector<std::string>& schemes) const { const std::vector<std::string>& schemes) const {
for (auto i = schemes.begin(); i != schemes.end(); ++i) { for (const auto& scheme : schemes) {
if (MatchesScheme(*i)) if (MatchesScheme(scheme))
return true; return true;
} }
@ -553,8 +553,8 @@ bool URLPattern::MatchesAnyScheme(
bool URLPattern::MatchesAllSchemes( bool URLPattern::MatchesAllSchemes(
const std::vector<std::string>& schemes) const { const std::vector<std::string>& schemes) const {
for (auto i = schemes.begin(); i != schemes.end(); ++i) { for (const auto& scheme : schemes) {
if (!MatchesScheme(*i)) if (!MatchesScheme(scheme))
return false; return false;
} }
@ -584,9 +584,9 @@ std::vector<std::string> URLPattern::GetExplicitSchemes() const {
return result; return result;
} }
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { for (auto& kValidScheme : kValidSchemes) {
if (MatchesScheme(kValidSchemes[i])) { if (MatchesScheme(kValidScheme)) {
result.push_back(kValidSchemes[i]); result.push_back(kValidScheme);
} }
} }