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_EXTENSION_INFO_MAP_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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 "chrome/browser/extensions/extensions_quota_service.h"
15 #include "chrome/browser/extensions/process_map.h"
16 #include "chrome/common/extensions/extension_set.h"
18 namespace extensions {
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
25 class ExtensionInfoMap : public base::RefCountedThreadSafe<ExtensionInfoMap> {
29 const ExtensionSet& extensions() const { return extensions_; }
30 const ExtensionSet& disabled_extensions() const {
31 return disabled_extensions_;
34 const extensions::ProcessMap& process_map() const;
36 // Callback for when new extensions are loaded.
37 void AddExtension(const extensions::Extension* extension,
38 base::Time install_time,
39 bool incognito_enabled);
41 // Callback for when an extension is unloaded.
42 void RemoveExtension(const std::string& extension_id,
43 const extensions::UnloadedExtensionInfo::Reason reason);
45 // Returns the time the extension was installed, or base::Time() if not found.
46 base::Time GetInstallTime(const std::string& extension_id) const;
48 // Returns true if the user has allowed this extension to run in incognito
50 bool IsIncognitoEnabled(const std::string& extension_id) const;
52 // Returns true if the given extension can see events and data from another
53 // sub-profile (incognito to original profile, or vice versa).
54 bool CanCrossIncognito(const extensions::Extension* extension) const;
56 // Adds an entry to process_map_.
57 void RegisterExtensionProcess(const std::string& extension_id,
59 int site_instance_id);
61 // Removes an entry from process_map_.
62 void UnregisterExtensionProcess(const std::string& extension_id,
64 int site_instance_id);
65 void UnregisterAllExtensionsInProcess(int process_id);
67 // Returns the subset of extensions which has the same |origin| in
68 // |process_id| with the specified |permission|.
69 void GetExtensionsWithAPIPermissionForSecurityOrigin(
72 extensions::APIPermission::ID permission,
73 ExtensionSet* extensions) const;
75 // Returns true if there is exists an extension with the same origin as
76 // |origin| in |process_id| with |permission|.
77 bool SecurityOriginHasAPIPermission(
78 const GURL& origin, int process_id,
79 extensions::APIPermission::ID permission) const;
81 ExtensionsQuotaService* GetQuotaService();
83 // Keep track of the signin process, so we can restrict extension access to
85 void SetSigninProcess(int process_id);
86 bool IsSigninProcess(int process_id) const;
89 friend class base::RefCountedThreadSafe<ExtensionInfoMap>;
91 // Extra dynamic data related to an extension.
93 // Map of extension_id to ExtraData.
94 typedef std::map<std::string, ExtraData> ExtraDataMap;
98 ExtensionSet extensions_;
99 ExtensionSet disabled_extensions_;
101 // Extra data associated with enabled extensions.
102 ExtraDataMap extra_data_;
104 // Used by dispatchers to limit API quota for individual extensions.
105 // The ExtensionQutoaService is not thread safe. We need to create and destroy
106 // it on the IO thread.
107 scoped_ptr<ExtensionsQuotaService> quota_service_;
109 // Assignment of extensions to processes.
110 extensions::ProcessMap process_map_;
112 int signin_process_id_;
115 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_