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

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

Issue 7901015: Revert 101269 - Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo, to ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
Property Changes:
Added: svn:mergeinfo
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>
10 #include <set> 9 #include <set>
11 #include <vector> 10 #include <vector>
12 11
13 #include "base/basictypes.h" 12 #include "base/basictypes.h"
14 #include "base/file_path.h" 13 #include "base/file_path.h"
15 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
17 #include "chrome/browser/prefs/pref_change_registrar.h" 15 #include "chrome/browser/prefs/pref_change_registrar.h"
18 #include "content/common/notification_observer.h" 16 #include "content/common/notification_observer.h"
19 17
20 class NotificationDetails; 18 class NotificationDetails;
21 class NotificationSource; 19 class NotificationSource;
22 class Profile; 20 class Profile;
23 21
24 namespace content { 22 namespace content {
25 class ResourceContext; 23 class ResourceContext;
26 } 24 }
27 25
28 namespace base { 26 namespace base {
29 class DictionaryValue; 27 class DictionaryValue;
30 class ListValue; 28 class ListValue;
31 } 29 }
32 30
33 namespace webkit { 31 namespace webkit {
34 struct WebPluginInfo; 32 struct WebPluginInfo;
35 namespace npapi { 33 namespace npapi {
36 class PluginGroup; 34 class PluginGroup;
37 } 35 }
38 } 36 }
39 37
40 // This class stores information about whether a plug-in or a plug-in group is 38 // This class stores information about whether a plug-in or a plug-in group is
41 // enabled or disabled. 39 // enabled or disabled.
42 // Except where otherwise noted, it can be used on every thread. 40 // Except for the |IsPluginEnabled| method, it should only be used on the UI
41 // thread.
43 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, 42 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
44 public NotificationObserver { 43 public NotificationObserver {
45 public: 44 public:
46 enum PolicyStatus {
47 NO_POLICY = 0, // Neither enabled or disabled by policy.
48 POLICY_ENABLED,
49 POLICY_DISABLED,
50 };
51
52 // Initializes the factory for this class for dependency tracking. 45 // Initializes the factory for this class for dependency tracking.
53 // This should be called before the first profile is created. 46 // This should be called before the first profile is created.
54 static void Initialize(); 47 static void Initialize();
55 48
56 // Returns the instance associated with |profile|, creating it if necessary. 49 // Returns the instance associated with |profile|, creating it if necessary.
57 static PluginPrefs* GetForProfile(Profile* profile); 50 static PluginPrefs* GetForProfile(Profile* profile);
58 51
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
64 // Creates a new instance. This method should only be used for testing. 52 // Creates a new instance. This method should only be used for testing.
65 PluginPrefs(); 53 PluginPrefs();
66 54
67 // Associates this instance with |prefs|. This enables or disables 55 // Associates this instance with |prefs|. This enables or disables
68 // plugin groups as defined by the user's preferences. 56 // plugin groups as defined by the user's preferences.
69 // This method should only be called on the UI thread.
70 void SetPrefs(PrefService* prefs); 57 void SetPrefs(PrefService* prefs);
71 58
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
76 // Enable or disable a plugin group. 59 // Enable or disable a plugin group.
77 void EnablePluginGroup(bool enable, const string16& group_name); 60 void EnablePluginGroup(bool enable, const string16& group_name);
78 61
79 // Enable or disable a specific plugin file. 62 // Enable or disable a specific plugin file.
80 void EnablePlugin(bool enable, const FilePath& file_path); 63 void EnablePlugin(bool enable, const FilePath& file_path);
81 64
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
91 // Returns whether the plugin is enabled or not. 65 // Returns whether the plugin is enabled or not.
92 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin); 66 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin);
93 67
94 // Registers the preferences used by this class. 68 // Write the enable/disable status to the user's preference file.
95 // This method should only be called on the UI thread. 69 void UpdatePreferences(int delay_ms);
70
71 // NotificationObserver method overrides
72 virtual void Observe(int type,
73 const NotificationSource& source,
74 const NotificationDetails& details);
75
96 static void RegisterPrefs(PrefService* prefs); 76 static void RegisterPrefs(PrefService* prefs);
97 77
98 // NotificationObserver method override. 78 void ShutdownOnUIThread();
99 virtual void Observe(int type,
100 const NotificationSource& source,
101 const NotificationDetails& details) OVERRIDE;
102 79
103 private: 80 private:
104 friend class base::RefCountedThreadSafe<PluginPrefs>; 81 friend class base::RefCountedThreadSafe<PluginPrefs>;
105 friend class PluginPrefsTest;
106 82
107 class Factory; 83 class Factory;
108 84
109 virtual ~PluginPrefs(); 85 virtual ~PluginPrefs();
110 86
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
117 // Called on the file thread to get the data necessary to update the saved 87 // Called on the file thread to get the data necessary to update the saved
118 // preferences. 88 // preferences.
119 void GetPreferencesDataOnFileThread(); 89 void GetPreferencesDataOnFileThread();
120 90
121 // Called on the UI thread with the plugin data to save the preferences. 91 // Called on the UI thread with the plugin data to save the preferences.
122 void OnUpdatePreferences(std::vector<webkit::npapi::PluginGroup> groups); 92 void OnUpdatePreferences(std::vector<webkit::WebPluginInfo> plugins,
93 std::vector<webkit::npapi::PluginGroup> groups);
123 94
124 // Sends the notification that plugin data has changed. 95 // Queues sending the notification that plugin data has changed. This is done
96 // so that if a bunch of changes happen, we only send one notification.
125 void NotifyPluginStatusChanged(); 97 void NotifyPluginStatusChanged();
126 98
127 static void ListValueToStringSet(const base::ListValue* src, 99 // Used for the post task to notify that plugin enabled status changed.
128 std::set<string16>* dest); 100 void OnNotifyPluginStatusChanged();
129 101
130 // Checks if |name| matches any of the patterns in |pattern_set|. 102 base::DictionaryValue* CreatePluginFileSummary(
131 static bool IsStringMatchedInSet(const string16& name, 103 const webkit::WebPluginInfo& plugin);
132 const std::set<string16>& pattern_set);
133 104
134 // Guards access to the following data structures. 105 // Force plugins to be enabled or disabled due to policy.
135 mutable base::Lock lock_; 106 // |disabled_list| contains the list of StringValues of the names of the
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);
136 112
137 std::map<FilePath, bool> plugin_state_; 113 void ListValueToStringSet(const base::ListValue* src,
138 std::map<string16, bool> plugin_group_state_; 114 std::set<string16>* dest);
139 115
140 std::set<string16> policy_disabled_plugin_patterns_; 116 // Weak pointer, owned by the profile.
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).
145 PrefService* prefs_; 117 PrefService* prefs_;
146 118
147 PrefChangeRegistrar registrar_; 119 PrefChangeRegistrar registrar_;
148 120
121 bool notify_pending_;
122
149 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); 123 DISALLOW_COPY_AND_ASSIGN(PluginPrefs);
150 }; 124 };
151 125
152 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_ 126 #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