Browse Source

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

Haojian Wu 8 years ago
parent
commit
55b3f1936f

+ 3 - 3
atom/browser/api/atom_api_session.cc

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

+ 3 - 3
atom/browser/api/atom_api_web_contents.cc

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

+ 4 - 4
atom/browser/common_web_contents_delegate.cc

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

+ 2 - 2
atom/browser/ui/accelerator_util.cc

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

+ 2 - 2
atom/browser/window_list.cc

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

+ 3 - 3
atom/common/api/atom_api_native_image.cc

@@ -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
   // expensive.
-  for (unsigned i = 0; i < node::arraysize(kScaleFactorPairs); ++i) {
-    if (base::EndsWith(filename, kScaleFactorPairs[i].name,
+  for (auto& kScaleFactorPair : kScaleFactorPairs) {
+    if (base::EndsWith(filename, kScaleFactorPair.name,
                        base::CompareCase::INSENSITIVE_ASCII))
-      return kScaleFactorPairs[i].scale;
+      return kScaleFactorPair.scale;
   }
 
   return 1.0f;

+ 3 - 3
atom/renderer/atom_render_view_observer.cc

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

+ 3 - 3
chromium_src/chrome/browser/extensions/global_shortcut_listener.cc

@@ -87,16 +87,16 @@ void GlobalShortcutListener::SetShortcutHandlingSuspended(bool suspended) {
     return;
 
   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
     // return in NotifyKeyPressed (similar to what we do for non-global
     // shortcuts) because we'd eat the keyboard event thereby preventing the
     // user from setting the shortcut. Therefore we must unregister while
     // handling is suspended and register when handling resumes.
     if (shortcut_handling_suspended_)
-      UnregisterAcceleratorImpl(it->first);
+      UnregisterAcceleratorImpl(it.first);
     else
-      RegisterAcceleratorImpl(it->first);
+      RegisterAcceleratorImpl(it.first);
   }
 }
 

+ 8 - 8
chromium_src/chrome/browser/media/native_desktop_media_list.cc

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

+ 5 - 6
chromium_src/chrome/browser/printing/print_job_manager.cc

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

+ 2 - 2
chromium_src/chrome/browser/process_singleton_posix.cc

@@ -820,9 +820,9 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout(
   to_send.append(current_dir.value());
 
   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.append(*it);
+    to_send.append(it);
   }
 
   // Send the message

+ 3 - 3
chromium_src/chrome/browser/renderer_host/pepper/pepper_flash_clipboard_message_filter.cc

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

+ 5 - 7
chromium_src/chrome/browser/renderer_host/pepper/widevine_cdm_message_filter.cc

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

+ 4 - 6
chromium_src/chrome/browser/speech/tts_controller_impl.cc

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

+ 4 - 4
chromium_src/chrome/renderer/media/chrome_key_systems.cc

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

+ 3 - 3
chromium_src/chrome/renderer/printing/print_web_view_helper.cc

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

+ 9 - 9
chromium_src/extensions/common/url_pattern.cc

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