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

Side by Side Diff: chrome/browser/content_settings/content_settings_policy_provider.cc

Issue 7344008: Make the hcsm and its providers communicate via an observer interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "remove commented code" 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 #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"
11 #include "chrome/browser/content_settings/content_settings_details.h" 11 #include "chrome/browser/content_settings/content_settings_details.h"
12 #include "chrome/browser/content_settings/content_settings_pattern.h" 12 #include "chrome/browser/content_settings/content_settings_pattern.h"
13 #include "chrome/browser/content_settings/content_settings_utils.h" 13 #include "chrome/browser/content_settings/content_settings_utils.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" 15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
20 #include "content/common/notification_details.h"
21 #include "content/common/notification_service.h" 20 #include "content/common/notification_service.h"
22 #include "content/common/notification_source.h" 21 #include "content/common/notification_source.h"
23 #include "webkit/plugins/npapi/plugin_group.h" 22 #include "webkit/plugins/npapi/plugin_group.h"
24 #include "webkit/plugins/npapi/plugin_list.h" 23 #include "webkit/plugins/npapi/plugin_list.h"
25 24
26 namespace { 25 namespace {
27 26
28 // Base pref path of the prefs that contain the managed default content 27 // Base pref path of the prefs that contain the managed default content
29 // settings values. 28 // settings values.
30 const std::string kManagedSettings = 29 const std::string kManagedSettings =
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, 269 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls,
271 PrefService::UNSYNCABLE_PREF); 270 PrefService::UNSYNCABLE_PREF);
272 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, 271 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls,
273 PrefService::UNSYNCABLE_PREF); 272 PrefService::UNSYNCABLE_PREF);
274 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, 273 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls,
275 PrefService::UNSYNCABLE_PREF); 274 PrefService::UNSYNCABLE_PREF);
276 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, 275 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls,
277 PrefService::UNSYNCABLE_PREF); 276 PrefService::UNSYNCABLE_PREF);
278 } 277 }
279 278
280 PolicyProvider::PolicyProvider(HostContentSettingsMap* map, 279 PolicyProvider::PolicyProvider(Observer* observer,
281 PrefService* prefs, 280 PrefService* prefs,
282 DefaultProviderInterface* default_provider) 281 DefaultProviderInterface* default_provider)
283 : host_content_settings_map_(map), 282 : prefs_(prefs),
284 prefs_(prefs),
285 default_provider_(default_provider) { 283 default_provider_(default_provider) {
284 AddObserver(observer);
286 ReadManagedContentSettings(false); 285 ReadManagedContentSettings(false);
287 286
288 pref_change_registrar_.Init(prefs_); 287 pref_change_registrar_.Init(prefs_);
289 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); 288 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this);
290 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); 289 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this);
291 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); 290 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this);
292 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); 291 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this);
293 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); 292 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this);
294 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); 293 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this);
295 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); 294 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 420 }
422 } 421 }
423 } 422 }
424 423
425 void PolicyProvider::ClearAllContentSettingsRules( 424 void PolicyProvider::ClearAllContentSettingsRules(
426 ContentSettingsType content_type) { 425 ContentSettingsType content_type) {
427 } 426 }
428 427
429 void PolicyProvider::ShutdownOnUIThread() { 428 void PolicyProvider::ShutdownOnUIThread() {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
430 RemoveAllObservers();
431 if (!prefs_) 431 if (!prefs_)
432 return; 432 return;
433 pref_change_registrar_.RemoveAll(); 433 pref_change_registrar_.RemoveAll();
434 prefs_ = NULL; 434 prefs_ = NULL;
435 host_content_settings_map_ = NULL;
436 }
437
438 void PolicyProvider::NotifyObservers(
439 const ContentSettingsDetails& details) {
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
441 if (host_content_settings_map_ == NULL)
442 return;
443 NotificationService::current()->Notify(
444 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
445 Source<HostContentSettingsMap>(host_content_settings_map_),
446 Details<const ContentSettingsDetails>(&details));
447 } 435 }
448 436
449 void PolicyProvider::Observe(int type, 437 void PolicyProvider::Observe(int type,
450 const NotificationSource& source, 438 const NotificationSource& source,
451 const NotificationDetails& details) { 439 const NotificationDetails& details) {
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
453 441
454 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 442 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
455 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); 443 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr());
456 std::string* name = Details<std::string>(details).ptr(); 444 std::string* name = Details<std::string>(details).ptr();
457 if (*name == prefs::kManagedCookiesAllowedForUrls || 445 if (*name == prefs::kManagedCookiesAllowedForUrls ||
458 *name == prefs::kManagedCookiesBlockedForUrls || 446 *name == prefs::kManagedCookiesBlockedForUrls ||
459 *name == prefs::kManagedCookiesSessionOnlyForUrls || 447 *name == prefs::kManagedCookiesSessionOnlyForUrls ||
460 *name == prefs::kManagedImagesAllowedForUrls || 448 *name == prefs::kManagedImagesAllowedForUrls ||
461 *name == prefs::kManagedImagesBlockedForUrls || 449 *name == prefs::kManagedImagesBlockedForUrls ||
462 *name == prefs::kManagedJavaScriptAllowedForUrls || 450 *name == prefs::kManagedJavaScriptAllowedForUrls ||
463 *name == prefs::kManagedJavaScriptBlockedForUrls || 451 *name == prefs::kManagedJavaScriptBlockedForUrls ||
464 *name == prefs::kManagedPluginsAllowedForUrls || 452 *name == prefs::kManagedPluginsAllowedForUrls ||
465 *name == prefs::kManagedPluginsBlockedForUrls || 453 *name == prefs::kManagedPluginsBlockedForUrls ||
466 *name == prefs::kManagedPopupsAllowedForUrls || 454 *name == prefs::kManagedPopupsAllowedForUrls ||
467 *name == prefs::kManagedPopupsBlockedForUrls) { 455 *name == prefs::kManagedPopupsBlockedForUrls) {
468 ReadManagedContentSettings(true); 456 ReadManagedContentSettings(true);
469 ContentSettingsDetails details(ContentSettingsPattern(), 457 NotifyObservers(ContentSettingsPattern(),
470 ContentSettingsPattern(), 458 ContentSettingsPattern(),
471 CONTENT_SETTINGS_TYPE_DEFAULT, 459 CONTENT_SETTINGS_TYPE_DEFAULT,
472 std::string()); 460 std::string());
473 NotifyObservers(details);
474 } 461 }
475 } else { 462 } else {
476 NOTREACHED() << "Unexpected notification"; 463 NOTREACHED() << "Unexpected notification";
477 } 464 }
478 } 465 }
479 466
480 } // namespace content_settings 467 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698