1 // Copyright (c) 2011 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.
5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/prefs/pref_change_registrar.h"
15 #include "base/synchronization/lock.h"
16 #include "components/content_settings/core/browser/content_settings_observable_provider.h"
20 namespace user_prefs {
21 class PrefRegistrySyncable;
24 namespace content_settings {
26 // Provider that provides default content settings based on
27 // user prefs. If no default values are set by the user we use the hard coded
29 class DefaultProvider : public ObservableProvider {
31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
33 DefaultProvider(PrefService* prefs,
35 ~DefaultProvider() override;
37 // ProviderInterface implementations.
38 RuleIterator* GetRuleIterator(ContentSettingsType content_type,
39 const ResourceIdentifier& resource_identifier,
40 bool incognito) const override;
42 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
43 const ContentSettingsPattern& secondary_pattern,
44 ContentSettingsType content_type,
45 const ResourceIdentifier& resource_identifier,
46 base::Value* value) override;
48 void ClearAllContentSettingsRules(ContentSettingsType content_type) override;
50 void ShutdownOnUIThread() override;
53 // Sets the fields of |settings| based on the values in |dictionary|.
54 void GetSettingsFromDictionary(const base::DictionaryValue* dictionary);
56 // Forces the default settings to be explicitly set instead of themselves
57 // being CONTENT_SETTING_DEFAULT.
58 void ForceDefaultsToBeExplicit();
60 // Reads the default settings from the preferences service. If |overwrite| is
61 // true and the preference is missing, the local copy will be cleared as well.
62 void ReadDefaultSettings(bool overwrite);
64 // Called on prefs change.
65 void OnPreferenceChanged(const std::string& pref_name);
67 typedef linked_ptr<base::Value> ValuePtr;
68 typedef std::map<ContentSettingsType, ValuePtr> ValueMap;
69 // Copies of the pref data, so that we can read it on the IO thread.
70 ValueMap default_settings_;
74 // Whether this settings map is for an Incognito session.
77 // Used around accesses to the |default_content_settings_| object to guarantee
79 mutable base::Lock lock_;
81 PrefChangeRegistrar pref_change_registrar_;
83 // Whether we are currently updating preferences, this is used to ignore
84 // notifications from the preferences service that we triggered ourself.
85 bool updating_preferences_;
87 DISALLOW_COPY_AND_ASSIGN(DefaultProvider);
90 } // namespace content_settings
92 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_