| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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" | |
| 17 | |
| 18 namespace extensions { | |
| 19 class Extension; | |
| 20 } | |
| 21 | |
| 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 ExtensionInfoMap : public base::RefCountedThreadSafe<ExtensionInfoMap> { | |
| 26 public: | |
| 27 ExtensionInfoMap(); | |
| 28 | |
| 29 const ExtensionSet& extensions() const { return extensions_; } | |
| 30 const ExtensionSet& disabled_extensions() const { | |
| 31 return disabled_extensions_; | |
| 32 } | |
| 33 | |
| 34 const extensions::ProcessMap& process_map() const; | |
| 35 | |
| 36 // Callback for when new extensions are loaded. | |
| 37 void AddExtension(const extensions::Extension* extension, | |
| 38 base::Time install_time, | |
| 39 bool incognito_enabled); | |
| 40 | |
| 41 // Callback for when an extension is unloaded. | |
| 42 void RemoveExtension(const std::string& extension_id, | |
| 43 const extensions::UnloadedExtensionInfo::Reason reason); | |
| 44 | |
| 45 // Returns the time the extension was installed, or base::Time() if not found. | |
| 46 base::Time GetInstallTime(const std::string& extension_id) const; | |
| 47 | |
| 48 // Returns true if the user has allowed this extension to run in incognito | |
| 49 // mode. | |
| 50 bool IsIncognitoEnabled(const std::string& extension_id) const; | |
| 51 | |
| 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; | |
| 55 | |
| 56 // Adds an entry to process_map_. | |
| 57 void RegisterExtensionProcess(const std::string& extension_id, | |
| 58 int process_id, | |
| 59 int site_instance_id); | |
| 60 | |
| 61 // Removes an entry from process_map_. | |
| 62 void UnregisterExtensionProcess(const std::string& extension_id, | |
| 63 int process_id, | |
| 64 int site_instance_id); | |
| 65 void UnregisterAllExtensionsInProcess(int process_id); | |
| 66 | |
| 67 // Returns the subset of extensions which has the same |origin| in | |
| 68 // |process_id| with the specified |permission|. | |
| 69 void GetExtensionsWithAPIPermissionForSecurityOrigin( | |
| 70 const GURL& origin, | |
| 71 int process_id, | |
| 72 extensions::APIPermission::ID permission, | |
| 73 ExtensionSet* extensions) const; | |
| 74 | |
| 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; | |
| 80 | |
| 81 ExtensionsQuotaService* GetQuotaService(); | |
| 82 | |
| 83 // Keep track of the signin process, so we can restrict extension access to | |
| 84 // it. | |
| 85 void SetSigninProcess(int process_id); | |
| 86 bool IsSigninProcess(int process_id) const; | |
| 87 | |
| 88 private: | |
| 89 friend class base::RefCountedThreadSafe<ExtensionInfoMap>; | |
| 90 | |
| 91 // Extra dynamic data related to an extension. | |
| 92 struct ExtraData; | |
| 93 // Map of extension_id to ExtraData. | |
| 94 typedef std::map<std::string, ExtraData> ExtraDataMap; | |
| 95 | |
| 96 ~ExtensionInfoMap(); | |
| 97 | |
| 98 ExtensionSet extensions_; | |
| 99 ExtensionSet disabled_extensions_; | |
| 100 | |
| 101 // Extra data associated with enabled extensions. | |
| 102 ExtraDataMap extra_data_; | |
| 103 | |
| 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_; | |
| 108 | |
| 109 // Assignment of extensions to processes. | |
| 110 extensions::ProcessMap process_map_; | |
| 111 | |
| 112 int signin_process_id_; | |
| 113 }; | |
| 114 | |
| 115 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_ | |
| OLD | NEW |