Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_pref_provider.h
blob17fda762e96eaec5fc75ccab52ded9e3a99a1a91
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/public/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 DictionaryValue;
25 namespace content_settings {
27 // Content settings provider that provides content settings from the user
28 // preference.
29 class PrefProvider : public ObservableProvider {
30 public:
31 static void RegisterUserPrefs(PrefService* prefs);
33 PrefProvider(PrefService* prefs,
34 bool incognito);
35 virtual ~PrefProvider();
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 Value* value) OVERRIDE;
50 virtual void ClearAllContentSettingsRules(
51 ContentSettingsType content_type) OVERRIDE;
53 virtual void ShutdownOnUIThread() OVERRIDE;
55 private:
56 friend class DeadlockCheckerThread; // For testing.
57 // Reads all content settings exceptions from the preference and load them
58 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is
59 // true.
60 void ReadContentSettingsFromPref(bool overwrite);
62 // Callback for changes in the pref with the same name.
63 void OnContentSettingsPatternPairsChanged();
65 // Update the preference that stores content settings exceptions and syncs the
66 // value to the obsolete preference. When calling this function, |lock_|
67 // should not be held, since this function will send out notifications of
68 // preference changes.
69 void UpdatePref(
70 const ContentSettingsPattern& primary_pattern,
71 const ContentSettingsPattern& secondary_pattern,
72 ContentSettingsType content_type,
73 const ResourceIdentifier& resource_identifier,
74 const base::Value* value);
76 // Updates the given |pattern_pairs_settings| dictionary value.
77 void UpdatePatternPairsSettings(
78 const ContentSettingsPattern& primary_pattern,
79 const ContentSettingsPattern& secondary_pattern,
80 ContentSettingsType content_type,
81 const ResourceIdentifier& resource_identifier,
82 const base::Value* value,
83 DictionaryValue* pattern_pairs_settings);
85 void MigrateObsoleteClearOnExitPref();
86 void MigrateObsoleteContentSettingsPatternPref();
87 void MigrateObsoleteGeolocationPref();
88 void MigrateObsoleteNotificationsPrefs();
90 static void CanonicalizeContentSettingsExceptions(
91 base::DictionaryValue* all_settings_dictionary);
93 // In the debug mode, asserts that |lock_| is not held by this thread. It's
94 // ok if some other thread holds |lock_|, as long as it will eventually
95 // release it.
96 void AssertLockNotHeld() const;
98 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
99 PrefService* prefs_;
101 bool is_incognito_;
103 PrefChangeRegistrar pref_change_registrar_;
105 // Whether we are currently updating preferences, this is used to ignore
106 // notifications from the preferences service that we triggered ourself.
107 bool updating_preferences_;
109 OriginIdentifierValueMap value_map_;
111 OriginIdentifierValueMap incognito_value_map_;
113 // Used around accesses to the value map objects to guarantee thread safety.
114 mutable base::Lock lock_;
116 DISALLOW_COPY_AND_ASSIGN(PrefProvider);
119 } // namespace content_settings
121 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_