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_
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"
17 #include "extensions/common/permissions/api_permission.h"
23 namespace extensions {
24 class ContentVerifier;
27 // Contains extension data that needs to be accessed on the IO thread. It can
28 // be created/destroyed on any thread, but all other methods must be called on
30 class InfoMap : public base::RefCountedThreadSafe<InfoMap> {
34 const ExtensionSet& extensions() const { return extensions_; }
35 const ExtensionSet& disabled_extensions() const {
36 return disabled_extensions_;
39 // Information about which extensions are assigned to which render processes.
40 const ProcessMap& process_map() const { return process_map_; }
41 // Information about which extensions are assigned to which worker processes.
42 const ProcessMap& worker_process_map() const { return worker_process_map_; }
44 // Callback for when new extensions are loaded.
45 void AddExtension(const extensions::Extension* extension,
46 base::Time install_time,
47 bool incognito_enabled,
48 bool notifications_disabled);
50 // Callback for when an extension is unloaded.
51 void RemoveExtension(const std::string& extension_id,
52 const extensions::UnloadedExtensionInfo::Reason reason);
54 // Returns the time the extension was installed, or base::Time() if not found.
55 base::Time GetInstallTime(const std::string& extension_id) const;
57 // Returns true if the user has allowed this extension to run in incognito
59 bool IsIncognitoEnabled(const std::string& extension_id) const;
61 // Returns true if the given extension can see events and data from another
62 // sub-profile (incognito to original profile, or vice versa).
63 bool CanCrossIncognito(const extensions::Extension* extension) const;
65 // Adds an entry to process_map_.
66 void RegisterExtensionProcess(const std::string& extension_id,
68 int site_instance_id);
70 // Removes an entry from process_map_.
71 void UnregisterExtensionProcess(const std::string& extension_id,
73 int site_instance_id);
74 void UnregisterAllExtensionsInProcess(int process_id);
76 // Adds an entry to worker_process_map_.
77 void RegisterExtensionWorkerProcess(const std::string& extension_id,
79 int site_instance_id);
81 // Removes an entry from worker_process_map_.
82 void UnregisterExtensionWorkerProcess(int process_id);
84 // Returns the subset of extensions which has the same |origin| in
85 // |process_id| with the specified |permission|.
86 void GetExtensionsWithAPIPermissionForSecurityOrigin(
89 extensions::APIPermission::ID permission,
90 ExtensionSet* extensions) const;
92 // Returns true if there is exists an extension with the same origin as
93 // |origin| in |process_id| with |permission|.
94 bool SecurityOriginHasAPIPermission(const GURL& origin,
96 extensions::APIPermission::ID permission)
99 // Maps a |file_url| to a |file_path| on the local filesystem, including
100 // resources in extensions. Returns true on success. See NaClBrowserDelegate
102 bool MapUrlToLocalFilePath(const GURL& file_url,
103 bool use_blocking_api,
104 base::FilePath* file_path);
106 // Returns the IO thread QuotaService. Creates the instance on first call.
107 QuotaService* GetQuotaService();
109 // Keep track of the signin process, so we can restrict extension access to
111 void SetSigninProcess(int process_id);
112 bool IsSigninProcess(int process_id) const;
114 // Notifications can be enabled/disabled in real time by the user.
115 void SetNotificationsDisabled(const std::string& extension_id,
116 bool notifications_disabled);
117 bool AreNotificationsDisabled(const std::string& extension_id) const;
119 void SetContentVerifier(ContentVerifier* verifier);
120 ContentVerifier* content_verifier() { return content_verifier_; }
123 friend class base::RefCountedThreadSafe<InfoMap>;
125 // Extra dynamic data related to an extension.
127 // Map of extension_id to ExtraData.
128 typedef std::map<std::string, ExtraData> ExtraDataMap;
132 ExtensionSet extensions_;
133 ExtensionSet disabled_extensions_;
135 // Extra data associated with enabled extensions.
136 ExtraDataMap extra_data_;
138 // Used by dispatchers to limit API quota for individual extensions.
139 // The QuotaService is not thread safe. We need to create and destroy it on
141 scoped_ptr<QuotaService> quota_service_;
143 // Assignment of extensions to renderer processes.
144 extensions::ProcessMap process_map_;
146 // Assignment of extensions to worker processes.
147 extensions::ProcessMap worker_process_map_;
149 int signin_process_id_;
151 scoped_refptr<ContentVerifier> content_verifier_;
154 } // namespace extensions
156 #endif // EXTENSIONS_BROWSER_INFO_MAP_H_