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

Side by Side Diff: chrome/browser/content_settings/content_settings_pref_provider.h

Issue 7218073: Explicitly ShutdownOnUIThread the HostContentSettingsMap when destroying the Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 5 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_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 explicit PrefDefaultProvider(HostContentSettingsMap* map,
markusheintz_ 2011/07/06 15:56:24 explicit not needed
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 void ResetToDefaults(); 46 virtual void ResetToDefaults();
45 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; 47 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const;
46 48
49 void ShutdownOnUIThread();
50
47 static void RegisterUserPrefs(PrefService* prefs); 51 static void RegisterUserPrefs(PrefService* prefs);
48 52
49 // NotificationObserver implementation. 53 // NotificationObserver implementation.
50 virtual void Observe(NotificationType type, 54 virtual void Observe(NotificationType type,
51 const NotificationSource& source, 55 const NotificationSource& source,
52 const NotificationDetails& details); 56 const NotificationDetails& details);
53 57
54 private: 58 private:
55 // Informs observers that content settings have changed. Make sure that 59 // Informs observers that content settings have changed. Make sure that
56 // |lock_| is not held when calling this, as listeners will usually call one 60 // |lock_| is not held when calling this, as listeners will usually call one
57 // of the GetSettings functions in response, which would then lead to a 61 // of the GetSettings functions in response, which would then lead to a
58 // mutex deadlock. 62 // mutex deadlock.
59 void NotifyObservers(const ContentSettingsDetails& details); 63 void NotifyObservers(const ContentSettingsDetails& details);
60 64
61 void UnregisterObservers();
62
63 // Sets the fields of |settings| based on the values in |dictionary|. 65 // Sets the fields of |settings| based on the values in |dictionary|.
64 void GetSettingsFromDictionary(const DictionaryValue* dictionary, 66 void GetSettingsFromDictionary(const DictionaryValue* dictionary,
65 ContentSettings* settings); 67 ContentSettings* settings);
66 68
67 // Forces the default settings to be explicitly set instead of themselves 69 // Forces the default settings to be explicitly set instead of themselves
68 // being CONTENT_SETTING_DEFAULT. 70 // being CONTENT_SETTING_DEFAULT.
69 void ForceDefaultsToBeExplicit(); 71 void ForceDefaultsToBeExplicit();
70 72
71 // Reads the default settings from the preferences service. If |overwrite| is 73 // Reads the default settings from the preferences service. If |overwrite| is
72 // true and the preference is missing, the local copy will be cleared as well. 74 // true and the preference is missing, the local copy will be cleared as well.
73 void ReadDefaultSettings(bool overwrite); 75 void ReadDefaultSettings(bool overwrite);
74 76
75 void MigrateObsoleteNotificationPref(PrefService* prefs); 77 void MigrateObsoleteNotificationPref();
76 78
77 // Copies of the pref data, so that we can read it on the IO thread. 79 // Copies of the pref data, so that we can read it on the IO thread.
78 ContentSettings default_content_settings_; 80 ContentSettings default_content_settings_;
79 81
80 Profile* profile_; 82 HostContentSettingsMap* map_;
83 PrefService* prefs_;
81 84
82 // Whether this settings map is for an Incognito session. 85 // Whether this settings map is for an Incognito session.
83 bool is_incognito_; 86 bool is_incognito_;
84 87
85 // Used around accesses to the default_content_settings_ object to guarantee 88 // Used around accesses to the default_content_settings_ object to guarantee
86 // thread safety. 89 // thread safety.
87 mutable base::Lock lock_; 90 mutable base::Lock lock_;
88 91
89 PrefChangeRegistrar pref_change_registrar_; 92 PrefChangeRegistrar pref_change_registrar_;
90 NotificationRegistrar notification_registrar_;
91 93
92 // Whether we are currently updating preferences, this is used to ignore 94 // Whether we are currently updating preferences, this is used to ignore
93 // notifications from the preferences service that we triggered ourself. 95 // notifications from the preferences service that we triggered ourself.
94 bool updating_preferences_; 96 bool updating_preferences_;
95 97
96 bool initializing_;
97
98 DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider); 98 DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider);
99 }; 99 };
100 100
101 // Content settings provider that provides content settings from the user 101 // Content settings provider that provides content settings from the user
102 // preference. 102 // preference.
103 class PrefProvider : public ProviderInterface, 103 class PrefProvider : public ProviderInterface,
104 public NotificationObserver { 104 public NotificationObserver {
105 public: 105 public:
106 static void RegisterUserPrefs(PrefService* prefs); 106 static void RegisterUserPrefs(PrefService* prefs);
107 107
108 explicit PrefProvider(Profile* profile); 108 explicit PrefProvider(HostContentSettingsMap* map,
markusheintz_ 2011/07/06 15:56:24 pls remove the explicit
109 PrefService* prefs,
110 bool incognito);
109 virtual ~PrefProvider(); 111 virtual ~PrefProvider();
110 112
111 // ProviderInterface implementations. 113 // ProviderInterface implementations.
112 virtual void SetContentSetting( 114 virtual void SetContentSetting(
113 const ContentSettingsPattern& primary_pattern, 115 const ContentSettingsPattern& primary_pattern,
114 const ContentSettingsPattern& secondary_pattern, 116 const ContentSettingsPattern& secondary_pattern,
115 ContentSettingsType content_type, 117 ContentSettingsType content_type,
116 const ResourceIdentifier& resource_identifier, 118 const ResourceIdentifier& resource_identifier,
117 ContentSetting content_setting); 119 ContentSetting content_setting);
118 120
119 virtual ContentSetting GetContentSetting( 121 virtual ContentSetting GetContentSetting(
120 const GURL& primary_url, 122 const GURL& primary_url,
121 const GURL& secondary_url, 123 const GURL& secondary_url,
122 ContentSettingsType content_type, 124 ContentSettingsType content_type,
123 const ResourceIdentifier& resource_identifier) const; 125 const ResourceIdentifier& resource_identifier) const;
124 126
125 virtual void GetAllContentSettingsRules( 127 virtual void GetAllContentSettingsRules(
126 ContentSettingsType content_type, 128 ContentSettingsType content_type,
127 const ResourceIdentifier& resource_identifier, 129 const ResourceIdentifier& resource_identifier,
128 Rules* content_setting_rules) const; 130 Rules* content_setting_rules) const;
129 131
130 virtual void ClearAllContentSettingsRules( 132 virtual void ClearAllContentSettingsRules(
131 ContentSettingsType content_type); 133 ContentSettingsType content_type);
132 134
133 virtual void ResetToDefaults(); 135 virtual void ResetToDefaults();
134 136
137 virtual void ShutdownOnUIThread();
138
135 // NotificationObserver implementation. 139 // NotificationObserver implementation.
136 virtual void Observe(NotificationType type, 140 virtual void Observe(NotificationType type,
137 const NotificationSource& source, 141 const NotificationSource& source,
138 const NotificationDetails& details); 142 const NotificationDetails& details);
139 143
140 private: 144 private:
141 void Init(); 145 void Init();
142 146
143 // Reads all content settings exceptions from the preference and load them 147 // Reads all content settings exceptions from the preference and load them
144 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is 148 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is
(...skipping 23 matching lines...) Expand all
168 // is obsolete and only used for compatibility reasons. 172 // is obsolete and only used for compatibility reasons.
169 void UpdatePatternsPref( 173 void UpdatePatternsPref(
170 const ContentSettingsPattern& primary_pattern, 174 const ContentSettingsPattern& primary_pattern,
171 const ContentSettingsPattern& secondary_pattern, 175 const ContentSettingsPattern& secondary_pattern,
172 ContentSettingsType content_type, 176 ContentSettingsType content_type,
173 const ResourceIdentifier& resource_identifier, 177 const ResourceIdentifier& resource_identifier,
174 ContentSetting setting); 178 ContentSetting setting);
175 179
176 // Various migration methods (old cookie, popup and per-host data gets 180 // Various migration methods (old cookie, popup and per-host data gets
177 // migrated to the new format). 181 // migrated to the new format).
178 void MigrateObsoletePerhostPref(PrefService* prefs); 182 void MigrateObsoletePerhostPref();
179 void MigrateObsoletePopupsPref(PrefService* prefs); 183 void MigrateObsoletePopupsPref();
180 void MigrateObsoleteContentSettingsPatternPref(PrefService* prefs); 184 void MigrateObsoleteContentSettingsPatternPref();
181 185
182 // Copies the value of the preference that stores the content settings 186 // Copies the value of the preference that stores the content settings
183 // exceptions to the obsolete preference for content settings exceptions. This 187 // exceptions to the obsolete preference for content settings exceptions. This
184 // is necessary to allow content settings exceptions beeing synced to older 188 // is necessary to allow content settings exceptions beeing synced to older
185 // versions of chrome that only use the obsolete. 189 // versions of chrome that only use the obsolete.
186 void SyncObsoletePref(PrefService* pref); 190 void SyncObsoletePref();
187 191
188 void CanonicalizeContentSettingsExceptions( 192 void CanonicalizeContentSettingsExceptions(
189 DictionaryValue* all_settings_dictionary); 193 DictionaryValue* all_settings_dictionary);
190 194
191 void NotifyObservers(const ContentSettingsDetails& details); 195 void NotifyObservers(const ContentSettingsDetails& details);
192 196
193 void UnregisterObservers(); 197 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
198 PrefService* prefs_;
194 199
195 Profile* profile_; 200 // Weak; owns us
201 HostContentSettingsMap* map_;
196 202
197 bool is_incognito_; 203 bool is_incognito_;
198 204
199 PrefChangeRegistrar pref_change_registrar_; 205 PrefChangeRegistrar pref_change_registrar_;
200 NotificationRegistrar notification_registrar_;
201 206
202 // Whether we are currently updating preferences, this is used to ignore 207 // Whether we are currently updating preferences, this is used to ignore
203 // notifications from the preferences service that we triggered ourself. 208 // notifications from the preferences service that we triggered ourself.
204 bool updating_preferences_; 209 bool updating_preferences_;
205 210
206 // Do not fire any Notifications as long as we are in the constructor.
207 bool initializing_;
208
209 OriginIdentifierValueMap value_map_; 211 OriginIdentifierValueMap value_map_;
210 212
211 OriginIdentifierValueMap incognito_value_map_; 213 OriginIdentifierValueMap incognito_value_map_;
212 214
213 // Used around accesses to the value map objects to guarantee 215 // Used around accesses to the value map objects to guarantee
214 // thread safety. 216 // thread safety.
215 mutable base::Lock lock_; 217 mutable base::Lock lock_;
216 218
217 DISALLOW_COPY_AND_ASSIGN(PrefProvider); 219 DISALLOW_COPY_AND_ASSIGN(PrefProvider);
218 }; 220 };
219 221
220 } // namespace content_settings 222 } // namespace content_settings
221 223
222 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ 224 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698