Chromium Code Reviews| Index: chrome/browser/plugins/plugin_finder.cc |
| diff --git a/chrome/browser/plugins/plugin_finder.cc b/chrome/browser/plugins/plugin_finder.cc |
| index b05f173cc73ca4f42f9607de1678c3bbf67ccacb..5ddea177b0b6ec16fecf72113f59d89c1c7110fc 100644 |
| --- a/chrome/browser/plugins/plugin_finder.cc |
| +++ b/chrome/browser/plugins/plugin_finder.cc |
| @@ -8,9 +8,9 @@ |
| #include "base/bind.h" |
| #include "base/json/json_reader.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/metrics/histogram_macros.h" |
| -#include "base/stl_util.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| @@ -95,7 +95,7 @@ void LoadMimeTypes(bool matching_mime_types, |
| } |
| } |
| -PluginMetadata* CreatePluginMetadata( |
| +std::unique_ptr<PluginMetadata> CreatePluginMetadata( |
| const std::string& identifier, |
| const base::DictionaryValue* plugin_dict) { |
| std::string url; |
| @@ -113,13 +113,9 @@ PluginMetadata* CreatePluginMetadata( |
| std::string language_str; |
| plugin_dict->GetString("lang", &language_str); |
| - PluginMetadata* plugin = new PluginMetadata(identifier, |
| - name, |
| - display_url, |
| - GURL(url), |
| - GURL(help_url), |
| - group_name_matcher, |
| - language_str); |
| + std::unique_ptr<PluginMetadata> plugin = base::MakeUnique<PluginMetadata>( |
| + identifier, name, display_url, GURL(url), GURL(help_url), |
| + group_name_matcher, language_str); |
| const base::ListValue* versions = NULL; |
| if (plugin_dict->GetList("versions", &versions)) { |
| for (base::ListValue::const_iterator it = versions->begin(); |
| @@ -143,8 +139,8 @@ PluginMetadata* CreatePluginMetadata( |
| } |
| } |
| - LoadMimeTypes(false, plugin_dict, plugin); |
| - LoadMimeTypes(true, plugin_dict, plugin); |
| + LoadMimeTypes(false, plugin_dict, plugin.get()); |
| + LoadMimeTypes(true, plugin_dict, plugin.get()); |
| return plugin; |
| } |
| @@ -247,10 +243,6 @@ base::DictionaryValue* PluginFinder::LoadBuiltInPluginList() { |
| } |
| PluginFinder::~PluginFinder() { |
| -#if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) |
| - base::STLDeleteValues(&installers_); |
| -#endif |
| - base::STLDeleteValues(&identifier_plugin_); |
| } |
| #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) |
| @@ -263,16 +255,15 @@ bool PluginFinder::FindPlugin( |
| return false; |
| base::AutoLock lock(mutex_); |
| - PluginMap::const_iterator metadata_it = identifier_plugin_.begin(); |
| + auto metadata_it = identifier_plugin_.begin(); |
| for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { |
| if (language == metadata_it->second->language() && |
| metadata_it->second->HasMimeType(mime_type)) { |
| *plugin_metadata = metadata_it->second->Clone(); |
| - std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| - installers_.find(metadata_it->second->identifier()); |
| + auto installer_it = installers_.find(metadata_it->second->identifier()); |
| DCHECK(installer_it != installers_.end()); |
| - *installer = installer_it->second; |
| + *installer = installer_it->second.get(); |
| return true; |
| } |
| } |
| @@ -284,17 +275,16 @@ bool PluginFinder::FindPluginWithIdentifier( |
| PluginInstaller** installer, |
| std::unique_ptr<PluginMetadata>* plugin_metadata) { |
| base::AutoLock lock(mutex_); |
| - PluginMap::const_iterator metadata_it = identifier_plugin_.find(identifier); |
| + auto metadata_it = identifier_plugin_.find(identifier); |
| if (metadata_it == identifier_plugin_.end()) |
| return false; |
| *plugin_metadata = metadata_it->second->Clone(); |
| if (installer) { |
| - std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| - installers_.find(identifier); |
| + auto installer_it = installers_.find(identifier); |
| if (installer_it == installers_.end()) |
| return false; |
| - *installer = installer_it->second; |
| + *installer = installer_it->second.get(); |
| } |
| return true; |
| } |
| @@ -311,7 +301,7 @@ void PluginFinder::ReinitializePlugins( |
| version_ = version; |
| - base::STLDeleteValues(&identifier_plugin_); |
| + identifier_plugin_.clear(); |
| for (base::DictionaryValue::Iterator plugin_it(*plugin_list); |
| !plugin_it.IsAtEnd(); plugin_it.Advance()) { |
| @@ -323,7 +313,7 @@ void PluginFinder::ReinitializePlugins( |
| #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) |
| if (installers_.find(identifier) == installers_.end()) |
| - installers_[identifier] = new PluginInstaller(); |
| + installers_[identifier] = base::MakeUnique<PluginInstaller>(); |
| #endif |
| } |
| } |
| @@ -332,8 +322,8 @@ void PluginFinder::ReinitializePlugins( |
| std::unique_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| const content::WebPluginInfo& plugin) { |
| base::AutoLock lock(mutex_); |
| - for (PluginMap::const_iterator it = identifier_plugin_.begin(); |
| - it != identifier_plugin_.end(); ++it) { |
| + for (auto it = identifier_plugin_.begin(); it != identifier_plugin_.end(); |
|
Nico
2016/10/24 18:41:02
nit: for-each loop?
Avi (use Gerrit)
2016/10/24 19:15:37
Done.
|
| + ++it) { |
| if (!it->second->MatchesPlugin(plugin)) |
| continue; |
| @@ -343,13 +333,9 @@ std::unique_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| // The plugin metadata was not found, create a dummy one holding |
| // the name, identifier and group name only. |
| std::string identifier = GetIdentifier(plugin); |
| - PluginMetadata* metadata = new PluginMetadata(identifier, |
| - GetGroupName(plugin), |
| - false, |
| - GURL(), |
| - GURL(), |
| - plugin.name, |
| - std::string()); |
| + std::unique_ptr<PluginMetadata> metadata = base::MakeUnique<PluginMetadata>( |
| + identifier, GetGroupName(plugin), false, GURL(), GURL(), plugin.name, |
| + std::string()); |
| for (size_t i = 0; i < plugin.mime_types.size(); ++i) |
| metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); |
| @@ -358,6 +344,6 @@ std::unique_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| identifier = GetLongIdentifier(plugin); |
| DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); |
| - identifier_plugin_[identifier] = metadata; |
| - return metadata->Clone(); |
| + identifier_plugin_[identifier] = std::move(metadata); |
| + return identifier_plugin_[identifier]->Clone(); |
| } |