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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 25 matching lines...) Expand all Loading... | |
36 typedef base::Callback<void(const ContentSettingsPattern&, | 36 typedef base::Callback<void(const ContentSettingsPattern&, |
37 const ContentSettingsPattern&, | 37 const ContentSettingsPattern&, |
38 ContentSettingsType, | 38 ContentSettingsType, |
39 const std::string&)> NotifyObserversCallback; | 39 const std::string&)> NotifyObserversCallback; |
40 | 40 |
41 ContentSettingsPref(ContentSettingsType content_type, | 41 ContentSettingsPref(ContentSettingsType content_type, |
42 PrefService* prefs, | 42 PrefService* prefs, |
43 PrefChangeRegistrar* registrar, | 43 PrefChangeRegistrar* registrar, |
44 const std::string& pref_name, | 44 const std::string& pref_name, |
45 bool incognito, | 45 bool incognito, |
46 bool store_last_modified, | |
46 NotifyObserversCallback notify_callback); | 47 NotifyObserversCallback notify_callback); |
47 ~ContentSettingsPref(); | 48 ~ContentSettingsPref(); |
48 | 49 |
49 // Returns nullptr to indicate the RuleIterator is empty. | 50 // Returns nullptr to indicate the RuleIterator is empty. |
50 std::unique_ptr<RuleIterator> GetRuleIterator( | 51 std::unique_ptr<RuleIterator> GetRuleIterator( |
51 const ResourceIdentifier& resource_identifier, | 52 const ResourceIdentifier& resource_identifier, |
52 bool incognito) const; | 53 bool incognito) const; |
53 | 54 |
54 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, | 55 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, |
55 const ContentSettingsPattern& secondary_pattern, | 56 const ContentSettingsPattern& secondary_pattern, |
56 const ResourceIdentifier& resource_identifier, | 57 const ResourceIdentifier& resource_identifier, |
57 base::Value* value); | 58 base::Value* value); |
58 | 59 |
60 // Delete a setting if its |last_modified| date is greater or equal to | |
61 // |begin_time|. | |
62 void DeleteWebsiteSetting(const ContentSettingsPattern& primary_pattern, | |
63 const ContentSettingsPattern& secondary_pattern, | |
64 base::Time begin_time); | |
raymes
2017/04/24 03:20:22
const base::Time&
| |
65 | |
59 void ClearPref(); | 66 void ClearPref(); |
60 | 67 |
61 void ClearAllContentSettingsRules(); | 68 void ClearAllContentSettingsRules(); |
62 | 69 |
63 size_t GetNumExceptions(); | 70 size_t GetNumExceptions(); |
64 | 71 |
65 // Tries to lock |lock_|. If successful, returns true and releases the lock. | 72 // Tries to lock |lock_|. If successful, returns true and releases the lock. |
66 bool TryLockForTesting() const; | 73 bool TryLockForTesting() const; |
67 | 74 |
68 private: | 75 private: |
69 // Reads all content settings exceptions from the preference and loads them | 76 // Reads all content settings exceptions from the preference and loads them |
70 // into the |value_map_|. The |value_map_| is cleared first. | 77 // into the |value_map_|. The |value_map_| is cleared first. |
71 void ReadContentSettingsFromPref(); | 78 void ReadContentSettingsFromPref(); |
72 | 79 |
73 // Callback for changes in the pref with the same name. | 80 // Callback for changes in the pref with the same name. |
74 void OnPrefChanged(); | 81 void OnPrefChanged(); |
75 | 82 |
76 // Update the preference that stores content settings exceptions and syncs the | 83 // Update the preference that stores content settings exceptions and syncs the |
77 // value to the obsolete preference. When calling this function, |lock_| | 84 // value to the obsolete preference. When calling this function, |lock_| |
78 // should not be held, since this function will send out notifications of | 85 // should not be held, since this function will send out notifications of |
79 // preference changes. | 86 // preference changes. |
80 void UpdatePref( | 87 void UpdatePref(const ContentSettingsPattern& primary_pattern, |
81 const ContentSettingsPattern& primary_pattern, | 88 const ContentSettingsPattern& secondary_pattern, |
82 const ContentSettingsPattern& secondary_pattern, | 89 const ResourceIdentifier& resource_identifier, |
83 const ResourceIdentifier& resource_identifier, | 90 const base::Time last_modified, |
raymes
2017/04/24 03:20:22
const base::Time&
| |
84 const base::Value* value); | 91 const base::Value* value); |
85 | 92 |
86 static void CanonicalizeContentSettingsExceptions( | 93 static void CanonicalizeContentSettingsExceptions( |
87 base::DictionaryValue* all_settings_dictionary); | 94 base::DictionaryValue* all_settings_dictionary); |
88 | 95 |
89 // In the debug mode, asserts that |lock_| is not held by this thread. It's | 96 // In the debug mode, asserts that |lock_| is not held by this thread. It's |
90 // ok if some other thread holds |lock_|, as long as it will eventually | 97 // ok if some other thread holds |lock_|, as long as it will eventually |
91 // release it. | 98 // release it. |
92 void AssertLockNotHeld() const; | 99 void AssertLockNotHeld() const; |
93 | 100 |
94 // The type of content settings stored in this pref. | 101 // The type of content settings stored in this pref. |
95 ContentSettingsType content_type_; | 102 ContentSettingsType content_type_; |
96 | 103 |
97 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | 104 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
98 PrefService* prefs_; | 105 PrefService* prefs_; |
99 | 106 |
100 // Owned by the PrefProvider. | 107 // Owned by the PrefProvider. |
101 PrefChangeRegistrar* registrar_; | 108 PrefChangeRegistrar* registrar_; |
102 | 109 |
103 // Name of the dictionary preference managed by this class. | 110 // Name of the dictionary preference managed by this class. |
104 const std::string& pref_name_; | 111 const std::string& pref_name_; |
105 | 112 |
106 bool is_incognito_; | 113 bool is_incognito_; |
107 | 114 |
115 bool store_last_modified_; | |
116 | |
108 // Whether we are currently updating preferences, this is used to ignore | 117 // Whether we are currently updating preferences, this is used to ignore |
109 // notifications from the preferences service that we triggered ourself. | 118 // notifications from the preferences service that we triggered ourself. |
110 bool updating_preferences_; | 119 bool updating_preferences_; |
111 | 120 |
112 OriginIdentifierValueMap value_map_; | 121 OriginIdentifierValueMap value_map_; |
113 | 122 |
114 OriginIdentifierValueMap incognito_value_map_; | 123 OriginIdentifierValueMap incognito_value_map_; |
115 | 124 |
116 NotifyObserversCallback notify_callback_; | 125 NotifyObserversCallback notify_callback_; |
117 | 126 |
118 // Used around accesses to the value map objects to guarantee thread safety. | 127 // Used around accesses to the value map objects to guarantee thread safety. |
119 mutable base::Lock lock_; | 128 mutable base::Lock lock_; |
120 | 129 |
121 base::ThreadChecker thread_checker_; | 130 base::ThreadChecker thread_checker_; |
122 | 131 |
123 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); | 132 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); |
124 }; | 133 }; |
125 | 134 |
126 } // namespace content_settings | 135 } // namespace content_settings |
127 | 136 |
128 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 137 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
OLD | NEW |