Chromium Code Reviews| Index: chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| diff --git a/chrome/browser/extensions/api/content_settings/content_settings_api.cc b/chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| index 7b734e5cbddb077add3cbd985205881595fee4dc..1ec2ce4f0eb0151f7f024d760f28236b92fff35b 100644 |
| --- a/chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| +++ b/chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/extensions/api/content_settings/content_settings_api.h" |
| +#include <set> |
| #include <vector> |
| #include "base/bind.h" |
| @@ -17,6 +18,7 @@ |
| #include "chrome/browser/extensions/extension_preference_api_constants.h" |
| #include "chrome/browser/extensions/extension_preference_helpers.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/plugin_installer.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -36,7 +38,7 @@ namespace pref_keys = extension_preference_api_constants; |
| namespace { |
| -const std::vector<webkit::npapi::PluginGroup>* g_testing_plugin_groups_; |
| +const std::vector<webkit::WebPluginInfo>* g_testing_plugins_; |
| bool RemoveContentType(ListValue* args, ContentSettingsType* content_type) { |
| std::string content_type_str; |
| @@ -51,6 +53,62 @@ bool RemoveContentType(ListValue* args, ContentSettingsType* content_type) { |
| return *content_type != CONTENT_SETTINGS_TYPE_DEFAULT; |
| } |
| +class CallbackBarrier : public base::RefCountedThreadSafe<CallbackBarrier> { |
|
ibraaaa
2012/08/30 08:51:52
How about moving this to chrome/browser/plugins_pl
ibraaaa
2012/08/30 11:58:51
we can also update code here to make use of it: ht
ibraaaa
2012/08/31 12:48:49
Apparently the callback required to get plugins (I
Bernhard Bauer
2012/08/31 12:55:55
SGTM! (Both here and in PluginInfoMessageFilter)
Bernhard Bauer
2012/08/31 12:55:55
The plugins are used in PluginInfoMessageFilter::P
|
| + public: |
| + typedef std::vector<webkit::WebPluginInfo> PluginVector; |
| + typedef base::Callback<void(PluginFinder*, const PluginVector&)> |
| + CombinedCallback; |
| + |
| + explicit CallbackBarrier(const CombinedCallback& callback) |
| + : callback_(callback), |
| + finder_(NULL), |
| + plugins_(NULL) { |
|
Bernhard Bauer
2012/08/31 12:55:55
The default constructor for a scoped_ptr already i
|
| + DCHECK(!callback_.is_null()); |
| + if (g_testing_plugins_) { |
| + plugins_.reset(new PluginVector(g_testing_plugins_->begin(), |
| + g_testing_plugins_->end())); |
| + } |
| + } |
| + |
| + base::Callback<void(PluginFinder*)> CreateGetPluginFinderCallback() { |
| + return base::Bind(&CallbackBarrier::SavePluginFinderAndMaybeRunCallback, |
| + this); |
| + } |
| + |
| + base::Callback<void(const PluginVector&)> CreateGetPluginVectorCallback() { |
| + return base::Bind(&CallbackBarrier::SavePluginVectorAndMaybeRunCallback, |
| + this); |
| + } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<CallbackBarrier>; |
| + |
| + ~CallbackBarrier() { |
| + DCHECK(callback_.is_null()); |
| + } |
| + |
| + void SavePluginFinderAndMaybeRunCallback(PluginFinder* finder) { |
|
Bernhard Bauer
2012/08/31 12:55:55
This method name is a bit verbose. Maybe just GotP
|
| + finder_ = finder; |
| + MaybeRunCallback(); |
| + } |
| + |
| + void SavePluginVectorAndMaybeRunCallback(const PluginVector& plugins) { |
| + plugins_.reset(new PluginVector(plugins.begin(), plugins.end())); |
|
Bernhard Bauer
2012/08/31 12:55:55
Could you simply use the copy constructor on vecto
|
| + MaybeRunCallback(); |
| + } |
| + |
| + void MaybeRunCallback() { |
| + if (!finder_ || !plugins_.get()) |
| + return; |
| + callback_.Run(finder_, *plugins_); |
| + callback_.Reset(); |
| + } |
| + |
| + CombinedCallback callback_; |
| + PluginFinder* finder_; |
| + scoped_ptr<std::vector<webkit::WebPluginInfo> > plugins_; |
|
Bernhard Bauer
2012/08/31 12:55:55
You typedef'd this as PluginVector above, so you c
|
| +}; |
| + |
| } // namespace |
| namespace extensions { |
| @@ -251,11 +309,13 @@ bool GetResourceIdentifiersFunction::RunImpl() { |
| EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| - if (g_testing_plugin_groups_) { |
| - OnGotPluginGroups(*g_testing_plugin_groups_); |
| - } else { |
| - PluginService::GetInstance()->GetPluginGroups( |
| - base::Bind(&GetResourceIdentifiersFunction::OnGotPluginGroups, this)); |
| + scoped_refptr<CallbackBarrier> barrier = new CallbackBarrier( |
| + base::Bind(&GetResourceIdentifiersFunction::OnGotPlugins, this)); |
| + |
| + PluginFinder::Get(base::Bind(barrier->CreateGetPluginFinderCallback())); |
| + if (!g_testing_plugins_) { |
| + PluginService::GetInstance()->GetPlugins( |
|
Bernhard Bauer
2012/08/31 12:55:55
You could switch the order of the parameters in On
|
| + base::Bind(barrier->CreateGetPluginVectorCallback())); |
| } |
| } else { |
| SendResponse(true); |
| @@ -264,15 +324,22 @@ bool GetResourceIdentifiersFunction::RunImpl() { |
| return true; |
| } |
| -void GetResourceIdentifiersFunction::OnGotPluginGroups( |
| - const std::vector<webkit::npapi::PluginGroup>& groups) { |
| +void GetResourceIdentifiersFunction::OnGotPlugins( |
| + PluginFinder* finder, |
| + const std::vector<webkit::WebPluginInfo>& plugins) { |
| + std::set<std::string> group_identifiers; |
| ListValue* list = new ListValue(); |
| - for (std::vector<webkit::npapi::PluginGroup>::const_iterator it = |
| - groups.begin(); |
| - it != groups.end(); ++it) { |
| + for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
| + it != plugins.end(); ++it) { |
| + PluginInstaller* installer = finder->GetPluginInstaller(*it); |
| + const std::string& group_identifier = installer->identifier(); |
| + if (group_identifiers.find(group_identifier) != group_identifiers.end()) |
| + continue; |
| + |
| + group_identifiers.insert(group_identifier); |
| DictionaryValue* dict = new DictionaryValue(); |
| - dict->SetString(keys::kIdKey, it->identifier()); |
| - dict->SetString(keys::kDescriptionKey, it->GetGroupName()); |
| + dict->SetString(keys::kIdKey, group_identifier); |
| + dict->SetString(keys::kDescriptionKey, installer->name()); |
| list->Append(dict); |
| } |
| SetResult(list); |
| @@ -282,9 +349,9 @@ void GetResourceIdentifiersFunction::OnGotPluginGroups( |
| } |
| // static |
| -void GetResourceIdentifiersFunction::SetPluginGroupsForTesting( |
| - const std::vector<webkit::npapi::PluginGroup>* plugin_groups) { |
| - g_testing_plugin_groups_ = plugin_groups; |
| +void GetResourceIdentifiersFunction::SetPluginsForTesting( |
| + const std::vector<webkit::WebPluginInfo>* plugins) { |
| + g_testing_plugins_ = plugins; |
| } |
| } // namespace extensions |