Index: chrome/browser/plugin_prefs.h |
diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h |
index d55a6000c15fae5a1cb57b1d7cd8b33b6fd1d13b..ecfd5856190fbdb1d745049f6d40dd7726afa162 100644 |
--- a/chrome/browser/plugin_prefs.h |
+++ b/chrome/browser/plugin_prefs.h |
@@ -6,12 +6,14 @@ |
#define CHROME_BROWSER_PLUGIN_PREFS_H_ |
#pragma once |
+#include <map> |
#include <set> |
#include <vector> |
#include "base/basictypes.h" |
#include "base/file_path.h" |
#include "base/memory/ref_counted.h" |
+#include "base/synchronization/lock.h" |
#include "chrome/browser/prefs/pref_change_registrar.h" |
#include "content/common/notification_observer.h" |
@@ -37,11 +39,16 @@ class PluginGroup; |
// This class stores information about whether a plug-in or a plug-in group is |
// enabled or disabled. |
-// Except for the |IsPluginEnabled| method, it should only be used on the UI |
-// thread. |
+// Except where otherwise noted, it can be used on every thread. |
class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, |
public NotificationObserver { |
public: |
+ enum PolicyStatus { |
+ NO_POLICY = 0, // Neither enabled or disabled by policy. |
+ POLICY_ENABLED, |
+ POLICY_DISABLED, |
+ }; |
+ |
// Initializes the factory for this class for dependency tracking. |
// This should be called before the first profile is created. |
static void Initialize(); |
@@ -49,77 +56,96 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, |
// Returns the instance associated with |profile|, creating it if necessary. |
static PluginPrefs* GetForProfile(Profile* profile); |
+ // Usually the PluginPrefs associated with a TestingProfile is NULL. |
+ // This method overrides that for a given TestingProfile, returning the newly |
+ // created PluginPrefs object. |
+ static PluginPrefs* GetForTestingProfile(Profile* profile); |
+ |
// Creates a new instance. This method should only be used for testing. |
PluginPrefs(); |
// Associates this instance with |prefs|. This enables or disables |
// plugin groups as defined by the user's preferences. |
+ // This method should only be called on the UI thread. |
void SetPrefs(PrefService* prefs); |
+ // Detaches from the PrefService before it is destroyed. |
+ // As the name says, this method should only be called on the UI thread. |
+ void ShutdownOnUIThread(); |
+ |
// Enable or disable a plugin group. |
void EnablePluginGroup(bool enable, const string16& group_name); |
// Enable or disable a specific plugin file. |
void EnablePlugin(bool enable, const FilePath& file_path); |
+ // Enable or disable a plug-in in all profiles. This sets a default for |
+ // profiles which are created later as well. |
+ // This method should only be called on the UI thread. |
+ static void EnablePluginGlobally(bool enable, const FilePath& file_path); |
+ |
+ // Returns whether there is a policy enabling or disabling plug-ins of the |
+ // given name. |
+ PolicyStatus PolicyStatusForPlugin(const string16& name); |
+ |
// Returns whether the plugin is enabled or not. |
bool IsPluginEnabled(const webkit::WebPluginInfo& plugin); |
- // Write the enable/disable status to the user's preference file. |
- void UpdatePreferences(int delay_ms); |
+ // Registers the preferences used by this class. |
+ // This method should only be called on the UI thread. |
+ static void RegisterPrefs(PrefService* prefs); |
- // NotificationObserver method overrides |
+ // NotificationObserver method override. |
virtual void Observe(int type, |
const NotificationSource& source, |
- const NotificationDetails& details); |
- |
- static void RegisterPrefs(PrefService* prefs); |
- |
- void ShutdownOnUIThread(); |
+ const NotificationDetails& details) OVERRIDE; |
private: |
friend class base::RefCountedThreadSafe<PluginPrefs>; |
+ friend class PluginPrefsTest; |
class Factory; |
virtual ~PluginPrefs(); |
+ // Allows unit tests to directly set enforced plug-in patterns. |
+ void SetPolicyEnforcedPluginPatterns( |
+ const std::set<string16>& disabled_patterns, |
+ const std::set<string16>& disabled_exception_patterns, |
+ const std::set<string16>& enabled_patterns); |
+ |
// Called on the file thread to get the data necessary to update the saved |
// preferences. |
void GetPreferencesDataOnFileThread(); |
// Called on the UI thread with the plugin data to save the preferences. |
- void OnUpdatePreferences(std::vector<webkit::WebPluginInfo> plugins, |
- std::vector<webkit::npapi::PluginGroup> groups); |
+ void OnUpdatePreferences(std::vector<webkit::npapi::PluginGroup> groups); |
- // Queues sending the notification that plugin data has changed. This is done |
- // so that if a bunch of changes happen, we only send one notification. |
+ // Sends the notification that plugin data has changed. |
void NotifyPluginStatusChanged(); |
- // Used for the post task to notify that plugin enabled status changed. |
- void OnNotifyPluginStatusChanged(); |
+ static void ListValueToStringSet(const base::ListValue* src, |
+ std::set<string16>* dest); |
+ |
+ // Checks if |name| matches any of the patterns in |pattern_set|. |
+ static bool IsStringMatchedInSet(const string16& name, |
+ const std::set<string16>& pattern_set); |
- base::DictionaryValue* CreatePluginFileSummary( |
- const webkit::WebPluginInfo& plugin); |
+ // Guards access to the following data structures. |
+ mutable base::Lock lock_; |
- // Force plugins to be enabled or disabled due to policy. |
- // |disabled_list| contains the list of StringValues of the names of the |
- // policy-disabled plugins, |exceptions_list| the policy-allowed plugins, |
- // and |enabled_list| the policy-enabled plugins. |
- void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list, |
- const base::ListValue* exceptions_list, |
- const base::ListValue* enabled_list); |
+ std::map<FilePath, bool> plugin_state_; |
+ std::map<string16, bool> plugin_group_state_; |
- void ListValueToStringSet(const base::ListValue* src, |
- std::set<string16>* dest); |
+ std::set<string16> policy_disabled_plugin_patterns_; |
+ std::set<string16> policy_disabled_plugin_exception_patterns_; |
+ std::set<string16> policy_enabled_plugin_patterns_; |
- // Weak pointer, owned by the profile. |
+ // Weak pointer, owned by the profile (which owns us). |
PrefService* prefs_; |
PrefChangeRegistrar registrar_; |
- bool notify_pending_; |
- |
DISALLOW_COPY_AND_ASSIGN(PluginPrefs); |
}; |