Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_pref_provider.h
blob08a9d1b9b415f369b84c748894ac4920cd5b8981
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.
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
8 // A content settings provider that takes its settings out of the pref service.
10 #include <vector>
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_observable_provider.h"
16 #include "chrome/browser/content_settings/content_settings_origin_identifier_value_map.h"
17 #include "chrome/browser/content_settings/content_settings_utils.h"
19 class PrefService;
21 namespace base {
22 class Clock;
23 class DictionaryValue;
26 namespace user_prefs {
27 class PrefRegistrySyncable;
30 namespace content_settings {
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);
38 PrefProvider(PrefService* prefs, bool incognito);
39 virtual ~PrefProvider();
41 // ProviderInterface implementations.
42 virtual RuleIterator* GetRuleIterator(
43 ContentSettingsType content_type,
44 const ResourceIdentifier& resource_identifier,
45 bool incognito) const OVERRIDE;
47 virtual bool SetWebsiteSetting(
48 const ContentSettingsPattern& primary_pattern,
49 const ContentSettingsPattern& secondary_pattern,
50 ContentSettingsType content_type,
51 const ResourceIdentifier& resource_identifier,
52 base::Value* value) OVERRIDE;
54 virtual void ClearAllContentSettingsRules(
55 ContentSettingsType content_type) OVERRIDE;
57 virtual void ShutdownOnUIThread() OVERRIDE;
59 // Records the last time the given pattern has used a certain content setting.
60 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern,
61 const ContentSettingsPattern& secondary_pattern,
62 ContentSettingsType content_type);
64 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern,
65 const ContentSettingsPattern& secondary_pattern,
66 ContentSettingsType content_type);
68 // Gains ownership of |clock|.
69 void SetClockForTesting(scoped_ptr<base::Clock> clock);
71 private:
72 friend class DeadlockCheckerThread; // For testing.
73 // Reads all content settings exceptions from the preference and load them
74 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is
75 // true.
76 void ReadContentSettingsFromPref(bool overwrite);
78 // Callback for changes in the pref with the same name.
79 void OnContentSettingsPatternPairsChanged();
81 // Update the preference that stores content settings exceptions and syncs the
82 // value to the obsolete preference. When calling this function, |lock_|
83 // should not be held, since this function will send out notifications of
84 // preference changes.
85 void UpdatePref(
86 const ContentSettingsPattern& primary_pattern,
87 const ContentSettingsPattern& secondary_pattern,
88 ContentSettingsType content_type,
89 const ResourceIdentifier& resource_identifier,
90 const base::Value* value);
92 // Migrate the old media setting into new mic/camera content settings.
93 void MigrateObsoleteMediaContentSetting();
95 static void CanonicalizeContentSettingsExceptions(
96 base::DictionaryValue* all_settings_dictionary);
98 // In the debug mode, asserts that |lock_| is not held by this thread. It's
99 // ok if some other thread holds |lock_|, as long as it will eventually
100 // release it.
101 void AssertLockNotHeld() const;
103 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
104 PrefService* prefs_;
106 // Can be set for testing.
107 scoped_ptr<base::Clock> clock_;
109 bool is_incognito_;
111 PrefChangeRegistrar pref_change_registrar_;
113 // Whether we are currently updating preferences, this is used to ignore
114 // notifications from the preferences service that we triggered ourself.
115 bool updating_preferences_;
117 OriginIdentifierValueMap value_map_;
119 OriginIdentifierValueMap incognito_value_map_;
121 // Used around accesses to the value map objects to guarantee thread safety.
122 mutable base::Lock lock_;
124 DISALLOW_COPY_AND_ASSIGN(PrefProvider);
127 } // namespace content_settings
129 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_