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

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

Issue 10872034: Changing PluginPrefs to use PluginFinder's async interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@test_async
Patch Set: Addressing more comments from bauerb 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "chrome/browser/api/prefs/pref_change_registrar.h" 15 #include "chrome/browser/api/prefs/pref_change_registrar.h"
16 #include "chrome/browser/plugin_finder.h"
16 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" 18 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
18 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
19 20
20 class Profile; 21 class Profile;
21 22
22 namespace base { 23 namespace base {
23 class ListValue; 24 class ListValue;
24 } 25 }
25 26
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 PluginPrefs(); 59 PluginPrefs();
59 60
60 // Associates this instance with |prefs|. This enables or disables 61 // Associates this instance with |prefs|. This enables or disables
61 // plugin groups as defined by the user's preferences. 62 // plugin groups as defined by the user's preferences.
62 // This method should only be called on the UI thread. 63 // This method should only be called on the UI thread.
63 void SetPrefs(PrefService* prefs); 64 void SetPrefs(PrefService* prefs);
64 65
65 // Enable or disable a plugin group. 66 // Enable or disable a plugin group.
66 void EnablePluginGroup(bool enable, const string16& group_name); 67 void EnablePluginGroup(bool enable, const string16& group_name);
67 68
68 // Returns true if the plug-in state can be enabled or disabled according to 69 // Enables or disables a specific plug-in file, if possible.
69 // |enable|, false if the plug-in state cannot be changed because of a policy. 70 // If the plug-in state can't be changed (because of a policy for example)
70 bool CanEnablePlugin(bool enable, const FilePath& file_path); 71 // then enabling/disabling the plug-in is ignored and |callback| is run
71 72 // with 'false' passed to it. Otherwise the plug-in state is changed
72 // Enables or disables a specific plugin file, and calls |callback| 73 // and |callback| is run with 'true' passed to it.
73 // afterwards.
74 // If the plug-in state cannot be changed because of a policy (as indicated
75 // by |CanEnablePlugin|), it will be silently ignored.
76 void EnablePlugin(bool enable, const FilePath& file_path, 74 void EnablePlugin(bool enable, const FilePath& file_path,
77 const base::Closure& callback); 75 const base::Callback<void(bool)>& callback);
78 76
79 // Enables or disables a plug-in in all profiles, and calls |callback| 77 // Enables or disables a plug-in in all profiles, and calls |callback|
80 // afterwards. This sets a default for profiles which are created later as 78 // afterwards. This sets a default for profiles which are created later as
81 // well. 79 // well.
82 // If the plug-in state in a profile cannot be changed because of a policy, 80 // If the plug-in state in a profile cannot be changed because of a policy,
83 // it will be silently ignored. 81 // it will be silently ignored.
84 // This method should only be called on the UI thread. 82 // This method should only be called on the UI thread.
85 static void EnablePluginGlobally(bool enable, const FilePath& file_path, 83 static void EnablePluginGlobally(bool enable, const FilePath& file_path,
86 const base::Closure& callback); 84 const base::Callback<void(bool)>& callback);
87 85
88 // Returns whether there is a policy enabling or disabling plug-ins of the 86 // Returns whether there is a policy enabling or disabling plug-ins of the
89 // given name. 87 // given name.
90 PolicyStatus PolicyStatusForPlugin(const string16& name) const; 88 PolicyStatus PolicyStatusForPlugin(const string16& name) const;
91 89
92 // Returns whether the plugin is enabled or not. 90 // Returns whether the plugin is enabled or not.
93 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin) const; 91 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin) const;
94 92
95 // Registers the preferences used by this class. 93 // Registers the preferences used by this class.
96 // This method should only be called on the UI thread. 94 // This method should only be called on the UI thread.
(...skipping 21 matching lines...) Expand all
118 const std::set<string16>& disabled_exception_patterns, 116 const std::set<string16>& disabled_exception_patterns,
119 const std::set<string16>& enabled_patterns); 117 const std::set<string16>& enabled_patterns);
120 118
121 // Returns the plugin list to use, either the singleton or the override. 119 // Returns the plugin list to use, either the singleton or the override.
122 webkit::npapi::PluginList* GetPluginList() const; 120 webkit::npapi::PluginList* GetPluginList() const;
123 121
124 // Callback for after the plugin groups have been loaded. 122 // Callback for after the plugin groups have been loaded.
125 void EnablePluginGroupInternal( 123 void EnablePluginGroupInternal(
126 bool enabled, 124 bool enabled,
127 const string16& group_name, 125 const string16& group_name,
128 const std::vector<webkit::npapi::PluginGroup>& groups); 126 PluginFinder* plugin_finder,
127 const std::vector<webkit::WebPluginInfo>& plugins);
129 void EnablePluginInternal( 128 void EnablePluginInternal(
130 bool enabled, 129 bool enabled,
131 const FilePath& path, 130 const FilePath& path,
132 const base::Closure& callback, 131 PluginFinder* plugin_finder,
133 const std::vector<webkit::npapi::PluginGroup>& groups); 132 const base::Callback<void(bool)>& callback,
133 const std::vector<webkit::WebPluginInfo>& plugins);
134 134
135 // Called on the file thread to get the data necessary to update the saved 135 // Called on the file thread to get the data necessary to update the saved
136 // preferences. 136 // preferences.
137 void GetPreferencesDataOnFileThread(); 137 void GetPreferencesDataOnFileThread();
138 138
139 // Called on the UI thread with the plugin data to save the preferences. 139 // Called on the UI thread with the plugin data to save the preferences.
140 void OnUpdatePreferences( 140 void OnUpdatePreferences(const std::vector<webkit::WebPluginInfo>& plugins,
141 const std::vector<webkit::npapi::PluginGroup>& groups); 141 PluginFinder* finder);
142 142
143 // Sends the notification that plugin data has changed. 143 // Sends the notification that plugin data has changed.
144 void NotifyPluginStatusChanged(); 144 void NotifyPluginStatusChanged();
145 145
146 static void ListValueToStringSet(const base::ListValue* src, 146 static void ListValueToStringSet(const base::ListValue* src,
147 std::set<string16>* dest); 147 std::set<string16>* dest);
148 148
149 // Checks if |name| matches any of the patterns in |pattern_set|. 149 // Checks if |name| matches any of the patterns in |pattern_set|.
150 static bool IsStringMatchedInSet(const string16& name, 150 static bool IsStringMatchedInSet(const string16& name,
151 const std::set<string16>& pattern_set); 151 const std::set<string16>& pattern_set);
152 152
153 // Callback method called by 'EnablePlugin' method.
154 // It performs the logic to check if a plug-in can be enabled.
155 void EnablePluginIfPossibleCallback(
156 bool enabled, const FilePath& path,
157 const base::Callback<void(bool)>& canEnableCallback,
158 PluginFinder* finder);
159
160 // Callback method that takes in the asynchronously created
161 // plug-in finder instance. It is called by 'EnablePluginGroup'.
162 void GetPluginFinderForEnablePluginGroup(bool enabled,
163 const string16& group_name,
164 PluginFinder* finder);
165
166 // Callback method that takes in the asynchronously created plug-in finder
167 // instance. It is called by 'GetPreferencesDataOnFileThread'.
168 void GetPluginFinderForGetPreferencesDataOnFileThread(PluginFinder* finder);
169
153 // Guards access to the following data structures. 170 // Guards access to the following data structures.
154 mutable base::Lock lock_; 171 mutable base::Lock lock_;
155 172
156 std::map<FilePath, bool> plugin_state_; 173 std::map<FilePath, bool> plugin_state_;
157 std::map<string16, bool> plugin_group_state_; 174 std::map<string16, bool> plugin_group_state_;
158 175
159 std::set<string16> policy_disabled_plugin_patterns_; 176 std::set<string16> policy_disabled_plugin_patterns_;
160 std::set<string16> policy_disabled_plugin_exception_patterns_; 177 std::set<string16> policy_disabled_plugin_exception_patterns_;
161 std::set<string16> policy_enabled_plugin_patterns_; 178 std::set<string16> policy_enabled_plugin_patterns_;
162 179
163 // Weak pointer, owns us. Only used as a notification source. 180 // Weak pointer, owns us. Only used as a notification source.
164 Profile* profile_; 181 Profile* profile_;
165 182
166 // Weak pointer, owned by the profile. 183 // Weak pointer, owned by the profile.
167 PrefService* prefs_; 184 PrefService* prefs_;
168 185
169 // PluginList to use for testing. If this is NULL, defaults to the global 186 // PluginList to use for testing. If this is NULL, defaults to the global
170 // singleton. 187 // singleton.
171 webkit::npapi::PluginList* plugin_list_; 188 webkit::npapi::PluginList* plugin_list_;
172 189
173 PrefChangeRegistrar registrar_; 190 PrefChangeRegistrar registrar_;
174 191
175 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); 192 DISALLOW_COPY_AND_ASSIGN(PluginPrefs);
176 }; 193 };
177 194
178 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_ 195 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698