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_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // A content settings provider that takes its settings out of the pref service. | 9 // A content settings provider that takes its settings out of the pref service. |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h" | 17 #include "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h" |
18 #include "chrome/browser/content_settings/content_settings_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_provider.h" |
19 #include "chrome/browser/content_settings/content_settings_utils.h" | 19 #include "chrome/browser/content_settings/content_settings_utils.h" |
20 #include "chrome/browser/prefs/pref_change_registrar.h" | 20 #include "chrome/browser/prefs/pref_change_registrar.h" |
21 #include "content/common/notification_observer.h" | 21 #include "content/common/notification_observer.h" |
22 #include "content/common/notification_registrar.h" | 22 #include "content/common/notification_registrar.h" |
23 | 23 |
24 class ContentSettingsDetails; | 24 class ContentSettingsDetails; |
25 class DictionaryValue; | 25 class DictionaryValue; |
26 class HostContentSettingsMap; | |
26 class PrefService; | 27 class PrefService; |
27 class Profile; | |
28 | 28 |
29 namespace content_settings { | 29 namespace content_settings { |
30 | 30 |
31 // Content settings provider that provides default content settings based on | 31 // Content settings provider that provides default content settings based on |
32 // user prefs. | 32 // user prefs. |
33 class PrefDefaultProvider : public DefaultProviderInterface, | 33 class PrefDefaultProvider : public DefaultProviderInterface, |
34 public NotificationObserver { | 34 public NotificationObserver { |
35 public: | 35 public: |
36 explicit PrefDefaultProvider(Profile* profile); | 36 PrefDefaultProvider(HostContentSettingsMap* map, |
37 PrefService* prefs, | |
38 bool incognito); | |
37 virtual ~PrefDefaultProvider(); | 39 virtual ~PrefDefaultProvider(); |
38 | 40 |
39 // DefaultContentSettingsProvider implementation. | 41 // DefaultContentSettingsProvider implementation. |
40 virtual ContentSetting ProvideDefaultSetting( | 42 virtual ContentSetting ProvideDefaultSetting( |
41 ContentSettingsType content_type) const; | 43 ContentSettingsType content_type) const; |
42 virtual void UpdateDefaultSetting(ContentSettingsType content_type, | 44 virtual void UpdateDefaultSetting(ContentSettingsType content_type, |
43 ContentSetting setting); | 45 ContentSetting setting); |
44 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; | 46 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; |
45 | 47 |
48 void ShutdownOnUIThread(); | |
49 | |
46 static void RegisterUserPrefs(PrefService* prefs); | 50 static void RegisterUserPrefs(PrefService* prefs); |
47 | 51 |
48 // NotificationObserver implementation. | 52 // NotificationObserver implementation. |
49 virtual void Observe(NotificationType type, | 53 virtual void Observe(NotificationType type, |
50 const NotificationSource& source, | 54 const NotificationSource& source, |
51 const NotificationDetails& details); | 55 const NotificationDetails& details); |
52 | 56 |
53 private: | 57 private: |
54 // Informs observers that content settings have changed. Make sure that | 58 // Informs observers that content settings have changed. Make sure that |
55 // |lock_| is not held when calling this, as listeners will usually call one | 59 // |lock_| is not held when calling this, as listeners will usually call one |
56 // of the GetSettings functions in response, which would then lead to a | 60 // of the GetSettings functions in response, which would then lead to a |
57 // mutex deadlock. | 61 // mutex deadlock. |
58 void NotifyObservers(const ContentSettingsDetails& details); | 62 void NotifyObservers(const ContentSettingsDetails& details); |
59 | 63 |
60 void UnregisterObservers(); | |
61 | |
62 // Sets the fields of |settings| based on the values in |dictionary|. | 64 // Sets the fields of |settings| based on the values in |dictionary|. |
63 void GetSettingsFromDictionary(const DictionaryValue* dictionary, | 65 void GetSettingsFromDictionary(const DictionaryValue* dictionary, |
64 ContentSettings* settings); | 66 ContentSettings* settings); |
65 | 67 |
66 // Forces the default settings to be explicitly set instead of themselves | 68 // Forces the default settings to be explicitly set instead of themselves |
67 // being CONTENT_SETTING_DEFAULT. | 69 // being CONTENT_SETTING_DEFAULT. |
68 void ForceDefaultsToBeExplicit(); | 70 void ForceDefaultsToBeExplicit(); |
69 | 71 |
70 // Reads the default settings from the preferences service. If |overwrite| is | 72 // Reads the default settings from the preferences service. If |overwrite| is |
71 // true and the preference is missing, the local copy will be cleared as well. | 73 // true and the preference is missing, the local copy will be cleared as well. |
72 void ReadDefaultSettings(bool overwrite); | 74 void ReadDefaultSettings(bool overwrite); |
73 | 75 |
74 void MigrateObsoleteNotificationPref(PrefService* prefs); | 76 void MigrateObsoleteNotificationPref(); |
75 | 77 |
76 // Copies of the pref data, so that we can read it on the IO thread. | 78 // Copies of the pref data, so that we can read it on the IO thread. |
77 ContentSettings default_content_settings_; | 79 ContentSettings default_content_settings_; |
78 | 80 |
79 Profile* profile_; | 81 HostContentSettingsMap* map_; |
markusheintz_
2011/07/07 15:23:18
Same as in content_settings_policy_provider.
Bernhard Bauer
2011/07/08 17:05:27
Done.
| |
82 PrefService* prefs_; | |
80 | 83 |
81 // Whether this settings map is for an Incognito session. | 84 // Whether this settings map is for an Incognito session. |
82 bool is_incognito_; | 85 bool is_incognito_; |
83 | 86 |
84 // Used around accesses to the default_content_settings_ object to guarantee | 87 // Used around accesses to the default_content_settings_ object to guarantee |
85 // thread safety. | 88 // thread safety. |
86 mutable base::Lock lock_; | 89 mutable base::Lock lock_; |
87 | 90 |
88 PrefChangeRegistrar pref_change_registrar_; | 91 PrefChangeRegistrar pref_change_registrar_; |
89 NotificationRegistrar notification_registrar_; | |
90 | 92 |
91 // Whether we are currently updating preferences, this is used to ignore | 93 // Whether we are currently updating preferences, this is used to ignore |
92 // notifications from the preferences service that we triggered ourself. | 94 // notifications from the preferences service that we triggered ourself. |
93 bool updating_preferences_; | 95 bool updating_preferences_; |
94 | 96 |
95 bool initializing_; | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider); | 97 DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider); |
98 }; | 98 }; |
99 | 99 |
100 // Content settings provider that provides content settings from the user | 100 // Content settings provider that provides content settings from the user |
101 // preference. | 101 // preference. |
102 class PrefProvider : public ProviderInterface, | 102 class PrefProvider : public ProviderInterface, |
103 public NotificationObserver { | 103 public NotificationObserver { |
104 public: | 104 public: |
105 static void RegisterUserPrefs(PrefService* prefs); | 105 static void RegisterUserPrefs(PrefService* prefs); |
106 | 106 |
107 explicit PrefProvider(Profile* profile); | 107 PrefProvider(HostContentSettingsMap* map, |
108 PrefService* prefs, | |
109 bool incognito); | |
108 virtual ~PrefProvider(); | 110 virtual ~PrefProvider(); |
109 | 111 |
110 // ProviderInterface implementations. | 112 // ProviderInterface implementations. |
111 virtual void SetContentSetting( | 113 virtual void SetContentSetting( |
112 const ContentSettingsPattern& primary_pattern, | 114 const ContentSettingsPattern& primary_pattern, |
113 const ContentSettingsPattern& secondary_pattern, | 115 const ContentSettingsPattern& secondary_pattern, |
114 ContentSettingsType content_type, | 116 ContentSettingsType content_type, |
115 const ResourceIdentifier& resource_identifier, | 117 const ResourceIdentifier& resource_identifier, |
116 ContentSetting content_setting); | 118 ContentSetting content_setting); |
117 | 119 |
118 virtual ContentSetting GetContentSetting( | 120 virtual ContentSetting GetContentSetting( |
119 const GURL& primary_url, | 121 const GURL& primary_url, |
120 const GURL& secondary_url, | 122 const GURL& secondary_url, |
121 ContentSettingsType content_type, | 123 ContentSettingsType content_type, |
122 const ResourceIdentifier& resource_identifier) const; | 124 const ResourceIdentifier& resource_identifier) const; |
123 | 125 |
124 virtual void GetAllContentSettingsRules( | 126 virtual void GetAllContentSettingsRules( |
125 ContentSettingsType content_type, | 127 ContentSettingsType content_type, |
126 const ResourceIdentifier& resource_identifier, | 128 const ResourceIdentifier& resource_identifier, |
127 Rules* content_setting_rules) const; | 129 Rules* content_setting_rules) const; |
128 | 130 |
129 virtual void ClearAllContentSettingsRules( | 131 virtual void ClearAllContentSettingsRules( |
130 ContentSettingsType content_type); | 132 ContentSettingsType content_type); |
131 | 133 |
134 virtual void ShutdownOnUIThread(); | |
135 | |
132 // NotificationObserver implementation. | 136 // NotificationObserver implementation. |
133 virtual void Observe(NotificationType type, | 137 virtual void Observe(NotificationType type, |
134 const NotificationSource& source, | 138 const NotificationSource& source, |
135 const NotificationDetails& details); | 139 const NotificationDetails& details); |
136 | 140 |
137 private: | 141 private: |
138 void Init(); | 142 void Init(); |
139 | 143 |
140 // Reads all content settings exceptions from the preference and load them | 144 // Reads all content settings exceptions from the preference and load them |
141 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is | 145 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is |
(...skipping 23 matching lines...) Expand all Loading... | |
165 // is obsolete and only used for compatibility reasons. | 169 // is obsolete and only used for compatibility reasons. |
166 void UpdatePatternsPref( | 170 void UpdatePatternsPref( |
167 const ContentSettingsPattern& primary_pattern, | 171 const ContentSettingsPattern& primary_pattern, |
168 const ContentSettingsPattern& secondary_pattern, | 172 const ContentSettingsPattern& secondary_pattern, |
169 ContentSettingsType content_type, | 173 ContentSettingsType content_type, |
170 const ResourceIdentifier& resource_identifier, | 174 const ResourceIdentifier& resource_identifier, |
171 ContentSetting setting); | 175 ContentSetting setting); |
172 | 176 |
173 // Various migration methods (old cookie, popup and per-host data gets | 177 // Various migration methods (old cookie, popup and per-host data gets |
174 // migrated to the new format). | 178 // migrated to the new format). |
175 void MigrateObsoletePerhostPref(PrefService* prefs); | 179 void MigrateObsoletePerhostPref(); |
176 void MigrateObsoletePopupsPref(PrefService* prefs); | 180 void MigrateObsoletePopupsPref(); |
177 void MigrateObsoleteContentSettingsPatternPref(PrefService* prefs); | 181 void MigrateObsoleteContentSettingsPatternPref(); |
178 | 182 |
179 // Copies the value of the preference that stores the content settings | 183 // Copies the value of the preference that stores the content settings |
180 // exceptions to the obsolete preference for content settings exceptions. This | 184 // exceptions to the obsolete preference for content settings exceptions. This |
181 // is necessary to allow content settings exceptions beeing synced to older | 185 // is necessary to allow content settings exceptions beeing synced to older |
182 // versions of chrome that only use the obsolete. | 186 // versions of chrome that only use the obsolete. |
183 void SyncObsoletePref(PrefService* pref); | 187 void SyncObsoletePref(); |
184 | 188 |
185 void CanonicalizeContentSettingsExceptions( | 189 static void CanonicalizeContentSettingsExceptions( |
186 DictionaryValue* all_settings_dictionary); | 190 DictionaryValue* all_settings_dictionary); |
187 | 191 |
188 void NotifyObservers(const ContentSettingsDetails& details); | 192 void NotifyObservers(const ContentSettingsDetails& details); |
189 | 193 |
190 void UnregisterObservers(); | 194 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
195 PrefService* prefs_; | |
191 | 196 |
192 Profile* profile_; | 197 // Weak; owns us |
198 HostContentSettingsMap* map_; | |
193 | 199 |
194 bool is_incognito_; | 200 bool is_incognito_; |
195 | 201 |
196 PrefChangeRegistrar pref_change_registrar_; | 202 PrefChangeRegistrar pref_change_registrar_; |
197 NotificationRegistrar notification_registrar_; | |
198 | 203 |
199 // Whether we are currently updating preferences, this is used to ignore | 204 // Whether we are currently updating preferences, this is used to ignore |
200 // notifications from the preferences service that we triggered ourself. | 205 // notifications from the preferences service that we triggered ourself. |
201 bool updating_preferences_; | 206 bool updating_preferences_; |
202 | 207 |
203 // Do not fire any Notifications as long as we are in the constructor. | |
204 bool initializing_; | |
205 | |
206 OriginIdentifierValueMap value_map_; | 208 OriginIdentifierValueMap value_map_; |
207 | 209 |
208 OriginIdentifierValueMap incognito_value_map_; | 210 OriginIdentifierValueMap incognito_value_map_; |
209 | 211 |
210 // Used around accesses to the value map objects to guarantee | 212 // Used around accesses to the value map objects to guarantee |
211 // thread safety. | 213 // thread safety. |
212 mutable base::Lock lock_; | 214 mutable base::Lock lock_; |
213 | 215 |
214 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | 216 DISALLOW_COPY_AND_ASSIGN(PrefProvider); |
215 }; | 217 }; |
216 | 218 |
217 } // namespace content_settings | 219 } // namespace content_settings |
218 | 220 |
219 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 221 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
OLD | NEW |