Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6591)

Unified Diff: chrome/browser/plugin_prefs.cc

Issue 10872034: Changing PluginPrefs to use PluginFinder's async interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@test_async
Patch Set: Remove exclusion of plugin_installer and plugin_finder from build when enable_plugin_installation i… Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/plugin_prefs.cc
diff --git a/chrome/browser/plugin_prefs.cc b/chrome/browser/plugin_prefs.cc
index 00472170397c438f6079862e772131a61e6e38e0..e7536bc313f4dbae9939f720c62eb1c65d499813 100644
--- a/chrome/browser/plugin_prefs.cc
+++ b/chrome/browser/plugin_prefs.cc
@@ -18,6 +18,7 @@
#include "base/values.h"
#include "base/version.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/plugin_installer.h"
#include "chrome/browser/plugin_prefs_factory.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
@@ -47,13 +48,14 @@ base::LazyInstance<std::map<FilePath, bool> > g_default_plugin_state =
class CallbackBarrier : public base::RefCountedThreadSafe<CallbackBarrier> {
public:
- explicit CallbackBarrier(const base::Closure& callback)
+ explicit CallbackBarrier(const base::Callback<void(bool)>& callback)
: callback_(callback),
- outstanding_callbacks_(0) {
+ outstanding_callbacks_(0),
+ did_enable_(true) {
DCHECK(!callback_.is_null());
}
- base::Closure CreateCallback() {
+ base::Callback<void(bool)> CreateCallback() {
outstanding_callbacks_++;
return base::Bind(&CallbackBarrier::MaybeRunCallback, this);
}
@@ -65,16 +67,18 @@ class CallbackBarrier : public base::RefCountedThreadSafe<CallbackBarrier> {
DCHECK(callback_.is_null());
}
- void MaybeRunCallback() {
+ void MaybeRunCallback(bool did_enable) {
DCHECK_GT(outstanding_callbacks_, 0);
+ did_enable_ = did_enable_ && did_enable;
if (--outstanding_callbacks_ == 0) {
- callback_.Run();
+ callback_.Run(did_enable_);
callback_.Reset();
}
}
- base::Closure callback_;
+ base::Callback<void(bool)> callback_;
int outstanding_callbacks_;
+ bool did_enable_;
};
} // namespace
@@ -102,106 +106,134 @@ void PluginPrefs::SetPluginListForTesting(
}
void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) {
- PluginService::GetInstance()->GetPluginGroups(
- base::Bind(&PluginPrefs::EnablePluginGroupInternal,
- this, enabled, group_name));
+ PluginFinder::Get(
+ base::Bind(&PluginPrefs::GetPluginFinderForEnablePluginGroup,
+ this, enabled, group_name));
+}
+
+void PluginPrefs::GetPluginFinderForEnablePluginGroup(
+ bool enabled,
+ const string16& group_name,
+ PluginFinder* finder) {
+ PluginService::GetInstance()->GetPlugins(
+ base::Bind(&PluginPrefs::EnablePluginGroupInternal,
+ this, enabled, group_name, finder));
}
void PluginPrefs::EnablePluginGroupInternal(
bool enabled,
const string16& group_name,
- const std::vector<webkit::npapi::PluginGroup>& groups) {
+ PluginFinder* finder,
+ const std::vector<webkit::WebPluginInfo>& plugins) {
base::AutoLock auto_lock(lock_);
// Set the desired state for the group.
plugin_group_state_[group_name] = enabled;
// Update the state for all plug-ins in the group.
- for (size_t i = 0; i < groups.size(); ++i) {
- if (groups[i].GetGroupName() != group_name)
+ for (size_t i = 0; i < plugins.size(); ++i) {
+ PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]);
+ if (group_name != installer->name())
continue;
- const std::vector<webkit::WebPluginInfo>& plugins =
- groups[i].web_plugin_infos();
- for (size_t j = 0; j < plugins.size(); ++j)
- plugin_state_[plugins[j].path] = enabled;
- break;
+ plugin_state_[plugins[i].path] = enabled;
}
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups));
+ base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder));
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this));
}
-bool PluginPrefs::CanEnablePlugin(bool enabled, const FilePath& path) {
- webkit::npapi::PluginList* plugin_list = GetPluginList();
+void PluginPrefs::EnablePluginIfPossibleCallback(
+ bool enabled, const FilePath& path,
+ const base::Callback<void(bool)>& callback,
+ PluginFinder* finder) {
webkit::WebPluginInfo plugin;
+ bool can_enable = true;
if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) {
- scoped_ptr<webkit::npapi::PluginGroup> group(
- plugin_list->GetPluginGroup(plugin));
+ PluginInstaller* installer = finder->GetPluginInstaller(plugin);
PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name);
- PolicyStatus group_status = PolicyStatusForPlugin(group->GetGroupName());
+ PolicyStatus group_status = PolicyStatusForPlugin(installer->name());
if (enabled) {
if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED)
- return false;
+ can_enable = false;
} else {
if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED)
- return false;
+ can_enable = false;
}
} else {
NOTREACHED();
}
- return true;
-}
-void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path,
- const base::Closure& callback) {
- PluginService::GetInstance()->GetPluginGroups(
+ if (!can_enable) {
+ callback.Run(false);
+ return;
+ }
+
+ PluginService::GetInstance()->GetPlugins(
base::Bind(&PluginPrefs::EnablePluginInternal, this,
- enabled, path, callback));
+ enabled, path, finder, callback));
+}
+
+void PluginPrefs::EnablePlugin(
+ bool enabled, const FilePath& path,
+ const base::Callback<void(bool)>& callback) {
+ PluginFinder::Get(base::Bind(&PluginPrefs::EnablePluginIfPossibleCallback,
+ this, enabled, path, callback));
}
void PluginPrefs::EnablePluginInternal(
bool enabled,
const FilePath& path,
- const base::Closure& callback,
- const std::vector<webkit::npapi::PluginGroup>& groups) {
+ PluginFinder* plugin_finder,
+ const base::Callback<void(bool)>& callback,
+ const std::vector<webkit::WebPluginInfo>& plugins) {
{
// Set the desired state for the plug-in.
base::AutoLock auto_lock(lock_);
plugin_state_[path] = enabled;
}
- bool found_group = false;
- for (size_t i = 0; i < groups.size(); ++i) {
- bool all_disabled = true;
- const std::vector<webkit::WebPluginInfo>& plugins =
- groups[i].web_plugin_infos();
- for (size_t j = 0; j < plugins.size(); ++j) {
- all_disabled = all_disabled && !IsPluginEnabled(plugins[j]);
- if (plugins[j].path == path) {
- found_group = true;
- DCHECK_EQ(enabled, IsPluginEnabled(plugins[j]));
- }
- }
- if (found_group) {
- // Update the state for the corresponding plug-in group.
- base::AutoLock auto_lock(lock_);
- plugin_group_state_[groups[i].GetGroupName()] = !all_disabled;
+ string16 group_name;
+ for (size_t i = 0; i < plugins.size(); ++i) {
+ if (plugins[i].path == path) {
+ PluginInstaller* installer =
+ plugin_finder->GetPluginInstaller(plugins[i]);
+ // set the group name for this plug-in.
+ group_name = installer->name();
+ DCHECK_EQ(enabled, IsPluginEnabled(plugins[i]));
break;
}
}
+ bool all_disabled = true;
+ for (size_t i = 0; i < plugins.size(); ++i) {
+ PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]);
+ DCHECK(!installer->name().empty());
+ if (group_name == installer->name()) {
+ all_disabled = all_disabled && !IsPluginEnabled(plugins[i]);
+ }
+ }
+
+ if (!group_name.empty()) {
+ // Update the state for the corresponding plug-in group.
+ base::AutoLock auto_lock(lock_);
+ plugin_group_state_[group_name] = !all_disabled;
+ }
+
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups));
+ base::Bind(&PluginPrefs::OnUpdatePreferences, this,
+ plugins, plugin_finder));
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this));
- callback.Run();
+ callback.Run(true);
}
// static
-void PluginPrefs::EnablePluginGlobally(bool enable, const FilePath& file_path,
- const base::Closure& callback) {
+void PluginPrefs::EnablePluginGlobally(
+ bool enable,
+ const FilePath& file_path,
+ const base::Callback<void(bool)>& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
g_default_plugin_state.Get()[file_path] = enable;
std::vector<Profile*> profiles =
@@ -511,17 +543,24 @@ webkit::npapi::PluginList* PluginPrefs::GetPluginList() const {
}
void PluginPrefs::GetPreferencesDataOnFileThread() {
- std::vector<webkit::npapi::PluginGroup> groups;
+ PluginFinder::Get(
+ base::Bind(&PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread,
+ this));
+}
+void PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread(
+ PluginFinder* finder) {
+ std::vector<webkit::WebPluginInfo> plugins;
webkit::npapi::PluginList* plugin_list = GetPluginList();
- plugin_list->GetPluginGroups(false, &groups);
+ plugin_list->GetPluginsNoRefresh(&plugins);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&PluginPrefs::OnUpdatePreferences, this, groups));
+ base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder));
}
void PluginPrefs::OnUpdatePreferences(
- const std::vector<webkit::npapi::PluginGroup>& groups) {
+ const std::vector<webkit::WebPluginInfo>& plugins,
+ PluginFinder* finder) {
if (!prefs_)
return;
@@ -535,35 +574,37 @@ void PluginPrefs::OnUpdatePreferences(
base::AutoLock auto_lock(lock_);
- // Add the plug-in groups.
- for (size_t i = 0; i < groups.size(); ++i) {
- // Add the plugin files to the same list.
- const std::vector<webkit::WebPluginInfo>& plugins =
- groups[i].web_plugin_infos();
- for (size_t j = 0; j < plugins.size(); ++j) {
- DictionaryValue* summary = new DictionaryValue();
- summary->SetString("path", plugins[j].path.value());
- summary->SetString("name", plugins[j].name);
- summary->SetString("version", plugins[j].version);
- bool enabled = true;
- std::map<FilePath, bool>::iterator it =
- plugin_state_.find(plugins[j].path);
- if (it != plugin_state_.end())
- enabled = it->second;
- summary->SetBoolean("enabled", enabled);
- plugins_list->Append(summary);
- }
-
+ // Add the plugin files.
+ std::set<string16> group_names;
+ for (size_t i = 0; i < plugins.size(); ++i) {
DictionaryValue* summary = new DictionaryValue();
- string16 name = groups[i].GetGroupName();
- summary->SetString("name", name);
+ summary->SetString("path", plugins[i].path.value());
+ summary->SetString("name", plugins[i].name);
+ summary->SetString("version", plugins[i].version);
bool enabled = true;
- std::map<string16, bool>::iterator it =
- plugin_group_state_.find(name);
- if (it != plugin_group_state_.end())
+ std::map<FilePath, bool>::iterator it = plugin_state_.find(plugins[i].path);
+ if (it != plugin_state_.end())
enabled = it->second;
summary->SetBoolean("enabled", enabled);
plugins_list->Append(summary);
+
+ PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]);
+ // Insert into a set of all group names.
+ group_names.insert(installer->name());
+ }
+
+ // Add the plug-in groups.
+ for (std::set<string16>::const_iterator it = group_names.begin();
+ it != group_names.end(); ++it) {
+ DictionaryValue* summary = new DictionaryValue();
+ summary->SetString("name", *it);
+ bool enabled = true;
+ std::map<string16, bool>::iterator gstate_it =
+ plugin_group_state_.find(*it);
+ if (gstate_it != plugin_group_state_.end())
+ enabled = gstate_it->second;
+ summary->SetBoolean("enabled", enabled);
+ plugins_list->Append(summary);
}
}

Powered by Google App Engine
This is Rietveld 408576698