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.
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"
22 class DictionaryValue
;
25 namespace user_prefs
{
26 class PrefRegistrySyncable
;
29 namespace content_settings
{
31 // Content settings provider that provides content settings from the user
33 class PrefProvider
: public ObservableProvider
{
35 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
37 PrefProvider(PrefService
* prefs
, bool incognito
);
38 virtual ~PrefProvider();
40 // ProviderInterface implementations.
41 virtual RuleIterator
* GetRuleIterator(
42 ContentSettingsType content_type
,
43 const ResourceIdentifier
& resource_identifier
,
44 bool incognito
) const OVERRIDE
;
46 virtual bool SetWebsiteSetting(
47 const ContentSettingsPattern
& primary_pattern
,
48 const ContentSettingsPattern
& secondary_pattern
,
49 ContentSettingsType content_type
,
50 const ResourceIdentifier
& resource_identifier
,
51 base::Value
* value
) OVERRIDE
;
53 virtual void ClearAllContentSettingsRules(
54 ContentSettingsType content_type
) OVERRIDE
;
56 virtual void ShutdownOnUIThread() OVERRIDE
;
59 friend class DeadlockCheckerThread
; // For testing.
60 // Reads all content settings exceptions from the preference and load them
61 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is
63 void ReadContentSettingsFromPref(bool overwrite
);
65 // Callback for changes in the pref with the same name.
66 void OnContentSettingsPatternPairsChanged();
68 // Update the preference that stores content settings exceptions and syncs the
69 // value to the obsolete preference. When calling this function, |lock_|
70 // should not be held, since this function will send out notifications of
71 // preference changes.
73 const ContentSettingsPattern
& primary_pattern
,
74 const ContentSettingsPattern
& secondary_pattern
,
75 ContentSettingsType content_type
,
76 const ResourceIdentifier
& resource_identifier
,
77 const base::Value
* value
);
79 // Migrate the old media setting into new mic/camera content settings.
80 void MigrateObsoleteMediaContentSetting();
82 static void CanonicalizeContentSettingsExceptions(
83 base::DictionaryValue
* all_settings_dictionary
);
85 // In the debug mode, asserts that |lock_| is not held by this thread. It's
86 // ok if some other thread holds |lock_|, as long as it will eventually
88 void AssertLockNotHeld() const;
90 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
95 PrefChangeRegistrar pref_change_registrar_
;
97 // Whether we are currently updating preferences, this is used to ignore
98 // notifications from the preferences service that we triggered ourself.
99 bool updating_preferences_
;
101 OriginIdentifierValueMap value_map_
;
103 OriginIdentifierValueMap incognito_value_map_
;
105 // Used around accesses to the value map objects to guarantee thread safety.
106 mutable base::Lock lock_
;
108 DISALLOW_COPY_AND_ASSIGN(PrefProvider
);
111 } // namespace content_settings
113 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_