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