Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / content_settings / content_settings_store.h
blob33aa9723cbd02ab1cfba79f668ba52f3c3848f25
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_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_STORE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_STORE_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "base/observer_list.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h"
15 #include "base/time/time.h"
16 #include "components/content_settings/core/browser/content_settings_provider.h"
17 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_pattern.h"
19 #include "extensions/browser/extension_prefs_scope.h"
21 namespace base {
22 class ListValue;
25 namespace content_settings {
26 class OriginIdentifierValueMap;
27 class RuleIterator;
30 namespace extensions {
32 // This class is the backend for extension-defined content settings. It is used
33 // by the content_settings::CustomExtensionProvider to integrate its settings
34 // into the HostContentSettingsMap and by the content settings extension API to
35 // provide extensions with access to content settings.
36 class ContentSettingsStore
37 : public base::RefCountedThreadSafe<ContentSettingsStore> {
38 public:
39 class Observer {
40 public:
41 virtual ~Observer() {}
43 // Called when a content setting changes in the
44 // ContentSettingsStore.
45 virtual void OnContentSettingChanged(
46 const std::string& extension_id,
47 bool incognito) = 0;
50 ContentSettingsStore();
52 // //////////////////////////////////////////////////////////////////////////
54 content_settings::RuleIterator* GetRuleIterator(
55 ContentSettingsType type,
56 const content_settings::ResourceIdentifier& identifier,
57 bool incognito) const;
59 // Sets the content |setting| for |pattern| of extension |ext_id|. The
60 // |incognito| flag allow to set whether the provided setting is for
61 // incognito mode only.
62 // Precondition: the extension must be registered.
63 // This method should only be called on the UI thread.
64 void SetExtensionContentSetting(
65 const std::string& ext_id,
66 const ContentSettingsPattern& embedded_pattern,
67 const ContentSettingsPattern& top_level_pattern,
68 ContentSettingsType type,
69 const content_settings::ResourceIdentifier& identifier,
70 ContentSetting setting,
71 ExtensionPrefsScope scope);
73 // Clears all contents settings set by the extension |ext_id|.
74 void ClearContentSettingsForExtension(const std::string& ext_id,
75 ExtensionPrefsScope scope);
77 // Serializes all content settings set by the extension with ID |extension_id|
78 // and returns them as a ListValue. The caller takes ownership of the returned
79 // value.
80 base::ListValue* GetSettingsForExtension(const std::string& extension_id,
81 ExtensionPrefsScope scope) const;
83 // Deserializes content settings rules from |list| and applies them as set by
84 // the extension with ID |extension_id|.
85 void SetExtensionContentSettingFromList(const std::string& extension_id,
86 const base::ListValue* list,
87 ExtensionPrefsScope scope);
89 // //////////////////////////////////////////////////////////////////////////
91 // Registers the time when an extension |ext_id| is installed.
92 void RegisterExtension(const std::string& ext_id,
93 const base::Time& install_time,
94 bool is_enabled);
96 // Deletes all entries related to extension |ext_id|.
97 void UnregisterExtension(const std::string& ext_id);
99 // Hides or makes the extension content settings of the specified extension
100 // visible.
101 void SetExtensionState(const std::string& ext_id, bool is_enabled);
103 // Adds |observer|. This method should only be called on the UI thread.
104 void AddObserver(Observer* observer);
106 // Remove |observer|. This method should only be called on the UI thread.
107 void RemoveObserver(Observer* observer);
109 private:
110 friend class base::RefCountedThreadSafe<ContentSettingsStore>;
112 struct ExtensionEntry;
114 typedef std::multimap<base::Time, ExtensionEntry*> ExtensionEntryMap;
116 virtual ~ContentSettingsStore();
118 content_settings::OriginIdentifierValueMap* GetValueMap(
119 const std::string& ext_id,
120 ExtensionPrefsScope scope);
122 const content_settings::OriginIdentifierValueMap* GetValueMap(
123 const std::string& ext_id,
124 ExtensionPrefsScope scope) const;
126 void NotifyOfContentSettingChanged(const std::string& extension_id,
127 bool incognito);
129 bool OnCorrectThread();
131 ExtensionEntryMap::iterator FindEntry(const std::string& ext_id);
132 ExtensionEntryMap::const_iterator FindEntry(const std::string& ext_id) const;
134 ExtensionEntryMap entries_;
136 base::ObserverList<Observer, false> observers_;
138 mutable base::Lock lock_;
140 DISALLOW_COPY_AND_ASSIGN(ContentSettingsStore);
143 } // namespace extensions
145 #endif // CHROME_BROWSER_EXTENSIONS_API_CONTENT_SETTINGS_CONTENT_SETTINGS_STORE_H_