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 | 7 |
8 // A content settings provider that takes its settings out of policies. | 8 // A content settings provider that takes its settings out of policies. |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/prefs/public/pref_change_registrar.h" | 13 #include "base/prefs/public/pref_change_registrar.h" |
14 #include "base/prefs/public/pref_observer.h" | |
15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
16 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 15 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
17 #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" |
18 | 17 |
19 class PrefService; | 18 class PrefService; |
20 | 19 |
21 namespace content_settings { | 20 namespace content_settings { |
22 | 21 |
23 // PolicyProvider that provides managed content-settings. | 22 // PolicyProvider that provides managed content-settings. |
24 class PolicyProvider : public ObservableProvider, | 23 class PolicyProvider : public ObservableProvider { |
25 public PrefObserver { | |
26 public: | 24 public: |
27 explicit PolicyProvider(PrefService* prefs); | 25 explicit PolicyProvider(PrefService* prefs); |
28 virtual ~PolicyProvider(); | 26 virtual ~PolicyProvider(); |
29 static void RegisterUserPrefs(PrefService* prefs); | 27 static void RegisterUserPrefs(PrefService* prefs); |
30 | 28 |
31 // ProviderInterface implementations. | 29 // ProviderInterface implementations. |
32 virtual RuleIterator* GetRuleIterator( | 30 virtual RuleIterator* GetRuleIterator( |
33 ContentSettingsType content_type, | 31 ContentSettingsType content_type, |
34 const ResourceIdentifier& resource_identifier, | 32 const ResourceIdentifier& resource_identifier, |
35 bool incognito) const OVERRIDE; | 33 bool incognito) const OVERRIDE; |
36 | 34 |
37 virtual bool SetWebsiteSetting( | 35 virtual bool SetWebsiteSetting( |
38 const ContentSettingsPattern& primary_pattern, | 36 const ContentSettingsPattern& primary_pattern, |
39 const ContentSettingsPattern& secondary_pattern, | 37 const ContentSettingsPattern& secondary_pattern, |
40 ContentSettingsType content_type, | 38 ContentSettingsType content_type, |
41 const ResourceIdentifier& resource_identifier, | 39 const ResourceIdentifier& resource_identifier, |
42 Value* value) OVERRIDE; | 40 Value* value) OVERRIDE; |
43 | 41 |
44 virtual void ClearAllContentSettingsRules( | 42 virtual void ClearAllContentSettingsRules( |
45 ContentSettingsType content_type) OVERRIDE; | 43 ContentSettingsType content_type) OVERRIDE; |
46 | 44 |
47 virtual void ShutdownOnUIThread() OVERRIDE; | 45 virtual void ShutdownOnUIThread() OVERRIDE; |
48 | 46 |
49 // PrefObserver implementation. | |
50 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
51 const std::string& pref_name) OVERRIDE; | |
52 | |
53 private: | 47 private: |
54 // Reads the policy managed default settings. | 48 // Reads the policy managed default settings. |
55 void ReadManagedDefaultSettings(); | 49 void ReadManagedDefaultSettings(); |
56 | 50 |
| 51 // Callback for preference changes. |
| 52 void OnPreferenceChanged(const std::string& pref_name); |
| 53 |
57 // Reads the policy controlled default settings for a specific content type. | 54 // Reads the policy controlled default settings for a specific content type. |
58 void UpdateManagedDefaultSetting(ContentSettingsType content_type); | 55 void UpdateManagedDefaultSetting(ContentSettingsType content_type); |
59 | 56 |
60 void ReadManagedContentSettings(bool overwrite); | 57 void ReadManagedContentSettings(bool overwrite); |
61 | 58 |
62 void GetContentSettingsFromPreferences(OriginIdentifierValueMap* rules); | 59 void GetContentSettingsFromPreferences(OriginIdentifierValueMap* rules); |
63 | 60 |
64 void GetAutoSelectCertificateSettingsFromPreferences( | 61 void GetAutoSelectCertificateSettingsFromPreferences( |
65 OriginIdentifierValueMap* value_map); | 62 OriginIdentifierValueMap* value_map); |
66 | 63 |
67 void ReadManagedContentSettingsTypes(ContentSettingsType content_type); | 64 void ReadManagedContentSettingsTypes(ContentSettingsType content_type); |
68 | 65 |
69 OriginIdentifierValueMap value_map_; | 66 OriginIdentifierValueMap value_map_; |
70 | 67 |
71 PrefService* prefs_; | 68 PrefService* prefs_; |
72 | 69 |
73 PrefChangeRegistrar pref_change_registrar_; | 70 PrefChangeRegistrar pref_change_registrar_; |
74 | 71 |
75 // Used around accesses to the |value_map_| object to guarantee | 72 // Used around accesses to the |value_map_| object to guarantee |
76 // thread safety. | 73 // thread safety. |
77 mutable base::Lock lock_; | 74 mutable base::Lock lock_; |
78 | 75 |
79 DISALLOW_COPY_AND_ASSIGN(PolicyProvider); | 76 DISALLOW_COPY_AND_ASSIGN(PolicyProvider); |
80 }; | 77 }; |
81 | 78 |
82 } // namespace content_settings | 79 } // namespace content_settings |
83 | 80 |
84 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ | 81 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_POLICY_PROVIDER_H_ |
OLD | NEW |