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"
18 namespace extensions
{
21 // Contains extension data that needs to be accessed on the IO thread. It can
22 // be created/destroyed on any thread, but all other methods must be called on
24 class InfoMap
: public base::RefCountedThreadSafe
<InfoMap
> {
28 const ExtensionSet
& extensions() const { return extensions_
; }
29 const ExtensionSet
& disabled_extensions() const {
30 return disabled_extensions_
;
33 // Information about which extensions are assigned to which render processes.
34 const extensions::ProcessMap
& process_map() const;
35 // Information about which extensions are assigned to which worker processes.
36 const extensions::ProcessMap
& worker_process_map() const;
38 // Callback for when new extensions are loaded.
39 void AddExtension(const extensions::Extension
* extension
,
40 base::Time install_time
,
41 bool incognito_enabled
,
42 bool notifications_disabled
);
44 // Callback for when an extension is unloaded.
45 void RemoveExtension(const std::string
& extension_id
,
46 const extensions::UnloadedExtensionInfo::Reason reason
);
48 // Returns the time the extension was installed, or base::Time() if not found.
49 base::Time
GetInstallTime(const std::string
& extension_id
) const;
51 // Returns true if the user has allowed this extension to run in incognito
53 bool IsIncognitoEnabled(const std::string
& extension_id
) const;
55 // Returns true if the given extension can see events and data from another
56 // sub-profile (incognito to original profile, or vice versa).
57 bool CanCrossIncognito(const extensions::Extension
* extension
) const;
59 // Adds an entry to process_map_.
60 void RegisterExtensionProcess(const std::string
& extension_id
,
62 int site_instance_id
);
64 // Removes an entry from process_map_.
65 void UnregisterExtensionProcess(const std::string
& extension_id
,
67 int site_instance_id
);
68 void UnregisterAllExtensionsInProcess(int process_id
);
70 // Adds an entry to worker_process_map_.
71 void RegisterExtensionWorkerProcess(const std::string
& extension_id
,
73 int site_instance_id
);
75 // Removes an entry from worker_process_map_.
76 void UnregisterExtensionWorkerProcess(int process_id
);
78 // Returns the subset of extensions which has the same |origin| in
79 // |process_id| with the specified |permission|.
80 void GetExtensionsWithAPIPermissionForSecurityOrigin(
83 extensions::APIPermission::ID permission
,
84 ExtensionSet
* extensions
) const;
86 // Returns true if there is exists an extension with the same origin as
87 // |origin| in |process_id| with |permission|.
88 bool SecurityOriginHasAPIPermission(const GURL
& origin
,
90 extensions::APIPermission::ID permission
)
93 // Returns the IO thread QuotaService. Creates the instance on first call.
94 QuotaService
* GetQuotaService();
96 // Keep track of the signin process, so we can restrict extension access to
98 void SetSigninProcess(int process_id
);
99 bool IsSigninProcess(int process_id
) const;
101 // Notifications can be enabled/disabled in real time by the user.
102 void SetNotificationsDisabled(const std::string
& extension_id
,
103 bool notifications_disabled
);
104 bool AreNotificationsDisabled(const std::string
& extension_id
) const;
107 friend class base::RefCountedThreadSafe
<InfoMap
>;
109 // Extra dynamic data related to an extension.
111 // Map of extension_id to ExtraData.
112 typedef std::map
<std::string
, ExtraData
> ExtraDataMap
;
116 ExtensionSet extensions_
;
117 ExtensionSet disabled_extensions_
;
119 // Extra data associated with enabled extensions.
120 ExtraDataMap extra_data_
;
122 // Used by dispatchers to limit API quota for individual extensions.
123 // The QuotaService is not thread safe. We need to create and destroy it on
125 scoped_ptr
<QuotaService
> quota_service_
;
127 // Assignment of extensions to renderer processes.
128 extensions::ProcessMap process_map_
;
130 // Assignment of extensions to worker processes.
131 extensions::ProcessMap worker_process_map_
;
133 int signin_process_id_
;
136 } // namespace extensions
138 #endif // EXTENSIONS_BROWSER_INFO_MAP_H_