| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | |
| 7 | |
| 8 // A content settings provider that takes its settings out of the pref service. | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/prefs/pref_change_registrar.h" | |
| 14 #include "base/synchronization/lock.h" | |
| 15 #include "chrome/browser/content_settings/content_settings_utils.h" | |
| 16 #include "components/content_settings/core/browser/content_settings_observable_p
rovider.h" | |
| 17 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" | |
| 18 | |
| 19 class PrefService; | |
| 20 | |
| 21 namespace base { | |
| 22 class Clock; | |
| 23 class DictionaryValue; | |
| 24 } | |
| 25 | |
| 26 namespace user_prefs { | |
| 27 class PrefRegistrySyncable; | |
| 28 } | |
| 29 | |
| 30 namespace content_settings { | |
| 31 | |
| 32 // Content settings provider that provides content settings from the user | |
| 33 // preference. | |
| 34 class PrefProvider : public ObservableProvider { | |
| 35 public: | |
| 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 37 | |
| 38 PrefProvider(PrefService* prefs, bool incognito); | |
| 39 ~PrefProvider() override; | |
| 40 | |
| 41 // ProviderInterface implementations. | |
| 42 RuleIterator* GetRuleIterator(ContentSettingsType content_type, | |
| 43 const ResourceIdentifier& resource_identifier, | |
| 44 bool incognito) const override; | |
| 45 | |
| 46 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, | |
| 47 const ContentSettingsPattern& secondary_pattern, | |
| 48 ContentSettingsType content_type, | |
| 49 const ResourceIdentifier& resource_identifier, | |
| 50 base::Value* value) override; | |
| 51 | |
| 52 void ClearAllContentSettingsRules(ContentSettingsType content_type) override; | |
| 53 | |
| 54 void ShutdownOnUIThread() override; | |
| 55 | |
| 56 // Records the last time the given pattern has used a certain content setting. | |
| 57 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, | |
| 58 const ContentSettingsPattern& secondary_pattern, | |
| 59 ContentSettingsType content_type); | |
| 60 | |
| 61 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, | |
| 62 const ContentSettingsPattern& secondary_pattern, | |
| 63 ContentSettingsType content_type); | |
| 64 | |
| 65 // Gains ownership of |clock|. | |
| 66 void SetClockForTesting(scoped_ptr<base::Clock> clock); | |
| 67 | |
| 68 private: | |
| 69 friend class DeadlockCheckerThread; // For testing. | |
| 70 // Reads all content settings exceptions from the preference and load them | |
| 71 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is | |
| 72 // true. | |
| 73 void ReadContentSettingsFromPref(bool overwrite); | |
| 74 | |
| 75 // Callback for changes in the pref with the same name. | |
| 76 void OnContentSettingsPatternPairsChanged(); | |
| 77 | |
| 78 // Update the preference that stores content settings exceptions and syncs the | |
| 79 // value to the obsolete preference. When calling this function, |lock_| | |
| 80 // should not be held, since this function will send out notifications of | |
| 81 // preference changes. | |
| 82 void UpdatePref( | |
| 83 const ContentSettingsPattern& primary_pattern, | |
| 84 const ContentSettingsPattern& secondary_pattern, | |
| 85 ContentSettingsType content_type, | |
| 86 const ResourceIdentifier& resource_identifier, | |
| 87 const base::Value* value); | |
| 88 | |
| 89 // Migrate the old media setting into new mic/camera content settings. | |
| 90 void MigrateObsoleteMediaContentSetting(); | |
| 91 | |
| 92 static void CanonicalizeContentSettingsExceptions( | |
| 93 base::DictionaryValue* all_settings_dictionary); | |
| 94 | |
| 95 // In the debug mode, asserts that |lock_| is not held by this thread. It's | |
| 96 // ok if some other thread holds |lock_|, as long as it will eventually | |
| 97 // release it. | |
| 98 void AssertLockNotHeld() const; | |
| 99 | |
| 100 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | |
| 101 PrefService* prefs_; | |
| 102 | |
| 103 // Can be set for testing. | |
| 104 scoped_ptr<base::Clock> clock_; | |
| 105 | |
| 106 bool is_incognito_; | |
| 107 | |
| 108 PrefChangeRegistrar pref_change_registrar_; | |
| 109 | |
| 110 // Whether we are currently updating preferences, this is used to ignore | |
| 111 // notifications from the preferences service that we triggered ourself. | |
| 112 bool updating_preferences_; | |
| 113 | |
| 114 OriginIdentifierValueMap value_map_; | |
| 115 | |
| 116 OriginIdentifierValueMap incognito_value_map_; | |
| 117 | |
| 118 // Used around accesses to the value map objects to guarantee thread safety. | |
| 119 mutable base::Lock lock_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | |
| 122 }; | |
| 123 | |
| 124 } // namespace content_settings | |
| 125 | |
| 126 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | |
| OLD | NEW |