- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / content_settings / content_settings_pref_provider.h
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.
4
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
7
8 // A content settings provider that takes its settings out of the pref service.
9
10 #include <vector>
11
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"
18
19 class PrefService;
20
21 namespace base {
22 class DictionaryValue;
23 }
24
25 namespace user_prefs {
26 class PrefRegistrySyncable;
27 }
28
29 namespace content_settings {
30
31 // Content settings provider that provides content settings from the user
32 // preference.
33 class PrefProvider : public ObservableProvider {
34  public:
35   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
36
37   PrefProvider(PrefService* prefs, bool incognito);
38   virtual ~PrefProvider();
39
40   // ProviderInterface implementations.
41   virtual RuleIterator* GetRuleIterator(
42       ContentSettingsType content_type,
43       const ResourceIdentifier& resource_identifier,
44       bool incognito) const OVERRIDE;
45
46   virtual bool SetWebsiteSetting(
47       const ContentSettingsPattern& primary_pattern,
48       const ContentSettingsPattern& secondary_pattern,
49       ContentSettingsType content_type,
50       const ResourceIdentifier& resource_identifier,
51       Value* value) OVERRIDE;
52
53   virtual void ClearAllContentSettingsRules(
54       ContentSettingsType content_type) OVERRIDE;
55
56   virtual void ShutdownOnUIThread() OVERRIDE;
57
58  private:
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
62   // true.
63   void ReadContentSettingsFromPref(bool overwrite);
64
65   // Callback for changes in the pref with the same name.
66   void OnContentSettingsPatternPairsChanged();
67
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.
72   void UpdatePref(
73       const ContentSettingsPattern& primary_pattern,
74       const ContentSettingsPattern& secondary_pattern,
75       ContentSettingsType content_type,
76       const ResourceIdentifier& resource_identifier,
77       const base::Value* value);
78
79   // Migrate the old media setting into new mic/camera content settings.
80   void MigrateObsoleteMediaContentSetting();
81
82   static void CanonicalizeContentSettingsExceptions(
83       base::DictionaryValue* all_settings_dictionary);
84
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
87   // release it.
88   void AssertLockNotHeld() const;
89
90   // Weak; owned by the Profile and reset in ShutdownOnUIThread.
91   PrefService* prefs_;
92
93   bool is_incognito_;
94
95   PrefChangeRegistrar pref_change_registrar_;
96
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_;
100
101   OriginIdentifierValueMap value_map_;
102
103   OriginIdentifierValueMap incognito_value_map_;
104
105   // Used around accesses to the value map objects to guarantee thread safety.
106   mutable base::Lock lock_;
107
108   DISALLOW_COPY_AND_ASSIGN(PrefProvider);
109 };
110
111 }  // namespace content_settings
112
113 #endif  // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_