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 d128f8d39c1c7e118141e84c865ec464e04c0b65..c054eb72a285916a8c90b76c09c95d96b598f747 100644 |
| --- a/chrome/browser/plugins/plugin_finder.cc |
| +++ b/chrome/browser/plugins/plugin_finder.cc |
| @@ -147,35 +147,21 @@ PluginFinder* PluginFinder::GetInstance() { |
| return Singleton<PluginFinder>::get(); |
| } |
| -PluginFinder::PluginFinder() { |
| +PluginFinder::PluginFinder() : version_(-1) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| } |
| void PluginFinder::Init() { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| - plugin_list_.reset(ComputePluginList()); |
| - DCHECK(plugin_list_.get()); |
| - |
| - InitInternal(); |
| -} |
| - |
| -// static |
| -DictionaryValue* PluginFinder::ComputePluginList() { |
| -#if defined(ENABLE_PLUGIN_INSTALLATION) |
| - const base::DictionaryValue* metadata = |
| - g_browser_process->local_state()->GetDictionary(prefs::kPluginsMetadata); |
| - if (!metadata->empty()) |
| - return metadata->DeepCopy(); |
| -#endif |
| - base::DictionaryValue* result = LoadPluginList(); |
| - if (result) |
| - return result; |
| - return new base::DictionaryValue(); |
| + // Load the built-in plug-in list first. If we have a newer version stored |
| + // locally or download one, we will replace this one with it. |
| + scoped_ptr<DictionaryValue> plugin_list(LoadBuiltInPluginList()); |
|
Chris Evans
2013/02/08 19:25:23
Would it be possible to DCHECK(plugin_list.get())
Bernhard Bauer
2013/02/11 09:58:19
Done (although we have unit tests for that).
|
| + if (plugin_list) |
| + ReinitializePlugins(plugin_list.get()); |
| } |
| // static |
| -DictionaryValue* PluginFinder::LoadPluginList() { |
| -#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| +DictionaryValue* PluginFinder::LoadBuiltInPluginList() { |
| base::StringPiece json_resource( |
| ResourceBundle::GetSharedInstance().GetRawDataResource( |
| IDR_PLUGIN_DB_JSON)); |
| @@ -192,9 +178,6 @@ DictionaryValue* PluginFinder::LoadPluginList() { |
| if (value->GetType() != base::Value::TYPE_DICTIONARY) |
| return NULL; |
| return static_cast<base::DictionaryValue*>(value.release()); |
| -#else |
| - return new DictionaryValue(); |
| -#endif |
| } |
| PluginFinder::~PluginFinder() { |
| @@ -210,10 +193,10 @@ bool PluginFinder::FindPlugin( |
| const std::string& language, |
| PluginInstaller** installer, |
| scoped_ptr<PluginMetadata>* plugin_metadata) { |
| - base::AutoLock lock(mutex_); |
| if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) |
| return false; |
| + base::AutoLock lock(mutex_); |
| PluginMap::const_iterator metadata_it = identifier_plugin_.begin(); |
| for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { |
| if (language == metadata_it->second->language() && |
| @@ -249,17 +232,37 @@ bool PluginFinder::FindPluginWithIdentifier( |
| } |
| return true; |
| } |
| +#endif |
| void PluginFinder::ReinitializePlugins( |
| - const base::DictionaryValue& json_metadata) { |
| + const base::DictionaryValue* plugin_list) { |
| base::AutoLock lock(mutex_); |
| + int version = 0; // If no version is defined, we default to 0. |
| + const char kVersionKey[] = "x-version"; |
| + plugin_list->GetInteger(kVersionKey, &version); |
| + if (version <= version_) |
| + return; |
| + |
| + version_ = version; |
| + |
| STLDeleteValues(&identifier_plugin_); |
| identifier_plugin_.clear(); |
| - plugin_list_.reset(json_metadata.DeepCopy()); |
| - InitInternal(); |
| -} |
| + for (DictionaryValue::Iterator plugin_it(*plugin_list); |
| + plugin_it.HasNext(); plugin_it.Advance()) { |
| + const DictionaryValue* plugin = NULL; |
| + const std::string& identifier = plugin_it.key(); |
| + if (plugin_list->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { |
| + DCHECK(!identifier_plugin_[identifier]); |
| + identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
| + |
| +#if defined(ENABLE_PLUGIN_INSTALLATION) |
| + if (installers_.find(identifier) == installers_.end()) |
| + installers_[identifier] = new PluginInstaller(); |
| #endif |
| + } |
| + } |
| +} |
| string16 PluginFinder::FindPluginNameWithIdentifier( |
| const std::string& identifier) { |
| @@ -302,20 +305,3 @@ scoped_ptr<PluginMetadata> PluginFinder::GetPluginMetadata( |
| identifier_plugin_[identifier] = metadata; |
| return metadata->Clone(); |
| } |
| - |
| -void PluginFinder::InitInternal() { |
| - for (DictionaryValue::Iterator plugin_it(*plugin_list_); |
| - plugin_it.HasNext(); plugin_it.Advance()) { |
| - DictionaryValue* plugin = NULL; |
| - const std::string& identifier = plugin_it.key(); |
| - if (plugin_list_->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { |
| - DCHECK(!identifier_plugin_[identifier]); |
| - identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
| - |
| -#if defined(ENABLE_PLUGIN_INSTALLATION) |
| - if (installers_.find(identifier) == installers_.end()) |
| - installers_[identifier] = new PluginInstaller(); |
| -#endif |
| - } |
| - } |
| -} |