Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_default_provider.h
blob9651b91a5f60ae30a43f3d104aa49602edf203f9
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 CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
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 "chrome/browser/content_settings/content_settings_observable_provider.h"
18 class PrefService;
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
28 // default values.
29 class DefaultProvider : public ObservableProvider {
30 public:
31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
33 DefaultProvider(PrefService* prefs,
34 bool incognito);
35 virtual ~DefaultProvider();
37 // ProviderInterface implementations.
38 virtual RuleIterator* GetRuleIterator(
39 ContentSettingsType content_type,
40 const ResourceIdentifier& resource_identifier,
41 bool incognito) const OVERRIDE;
43 virtual bool SetWebsiteSetting(
44 const ContentSettingsPattern& primary_pattern,
45 const ContentSettingsPattern& secondary_pattern,
46 ContentSettingsType content_type,
47 const ResourceIdentifier& resource_identifier,
48 base::Value* value) OVERRIDE;
50 virtual void ClearAllContentSettingsRules(
51 ContentSettingsType content_type) OVERRIDE;
53 virtual void ShutdownOnUIThread() OVERRIDE;
55 private:
56 // Sets the fields of |settings| based on the values in |dictionary|.
57 void GetSettingsFromDictionary(const base::DictionaryValue* dictionary);
59 // Forces the default settings to be explicitly set instead of themselves
60 // being CONTENT_SETTING_DEFAULT.
61 void ForceDefaultsToBeExplicit();
63 // Reads the default settings from the preferences service. If |overwrite| is
64 // true and the preference is missing, the local copy will be cleared as well.
65 void ReadDefaultSettings(bool overwrite);
67 // Called on prefs change.
68 void OnPreferenceChanged(const std::string& pref_name);
70 typedef linked_ptr<base::Value> ValuePtr;
71 typedef std::map<ContentSettingsType, ValuePtr> ValueMap;
72 // Copies of the pref data, so that we can read it on the IO thread.
73 ValueMap default_settings_;
75 PrefService* prefs_;
77 // Whether this settings map is for an Incognito session.
78 bool is_incognito_;
80 // Used around accesses to the |default_content_settings_| object to guarantee
81 // thread safety.
82 mutable base::Lock lock_;
84 PrefChangeRegistrar pref_change_registrar_;
86 // Whether we are currently updating preferences, this is used to ignore
87 // notifications from the preferences service that we triggered ourself.
88 bool updating_preferences_;
90 DISALLOW_COPY_AND_ASSIGN(DefaultProvider);
93 } // namespace content_settings
95 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_