OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 namespace user_prefs { | 27 namespace user_prefs { |
28 class PrefRegistrySyncable; | 28 class PrefRegistrySyncable; |
29 } | 29 } |
30 | 30 |
31 namespace content_settings { | 31 namespace content_settings { |
32 | 32 |
33 class RuleIterator; | 33 class RuleIterator; |
34 | 34 |
35 // Represents a single pref for reading/writing content settings. | 35 // Represents a single pref for reading/writing content settings of one type. |
36 // TODO(raymes): Currently all content settings types are stored in a single | |
37 // instance of one of these. But the intention is that there will be one | |
38 // instance of this class per content settings type. | |
39 class ContentSettingsPref { | 36 class ContentSettingsPref { |
40 public: | 37 public: |
41 typedef base::Callback<void(const ContentSettingsPattern&, | 38 typedef base::Callback<void(const ContentSettingsPattern&, |
42 const ContentSettingsPattern&, | 39 const ContentSettingsPattern&, |
43 ContentSettingsType, | 40 ContentSettingsType, |
44 const std::string&)> NotifyObserversCallback; | 41 const std::string&)> NotifyObserversCallback; |
45 | 42 |
46 ContentSettingsPref(PrefService* prefs, | 43 ContentSettingsPref(ContentSettingsType content_type, |
| 44 PrefService* prefs, |
47 PrefChangeRegistrar* registrar, | 45 PrefChangeRegistrar* registrar, |
48 base::Clock* clock, | 46 const char* pref_name, |
49 bool incognito, | 47 bool incognito, |
| 48 bool* updating_old_preferences_flag, |
50 NotifyObserversCallback notify_callback); | 49 NotifyObserversCallback notify_callback); |
51 ~ContentSettingsPref(); | 50 ~ContentSettingsPref(); |
52 | 51 |
53 RuleIterator* GetRuleIterator(ContentSettingsType content_type, | 52 RuleIterator* GetRuleIterator(const ResourceIdentifier& resource_identifier, |
54 const ResourceIdentifier& resource_identifier, | |
55 bool incognito) const; | 53 bool incognito) const; |
56 | 54 |
57 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, | 55 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, |
58 const ContentSettingsPattern& secondary_pattern, | 56 const ContentSettingsPattern& secondary_pattern, |
59 ContentSettingsType content_type, | |
60 const ResourceIdentifier& resource_identifier, | 57 const ResourceIdentifier& resource_identifier, |
61 base::Value* value); | 58 base::Value* value); |
62 | 59 |
63 void ClearAllContentSettingsRules(ContentSettingsType content_type); | 60 void ClearAllContentSettingsRules(); |
64 | 61 |
65 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, | 62 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, |
66 const ContentSettingsPattern& secondary_pattern, | 63 const ContentSettingsPattern& secondary_pattern, |
67 ContentSettingsType content_type); | 64 base::Clock* clock); |
68 | 65 |
69 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, | 66 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, |
70 const ContentSettingsPattern& secondary_pattern, | 67 const ContentSettingsPattern& secondary_pattern); |
71 ContentSettingsType content_type); | |
72 | 68 |
73 size_t GetNumExceptions(); | 69 size_t GetNumExceptions(); |
74 | 70 |
75 void SetClockForTesting(base::Clock* clock); | |
76 private: | 71 private: |
77 friend class DeadlockCheckerThread; // For testing. | 72 // Only to access static method CanonicalizeContentSettingsExceptions, |
| 73 // so that we reduce duplicity between the two. |
| 74 // TODO(msramek): Remove this after the migration is over. |
| 75 friend class PrefProvider; |
78 | 76 |
79 // Reads all content settings exceptions from the preference and load them | 77 // Reads all content settings exceptions from the preference and load them |
80 // into the |value_map_|. The |value_map_| is cleared first. | 78 // into the |value_map_|. The |value_map_| is cleared first. |
81 void ReadContentSettingsFromPref(); | 79 void ReadContentSettingsFromPrefAndWriteToOldPref(); |
82 | 80 |
83 // Callback for changes in the pref with the same name. | 81 // Callback for changes in the pref with the same name. |
84 void OnContentSettingsPatternPairsChanged(); | 82 void OnPrefChanged(); |
85 | 83 |
86 // Update the preference that stores content settings exceptions and syncs the | 84 // Update the preference that stores content settings exceptions and syncs the |
87 // value to the obsolete preference. When calling this function, |lock_| | 85 // value to the obsolete preference. When calling this function, |lock_| |
88 // should not be held, since this function will send out notifications of | 86 // should not be held, since this function will send out notifications of |
89 // preference changes. | 87 // preference changes. |
90 void UpdatePref( | 88 void UpdatePref( |
91 const ContentSettingsPattern& primary_pattern, | 89 const ContentSettingsPattern& primary_pattern, |
92 const ContentSettingsPattern& secondary_pattern, | 90 const ContentSettingsPattern& secondary_pattern, |
93 ContentSettingsType content_type, | |
94 const ResourceIdentifier& resource_identifier, | 91 const ResourceIdentifier& resource_identifier, |
95 const base::Value* value); | 92 const base::Value* value); |
96 | 93 |
97 static void CanonicalizeContentSettingsExceptions( | 94 static void CanonicalizeContentSettingsExceptions( |
98 base::DictionaryValue* all_settings_dictionary); | 95 base::DictionaryValue* all_settings_dictionary); |
99 | 96 |
100 // In the debug mode, asserts that |lock_| is not held by this thread. It's | 97 // In the debug mode, asserts that |lock_| is not held by this thread. It's |
101 // ok if some other thread holds |lock_|, as long as it will eventually | 98 // ok if some other thread holds |lock_|, as long as it will eventually |
102 // release it. | 99 // release it. |
103 void AssertLockNotHeld() const; | 100 void AssertLockNotHeld() const; |
104 | 101 |
| 102 // Update the old aggregate preference, so that the settings can be synced |
| 103 // to old versions of Chrome. |
| 104 // TODO(msramek): Remove after the migration is over. |
| 105 void UpdateOldPref( |
| 106 const ContentSettingsPattern& primary_pattern, |
| 107 const ContentSettingsPattern& secondary_pattern, |
| 108 const ResourceIdentifier& resource_identifier, |
| 109 const base::Value* value); |
| 110 |
| 111 // Remove all exceptions of |content_type_| from the old aggregate dictionary |
| 112 // preference. |
| 113 // TODO(msramek): Remove after the migration is over. |
| 114 void ClearOldPreference(); |
| 115 |
| 116 // The type of content settings stored in this pref. |
| 117 ContentSettingsType content_type_; |
| 118 |
105 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | 119 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
106 PrefService* prefs_; | 120 PrefService* prefs_; |
107 | 121 |
108 // Owned by the PrefProvider. | 122 // Owned by the PrefProvider. |
109 base::Clock* clock_; | 123 PrefChangeRegistrar* registrar_; |
110 | 124 |
111 // Owned by the PrefProvider. | 125 // Name of the dictionary preference managed by this class. |
112 PrefChangeRegistrar* registrar_; | 126 const char* pref_name_; |
113 | 127 |
114 bool is_incognito_; | 128 bool is_incognito_; |
115 | 129 |
116 // Whether we are currently updating preferences, this is used to ignore | 130 // Whether we are currently updating preferences, this is used to ignore |
117 // notifications from the preferences service that we triggered ourself. | 131 // notifications from the preferences service that we triggered ourself. |
118 bool updating_preferences_; | 132 bool updating_preferences_; |
119 | 133 |
| 134 // Whether we are currently updating the old aggregate dictionary preference. |
| 135 // Owned by the parent |PrefProvider| and shared by all its children |
| 136 // |ContentSettingsPref|s. |
| 137 bool* updating_old_preferences_; |
| 138 |
120 OriginIdentifierValueMap value_map_; | 139 OriginIdentifierValueMap value_map_; |
121 | 140 |
122 OriginIdentifierValueMap incognito_value_map_; | 141 OriginIdentifierValueMap incognito_value_map_; |
123 | 142 |
124 NotifyObserversCallback notify_callback_; | 143 NotifyObserversCallback notify_callback_; |
125 | 144 |
126 // Used around accesses to the value map objects to guarantee thread safety. | 145 // Used around accesses to the value map objects to guarantee thread safety. |
127 mutable base::Lock lock_; | 146 mutable base::Lock lock_; |
128 | 147 |
129 base::ThreadChecker thread_checker_; | 148 base::ThreadChecker thread_checker_; |
130 | 149 |
131 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); | 150 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); |
132 }; | 151 }; |
133 | 152 |
134 } // namespace content_settings | 153 } // namespace content_settings |
135 | 154 |
136 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 155 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
OLD | NEW |