diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 15:33:45 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 15:33:45 +0000 |
commit | f7be2cbadb7d6f2f96ea6a836f70961640bdb5e6 (patch) | |
tree | 14a6c5f61d11697047bb0d6a08625271f314fe45 /chrome/browser/plugin_prefs.h | |
parent | 411f5d0bcab149cbea4c482a06bfd7c851a71c7d (diff) | |
download | chromium_src-f7be2cbadb7d6f2f96ea6a836f70961640bdb5e6.zip chromium_src-f7be2cbadb7d6f2f96ea6a836f70961640bdb5e6.tar.gz chromium_src-f7be2cbadb7d6f2f96ea6a836f70961640bdb5e6.tar.bz2 |
Reland r101269: Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo, to allow different sets of enabled/disabled plug-ins to be specified per profile.
The relanded version fixes GViewRequestInterceptorTest on ChromeOS and a memory leak in PluginListTest.GetPluginGroup.
Original review URL: http://codereview.chromium.org/7848025
TBR=jam@chromium.org
BUG=80794
TEST=Open two profiles, disable different plugins in them.
Review URL: http://codereview.chromium.org/7904009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101297 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/plugin_prefs.h')
-rw-r--r-- | chrome/browser/plugin_prefs.h | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h index d55a600..ecfd585 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); }; |