1// Copyright 2014 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_SYSTEM_IMPL_H_ 6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_ 7 8#include "base/memory/scoped_vector.h" 9#include "extensions/browser/extension_system.h" 10#include "extensions/common/one_shot_event.h" 11 12class Profile; 13 14namespace extensions { 15 16class ContentVerifier; 17class DeclarativeUserScriptMaster; 18class ExtensionSystemSharedFactory; 19class ExtensionWarningBadgeService; 20class NavigationObserver; 21class SharedUserScriptMaster; 22class StateStoreNotificationObserver; 23 24// The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. 25// Implementation details: non-shared services are owned by 26// ExtensionSystemImpl, a KeyedService with separate incognito 27// instances. A private Shared class (also a KeyedService, 28// but with a shared instance for incognito) keeps the common services. 29class ExtensionSystemImpl : public ExtensionSystem { 30 public: 31 explicit ExtensionSystemImpl(Profile* profile); 32 virtual ~ExtensionSystemImpl(); 33 34 // KeyedService implementation. 35 virtual void Shutdown() OVERRIDE; 36 37 virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE; 38 39 virtual ExtensionService* extension_service() OVERRIDE; // shared 40 virtual RuntimeData* runtime_data() OVERRIDE; // shared 41 virtual ManagementPolicy* management_policy() OVERRIDE; // shared 42 // shared 43 virtual SharedUserScriptMaster* shared_user_script_master() OVERRIDE; 44 virtual ProcessManager* process_manager() OVERRIDE; 45 virtual StateStore* state_store() OVERRIDE; // shared 46 virtual StateStore* rules_store() OVERRIDE; // shared 47 virtual LazyBackgroundTaskQueue* lazy_background_task_queue() 48 OVERRIDE; // shared 49 virtual InfoMap* info_map() OVERRIDE; // shared 50 virtual EventRouter* event_router() OVERRIDE; // shared 51 virtual WarningService* warning_service() OVERRIDE; 52 virtual Blacklist* blacklist() OVERRIDE; // shared 53 virtual ErrorConsole* error_console() OVERRIDE; 54 virtual InstallVerifier* install_verifier() OVERRIDE; 55 virtual QuotaService* quota_service() OVERRIDE; // shared 56 57 virtual void RegisterExtensionWithRequestContexts( 58 const Extension* extension) OVERRIDE; 59 60 virtual void UnregisterExtensionWithRequestContexts( 61 const std::string& extension_id, 62 const UnloadedExtensionInfo::Reason reason) OVERRIDE; 63 64 virtual const OneShotEvent& ready() const OVERRIDE; 65 virtual ContentVerifier* content_verifier() OVERRIDE; // shared 66 virtual scoped_ptr<ExtensionSet> GetDependentExtensions( 67 const Extension* extension) OVERRIDE; 68 69 virtual DeclarativeUserScriptMaster* 70 GetDeclarativeUserScriptMasterByExtension( 71 const ExtensionId& extension_id) OVERRIDE; // shared 72 73 private: 74 friend class ExtensionSystemSharedFactory; 75 76 // Owns the Extension-related systems that have a single instance 77 // shared between normal and incognito profiles. 78 class Shared : public KeyedService { 79 public: 80 explicit Shared(Profile* profile); 81 virtual ~Shared(); 82 83 // Initialization takes place in phases. 84 virtual void InitPrefs(); 85 // This must not be called until all the providers have been created. 86 void RegisterManagementPolicyProviders(); 87 void Init(bool extensions_enabled); 88 89 // KeyedService implementation. 90 virtual void Shutdown() OVERRIDE; 91 92 StateStore* state_store(); 93 StateStore* rules_store(); 94 ExtensionService* extension_service(); 95 RuntimeData* runtime_data(); 96 ManagementPolicy* management_policy(); 97 SharedUserScriptMaster* shared_user_script_master(); 98 Blacklist* blacklist(); 99 InfoMap* info_map(); 100 LazyBackgroundTaskQueue* lazy_background_task_queue(); 101 EventRouter* event_router(); 102 WarningService* warning_service(); 103 ErrorConsole* error_console(); 104 InstallVerifier* install_verifier(); 105 QuotaService* quota_service(); 106 const OneShotEvent& ready() const { return ready_; } 107 ContentVerifier* content_verifier(); 108 109 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByExtension( 110 const ExtensionId& extension_id); 111 112 private: 113 Profile* profile_; 114 115 // The services that are shared between normal and incognito profiles. 116 117 scoped_ptr<StateStore> state_store_; 118 scoped_ptr<StateStoreNotificationObserver> 119 state_store_notification_observer_; 120 scoped_ptr<StateStore> rules_store_; 121 // LazyBackgroundTaskQueue is a dependency of 122 // MessageService and EventRouter. 123 scoped_ptr<LazyBackgroundTaskQueue> lazy_background_task_queue_; 124 scoped_ptr<EventRouter> event_router_; 125 scoped_ptr<NavigationObserver> navigation_observer_; 126 // Shared memory region manager for scripts statically declared in extension 127 // manifests. This region is shared between all extensions. 128 scoped_ptr<SharedUserScriptMaster> shared_user_script_master_; 129 // Shared memory region manager for programmatically declared scripts, one 130 // per extension. Managers are instantiated the first time the declarative 131 // API is used by an extension to request content scripts. 132 ScopedVector<DeclarativeUserScriptMaster> declarative_user_script_masters_; 133 scoped_ptr<Blacklist> blacklist_; 134 scoped_ptr<RuntimeData> runtime_data_; 135 // ExtensionService depends on StateStore, Blacklist and RuntimeData. 136 scoped_ptr<ExtensionService> extension_service_; 137 scoped_ptr<ManagementPolicy> management_policy_; 138 // extension_info_map_ needs to outlive process_manager_. 139 scoped_refptr<InfoMap> extension_info_map_; 140 scoped_ptr<WarningService> warning_service_; 141 scoped_ptr<ExtensionWarningBadgeService> extension_warning_badge_service_; 142 scoped_ptr<ErrorConsole> error_console_; 143 scoped_ptr<InstallVerifier> install_verifier_; 144 scoped_ptr<QuotaService> quota_service_; 145 146 // For verifying the contents of extensions read from disk. 147 scoped_refptr<ContentVerifier> content_verifier_; 148 149#if defined(OS_CHROMEOS) 150 scoped_ptr<chromeos::DeviceLocalAccountManagementPolicyProvider> 151 device_local_account_management_policy_provider_; 152#endif 153 154 OneShotEvent ready_; 155 }; 156 157 Profile* profile_; 158 159 Shared* shared_; 160 161 // |process_manager_| must be destroyed before the Profile's |io_data_|. While 162 // |process_manager_| still lives, we handle incoming resource requests from 163 // extension processes and those require access to the ResourceContext owned 164 // by |io_data_|. 165 scoped_ptr<ProcessManager> process_manager_; 166 167 DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl); 168}; 169 170} // namespace extensions 171 172#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_ 173