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_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_CUSTOM_EXTENSION_PROVIDER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_CUSTOM_EXTENSION_PROVIDER_H_
7 
8 #include <string>
9 
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/extensions/api/content_settings/content_settings_store.h"
13 #include "components/content_settings/core/browser/content_settings_observable_provider.h"
14 
15 namespace content_settings {
16 
17 // A content settings provider which manages settings defined by extensions.
18 class CustomExtensionProvider : public ObservableProvider,
19                           public extensions::ContentSettingsStore::Observer {
20  public:
21   CustomExtensionProvider(const scoped_refptr<extensions::ContentSettingsStore>&
22                               extensions_settings,
23                           bool incognito);
24 
25   ~CustomExtensionProvider() override;
26 
27   // ProviderInterface methods:
28   std::unique_ptr<RuleIterator> GetRuleIterator(
29       ContentSettingsType content_type,
30       bool incognito) const override;
31 
32   std::unique_ptr<RuleIterator> GetDiscardedRuleIterator(
33       ContentSettingsType content_type,
34       bool incognito) const override;
35 
36   bool SetWebsiteSetting(
37       const ContentSettingsPattern& primary_pattern,
38       const ContentSettingsPattern& secondary_pattern,
39       ContentSettingsType content_type,
40       std::unique_ptr<base::Value>&& value,
41       const ContentSettingConstraints& constraint = {}) override;
42 
ClearAllContentSettingsRules(ContentSettingsType content_type)43   void ClearAllContentSettingsRules(ContentSettingsType content_type) override {
44   }
45 
46   void ShutdownOnUIThread() override;
47 
48   // extensions::ContentSettingsStore::Observer methods:
49   void OnContentSettingChanged(const std::string& extension_id,
50                                bool incognito) override;
51 
52  private:
53   // Specifies whether this provider manages settings for incognito or regular
54   // sessions.
55   bool incognito_;
56 
57   // The backend storing content setting rules defined by extensions.
58   scoped_refptr<extensions::ContentSettingsStore> extensions_settings_;
59 
60   DISALLOW_COPY_AND_ASSIGN(CustomExtensionProvider);
61 };
62 
63 }  // namespace content_settings
64 
65 #endif  // CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_CUSTOM_EXTENSION_PROVIDER_H_
66