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 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 prefs::kManagedPopupsBlockedForUrls, | 92 prefs::kManagedPopupsBlockedForUrls, |
93 CONTENT_SETTINGS_TYPE_POPUPS, | 93 CONTENT_SETTINGS_TYPE_POPUPS, |
94 CONTENT_SETTING_BLOCK | 94 CONTENT_SETTING_BLOCK |
95 } | 95 } |
96 }; | 96 }; |
97 | 97 |
98 } // namespace | 98 } // namespace |
99 | 99 |
100 namespace content_settings { | 100 namespace content_settings { |
101 | 101 |
102 PolicyDefaultProvider::PolicyDefaultProvider(Profile* profile) | 102 PolicyDefaultProvider::PolicyDefaultProvider(HostContentSettingsMap* map, |
103 : profile_(profile), | 103 PrefService* prefs) |
104 is_off_the_record_(profile_->IsOffTheRecord()) { | 104 : map_(map), |
105 PrefService* prefs = profile->GetPrefs(); | 105 prefs_(prefs) { |
106 | |
107 // Read global defaults. | 106 // Read global defaults. |
108 DCHECK_EQ(arraysize(kPrefToManageType), | 107 DCHECK_EQ(arraysize(kPrefToManageType), |
109 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); | 108 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); |
110 ReadManagedDefaultSettings(); | 109 ReadManagedDefaultSettings(); |
111 | 110 |
112 pref_change_registrar_.Init(prefs); | 111 pref_change_registrar_.Init(prefs_); |
113 // The following preferences are only used to indicate if a | 112 // The following preferences are only used to indicate if a |
114 // default-content-setting is managed and to hold the managed default-setting | 113 // default-content-setting is managed and to hold the managed default-setting |
115 // value. If the value for any of the following perferences is set then the | 114 // value. If the value for any of the following perferences is set then the |
116 // corresponding default-content-setting is managed. These preferences exist | 115 // corresponding default-content-setting is managed. These preferences exist |
117 // in parallel to the preference default-content-settings. If a | 116 // in parallel to the preference default-content-settings. If a |
118 // default-content-settings-type is managed any user defined excpetions | 117 // default-content-settings-type is managed any user defined excpetions |
119 // (patterns) for this type are ignored. | 118 // (patterns) for this type are ignored. |
120 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); | 119 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); |
121 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); | 120 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); |
122 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); | 121 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); |
123 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); | 122 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); |
124 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); | 123 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); |
125 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | |
126 Source<Profile>(profile_)); | |
127 } | 124 } |
128 | 125 |
129 PolicyDefaultProvider::~PolicyDefaultProvider() { | 126 PolicyDefaultProvider::~PolicyDefaultProvider() { |
130 UnregisterObservers(); | 127 DCHECK(!prefs_); |
131 } | 128 } |
132 | 129 |
133 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( | 130 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( |
134 ContentSettingsType content_type) const { | 131 ContentSettingsType content_type) const { |
135 base::AutoLock auto_lock(lock_); | 132 base::AutoLock auto_lock(lock_); |
136 return managed_default_content_settings_.settings[content_type]; | 133 return managed_default_content_settings_.settings[content_type]; |
137 } | 134 } |
138 | 135 |
139 void PolicyDefaultProvider::UpdateDefaultSetting( | 136 void PolicyDefaultProvider::UpdateDefaultSetting( |
140 ContentSettingsType content_type, | 137 ContentSettingsType content_type, |
(...skipping 13 matching lines...) Expand all Loading... |
154 | 151 |
155 void PolicyDefaultProvider::ResetToDefaults() { | 152 void PolicyDefaultProvider::ResetToDefaults() { |
156 } | 153 } |
157 | 154 |
158 void PolicyDefaultProvider::Observe(NotificationType type, | 155 void PolicyDefaultProvider::Observe(NotificationType type, |
159 const NotificationSource& source, | 156 const NotificationSource& source, |
160 const NotificationDetails& details) { | 157 const NotificationDetails& details) { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
162 | 159 |
163 if (type == NotificationType::PREF_CHANGED) { | 160 if (type == NotificationType::PREF_CHANGED) { |
164 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 161 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
165 std::string* name = Details<std::string>(details).ptr(); | 162 std::string* name = Details<std::string>(details).ptr(); |
166 if (*name == prefs::kManagedDefaultCookiesSetting) { | 163 if (*name == prefs::kManagedDefaultCookiesSetting) { |
167 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); | 164 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); |
168 } else if (*name == prefs::kManagedDefaultImagesSetting) { | 165 } else if (*name == prefs::kManagedDefaultImagesSetting) { |
169 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES); | 166 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES); |
170 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { | 167 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { |
171 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 168 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
172 } else if (*name == prefs::kManagedDefaultPluginsSetting) { | 169 } else if (*name == prefs::kManagedDefaultPluginsSetting) { |
173 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); | 170 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); |
174 } else if (*name == prefs::kManagedDefaultPopupsSetting) { | 171 } else if (*name == prefs::kManagedDefaultPopupsSetting) { |
175 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); | 172 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); |
176 } else { | 173 } else { |
177 NOTREACHED() << "Unexpected preference observed"; | 174 NOTREACHED() << "Unexpected preference observed"; |
178 return; | 175 return; |
179 } | 176 } |
180 | 177 |
181 if (!is_off_the_record_) { | 178 ContentSettingsDetails details(ContentSettingsPattern(), |
182 ContentSettingsDetails details(ContentSettingsPattern(), | 179 ContentSettingsPattern(), |
183 ContentSettingsPattern(), | 180 CONTENT_SETTINGS_TYPE_DEFAULT, |
184 CONTENT_SETTINGS_TYPE_DEFAULT, | 181 std::string()); |
185 std::string()); | 182 NotifyObservers(details); |
186 NotifyObservers(details); | |
187 } | |
188 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
189 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
190 UnregisterObservers(); | |
191 } else { | 183 } else { |
192 NOTREACHED() << "Unexpected notification"; | 184 NOTREACHED() << "Unexpected notification"; |
193 } | 185 } |
194 } | 186 } |
195 | 187 |
196 void PolicyDefaultProvider::UnregisterObservers() { | 188 void PolicyDefaultProvider::ShutdownOnUIThread() { |
| 189 if (!prefs_) |
| 190 return; |
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
198 if (!profile_) | |
199 return; | |
200 pref_change_registrar_.RemoveAll(); | 192 pref_change_registrar_.RemoveAll(); |
201 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 193 prefs_ = NULL; |
202 Source<Profile>(profile_)); | 194 map_ = NULL; |
203 profile_ = NULL; | |
204 } | 195 } |
205 | 196 |
206 | 197 |
207 void PolicyDefaultProvider::NotifyObservers( | 198 void PolicyDefaultProvider::NotifyObservers( |
208 const ContentSettingsDetails& details) { | 199 const ContentSettingsDetails& details) { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
210 if (profile_ == NULL) | 201 if (map_ == NULL) |
211 return; | 202 return; |
212 NotificationService::current()->Notify( | 203 NotificationService::current()->Notify( |
213 NotificationType::CONTENT_SETTINGS_CHANGED, | 204 NotificationType::CONTENT_SETTINGS_CHANGED, |
214 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 205 Source<HostContentSettingsMap>(map_), |
215 Details<const ContentSettingsDetails>(&details)); | 206 Details<const ContentSettingsDetails>(&details)); |
216 } | 207 } |
217 | 208 |
218 void PolicyDefaultProvider::ReadManagedDefaultSettings() { | 209 void PolicyDefaultProvider::ReadManagedDefaultSettings() { |
219 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { | 210 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { |
220 if (kPrefToManageType[type] == NULL) { | 211 if (kPrefToManageType[type] == NULL) { |
221 continue; | 212 continue; |
222 } | 213 } |
223 UpdateManagedDefaultSetting(ContentSettingsType(type)); | 214 UpdateManagedDefaultSetting(ContentSettingsType(type)); |
224 } | 215 } |
225 } | 216 } |
226 | 217 |
227 void PolicyDefaultProvider::UpdateManagedDefaultSetting( | 218 void PolicyDefaultProvider::UpdateManagedDefaultSetting( |
228 ContentSettingsType type) { | 219 ContentSettingsType type) { |
229 // If a pref to manage a default-content-setting was not set (NOTICE: | 220 // If a pref to manage a default-content-setting was not set (NOTICE: |
230 // "HasPrefPath" returns false if no value was set for a registered pref) then | 221 // "HasPrefPath" returns false if no value was set for a registered pref) then |
231 // the default value of the preference is used. The default value of a | 222 // the default value of the preference is used. The default value of a |
232 // preference to manage a default-content-settings is CONTENT_SETTING_DEFAULT. | 223 // preference to manage a default-content-settings is CONTENT_SETTING_DEFAULT. |
233 // This indicates that no managed value is set. If a pref was set, than it | 224 // This indicates that no managed value is set. If a pref was set, than it |
234 // MUST be managed. | 225 // MUST be managed. |
235 PrefService* prefs = profile_->GetPrefs(); | 226 DCHECK(!prefs_->HasPrefPath(kPrefToManageType[type]) || |
236 DCHECK(!prefs->HasPrefPath(kPrefToManageType[type]) || | 227 prefs_->IsManagedPreference(kPrefToManageType[type])); |
237 prefs->IsManagedPreference(kPrefToManageType[type])); | |
238 base::AutoLock auto_lock(lock_); | 228 base::AutoLock auto_lock(lock_); |
239 managed_default_content_settings_.settings[type] = IntToContentSetting( | 229 managed_default_content_settings_.settings[type] = IntToContentSetting( |
240 prefs->GetInteger(kPrefToManageType[type])); | 230 prefs_->GetInteger(kPrefToManageType[type])); |
241 } | 231 } |
242 | 232 |
243 // static | 233 // static |
244 void PolicyDefaultProvider::RegisterUserPrefs(PrefService* prefs) { | 234 void PolicyDefaultProvider::RegisterUserPrefs(PrefService* prefs) { |
245 // Preferences for default content setting policies. A policy is not set of | 235 // Preferences for default content setting policies. A policy is not set of |
246 // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT. | 236 // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT. |
247 prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting, | 237 prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting, |
248 CONTENT_SETTING_DEFAULT, | 238 CONTENT_SETTING_DEFAULT, |
249 PrefService::UNSYNCABLE_PREF); | 239 PrefService::UNSYNCABLE_PREF); |
250 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, | 240 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, | 273 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, |
284 PrefService::UNSYNCABLE_PREF); | 274 PrefService::UNSYNCABLE_PREF); |
285 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, | 275 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, |
286 PrefService::UNSYNCABLE_PREF); | 276 PrefService::UNSYNCABLE_PREF); |
287 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, | 277 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, |
288 PrefService::UNSYNCABLE_PREF); | 278 PrefService::UNSYNCABLE_PREF); |
289 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, | 279 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, |
290 PrefService::UNSYNCABLE_PREF); | 280 PrefService::UNSYNCABLE_PREF); |
291 } | 281 } |
292 | 282 |
293 PolicyProvider::PolicyProvider(Profile* profile, | 283 PolicyProvider::PolicyProvider(HostContentSettingsMap* map, |
| 284 PrefService* prefs, |
294 DefaultProviderInterface* default_provider) | 285 DefaultProviderInterface* default_provider) |
295 : profile_(profile), | 286 : map_(map), |
| 287 prefs_(prefs), |
296 default_provider_(default_provider) { | 288 default_provider_(default_provider) { |
297 Init(); | |
298 } | |
299 | |
300 PolicyProvider::~PolicyProvider() { | |
301 UnregisterObservers(); | |
302 } | |
303 | |
304 void PolicyProvider::Init() { | |
305 PrefService* prefs = profile_->GetPrefs(); | |
306 | |
307 ReadManagedContentSettings(false); | 289 ReadManagedContentSettings(false); |
308 | 290 |
309 pref_change_registrar_.Init(prefs); | 291 pref_change_registrar_.Init(prefs_); |
310 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); | 292 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); |
311 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); | 293 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); |
312 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); | 294 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); |
313 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); | 295 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); |
314 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); | 296 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); |
315 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); | 297 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); |
316 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); | 298 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); |
317 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); | 299 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); |
318 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); | 300 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); |
319 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); | 301 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); |
320 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); | 302 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); |
| 303 } |
321 | 304 |
322 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 305 PolicyProvider::~PolicyProvider() { |
323 Source<Profile>(profile_)); | 306 DCHECK(!prefs_); |
324 } | 307 } |
325 | 308 |
326 void PolicyProvider::GetContentSettingsFromPreferences( | 309 void PolicyProvider::GetContentSettingsFromPreferences( |
327 PrefService* prefs, | |
328 ContentSettingsRules* rules) { | 310 ContentSettingsRules* rules) { |
329 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { | 311 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { |
330 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; | 312 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; |
331 // Skip unset policies. | 313 // Skip unset policies. |
332 if (!prefs->HasPrefPath(pref_name)) { | 314 if (!prefs_->HasPrefPath(pref_name)) { |
333 VLOG(2) << "Skipping unset preference: " << pref_name; | 315 VLOG(2) << "Skipping unset preference: " << pref_name; |
334 continue; | 316 continue; |
335 } | 317 } |
336 | 318 |
337 const PrefService::Preference* pref = prefs->FindPreference(pref_name); | 319 const PrefService::Preference* pref = prefs_->FindPreference(pref_name); |
338 DCHECK(pref); | 320 DCHECK(pref); |
339 DCHECK(pref->IsManaged()); | 321 DCHECK(pref->IsManaged()); |
340 DCHECK_EQ(Value::TYPE_LIST, pref->GetType()); | |
341 | 322 |
342 const ListValue* pattern_str_list = | 323 const ListValue* pattern_str_list = NULL; |
343 static_cast<const ListValue*>(pref->GetValue()); | 324 if (!pref->GetValue()->GetAsList(&pattern_str_list)) { |
| 325 NOTREACHED(); |
| 326 return; |
| 327 } |
| 328 |
344 for (size_t j = 0; j < pattern_str_list->GetSize(); ++j) { | 329 for (size_t j = 0; j < pattern_str_list->GetSize(); ++j) { |
345 std::string original_pattern_str; | 330 std::string original_pattern_str; |
346 pattern_str_list->GetString(j, &original_pattern_str); | 331 pattern_str_list->GetString(j, &original_pattern_str); |
347 PatternPair pattern_pair = ParsePatternString(original_pattern_str); | 332 PatternPair pattern_pair = ParsePatternString(original_pattern_str); |
348 // Ignore invalid patterns. | 333 // Ignore invalid patterns. |
349 if (!pattern_pair.first.IsValid()) { | 334 if (!pattern_pair.first.IsValid()) { |
350 VLOG(1) << "Ignoring invalid content settings pattern: " << | 335 VLOG(1) << "Ignoring invalid content settings pattern: " << |
351 original_pattern_str; | 336 original_pattern_str; |
352 continue; | 337 continue; |
353 } | 338 } |
354 | 339 |
355 ContentSettingsType content_type = | 340 ContentSettingsType content_type = |
356 kPrefsForManagedContentSettingsMap[i].content_type; | 341 kPrefsForManagedContentSettingsMap[i].content_type; |
357 // If only one pattern was defined auto expand it to a pattern pair. | 342 // If only one pattern was defined auto expand it to a pattern pair. |
358 rules->push_back(MakeTuple( | 343 rules->push_back(MakeTuple( |
359 pattern_pair.first, | 344 pattern_pair.first, |
360 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() | 345 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() |
361 : pattern_pair.second, | 346 : pattern_pair.second, |
362 content_type, | 347 content_type, |
363 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), | 348 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), |
364 kPrefsForManagedContentSettingsMap[i].setting)); | 349 kPrefsForManagedContentSettingsMap[i].setting)); |
365 } | 350 } |
366 } | 351 } |
367 } | 352 } |
368 | 353 |
369 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { | 354 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { |
370 ContentSettingsRules rules; | 355 ContentSettingsRules rules; |
371 PrefService* prefs = profile_->GetPrefs(); | 356 GetContentSettingsFromPreferences(&rules); |
372 GetContentSettingsFromPreferences(prefs, &rules); | |
373 { | 357 { |
374 base::AutoLock auto_lock(lock_); | 358 base::AutoLock auto_lock(lock_); |
375 if (overwrite) | 359 if (overwrite) |
376 value_map_.clear(); | 360 value_map_.clear(); |
377 for (ContentSettingsRules::iterator rule = rules.begin(); | 361 for (ContentSettingsRules::iterator rule = rules.begin(); |
378 rule != rules.end(); | 362 rule != rules.end(); |
379 ++rule) { | 363 ++rule) { |
380 value_map_.SetValue(rule->a, | 364 value_map_.SetValue(rule->a, |
381 rule->b, | 365 rule->b, |
382 rule->c, | 366 rule->c, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 425 } |
442 } | 426 } |
443 | 427 |
444 void PolicyProvider::ClearAllContentSettingsRules( | 428 void PolicyProvider::ClearAllContentSettingsRules( |
445 ContentSettingsType content_type) { | 429 ContentSettingsType content_type) { |
446 } | 430 } |
447 | 431 |
448 void PolicyProvider::ResetToDefaults() { | 432 void PolicyProvider::ResetToDefaults() { |
449 } | 433 } |
450 | 434 |
451 void PolicyProvider::UnregisterObservers() { | 435 void PolicyProvider::ShutdownOnUIThread() { |
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
453 if (!profile_) | 437 if (!prefs_) |
454 return; | 438 return; |
455 pref_change_registrar_.RemoveAll(); | 439 pref_change_registrar_.RemoveAll(); |
456 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 440 prefs_ = NULL; |
457 Source<Profile>(profile_)); | 441 map_ = NULL; |
458 profile_ = NULL; | |
459 } | 442 } |
460 | 443 |
461 void PolicyProvider::NotifyObservers( | 444 void PolicyProvider::NotifyObservers( |
462 const ContentSettingsDetails& details) { | 445 const ContentSettingsDetails& details) { |
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
464 if (profile_ == NULL) | 447 if (map_ == NULL) |
465 return; | 448 return; |
466 NotificationService::current()->Notify( | 449 NotificationService::current()->Notify( |
467 NotificationType::CONTENT_SETTINGS_CHANGED, | 450 NotificationType::CONTENT_SETTINGS_CHANGED, |
468 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 451 Source<HostContentSettingsMap>(map_), |
469 Details<const ContentSettingsDetails>(&details)); | 452 Details<const ContentSettingsDetails>(&details)); |
470 } | 453 } |
471 | 454 |
472 void PolicyProvider::Observe(NotificationType type, | 455 void PolicyProvider::Observe(NotificationType type, |
473 const NotificationSource& source, | 456 const NotificationSource& source, |
474 const NotificationDetails& details) { | 457 const NotificationDetails& details) { |
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
476 | 459 |
477 if (type == NotificationType::PREF_CHANGED) { | 460 if (type == NotificationType::PREF_CHANGED) { |
478 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 461 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
479 std::string* name = Details<std::string>(details).ptr(); | 462 std::string* name = Details<std::string>(details).ptr(); |
480 if (*name == prefs::kManagedCookiesAllowedForUrls || | 463 if (*name == prefs::kManagedCookiesAllowedForUrls || |
481 *name == prefs::kManagedCookiesBlockedForUrls || | 464 *name == prefs::kManagedCookiesBlockedForUrls || |
482 *name == prefs::kManagedCookiesSessionOnlyForUrls || | 465 *name == prefs::kManagedCookiesSessionOnlyForUrls || |
483 *name == prefs::kManagedImagesAllowedForUrls || | 466 *name == prefs::kManagedImagesAllowedForUrls || |
484 *name == prefs::kManagedImagesBlockedForUrls || | 467 *name == prefs::kManagedImagesBlockedForUrls || |
485 *name == prefs::kManagedJavaScriptAllowedForUrls || | 468 *name == prefs::kManagedJavaScriptAllowedForUrls || |
486 *name == prefs::kManagedJavaScriptBlockedForUrls || | 469 *name == prefs::kManagedJavaScriptBlockedForUrls || |
487 *name == prefs::kManagedPluginsAllowedForUrls || | 470 *name == prefs::kManagedPluginsAllowedForUrls || |
488 *name == prefs::kManagedPluginsBlockedForUrls || | 471 *name == prefs::kManagedPluginsBlockedForUrls || |
489 *name == prefs::kManagedPopupsAllowedForUrls || | 472 *name == prefs::kManagedPopupsAllowedForUrls || |
490 *name == prefs::kManagedPopupsBlockedForUrls) { | 473 *name == prefs::kManagedPopupsBlockedForUrls) { |
491 ReadManagedContentSettings(true); | 474 ReadManagedContentSettings(true); |
492 ContentSettingsDetails details(ContentSettingsPattern(), | 475 ContentSettingsDetails details(ContentSettingsPattern(), |
493 ContentSettingsPattern(), | 476 ContentSettingsPattern(), |
494 CONTENT_SETTINGS_TYPE_DEFAULT, | 477 CONTENT_SETTINGS_TYPE_DEFAULT, |
495 std::string()); | 478 std::string()); |
496 NotifyObservers(details); | 479 NotifyObservers(details); |
497 } | 480 } |
498 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
499 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
500 UnregisterObservers(); | |
501 } else { | 481 } else { |
502 NOTREACHED() << "Unexpected notification"; | 482 NOTREACHED() << "Unexpected notification"; |
503 } | 483 } |
504 } | 484 } |
505 | 485 |
506 } // namespace content_settings | 486 } // namespace content_settings |
OLD | NEW |