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

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

Issue 10933044: Move chrome/browser/plugin_* to chrome/browser/plugins/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@remove_plugin_group
Patch Set: . 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/plugin_observer.cc ('k') | chrome/browser/plugin_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PLUGIN_PREFS_H_
6 #define CHROME_BROWSER_PLUGIN_PREFS_H_
7
8 #include <map>
9 #include <set>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/file_path.h"
14 #include "base/synchronization/lock.h"
15 #include "chrome/browser/api/prefs/pref_change_registrar.h"
16 #include "chrome/browser/plugin_finder.h"
17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
19 #include "content/public/browser/notification_observer.h"
20
21 class Profile;
22
23 namespace base {
24 class ListValue;
25 }
26
27 namespace webkit {
28 struct WebPluginInfo;
29 namespace npapi {
30 class PluginGroup;
31 class PluginList;
32 }
33 }
34
35 // This class stores information about whether a plug-in or a plug-in group is
36 // enabled or disabled.
37 // Except where otherwise noted, it can be used on every thread.
38 class PluginPrefs : public RefcountedProfileKeyedService,
39 public content::NotificationObserver {
40 public:
41 enum PolicyStatus {
42 NO_POLICY = 0, // Neither enabled or disabled by policy.
43 POLICY_ENABLED,
44 POLICY_DISABLED,
45 };
46
47 // Returns the instance associated with |profile|, creating it if necessary.
48 static scoped_refptr<PluginPrefs> GetForProfile(Profile* profile);
49
50 // Usually the PluginPrefs associated with a TestingProfile is NULL.
51 // This method overrides that for a given TestingProfile, returning the newly
52 // created PluginPrefs object.
53 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile);
54
55 // Sets the plug-in list for tests.
56 void SetPluginListForTesting(webkit::npapi::PluginList* plugin_list);
57
58 // Creates a new instance. This method should only be used for testing.
59 PluginPrefs();
60
61 // Associates this instance with |prefs|. This enables or disables
62 // plugin groups as defined by the user's preferences.
63 // This method should only be called on the UI thread.
64 void SetPrefs(PrefService* prefs);
65
66 // Enable or disable a plugin group.
67 void EnablePluginGroup(bool enable, const string16& group_name);
68
69 // Enables or disables a specific plug-in file, if possible.
70 // If the plug-in state can't be changed (because of a policy for example)
71 // then enabling/disabling the plug-in is ignored and |callback| is run
72 // with 'false' passed to it. Otherwise the plug-in state is changed
73 // and |callback| is run with 'true' passed to it.
74 void EnablePlugin(bool enable, const FilePath& file_path,
75 const base::Callback<void(bool)>& callback);
76
77 // Returns whether there is a policy enabling or disabling plug-ins of the
78 // given name.
79 PolicyStatus PolicyStatusForPlugin(const string16& name) const;
80
81 // Returns whether the plugin is enabled or not.
82 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin) const;
83
84 void set_profile(Profile* profile) { profile_ = profile; }
85
86 // RefCountedProfileKeyedBase method override.
87 virtual void ShutdownOnUIThread() OVERRIDE;
88
89 // content::NotificationObserver method override.
90 virtual void Observe(int type,
91 const content::NotificationSource& source,
92 const content::NotificationDetails& details) OVERRIDE;
93
94 private:
95 friend class base::RefCountedThreadSafe<PluginPrefs>;
96 friend class PluginPrefsTest;
97
98 // PluginState stores a mapping from plugin path to enable/disable state. We
99 // don't simply use a std::map, because we would like to keep the state of
100 // some plugins in sync with each other.
101 class PluginState {
102 public:
103 PluginState();
104 ~PluginState();
105
106 // Returns whether |plugin| is found. If |plugin| cannot be found,
107 // |*enabled| won't be touched.
108 bool Get(const FilePath& plugin, bool* enabled) const;
109 void Set(const FilePath& plugin, bool enabled);
110 // It is similar to Set(), except that it does nothing if |plugin| needs to
111 // be converted to a different key.
112 void SetIgnorePseudoKey(const FilePath& plugin, bool enabled);
113
114 private:
115 FilePath ConvertMapKey(const FilePath& plugin) const;
116
117 std::map<FilePath, bool> state_;
118 };
119
120 virtual ~PluginPrefs();
121
122 // Allows unit tests to directly set enforced plug-in patterns.
123 void SetPolicyEnforcedPluginPatterns(
124 const std::set<string16>& disabled_patterns,
125 const std::set<string16>& disabled_exception_patterns,
126 const std::set<string16>& enabled_patterns);
127
128 // Returns the plugin list to use, either the singleton or the override.
129 webkit::npapi::PluginList* GetPluginList() const;
130
131 // Callback for after the plugin groups have been loaded.
132 void EnablePluginGroupInternal(
133 bool enabled,
134 const string16& group_name,
135 PluginFinder* plugin_finder,
136 const std::vector<webkit::WebPluginInfo>& plugins);
137 void EnablePluginInternal(
138 bool enabled,
139 const FilePath& path,
140 PluginFinder* plugin_finder,
141 const base::Callback<void(bool)>& callback,
142 const std::vector<webkit::WebPluginInfo>& plugins);
143
144 // Called on the file thread to get the data necessary to update the saved
145 // preferences.
146 void GetPreferencesDataOnFileThread();
147
148 // Called on the UI thread with the plugin data to save the preferences.
149 void OnUpdatePreferences(const std::vector<webkit::WebPluginInfo>& plugins,
150 PluginFinder* finder);
151
152 // Sends the notification that plugin data has changed.
153 void NotifyPluginStatusChanged();
154
155 static void ListValueToStringSet(const base::ListValue* src,
156 std::set<string16>* dest);
157
158 // Checks if |name| matches any of the patterns in |pattern_set|.
159 static bool IsStringMatchedInSet(const string16& name,
160 const std::set<string16>& pattern_set);
161
162 // Callback method called by 'EnablePlugin' method.
163 // It performs the logic to check if a plug-in can be enabled.
164 void EnablePluginIfPossibleCallback(
165 bool enabled, const FilePath& path,
166 const base::Callback<void(bool)>& canEnableCallback,
167 PluginFinder* finder);
168
169 // Callback method that takes in the asynchronously created
170 // plug-in finder instance. It is called by 'EnablePluginGroup'.
171 void GetPluginFinderForEnablePluginGroup(bool enabled,
172 const string16& group_name,
173 PluginFinder* finder);
174
175 // Callback method that takes in the asynchronously created plug-in finder
176 // instance. It is called by 'GetPreferencesDataOnFileThread'.
177 void GetPluginFinderForGetPreferencesDataOnFileThread(PluginFinder* finder);
178
179 // Guards access to the following data structures.
180 mutable base::Lock lock_;
181
182 PluginState plugin_state_;
183 std::map<string16, bool> plugin_group_state_;
184
185 std::set<string16> policy_disabled_plugin_patterns_;
186 std::set<string16> policy_disabled_plugin_exception_patterns_;
187 std::set<string16> policy_enabled_plugin_patterns_;
188
189 // Weak pointer, owns us. Only used as a notification source.
190 Profile* profile_;
191
192 // Weak pointer, owned by the profile.
193 PrefService* prefs_;
194
195 // PluginList to use for testing. If this is NULL, defaults to the global
196 // singleton.
197 webkit::npapi::PluginList* plugin_list_;
198
199 PrefChangeRegistrar registrar_;
200
201 DISALLOW_COPY_AND_ASSIGN(PluginPrefs);
202 };
203
204 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_
OLDNEW
« no previous file with comments | « chrome/browser/plugin_observer.cc ('k') | chrome/browser/plugin_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698