Chromium Code Reviews| 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_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // A content settings provider that takes its settings out of policies. | 9 // A content settings provider that takes its settings out of policies. |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "base/tuple.h" | 15 #include "base/tuple.h" |
| 16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h" | 16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h" |
| 17 #include "chrome/browser/content_settings/content_settings_provider.h" | 17 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 18 #include "chrome/browser/prefs/pref_change_registrar.h" | 18 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 19 #include "content/common/notification_observer.h" | 19 #include "content/common/notification_observer.h" |
| 20 #include "content/common/notification_registrar.h" | 20 #include "content/common/notification_registrar.h" |
| 21 | 21 |
| 22 class ContentSettingsDetails; | 22 class ContentSettingsDetails; |
| 23 class DictionaryValue; | 23 class DictionaryValue; |
| 24 class HostContentSettingsMap; | |
| 24 class PrefService; | 25 class PrefService; |
| 25 class Profile; | |
| 26 | 26 |
| 27 namespace content_settings { | 27 namespace content_settings { |
| 28 | 28 |
| 29 class PolicyDefaultProvider : public DefaultProviderInterface, | 29 class PolicyDefaultProvider : public DefaultProviderInterface, |
| 30 public NotificationObserver { | 30 public NotificationObserver { |
| 31 public: | 31 public: |
| 32 explicit PolicyDefaultProvider(Profile* profile); | 32 PolicyDefaultProvider(HostContentSettingsMap* map, PrefService* prefs); |
| 33 virtual ~PolicyDefaultProvider(); | 33 virtual ~PolicyDefaultProvider(); |
| 34 | 34 |
| 35 // DefaultContentSettingsProvider implementation. | 35 // DefaultContentSettingsProvider implementation. |
| 36 virtual ContentSetting ProvideDefaultSetting( | 36 virtual ContentSetting ProvideDefaultSetting( |
| 37 ContentSettingsType content_type) const; | 37 ContentSettingsType content_type) const; |
| 38 virtual void UpdateDefaultSetting(ContentSettingsType content_type, | 38 virtual void UpdateDefaultSetting(ContentSettingsType content_type, |
| 39 ContentSetting setting); | 39 ContentSetting setting); |
| 40 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; | 40 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; |
| 41 | 41 |
| 42 void ShutdownOnUIThread(); | |
| 43 | |
| 42 static void RegisterUserPrefs(PrefService* prefs); | 44 static void RegisterUserPrefs(PrefService* prefs); |
| 43 | 45 |
| 44 // NotificationObserver implementation. | 46 // NotificationObserver implementation. |
| 45 virtual void Observe(NotificationType type, | 47 virtual void Observe(NotificationType type, |
| 46 const NotificationSource& source, | 48 const NotificationSource& source, |
| 47 const NotificationDetails& details); | 49 const NotificationDetails& details); |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 // Informs observers that content settings have changed. Make sure that | 52 // Informs observers that content settings have changed. Make sure that |
| 51 // |lock_| is not held when calling this, as listeners will usually call one | 53 // |lock_| is not held when calling this, as listeners will usually call one |
| 52 // of the GetSettings functions in response, which would then lead to a | 54 // of the GetSettings functions in response, which would then lead to a |
| 53 // mutex deadlock. | 55 // mutex deadlock. |
| 54 void NotifyObservers(const ContentSettingsDetails& details); | 56 void NotifyObservers(const ContentSettingsDetails& details); |
| 55 | 57 |
| 56 void UnregisterObservers(); | |
| 57 | |
| 58 // Reads the policy managed default settings. | 58 // Reads the policy managed default settings. |
| 59 void ReadManagedDefaultSettings(); | 59 void ReadManagedDefaultSettings(); |
| 60 | 60 |
| 61 // Reads the policy controlled default settings for a specific content type. | 61 // Reads the policy controlled default settings for a specific content type. |
| 62 void UpdateManagedDefaultSetting(ContentSettingsType content_type); | 62 void UpdateManagedDefaultSetting(ContentSettingsType content_type); |
| 63 | 63 |
| 64 // Copies of the pref data, so that we can read it on the IO thread. | 64 // Copies of the pref data, so that we can read it on the IO thread. |
| 65 ContentSettings managed_default_content_settings_; | 65 ContentSettings managed_default_content_settings_; |
| 66 | 66 |
| 67 Profile* profile_; | 67 HostContentSettingsMap* map_; |
| 68 | 68 PrefService* prefs_; |
| 69 // Whether this settings map is for an OTR session. | |
| 70 bool is_off_the_record_; | |
| 71 | 69 |
| 72 // Used around accesses to the managed_default_content_settings_ object to | 70 // Used around accesses to the managed_default_content_settings_ object to |
| 73 // guarantee thread safety. | 71 // guarantee thread safety. |
| 74 mutable base::Lock lock_; | 72 mutable base::Lock lock_; |
| 75 | 73 |
| 76 PrefChangeRegistrar pref_change_registrar_; | 74 PrefChangeRegistrar pref_change_registrar_; |
| 77 NotificationRegistrar notification_registrar_; | 75 NotificationRegistrar notification_registrar_; |
| 78 | 76 |
| 79 DISALLOW_COPY_AND_ASSIGN(PolicyDefaultProvider); | 77 DISALLOW_COPY_AND_ASSIGN(PolicyDefaultProvider); |
| 80 }; | 78 }; |
| 81 | 79 |
| 82 // PolicyProvider that provider managed content-settings. | 80 // PolicyProvider that provider managed content-settings. |
| 83 class PolicyProvider : public ProviderInterface, | 81 class PolicyProvider : public ProviderInterface, |
| 84 public NotificationObserver { | 82 public NotificationObserver { |
| 85 public: | 83 public: |
| 86 explicit PolicyProvider(Profile* profile, | 84 PolicyProvider(HostContentSettingsMap* map, |
| 87 DefaultProviderInterface* default_provider); | 85 PrefService* prefs, |
| 86 DefaultProviderInterface* default_provider); | |
| 88 virtual ~PolicyProvider(); | 87 virtual ~PolicyProvider(); |
| 89 static void RegisterUserPrefs(PrefService* prefs); | 88 static void RegisterUserPrefs(PrefService* prefs); |
| 90 | 89 |
| 91 // ProviderInterface Implementation | 90 // ProviderInterface Implementation |
| 92 virtual void Init(); | |
| 93 | |
| 94 virtual void SetContentSetting( | 91 virtual void SetContentSetting( |
| 95 const ContentSettingsPattern& primary_pattern, | 92 const ContentSettingsPattern& primary_pattern, |
| 96 const ContentSettingsPattern& secondary_pattern, | 93 const ContentSettingsPattern& secondary_pattern, |
| 97 ContentSettingsType content_type, | 94 ContentSettingsType content_type, |
| 98 const ResourceIdentifier& resource_identifier, | 95 const ResourceIdentifier& resource_identifier, |
| 99 ContentSetting content_setting); | 96 ContentSetting content_setting); |
| 100 | 97 |
| 101 virtual ContentSetting GetContentSetting( | 98 virtual ContentSetting GetContentSetting( |
| 102 const GURL& primary_url, | 99 const GURL& primary_url, |
| 103 const GURL& secondary_url, | 100 const GURL& secondary_url, |
| 104 ContentSettingsType content_type, | 101 ContentSettingsType content_type, |
| 105 const ResourceIdentifier& resource_identifier) const; | 102 const ResourceIdentifier& resource_identifier) const; |
| 106 | 103 |
| 107 virtual void GetAllContentSettingsRules( | 104 virtual void GetAllContentSettingsRules( |
| 108 ContentSettingsType content_type, | 105 ContentSettingsType content_type, |
| 109 const ResourceIdentifier& resource_identifier, | 106 const ResourceIdentifier& resource_identifier, |
| 110 Rules* content_setting_rules) const; | 107 Rules* content_setting_rules) const; |
| 111 | 108 |
| 112 virtual void ClearAllContentSettingsRules( | 109 virtual void ClearAllContentSettingsRules( |
| 113 ContentSettingsType content_type); | 110 ContentSettingsType content_type); |
| 114 | 111 |
| 112 virtual void ShutdownOnUIThread(); | |
| 113 | |
| 115 // NotificationObserver implementation. | 114 // NotificationObserver implementation. |
| 116 virtual void Observe(NotificationType type, | 115 virtual void Observe(NotificationType type, |
| 117 const NotificationSource& source, | 116 const NotificationSource& source, |
| 118 const NotificationDetails& details); | 117 const NotificationDetails& details); |
| 119 private: | 118 private: |
| 120 typedef Tuple5< | 119 typedef Tuple5< |
| 121 ContentSettingsPattern, | 120 ContentSettingsPattern, |
| 122 ContentSettingsPattern, | 121 ContentSettingsPattern, |
| 123 ContentSettingsType, | 122 ContentSettingsType, |
| 124 ResourceIdentifier, | 123 ResourceIdentifier, |
| 125 ContentSetting> ContentSettingsRule; | 124 ContentSetting> ContentSettingsRule; |
| 126 | 125 |
| 127 typedef std::vector<ContentSettingsRule> ContentSettingsRules; | 126 typedef std::vector<ContentSettingsRule> ContentSettingsRules; |
| 128 | 127 |
| 129 void ReadManagedContentSettings(bool overwrite); | 128 void ReadManagedContentSettings(bool overwrite); |
| 130 | 129 |
| 131 void GetContentSettingsFromPreferences(PrefService* prefs, | 130 void GetContentSettingsFromPreferences(ContentSettingsRules* rules); |
| 132 ContentSettingsRules* rules); | |
| 133 | 131 |
| 134 void ReadManagedContentSettingsTypes( | 132 void ReadManagedContentSettingsTypes(ContentSettingsType content_type); |
| 135 ContentSettingsType content_type); | |
| 136 | 133 |
| 137 void NotifyObservers(const ContentSettingsDetails& details); | 134 void NotifyObservers(const ContentSettingsDetails& details); |
| 138 | 135 |
| 139 void UnregisterObservers(); | |
| 140 | |
| 141 OriginIdentifierValueMap value_map_; | 136 OriginIdentifierValueMap value_map_; |
| 142 | 137 |
| 143 Profile* profile_; | 138 HostContentSettingsMap* map_; |
|
markusheintz_
2011/07/07 15:23:18
Maybe you should use a better name here.
e.g. host
Bernhard Bauer
2011/07/08 17:05:27
Done.
| |
| 139 PrefService* prefs_; | |
| 144 | 140 |
| 145 // Weak, owned by HostContentSettingsMap. | 141 // Weak, owned by HostContentSettingsMap. |
| 146 DefaultProviderInterface* default_provider_; | 142 DefaultProviderInterface* default_provider_; |
| 147 | 143 |
| 148 PrefChangeRegistrar pref_change_registrar_; | 144 PrefChangeRegistrar pref_change_registrar_; |
| 149 NotificationRegistrar notification_registrar_; | |
| 150 | 145 |
| 151 // Used around accesses to the content_settings_ object to guarantee | 146 // Used around accesses to the content_settings_ object to guarantee |
| 152 // thread safety. | 147 // thread safety. |
| 153 mutable base::Lock lock_; | 148 mutable base::Lock lock_; |
| 154 | 149 |
| 155 DISALLOW_COPY_AND_ASSIGN(PolicyProvider); | 150 DISALLOW_COPY_AND_ASSIGN(PolicyProvider); |
| 156 }; | 151 }; |
| 157 | 152 |
| 158 } // namespace content_settings | 153 } // namespace content_settings |
| 159 | 154 |
| 160 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ | 155 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ |
| OLD | NEW |