| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
| 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/synchronization/lock.h" |
| 12 #include "base/threading/thread_checker.h" |
| 13 #include "base/values.h" |
| 14 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" |
| 15 #include "components/content_settings/core/browser/content_settings_provider.h" |
| 16 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 |
| 19 class PrefService; |
| 20 class PrefChangeRegistrar; |
| 21 |
| 22 namespace base { |
| 23 class Clock; |
| 24 class DictionaryValue; |
| 25 } |
| 26 |
| 27 namespace user_prefs { |
| 28 class PrefRegistrySyncable; |
| 29 } |
| 30 |
| 31 namespace content_settings { |
| 32 |
| 33 class RuleIterator; |
| 34 |
| 35 // Represents a single pref for reading/writing content settings. |
| 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 { |
| 40 public: |
| 41 typedef base::Callback<void(const ContentSettingsPattern&, |
| 42 const ContentSettingsPattern&, |
| 43 ContentSettingsType, |
| 44 const std::string&)> NotifyObserversCallback; |
| 45 |
| 46 ContentSettingsPref(PrefService* prefs, |
| 47 PrefChangeRegistrar* registrar, |
| 48 base::Clock* clock, |
| 49 bool incognito, |
| 50 NotifyObserversCallback notify_callback); |
| 51 ~ContentSettingsPref(); |
| 52 |
| 53 RuleIterator* GetRuleIterator(ContentSettingsType content_type, |
| 54 const ResourceIdentifier& resource_identifier, |
| 55 bool incognito) const; |
| 56 |
| 57 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, |
| 58 const ContentSettingsPattern& secondary_pattern, |
| 59 ContentSettingsType content_type, |
| 60 const ResourceIdentifier& resource_identifier, |
| 61 base::Value* value); |
| 62 |
| 63 void ClearAllContentSettingsRules(ContentSettingsType content_type); |
| 64 |
| 65 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, |
| 66 const ContentSettingsPattern& secondary_pattern, |
| 67 ContentSettingsType content_type); |
| 68 |
| 69 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, |
| 70 const ContentSettingsPattern& secondary_pattern, |
| 71 ContentSettingsType content_type); |
| 72 |
| 73 size_t GetNumExceptions(); |
| 74 |
| 75 void SetClockForTesting(base::Clock* clock); |
| 76 private: |
| 77 friend class DeadlockCheckerThread; // For testing. |
| 78 |
| 79 // Reads all content settings exceptions from the preference and load them |
| 80 // into the |value_map_|. The |value_map_| is cleared first. |
| 81 void ReadContentSettingsFromPref(); |
| 82 |
| 83 // Callback for changes in the pref with the same name. |
| 84 void OnContentSettingsPatternPairsChanged(); |
| 85 |
| 86 // Update the preference that stores content settings exceptions and syncs the |
| 87 // value to the obsolete preference. When calling this function, |lock_| |
| 88 // should not be held, since this function will send out notifications of |
| 89 // preference changes. |
| 90 void UpdatePref( |
| 91 const ContentSettingsPattern& primary_pattern, |
| 92 const ContentSettingsPattern& secondary_pattern, |
| 93 ContentSettingsType content_type, |
| 94 const ResourceIdentifier& resource_identifier, |
| 95 const base::Value* value); |
| 96 |
| 97 static void CanonicalizeContentSettingsExceptions( |
| 98 base::DictionaryValue* all_settings_dictionary); |
| 99 |
| 100 // 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 |
| 102 // release it. |
| 103 void AssertLockNotHeld() const; |
| 104 |
| 105 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
| 106 PrefService* prefs_; |
| 107 |
| 108 // Owned by the PrefProvider. |
| 109 base::Clock* clock_; |
| 110 |
| 111 // Owned by the PrefProvider. |
| 112 PrefChangeRegistrar* registrar_; |
| 113 |
| 114 bool is_incognito_; |
| 115 |
| 116 // Whether we are currently updating preferences, this is used to ignore |
| 117 // notifications from the preferences service that we triggered ourself. |
| 118 bool updating_preferences_; |
| 119 |
| 120 OriginIdentifierValueMap value_map_; |
| 121 |
| 122 OriginIdentifierValueMap incognito_value_map_; |
| 123 |
| 124 NotifyObserversCallback notify_callback_; |
| 125 |
| 126 // Used around accesses to the value map objects to guarantee thread safety. |
| 127 mutable base::Lock lock_; |
| 128 |
| 129 base::ThreadChecker thread_checker_; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); |
| 132 }; |
| 133 |
| 134 } // namespace content_settings |
| 135 |
| 136 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
| OLD | NEW |