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