OLD | NEW |
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_UPDATER_H_ |
6 #define CHROME_BROWSER_PLUGIN_PREFS_H_ | 6 #define CHROME_BROWSER_PLUGIN_UPDATER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
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/memory/ref_counted.h" | 14 #include "base/memory/singleton.h" |
15 #include "chrome/browser/prefs/pref_change_registrar.h" | 15 #include "chrome/browser/prefs/pref_change_registrar.h" |
16 #include "content/common/notification_observer.h" | 16 #include "content/common/notification_observer.h" |
17 | 17 |
18 class NotificationDetails; | 18 class NotificationDetails; |
19 class NotificationSource; | 19 class NotificationSource; |
20 class Profile; | 20 class Profile; |
21 | 21 |
22 namespace content { | |
23 class ResourceContext; | |
24 } | |
25 | |
26 namespace base { | 22 namespace base { |
27 class DictionaryValue; | 23 class DictionaryValue; |
28 class ListValue; | 24 class ListValue; |
29 } | 25 } |
30 | 26 |
31 namespace webkit { | 27 namespace webkit { |
32 namespace npapi { | 28 namespace npapi { |
33 class PluginGroup; | 29 class PluginGroup; |
34 struct WebPluginInfo; | 30 struct WebPluginInfo; |
35 } | 31 } |
36 } | 32 } |
37 | 33 |
38 // This class stores information about whether a plug-in or a plug-in group is | 34 class PluginUpdater : public NotificationObserver { |
39 // enabled or disabled. | |
40 // Except for the |IsPluginEnabled| method, it should only be used on the UI | |
41 // thread. | |
42 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, | |
43 public NotificationObserver { | |
44 public: | 35 public: |
45 // Initializes the factory for this class for dependency tracking. | 36 // Get a list of all the plugin groups. The caller should take ownership |
46 // This should be called before the first profile is created. | 37 // of the returned ListValue. |
47 static void Initialize(); | 38 static base::ListValue* GetPluginGroupsData(); |
48 | |
49 static PluginPrefs* GetForProfile(Profile* profile); | |
50 | 39 |
51 // Enable or disable a plugin group. | 40 // Enable or disable a plugin group. |
52 void EnablePluginGroup(bool enable, const string16& group_name); | 41 void EnablePluginGroup(bool enable, const string16& group_name); |
53 | 42 |
54 // Enable or disable a specific plugin file. | 43 // Enable or disable a specific plugin file. |
55 void EnablePlugin(bool enable, const FilePath& file_path); | 44 void EnablePlugin(bool enable, const FilePath::StringType& file_path); |
56 | 45 |
57 // Returns whether the plugin is enabled or not. | 46 // Associates the PluginUpdater with |profile|. This enables or disables |
58 bool IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin); | 47 // plugin groups as defined by the user's preferences. |
| 48 void SetProfile(Profile* profile); |
| 49 |
| 50 // Called at shutdown before the profile is destroyed. |
| 51 void Shutdown(); |
59 | 52 |
60 // Write the enable/disable status to the user's preference file. | 53 // Write the enable/disable status to the user's preference file. |
61 void UpdatePreferences(int delay_ms); | 54 void UpdatePreferences(Profile* profile, int delay_ms); |
62 | 55 |
63 // NotificationObserver method overrides | 56 // NotificationObserver method overrides |
64 virtual void Observe(int type, | 57 virtual void Observe(int type, |
65 const NotificationSource& source, | 58 const NotificationSource& source, |
66 const NotificationDetails& details); | 59 const NotificationDetails& details); |
67 | 60 |
| 61 static PluginUpdater* GetInstance(); |
| 62 |
68 static void RegisterPrefs(PrefService* prefs); | 63 static void RegisterPrefs(PrefService* prefs); |
69 | 64 |
70 void ShutdownOnUIThread(); | |
71 | |
72 private: | 65 private: |
73 friend class base::RefCountedThreadSafe<PluginPrefs>; | 66 PluginUpdater(); |
74 | 67 virtual ~PluginUpdater() {} |
75 class Factory; | |
76 | |
77 PluginPrefs(); | |
78 virtual ~PluginPrefs(); | |
79 | |
80 // Associates the PluginPrefs with |profile|. This enables or disables | |
81 // plugin groups as defined by the user's preferences. | |
82 void SetProfile(Profile* profile); | |
83 | 68 |
84 // Called on the file thread to get the data necessary to update the saved | 69 // Called on the file thread to get the data necessary to update the saved |
85 // preferences. | 70 // preferences. The profile pointer is only to be passed to the UI thread. |
86 void GetPreferencesDataOnFileThread(); | 71 static void GetPreferencesDataOnFileThread(void* profile); |
87 | 72 |
88 // Called on the UI thread with the plugin data to save the preferences. | 73 // Called on the UI thread with the plugin data to save the preferences. |
89 void OnUpdatePreferences(std::vector<webkit::npapi::WebPluginInfo> plugins, | 74 static void OnUpdatePreferences( |
90 std::vector<webkit::npapi::PluginGroup> groups); | 75 Profile* profile, |
| 76 const std::vector<webkit::npapi::WebPluginInfo>& plugins, |
| 77 const std::vector<webkit::npapi::PluginGroup>& groups); |
91 | 78 |
92 // Queues sending the notification that plugin data has changed. This is done | 79 // Queues sending the notification that plugin data has changed. This is done |
93 // so that if a bunch of changes happen, we only send one notification. | 80 // so that if a bunch of changes happen, we only send one notification. |
94 void NotifyPluginStatusChanged(); | 81 void NotifyPluginStatusChanged(); |
95 | 82 |
96 // Used for the post task to notify that plugin enabled status changed. | 83 // Used for the post task to notify that plugin enabled status changed. |
97 void OnNotifyPluginStatusChanged(); | 84 static void OnNotifyPluginStatusChanged(); |
98 | 85 |
99 base::DictionaryValue* CreatePluginFileSummary( | 86 static base::DictionaryValue* CreatePluginFileSummary( |
100 const webkit::npapi::WebPluginInfo& plugin); | 87 const webkit::npapi::WebPluginInfo& plugin); |
101 | 88 |
102 // Force plugins to be enabled or disabled due to policy. | 89 // Force plugins to be enabled or disabled due to policy. |
103 // |disabled_list| contains the list of StringValues of the names of the | 90 // |disabled_list| contains the list of StringValues of the names of the |
104 // policy-disabled plugins, |exceptions_list| the policy-allowed plugins, | 91 // policy-disabled plugins, |exceptions_list| the policy-allowed plugins, |
105 // and |enabled_list| the policy-enabled plugins. | 92 // and |enabled_list| the policy-enabled plugins. |
106 void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list, | 93 void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list, |
107 const base::ListValue* exceptions_list, | 94 const base::ListValue* exceptions_list, |
108 const base::ListValue* enabled_list); | 95 const base::ListValue* enabled_list); |
109 | 96 |
110 void ListValueToStringSet(const base::ListValue* src, | 97 void ListValueToStringSet(const base::ListValue* src, |
111 std::set<string16>* dest); | 98 std::set<string16>* dest); |
112 | 99 |
113 // Weak pointer, owned by the profile. | 100 // Needed to allow singleton instantiation using private constructor. |
114 PrefService* prefs_; | 101 friend struct DefaultSingletonTraits<PluginUpdater>; |
115 | 102 |
116 PrefChangeRegistrar registrar_; | 103 PrefChangeRegistrar registrar_; |
117 | 104 |
118 bool notify_pending_; | 105 bool notify_pending_; |
119 | 106 |
120 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); | 107 DISALLOW_COPY_AND_ASSIGN(PluginUpdater); |
121 }; | 108 }; |
122 | 109 |
123 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_ | 110 #endif // CHROME_BROWSER_PLUGIN_UPDATER_H_ |
OLD | NEW |