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

Side by Side Diff: chrome/browser/plugin_prefs.h

Issue 7848025: Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PLUGIN_PREFS_H_ 5 #ifndef CHROME_BROWSER_PLUGIN_PREFS_H_
6 #define CHROME_BROWSER_PLUGIN_PREFS_H_ 6 #define CHROME_BROWSER_PLUGIN_PREFS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
9 #include <set> 10 #include <set>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/file_path.h" 14 #include "base/file_path.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
15 #include "chrome/browser/prefs/pref_change_registrar.h" 17 #include "chrome/browser/prefs/pref_change_registrar.h"
16 #include "content/common/notification_observer.h" 18 #include "content/common/notification_observer.h"
17 19
18 class NotificationDetails; 20 class NotificationDetails;
19 class NotificationSource; 21 class NotificationSource;
20 class Profile; 22 class Profile;
21 23
22 namespace content { 24 namespace content {
23 class ResourceContext; 25 class ResourceContext;
24 } 26 }
25 27
26 namespace base { 28 namespace base {
27 class DictionaryValue; 29 class DictionaryValue;
28 class ListValue; 30 class ListValue;
29 } 31 }
30 32
31 namespace webkit { 33 namespace webkit {
32 struct WebPluginInfo; 34 struct WebPluginInfo;
33 namespace npapi { 35 namespace npapi {
34 class PluginGroup; 36 class PluginGroup;
35 } 37 }
36 } 38 }
37 39
38 // This class stores information about whether a plug-in or a plug-in group is 40 // This class stores information about whether a plug-in or a plug-in group is
39 // enabled or disabled. 41 // enabled or disabled.
40 // Except for the |IsPluginEnabled| method, it should only be used on the UI 42 // Except where otherwise noted, it can be used on every thread.
41 // thread.
42 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, 43 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
43 public NotificationObserver { 44 public NotificationObserver {
44 public: 45 public:
46 enum PolicyStatus {
47 NO_POLICY = 0, // Neither enabled or disabled by policy.
48 POLICY_ENABLED,
49 POLICY_DISABLED,
50 };
51
45 // Initializes the factory for this class for dependency tracking. 52 // Initializes the factory for this class for dependency tracking.
46 // This should be called before the first profile is created. 53 // This should be called before the first profile is created.
47 static void Initialize(); 54 static void Initialize();
48 55
49 // Returns the instance associated with |profile|, creating it if necessary. 56 // Returns the instance associated with |profile|, creating it if necessary.
50 static PluginPrefs* GetForProfile(Profile* profile); 57 static PluginPrefs* GetForProfile(Profile* profile);
51 58
59 // Usually the PluginPrefs associated with a TestingProfile is NULL.
60 // This method overrides that for a given TestingProfile, returning the newly
61 // created PluginPrefs object.
62 static PluginPrefs* GetForTestingProfile(Profile* profile);
63
52 // Creates a new instance. This method should only be used for testing. 64 // Creates a new instance. This method should only be used for testing.
53 PluginPrefs(); 65 PluginPrefs();
54 66
55 // Associates this instance with |prefs|. This enables or disables 67 // Associates this instance with |prefs|. This enables or disables
56 // plugin groups as defined by the user's preferences. 68 // plugin groups as defined by the user's preferences.
69 // This method should only be called on the UI thread.
57 void SetPrefs(PrefService* prefs); 70 void SetPrefs(PrefService* prefs);
58 71
72 // Detaches from the PrefService before it is destroyed.
73 // As the name says, this method should only be called on the UI thread.
74 void ShutdownOnUIThread();
75
59 // Enable or disable a plugin group. 76 // Enable or disable a plugin group.
60 void EnablePluginGroup(bool enable, const string16& group_name); 77 void EnablePluginGroup(bool enable, const string16& group_name);
61 78
62 // Enable or disable a specific plugin file. 79 // Enable or disable a specific plugin file.
63 void EnablePlugin(bool enable, const FilePath& file_path); 80 void EnablePlugin(bool enable, const FilePath& file_path);
64 81
82 // Enable or disable a plug-in in all profiles. This sets a default for
83 // profiles which are created later as well.
84 // This method should only be called on the UI thread.
85 static void EnablePluginGlobally(bool enable, const FilePath& file_path);
86
87 // Returns whether there is a policy enabling or disabling plug-ins of the
88 // given name.
89 PolicyStatus PolicyStatusForPlugin(const string16& name);
90
65 // Returns whether the plugin is enabled or not. 91 // Returns whether the plugin is enabled or not.
66 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin); 92 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin);
67 93
68 // Write the enable/disable status to the user's preference file. 94 // Registers the preferences used by this class.
69 void UpdatePreferences(int delay_ms); 95 // This method should only be called on the UI thread.
96 static void RegisterPrefs(PrefService* prefs);
70 97
71 // NotificationObserver method overrides 98 // NotificationObserver method override.
72 virtual void Observe(int type, 99 virtual void Observe(int type,
73 const NotificationSource& source, 100 const NotificationSource& source,
74 const NotificationDetails& details); 101 const NotificationDetails& details) OVERRIDE;
75
76 static void RegisterPrefs(PrefService* prefs);
77
78 void ShutdownOnUIThread();
79 102
80 private: 103 private:
81 friend class base::RefCountedThreadSafe<PluginPrefs>; 104 friend class base::RefCountedThreadSafe<PluginPrefs>;
105 friend class PluginPrefsTest;
82 106
83 class Factory; 107 class Factory;
84 108
85 virtual ~PluginPrefs(); 109 virtual ~PluginPrefs();
86 110
111 // Allows unit tests to directly set enforced plug-in patterns.
112 void SetPolicyEnforcedPluginPatterns(
113 const std::set<string16>& disabled_patterns,
114 const std::set<string16>& disabled_exception_patterns,
115 const std::set<string16>& enabled_patterns);
116
87 // Called on the file thread to get the data necessary to update the saved 117 // Called on the file thread to get the data necessary to update the saved
88 // preferences. 118 // preferences.
89 void GetPreferencesDataOnFileThread(); 119 void GetPreferencesDataOnFileThread();
90 120
91 // Called on the UI thread with the plugin data to save the preferences. 121 // Called on the UI thread with the plugin data to save the preferences.
92 void OnUpdatePreferences(std::vector<webkit::WebPluginInfo> plugins, 122 void OnUpdatePreferences(std::vector<webkit::npapi::PluginGroup> groups);
93 std::vector<webkit::npapi::PluginGroup> groups);
94 123
95 // Queues sending the notification that plugin data has changed. This is done 124 // Sends the notification that plugin data has changed.
96 // so that if a bunch of changes happen, we only send one notification.
97 void NotifyPluginStatusChanged(); 125 void NotifyPluginStatusChanged();
98 126
99 // Used for the post task to notify that plugin enabled status changed. 127 static void ListValueToStringSet(const base::ListValue* src,
100 void OnNotifyPluginStatusChanged(); 128 std::set<string16>* dest);
101 129
102 base::DictionaryValue* CreatePluginFileSummary( 130 // Checks if |name| matches any of the patterns in |pattern_set|.
103 const webkit::WebPluginInfo& plugin); 131 static bool IsStringMatchedInSet(const string16& name,
132 const std::set<string16>& pattern_set);
104 133
105 // Force plugins to be enabled or disabled due to policy. 134 // Guards access to the following data structures.
106 // |disabled_list| contains the list of StringValues of the names of the 135 mutable base::Lock lock_;
107 // policy-disabled plugins, |exceptions_list| the policy-allowed plugins,
108 // and |enabled_list| the policy-enabled plugins.
109 void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list,
110 const base::ListValue* exceptions_list,
111 const base::ListValue* enabled_list);
112 136
113 void ListValueToStringSet(const base::ListValue* src, 137 std::map<FilePath, bool> plugin_state_;
114 std::set<string16>* dest); 138 std::map<string16, bool> plugin_group_state_;
115 139
116 // Weak pointer, owned by the profile. 140 std::set<string16> policy_disabled_plugin_patterns_;
141 std::set<string16> policy_disabled_plugin_exception_patterns_;
142 std::set<string16> policy_enabled_plugin_patterns_;
143
144 // Weak pointer, owned by the profile (which owns us).
117 PrefService* prefs_; 145 PrefService* prefs_;
118 146
119 PrefChangeRegistrar registrar_; 147 PrefChangeRegistrar registrar_;
120 148
121 bool notify_pending_;
122
123 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); 149 DISALLOW_COPY_AND_ASSIGN(PluginPrefs);
124 }; 150 };
125 151
126 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_ 152 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_
OLDNEW
« no previous file with comments | « chrome/browser/plugin_exceptions_table_model_unittest.cc ('k') | chrome/browser/plugin_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698