info_map.h revision 010d83a9304c5a91596085d917d248abff47903a
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. 4 5#ifndef EXTENSIONS_BROWSER_INFO_MAP_H_ 6#define EXTENSIONS_BROWSER_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 "extensions/browser/process_map.h" 15#include "extensions/browser/quota_service.h" 16#include "extensions/common/extension_set.h" 17 18namespace extensions { 19class ContentVerifier; 20class Extension; 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. 25class InfoMap : public base::RefCountedThreadSafe<InfoMap> { 26 public: 27 InfoMap(); 28 29 const ExtensionSet& extensions() const { return extensions_; } 30 const ExtensionSet& disabled_extensions() const { 31 return disabled_extensions_; 32 } 33 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; 38 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); 44 45 // Callback for when an extension is unloaded. 46 void RemoveExtension(const std::string& extension_id, 47 const extensions::UnloadedExtensionInfo::Reason reason); 48 49 // Returns the time the extension was installed, or base::Time() if not found. 50 base::Time GetInstallTime(const std::string& extension_id) const; 51 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; 55 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; 59 60 // Adds an entry to process_map_. 61 void RegisterExtensionProcess(const std::string& extension_id, 62 int process_id, 63 int site_instance_id); 64 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); 70 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); 75 76 // Removes an entry from worker_process_map_. 77 void UnregisterExtensionWorkerProcess(int process_id); 78 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; 86 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; 93 94 // Returns the IO thread QuotaService. Creates the instance on first call. 95 QuotaService* GetQuotaService(); 96 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; 101 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; 106 107 void SetContentVerifier(ContentVerifier* verifier); 108 ContentVerifier* content_verifier() { return content_verifier_; } 109 110 private: 111 friend class base::RefCountedThreadSafe<InfoMap>; 112 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; 117 118 ~InfoMap(); 119 120 ExtensionSet extensions_; 121 ExtensionSet disabled_extensions_; 122 123 // Extra data associated with enabled extensions. 124 ExtraDataMap extra_data_; 125 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_; 130 131 // Assignment of extensions to renderer processes. 132 extensions::ProcessMap process_map_; 133 134 // Assignment of extensions to worker processes. 135 extensions::ProcessMap worker_process_map_; 136 137 int signin_process_id_; 138 139 scoped_refptr<ContentVerifier> content_verifier_; 140}; 141 142} // namespace extensions 143 144#endif // EXTENSIONS_BROWSER_INFO_MAP_H_ 145