| 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 explicit PolicyDefaultProvider(HostContentSettingsMap* map, |
| 33 PrefService* prefs); |
| 33 virtual ~PolicyDefaultProvider(); | 34 virtual ~PolicyDefaultProvider(); |
| 34 | 35 |
| 35 // DefaultContentSettingsProvider implementation. | 36 // DefaultContentSettingsProvider implementation. |
| 36 virtual ContentSetting ProvideDefaultSetting( | 37 virtual ContentSetting ProvideDefaultSetting( |
| 37 ContentSettingsType content_type) const; | 38 ContentSettingsType content_type) const; |
| 38 virtual void UpdateDefaultSetting(ContentSettingsType content_type, | 39 virtual void UpdateDefaultSetting(ContentSettingsType content_type, |
| 39 ContentSetting setting); | 40 ContentSetting setting); |
| 40 virtual void ResetToDefaults(); | 41 virtual void ResetToDefaults(); |
| 41 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; | 42 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; |
| 42 | 43 |
| 44 void ShutdownOnUIThread(); |
| 45 |
| 43 static void RegisterUserPrefs(PrefService* prefs); | 46 static void RegisterUserPrefs(PrefService* prefs); |
| 44 | 47 |
| 45 // NotificationObserver implementation. | 48 // NotificationObserver implementation. |
| 46 virtual void Observe(NotificationType type, | 49 virtual void Observe(NotificationType type, |
| 47 const NotificationSource& source, | 50 const NotificationSource& source, |
| 48 const NotificationDetails& details); | 51 const NotificationDetails& details); |
| 49 | 52 |
| 50 private: | 53 private: |
| 51 // Informs observers that content settings have changed. Make sure that | 54 // Informs observers that content settings have changed. Make sure that |
| 52 // |lock_| is not held when calling this, as listeners will usually call one | 55 // |lock_| is not held when calling this, as listeners will usually call one |
| 53 // of the GetSettings functions in response, which would then lead to a | 56 // of the GetSettings functions in response, which would then lead to a |
| 54 // mutex deadlock. | 57 // mutex deadlock. |
| 55 void NotifyObservers(const ContentSettingsDetails& details); | 58 void NotifyObservers(const ContentSettingsDetails& details); |
| 56 | 59 |
| 57 void UnregisterObservers(); | |
| 58 | |
| 59 // Reads the policy managed default settings. | 60 // Reads the policy managed default settings. |
| 60 void ReadManagedDefaultSettings(); | 61 void ReadManagedDefaultSettings(); |
| 61 | 62 |
| 62 // Reads the policy controlled default settings for a specific content type. | 63 // Reads the policy controlled default settings for a specific content type. |
| 63 void UpdateManagedDefaultSetting(ContentSettingsType content_type); | 64 void UpdateManagedDefaultSetting(ContentSettingsType content_type); |
| 64 | 65 |
| 65 // Copies of the pref data, so that we can read it on the IO thread. | 66 // Copies of the pref data, so that we can read it on the IO thread. |
| 66 ContentSettings managed_default_content_settings_; | 67 ContentSettings managed_default_content_settings_; |
| 67 | 68 |
| 68 Profile* profile_; | 69 HostContentSettingsMap* map_; |
| 69 | 70 PrefService* prefs_; |
| 70 // Whether this settings map is for an OTR session. | |
| 71 bool is_off_the_record_; | |
| 72 | 71 |
| 73 // Used around accesses to the managed_default_content_settings_ object to | 72 // Used around accesses to the managed_default_content_settings_ object to |
| 74 // guarantee thread safety. | 73 // guarantee thread safety. |
| 75 mutable base::Lock lock_; | 74 mutable base::Lock lock_; |
| 76 | 75 |
| 77 PrefChangeRegistrar pref_change_registrar_; | 76 PrefChangeRegistrar pref_change_registrar_; |
| 78 NotificationRegistrar notification_registrar_; | 77 NotificationRegistrar notification_registrar_; |
| 79 | 78 |
| 80 DISALLOW_COPY_AND_ASSIGN(PolicyDefaultProvider); | 79 DISALLOW_COPY_AND_ASSIGN(PolicyDefaultProvider); |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 // PolicyProvider that provider managed content-settings. | 82 // PolicyProvider that provider managed content-settings. |
| 84 class PolicyProvider : public ProviderInterface, | 83 class PolicyProvider : public ProviderInterface, |
| 85 public NotificationObserver { | 84 public NotificationObserver { |
| 86 public: | 85 public: |
| 87 explicit PolicyProvider(Profile* profile, | 86 explicit PolicyProvider(HostContentSettingsMap* map, |
| 87 PrefService* prefs, |
| 88 DefaultProviderInterface* default_provider); | 88 DefaultProviderInterface* default_provider); |
| 89 virtual ~PolicyProvider(); | 89 virtual ~PolicyProvider(); |
| 90 static void RegisterUserPrefs(PrefService* prefs); | 90 static void RegisterUserPrefs(PrefService* prefs); |
| 91 | 91 |
| 92 // ProviderInterface Implementation | 92 // ProviderInterface Implementation |
| 93 virtual void Init(); | |
| 94 | |
| 95 virtual void SetContentSetting( | 93 virtual void SetContentSetting( |
| 96 const ContentSettingsPattern& primary_pattern, | 94 const ContentSettingsPattern& primary_pattern, |
| 97 const ContentSettingsPattern& secondary_pattern, | 95 const ContentSettingsPattern& secondary_pattern, |
| 98 ContentSettingsType content_type, | 96 ContentSettingsType content_type, |
| 99 const ResourceIdentifier& resource_identifier, | 97 const ResourceIdentifier& resource_identifier, |
| 100 ContentSetting content_setting); | 98 ContentSetting content_setting); |
| 101 | 99 |
| 102 virtual ContentSetting GetContentSetting( | 100 virtual ContentSetting GetContentSetting( |
| 103 const GURL& primary_url, | 101 const GURL& primary_url, |
| 104 const GURL& secondary_url, | 102 const GURL& secondary_url, |
| 105 ContentSettingsType content_type, | 103 ContentSettingsType content_type, |
| 106 const ResourceIdentifier& resource_identifier) const; | 104 const ResourceIdentifier& resource_identifier) const; |
| 107 | 105 |
| 108 virtual void GetAllContentSettingsRules( | 106 virtual void GetAllContentSettingsRules( |
| 109 ContentSettingsType content_type, | 107 ContentSettingsType content_type, |
| 110 const ResourceIdentifier& resource_identifier, | 108 const ResourceIdentifier& resource_identifier, |
| 111 Rules* content_setting_rules) const; | 109 Rules* content_setting_rules) const; |
| 112 | 110 |
| 113 virtual void ClearAllContentSettingsRules( | 111 virtual void ClearAllContentSettingsRules( |
| 114 ContentSettingsType content_type); | 112 ContentSettingsType content_type); |
| 115 | 113 |
| 116 virtual void ResetToDefaults(); | 114 virtual void ResetToDefaults(); |
| 117 | 115 |
| 116 virtual void ShutdownOnUIThread(); |
| 117 |
| 118 // NotificationObserver implementation. | 118 // NotificationObserver implementation. |
| 119 virtual void Observe(NotificationType type, | 119 virtual void Observe(NotificationType type, |
| 120 const NotificationSource& source, | 120 const NotificationSource& source, |
| 121 const NotificationDetails& details); | 121 const NotificationDetails& details); |
| 122 private: | 122 private: |
| 123 typedef Tuple5< | 123 typedef Tuple5< |
| 124 ContentSettingsPattern, | 124 ContentSettingsPattern, |
| 125 ContentSettingsPattern, | 125 ContentSettingsPattern, |
| 126 ContentSettingsType, | 126 ContentSettingsType, |
| 127 ResourceIdentifier, | 127 ResourceIdentifier, |
| 128 ContentSetting> ContentSettingsRule; | 128 ContentSetting> ContentSettingsRule; |
| 129 | 129 |
| 130 typedef std::vector<ContentSettingsRule> ContentSettingsRules; | 130 typedef std::vector<ContentSettingsRule> ContentSettingsRules; |
| 131 | 131 |
| 132 void ReadManagedContentSettings(bool overwrite); | 132 void ReadManagedContentSettings(bool overwrite); |
| 133 | 133 |
| 134 void GetContentSettingsFromPreferences(PrefService* prefs, | 134 void GetContentSettingsFromPreferences(ContentSettingsRules* rules); |
| 135 ContentSettingsRules* rules); | |
| 136 | 135 |
| 137 void ReadManagedContentSettingsTypes( | 136 void ReadManagedContentSettingsTypes(ContentSettingsType content_type); |
| 138 ContentSettingsType content_type); | |
| 139 | 137 |
| 140 void NotifyObservers(const ContentSettingsDetails& details); | 138 void NotifyObservers(const ContentSettingsDetails& details); |
| 141 | 139 |
| 142 void UnregisterObservers(); | 140 void UnregisterObservers(); |
| 143 | 141 |
| 144 OriginIdentifierValueMap value_map_; | 142 OriginIdentifierValueMap value_map_; |
| 145 | 143 |
| 146 Profile* profile_; | 144 HostContentSettingsMap* map_; |
| 145 PrefService* prefs_; |
| 147 | 146 |
| 148 // Weak, owned by HostContentSettingsMap. | 147 // Weak, owned by HostContentSettingsMap. |
| 149 DefaultProviderInterface* default_provider_; | 148 DefaultProviderInterface* default_provider_; |
| 150 | 149 |
| 151 PrefChangeRegistrar pref_change_registrar_; | 150 PrefChangeRegistrar pref_change_registrar_; |
| 152 NotificationRegistrar notification_registrar_; | 151 NotificationRegistrar notification_registrar_; |
| 153 | 152 |
| 154 // Used around accesses to the content_settings_ object to guarantee | 153 // Used around accesses to the content_settings_ object to guarantee |
| 155 // thread safety. | 154 // thread safety. |
| 156 mutable base::Lock lock_; | 155 mutable base::Lock lock_; |
| 157 | 156 |
| 158 DISALLOW_COPY_AND_ASSIGN(PolicyProvider); | 157 DISALLOW_COPY_AND_ASSIGN(PolicyProvider); |
| 159 }; | 158 }; |
| 160 | 159 |
| 161 } // namespace content_settings | 160 } // namespace content_settings |
| 162 | 161 |
| 163 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ | 162 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ |
| OLD | NEW |