| 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 DeleteWebsiteSettingAfterDate( |
| 63 const ContentSettingsPattern& primary_pattern, |
| 64 const ContentSettingsPattern& secondary_pattern, |
| 65 base::Time begin_time); |
| 66 |
| 59 void ClearPref(); | 67 void ClearPref(); |
| 60 | 68 |
| 61 void ClearAllContentSettingsRules(); | 69 void ClearAllContentSettingsRules(); |
| 62 | 70 |
| 63 size_t GetNumExceptions(); | 71 size_t GetNumExceptions(); |
| 64 | 72 |
| 65 // Tries to lock |lock_|. If successful, returns true and releases the lock. | 73 // Tries to lock |lock_|. If successful, returns true and releases the lock. |
| 66 bool TryLockForTesting() const; | 74 bool TryLockForTesting() const; |
| 67 | 75 |
| 68 private: | 76 private: |
| 69 // Reads all content settings exceptions from the preference and loads them | 77 // Reads all content settings exceptions from the preference and loads them |
| 70 // into the |value_map_|. The |value_map_| is cleared first. | 78 // into the |value_map_|. The |value_map_| is cleared first. |
| 71 void ReadContentSettingsFromPref(); | 79 void ReadContentSettingsFromPref(); |
| 72 | 80 |
| 73 // Callback for changes in the pref with the same name. | 81 // Callback for changes in the pref with the same name. |
| 74 void OnPrefChanged(); | 82 void OnPrefChanged(); |
| 75 | 83 |
| 76 // Update the preference that stores content settings exceptions and syncs the | 84 // Update the preference that stores content settings exceptions and syncs the |
| 77 // value to the obsolete preference. When calling this function, |lock_| | 85 // value to the obsolete preference. When calling this function, |lock_| |
| 78 // 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 |
| 79 // preference changes. | 87 // preference changes. |
| 80 void UpdatePref( | 88 void UpdatePref(const ContentSettingsPattern& primary_pattern, |
| 81 const ContentSettingsPattern& primary_pattern, | 89 const ContentSettingsPattern& secondary_pattern, |
| 82 const ContentSettingsPattern& secondary_pattern, | 90 const ResourceIdentifier& resource_identifier, |
| 83 const ResourceIdentifier& resource_identifier, | 91 const base::Time last_modified, |
| 84 const base::Value* value); | 92 const base::Value* value); |
| 85 | 93 |
| 86 static void CanonicalizeContentSettingsExceptions( | 94 static void CanonicalizeContentSettingsExceptions( |
| 87 base::DictionaryValue* all_settings_dictionary); | 95 base::DictionaryValue* all_settings_dictionary); |
| 88 | 96 |
| 89 // 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 |
| 90 // 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 |
| 91 // release it. | 99 // release it. |
| 92 void AssertLockNotHeld() const; | 100 void AssertLockNotHeld() const; |
| 93 | 101 |
| 94 // The type of content settings stored in this pref. | 102 // The type of content settings stored in this pref. |
| 95 ContentSettingsType content_type_; | 103 ContentSettingsType content_type_; |
| 96 | 104 |
| 97 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | 105 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
| 98 PrefService* prefs_; | 106 PrefService* prefs_; |
| 99 | 107 |
| 100 // Owned by the PrefProvider. | 108 // Owned by the PrefProvider. |
| 101 PrefChangeRegistrar* registrar_; | 109 PrefChangeRegistrar* registrar_; |
| 102 | 110 |
| 103 // Name of the dictionary preference managed by this class. | 111 // Name of the dictionary preference managed by this class. |
| 104 const std::string& pref_name_; | 112 const std::string& pref_name_; |
| 105 | 113 |
| 106 bool is_incognito_; | 114 bool is_incognito_; |
| 107 | 115 |
| 116 bool store_last_modified_; |
| 117 |
| 108 // Whether we are currently updating preferences, this is used to ignore | 118 // Whether we are currently updating preferences, this is used to ignore |
| 109 // notifications from the preferences service that we triggered ourself. | 119 // notifications from the preferences service that we triggered ourself. |
| 110 bool updating_preferences_; | 120 bool updating_preferences_; |
| 111 | 121 |
| 112 OriginIdentifierValueMap value_map_; | 122 OriginIdentifierValueMap value_map_; |
| 113 | 123 |
| 114 OriginIdentifierValueMap incognito_value_map_; | 124 OriginIdentifierValueMap incognito_value_map_; |
| 115 | 125 |
| 116 NotifyObserversCallback notify_callback_; | 126 NotifyObserversCallback notify_callback_; |
| 117 | 127 |
| 118 // Used around accesses to the value map objects to guarantee thread safety. | 128 // Used around accesses to the value map objects to guarantee thread safety. |
| 119 mutable base::Lock lock_; | 129 mutable base::Lock lock_; |
| 120 | 130 |
| 121 base::ThreadChecker thread_checker_; | 131 base::ThreadChecker thread_checker_; |
| 122 | 132 |
| 123 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); | 133 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); |
| 124 }; | 134 }; |
| 125 | 135 |
| 126 } // namespace content_settings | 136 } // namespace content_settings |
| 127 | 137 |
| 128 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 138 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
| OLD | NEW |