OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PREF_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
7 | 7 |
8 // A content settings provider that takes its settings out of the pref service. | 8 // A content settings provider that takes its settings out of the pref service. |
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" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 16 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" | 17 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" |
17 #include "chrome/browser/content_settings/content_settings_utils.h" | 18 #include "chrome/browser/content_settings/content_settings_utils.h" |
18 #include "content/public/browser/notification_observer.h" | |
19 #include "content/public/browser/notification_registrar.h" | |
20 | 19 |
21 class PrefService; | 20 class PrefService; |
22 | 21 |
23 namespace base { | 22 namespace base { |
24 class DictionaryValue; | 23 class DictionaryValue; |
25 } | 24 } |
26 | 25 |
27 namespace content_settings { | 26 namespace content_settings { |
28 | 27 |
29 // Content settings provider that provides content settings from the user | 28 // Content settings provider that provides content settings from the user |
30 // preference. | 29 // preference. |
31 class PrefProvider : public ObservableProvider, | 30 class PrefProvider : public ObservableProvider, |
32 public content::NotificationObserver { | 31 public PrefObserver { |
33 public: | 32 public: |
34 static void RegisterUserPrefs(PrefService* prefs); | 33 static void RegisterUserPrefs(PrefService* prefs); |
35 | 34 |
36 PrefProvider(PrefService* prefs, | 35 PrefProvider(PrefService* prefs, |
37 bool incognito); | 36 bool incognito); |
38 virtual ~PrefProvider(); | 37 virtual ~PrefProvider(); |
39 | 38 |
40 // ProviderInterface implementations. | 39 // ProviderInterface implementations. |
41 virtual RuleIterator* GetRuleIterator( | 40 virtual RuleIterator* GetRuleIterator( |
42 ContentSettingsType content_type, | 41 ContentSettingsType content_type, |
43 const ResourceIdentifier& resource_identifier, | 42 const ResourceIdentifier& resource_identifier, |
44 bool incognito) const OVERRIDE; | 43 bool incognito) const OVERRIDE; |
45 | 44 |
46 virtual bool SetWebsiteSetting( | 45 virtual bool SetWebsiteSetting( |
47 const ContentSettingsPattern& primary_pattern, | 46 const ContentSettingsPattern& primary_pattern, |
48 const ContentSettingsPattern& secondary_pattern, | 47 const ContentSettingsPattern& secondary_pattern, |
49 ContentSettingsType content_type, | 48 ContentSettingsType content_type, |
50 const ResourceIdentifier& resource_identifier, | 49 const ResourceIdentifier& resource_identifier, |
51 Value* value) OVERRIDE; | 50 Value* value) OVERRIDE; |
52 | 51 |
53 virtual void ClearAllContentSettingsRules( | 52 virtual void ClearAllContentSettingsRules( |
54 ContentSettingsType content_type) OVERRIDE; | 53 ContentSettingsType content_type) OVERRIDE; |
55 | 54 |
56 virtual void ShutdownOnUIThread() OVERRIDE; | 55 virtual void ShutdownOnUIThread() OVERRIDE; |
57 | 56 |
58 // content::NotificationObserver implementation. | 57 // PrefObserver implementation. |
59 virtual void Observe(int type, | 58 virtual void OnPreferenceChanged(PrefServiceBase* service, |
60 const content::NotificationSource& source, | 59 const std::string& pref_name) OVERRIDE; |
61 const content::NotificationDetails& details) OVERRIDE; | |
62 | 60 |
63 private: | 61 private: |
64 friend class DeadlockCheckerThread; // For testing. | 62 friend class DeadlockCheckerThread; // For testing. |
65 // Reads all content settings exceptions from the preference and load them | 63 // Reads all content settings exceptions from the preference and load them |
66 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is | 64 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is |
67 // true. | 65 // true. |
68 void ReadContentSettingsFromPref(bool overwrite); | 66 void ReadContentSettingsFromPref(bool overwrite); |
69 | 67 |
70 // Update the preference that stores content settings exceptions and syncs the | 68 // Update the preference that stores content settings exceptions and syncs the |
71 // value to the obsolete preference. When calling this function, |lock_| | 69 // value to the obsolete preference. When calling this function, |lock_| |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 115 |
118 // Used around accesses to the value map objects to guarantee thread safety. | 116 // Used around accesses to the value map objects to guarantee thread safety. |
119 mutable base::Lock lock_; | 117 mutable base::Lock lock_; |
120 | 118 |
121 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | 119 DISALLOW_COPY_AND_ASSIGN(PrefProvider); |
122 }; | 120 }; |
123 | 121 |
124 } // namespace content_settings | 122 } // namespace content_settings |
125 | 123 |
126 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 124 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
OLD | NEW |