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

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

Issue 7564006: Rename PluginUpdater to PluginPrefs and make it per-profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 4 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_UPDATER_H_ 5 #ifndef CHROME_BROWSER_PLUGIN_PREFS_H_
6 #define CHROME_BROWSER_PLUGIN_UPDATER_H_ 6 #define CHROME_BROWSER_PLUGIN_PREFS_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/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/task.h"
15 #include "chrome/browser/prefs/pref_change_registrar.h" 16 #include "chrome/browser/prefs/pref_change_registrar.h"
17 #include "chrome/browser/profiles/profile_keyed_service.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 base { 24 namespace base {
23 class DictionaryValue; 25 class DictionaryValue;
24 class ListValue; 26 class ListValue;
25 } 27 }
26 28
27 namespace webkit { 29 namespace webkit {
28 namespace npapi { 30 namespace npapi {
29 class PluginGroup; 31 class PluginGroup;
30 struct WebPluginInfo; 32 struct WebPluginInfo;
31 } 33 }
32 } 34 }
33 35
34 class PluginUpdater : public NotificationObserver { 36 class PluginPrefs : public ProfileKeyedService,
Elliot Glaysher 2011/08/04 17:51:00 Consider calling this PluginService, if to have a
Bernhard Bauer 2011/08/05 13:42:20 There is already a singleton in content/ called Pl
37 public NotificationObserver {
35 public: 38 public:
36 // Get a list of all the plugin groups. The caller should take ownership 39 // This should be called before the first profile is created.
Elliot Glaysher 2011/08/04 17:51:00 Please mention that this will initialize the facto
Bernhard Bauer 2011/08/05 13:42:20 Done.
37 // of the returned ListValue. 40 static void Initialize();
38 static base::ListValue* GetPluginGroupsData(); 41
42 // This method should only be called on the UI thread.
43 static PluginPrefs* GetForProfile(Profile* profile);
39 44
40 // Enable or disable a plugin group. 45 // Enable or disable a plugin group.
41 void EnablePluginGroup(bool enable, const string16& group_name); 46 void EnablePluginGroup(bool enable, const string16& group_name);
42 47
43 // Enable or disable a specific plugin file. 48 // Enable or disable a specific plugin file.
44 void EnablePlugin(bool enable, const FilePath::StringType& file_path); 49 void EnablePlugin(bool enable, const FilePath& file_path);
45 50
46 // Associates the PluginUpdater with |profile|. This enables or disables 51 // Returns whether the plugin is enabled or not.
52 bool IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin);
53
54 // Associates the PluginPrefs with |profile|. This enables or disables
47 // plugin groups as defined by the user's preferences. 55 // plugin groups as defined by the user's preferences.
48 void SetProfile(Profile* profile); 56 void SetProfile(Profile* profile);
49 57
50 // Called at shutdown before the profile is destroyed.
51 void Shutdown();
52
53 // Write the enable/disable status to the user's preference file. 58 // Write the enable/disable status to the user's preference file.
54 void UpdatePreferences(Profile* profile, int delay_ms); 59 void UpdatePreferences(int delay_ms);
55 60
56 // NotificationObserver method overrides 61 // NotificationObserver method overrides
57 virtual void Observe(int type, 62 virtual void Observe(int type,
58 const NotificationSource& source, 63 const NotificationSource& source,
59 const NotificationDetails& details); 64 const NotificationDetails& details);
60 65
61 static PluginUpdater* GetInstance();
62
63 static void RegisterPrefs(PrefService* prefs); 66 static void RegisterPrefs(PrefService* prefs);
64 67
68 // ProfileKeyedService methods:
69 virtual void Shutdown() OVERRIDE;
70
65 private: 71 private:
66 PluginUpdater(); 72 class Factory;
67 virtual ~PluginUpdater() {} 73 struct PluginInfo;
74
75 PluginPrefs();
76 virtual ~PluginPrefs() {}
68 77
69 // Called on the file thread to get the data necessary to update the saved 78 // Called on the file thread to get the data necessary to update the saved
70 // preferences. The profile pointer is only to be passed to the UI thread. 79 // preferences.
71 static void GetPreferencesDataOnFileThread(void* profile); 80 static void GetPreferencesDataOnFileThread(PluginInfo* plugin_info,
81 Task* callback);
72 82
73 // Called on the UI thread with the plugin data to save the preferences. 83 // Called on the UI thread with the plugin data to save the preferences.
74 static void OnUpdatePreferences( 84 void OnUpdatePreferences(const PluginInfo* plugin_info);
75 Profile* profile, 85
76 const std::vector<webkit::npapi::WebPluginInfo>& plugins, 86 // Called on the UI thread after |OnUpdatePreference| to make sure that
77 const std::vector<webkit::npapi::PluginGroup>& groups); 87 // |plugin_info| isn't leaked even when the PluginPrefs instance should go
88 // away.
89 static void DeletePluginInfo(PluginInfo* plugin_info);
78 90
79 // Queues sending the notification that plugin data has changed. This is done 91 // Queues sending the notification that plugin data has changed. This is done
80 // so that if a bunch of changes happen, we only send one notification. 92 // so that if a bunch of changes happen, we only send one notification.
81 void NotifyPluginStatusChanged(); 93 void NotifyPluginStatusChanged();
82 94
83 // Used for the post task to notify that plugin enabled status changed. 95 // Used for the post task to notify that plugin enabled status changed.
84 static void OnNotifyPluginStatusChanged(); 96 void OnNotifyPluginStatusChanged();
85 97
86 static base::DictionaryValue* CreatePluginFileSummary( 98 base::DictionaryValue* CreatePluginFileSummary(
87 const webkit::npapi::WebPluginInfo& plugin); 99 const webkit::npapi::WebPluginInfo& plugin);
88 100
89 // Force plugins to be enabled or disabled due to policy. 101 // Force plugins to be enabled or disabled due to policy.
90 // |disabled_list| contains the list of StringValues of the names of the 102 // |disabled_list| contains the list of StringValues of the names of the
91 // policy-disabled plugins, |exceptions_list| the policy-allowed plugins, 103 // policy-disabled plugins, |exceptions_list| the policy-allowed plugins,
92 // and |enabled_list| the policy-enabled plugins. 104 // and |enabled_list| the policy-enabled plugins.
93 void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list, 105 void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list,
94 const base::ListValue* exceptions_list, 106 const base::ListValue* exceptions_list,
95 const base::ListValue* enabled_list); 107 const base::ListValue* enabled_list);
96 108
97 void ListValueToStringSet(const base::ListValue* src, 109 void ListValueToStringSet(const base::ListValue* src,
98 std::set<string16>* dest); 110 std::set<string16>* dest);
99 111
100 // Needed to allow singleton instantiation using private constructor. 112 // Weak pointer, owned by the profile.
101 friend struct DefaultSingletonTraits<PluginUpdater>; 113 PrefService* prefs_;
114
115 ScopedRunnableMethodFactory<PluginPrefs> factory_;
102 116
103 PrefChangeRegistrar registrar_; 117 PrefChangeRegistrar registrar_;
104 118
105 bool notify_pending_; 119 bool notify_pending_;
106 120
107 DISALLOW_COPY_AND_ASSIGN(PluginUpdater); 121 DISALLOW_COPY_AND_ASSIGN(PluginPrefs);
108 }; 122 };
109 123
110 #endif // CHROME_BROWSER_PLUGIN_UPDATER_H_ 124 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698