Implementation of leveldb-backed PrefStore.
[chromium-blink-merge.git] / extensions / browser / info_map.h
blob5dfc9c2449d9d4d37f972f04cd406cb938be7788
1 // Copyright 2013 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 EXTENSIONS_BROWSER_INFO_MAP_H_
6 #define EXTENSIONS_BROWSER_INFO_MAP_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "extensions/browser/process_map.h"
15 #include "extensions/browser/quota_service.h"
16 #include "extensions/common/extension_set.h"
18 namespace extensions {
19 class ContentVerifier;
20 class Extension;
22 // Contains extension data that needs to be accessed on the IO thread. It can
23 // be created/destroyed on any thread, but all other methods must be called on
24 // the IO thread.
25 class InfoMap : public base::RefCountedThreadSafe<InfoMap> {
26 public:
27 InfoMap();
29 const ExtensionSet& extensions() const { return extensions_; }
30 const ExtensionSet& disabled_extensions() const {
31 return disabled_extensions_;
34 // Information about which extensions are assigned to which render processes.
35 const extensions::ProcessMap& process_map() const;
36 // Information about which extensions are assigned to which worker processes.
37 const extensions::ProcessMap& worker_process_map() const;
39 // Callback for when new extensions are loaded.
40 void AddExtension(const extensions::Extension* extension,
41 base::Time install_time,
42 bool incognito_enabled,
43 bool notifications_disabled);
45 // Callback for when an extension is unloaded.
46 void RemoveExtension(const std::string& extension_id,
47 const extensions::UnloadedExtensionInfo::Reason reason);
49 // Returns the time the extension was installed, or base::Time() if not found.
50 base::Time GetInstallTime(const std::string& extension_id) const;
52 // Returns true if the user has allowed this extension to run in incognito
53 // mode.
54 bool IsIncognitoEnabled(const std::string& extension_id) const;
56 // Returns true if the given extension can see events and data from another
57 // sub-profile (incognito to original profile, or vice versa).
58 bool CanCrossIncognito(const extensions::Extension* extension) const;
60 // Adds an entry to process_map_.
61 void RegisterExtensionProcess(const std::string& extension_id,
62 int process_id,
63 int site_instance_id);
65 // Removes an entry from process_map_.
66 void UnregisterExtensionProcess(const std::string& extension_id,
67 int process_id,
68 int site_instance_id);
69 void UnregisterAllExtensionsInProcess(int process_id);
71 // Adds an entry to worker_process_map_.
72 void RegisterExtensionWorkerProcess(const std::string& extension_id,
73 int process_id,
74 int site_instance_id);
76 // Removes an entry from worker_process_map_.
77 void UnregisterExtensionWorkerProcess(int process_id);
79 // Returns the subset of extensions which has the same |origin| in
80 // |process_id| with the specified |permission|.
81 void GetExtensionsWithAPIPermissionForSecurityOrigin(
82 const GURL& origin,
83 int process_id,
84 extensions::APIPermission::ID permission,
85 ExtensionSet* extensions) const;
87 // Returns true if there is exists an extension with the same origin as
88 // |origin| in |process_id| with |permission|.
89 bool SecurityOriginHasAPIPermission(const GURL& origin,
90 int process_id,
91 extensions::APIPermission::ID permission)
92 const;
94 // Returns the IO thread QuotaService. Creates the instance on first call.
95 QuotaService* GetQuotaService();
97 // Keep track of the signin process, so we can restrict extension access to
98 // it.
99 void SetSigninProcess(int process_id);
100 bool IsSigninProcess(int process_id) const;
102 // Notifications can be enabled/disabled in real time by the user.
103 void SetNotificationsDisabled(const std::string& extension_id,
104 bool notifications_disabled);
105 bool AreNotificationsDisabled(const std::string& extension_id) const;
107 void SetContentVerifier(ContentVerifier* verifier);
108 ContentVerifier* content_verifier() { return content_verifier_; }
110 private:
111 friend class base::RefCountedThreadSafe<InfoMap>;
113 // Extra dynamic data related to an extension.
114 struct ExtraData;
115 // Map of extension_id to ExtraData.
116 typedef std::map<std::string, ExtraData> ExtraDataMap;
118 ~InfoMap();
120 ExtensionSet extensions_;
121 ExtensionSet disabled_extensions_;
123 // Extra data associated with enabled extensions.
124 ExtraDataMap extra_data_;
126 // Used by dispatchers to limit API quota for individual extensions.
127 // The QuotaService is not thread safe. We need to create and destroy it on
128 // the IO thread.
129 scoped_ptr<QuotaService> quota_service_;
131 // Assignment of extensions to renderer processes.
132 extensions::ProcessMap process_map_;
134 // Assignment of extensions to worker processes.
135 extensions::ProcessMap worker_process_map_;
137 int signin_process_id_;
139 scoped_refptr<ContentVerifier> content_verifier_;
142 } // namespace extensions
144 #endif // EXTENSIONS_BROWSER_INFO_MAP_H_