Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: chrome/browser/extensions/extension_content_settings_store.h

Issue 10381097: Move content settings extension API to content_settings dir. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed conflict Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_EXTENSION_CONTENT_SETTINGS_STORE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTENT_SETTINGS_STORE_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/observer_list.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/time.h"
15 #include "base/tuple.h"
16 #include "chrome/browser/content_settings/content_settings_provider.h"
17 #include "chrome/browser/extensions/extension_prefs_scope.h"
18 #include "chrome/common/content_settings.h"
19 #include "chrome/common/content_settings_pattern.h"
20 #include "googleurl/src/gurl.h"
21
22 namespace base {
23 class ListValue;
24 }
25
26 namespace content_settings {
27 class OriginIdentifierValueMap;
28 class RuleIterator;
29 }
30
31 // This class is the backend for extension-defined content settings. It is used
32 // by the content_settings::ExtensionProvider to integrate its settings into the
33 // HostContentSettingsMap and by the content settings extension API to provide
34 // extensions with access to content settings.
35 class ExtensionContentSettingsStore
36 : public base::RefCountedThreadSafe<ExtensionContentSettingsStore> {
37 public:
38 class Observer {
39 public:
40 virtual ~Observer() {}
41
42 // Called when a content setting changes in the
43 // ExtensionContentSettingsStore.
44 virtual void OnContentSettingChanged(
45 const std::string& extension_id,
46 bool incognito) = 0;
47 };
48
49 ExtensionContentSettingsStore();
50
51 // //////////////////////////////////////////////////////////////////////////
52
53 content_settings::RuleIterator* GetRuleIterator(
54 ContentSettingsType type,
55 const content_settings::ResourceIdentifier& identifier,
56 bool incognito) const;
57
58 // Sets the content |setting| for |pattern| of extension |ext_id|. The
59 // |incognito| flag allow to set whether the provided setting is for
60 // incognito mode only.
61 // Precondition: the extension must be registered.
62 // This method should only be called on the UI thread.
63 void SetExtensionContentSetting(
64 const std::string& ext_id,
65 const ContentSettingsPattern& embedded_pattern,
66 const ContentSettingsPattern& top_level_pattern,
67 ContentSettingsType type,
68 const content_settings::ResourceIdentifier& identifier,
69 ContentSetting setting,
70 ExtensionPrefsScope scope);
71
72 // Clears all contents settings set by the extension |ext_id|.
73 void ClearContentSettingsForExtension(const std::string& ext_id,
74 ExtensionPrefsScope scope);
75
76 // Serializes all content settings set by the extension with ID |extension_id|
77 // and returns them as a ListValue. The caller takes ownership of the returned
78 // value.
79 base::ListValue* GetSettingsForExtension(const std::string& extension_id,
80 ExtensionPrefsScope scope) const;
81
82 // Deserializes content settings rules from |list| and applies them as set by
83 // the extension with ID |extension_id|.
84 void SetExtensionContentSettingsFromList(const std::string& extension_id,
85 const base::ListValue* list,
86 ExtensionPrefsScope scope);
87
88 // //////////////////////////////////////////////////////////////////////////
89
90 // Registers the time when an extension |ext_id| is installed.
91 void RegisterExtension(const std::string& ext_id,
92 const base::Time& install_time,
93 bool is_enabled);
94
95 // Deletes all entries related to extension |ext_id|.
96 void UnregisterExtension(const std::string& ext_id);
97
98 // Hides or makes the extension content settings of the specified extension
99 // visible.
100 void SetExtensionState(const std::string& ext_id, bool is_enabled);
101
102 // Adds |observer|. This method should only be called on the UI thread.
103 void AddObserver(Observer* observer);
104
105 // Remove |observer|. This method should only be called on the UI thread.
106 void RemoveObserver(Observer* observer);
107
108 private:
109 friend class base::RefCountedThreadSafe<ExtensionContentSettingsStore>;
110
111 struct ExtensionEntry;
112
113 typedef std::multimap<base::Time, ExtensionEntry*> ExtensionEntryMap;
114
115 virtual ~ExtensionContentSettingsStore();
116
117 content_settings::OriginIdentifierValueMap* GetValueMap(
118 const std::string& ext_id,
119 ExtensionPrefsScope scope);
120
121 const content_settings::OriginIdentifierValueMap* GetValueMap(
122 const std::string& ext_id,
123 ExtensionPrefsScope scope) const;
124
125 void NotifyOfContentSettingChanged(const std::string& extension_id,
126 bool incognito);
127
128 bool OnCorrectThread();
129
130 ExtensionEntryMap::iterator FindEntry(const std::string& ext_id);
131 ExtensionEntryMap::const_iterator FindEntry(const std::string& ext_id) const;
132
133 ExtensionEntryMap entries_;
134
135 ObserverList<Observer, false> observers_;
136
137 mutable base::Lock lock_;
138
139 DISALLOW_COPY_AND_ASSIGN(ExtensionContentSettingsStore);
140 };
141
142 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTENT_SETTINGS_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698