OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_OVERRIDE_PROVIDER_H_ | |
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_OVERRIDE_PROVIDER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/synchronization/lock.h" | |
10 #include "base/threading/thread_checker.h" | |
11 #include "components/content_settings/core/browser/content_settings_provider.h" | |
12 #include "components/content_settings/core/common/content_settings_types.h" | |
13 | |
14 class ContentSettingsPattern; | |
15 class PrefService; | |
16 | |
17 namespace user_prefs { | |
18 class PrefRegistrySyncable; | |
19 } | |
20 | |
21 namespace content_settings { | |
22 | |
23 // OverrideProvider contains if certain content settings are enabled or | |
24 // globally disabled. It may only be written to using the UI thread, but may be | |
25 // read on any thread. | |
26 class OverrideProvider : public ProviderInterface { | |
27 public: | |
28 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
29 | |
30 OverrideProvider(PrefService* prefs, bool incognito); | |
31 ~OverrideProvider() override; | |
32 | |
33 // ProviderInterface implementations. | |
34 RuleIterator* GetRuleIterator(ContentSettingsType content_type, | |
35 const ResourceIdentifier& resource_identifier, | |
36 bool incognito) const override; | |
37 | |
38 void ClearAllContentSettingsRules(ContentSettingsType content_type) override; | |
39 | |
40 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, | |
41 const ContentSettingsPattern& secondary_pattern, | |
42 ContentSettingsType content_type, | |
43 const ResourceIdentifier& resource_identifier, | |
44 base::Value* value) override; | |
45 | |
46 void ShutdownOnUIThread() override; | |
47 | |
48 // Sets if a given |content_type| is |enabled|. | |
49 void SetOverrideSetting(ContentSettingsType content_type, bool enabled); | |
50 | |
51 // Returns if |content_type| is enabled. If it is not enabled, the content | |
52 // setting type is considered globally disabled and acts as though it is | |
53 // blocked. If it is enabled, the content setting type's permission is granted | |
54 // by the other providers. | |
55 bool IsEnabled(ContentSettingsType content_type) const; | |
56 | |
57 private: | |
58 // Reads the override settings from the preferences service. | |
59 void ReadOverrideSettings(); | |
60 | |
61 // Copies of the pref data, so that we can read it on the IO thread. | |
62 bool allowed_settings_[CONTENT_SETTINGS_NUM_TYPES]; | |
63 | |
64 PrefService* prefs_; | |
65 | |
66 bool is_incognito_; | |
67 | |
68 // Used around accesses to the |override_content_settings_| object to | |
69 // guarantee thread safety. | |
70 mutable base::Lock lock_; | |
71 | |
72 base::ThreadChecker thread_checker_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(OverrideProvider); | |
75 }; | |
76 | |
77 } // namespace content_settings | |
78 | |
79 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_OVERRIDE_PROVIDER_H_ | |
OLD | NEW |