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_SYSTEM_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" |
| 15 |
| 16 class Extension; |
| 17 class ExtensionDevToolsManager; |
| 18 class ExtensionEventRouter; |
| 19 class ExtensionInfoMap; |
| 20 class ExtensionMessageService; |
| 21 class ExtensionNavigationObserver; |
| 22 class ExtensionPrefs; |
| 23 class ExtensionPrefValueMap; |
| 24 class ExtensionProcessManager; |
| 25 class ExtensionService; |
| 26 class Profile; |
| 27 class UserScriptMaster; |
| 28 |
| 29 // The ExtensionSystem manages the creation and destruction of services |
| 30 // related to extensions. Most objects are shared between normal |
| 31 // and incognito Profiles, except for the process manager. |
| 32 // This interface is analogous to ExtensionServiceInterface; it supports |
| 33 // using TestExtensionSystem for TestingProfiles that don't want all of the |
| 34 // extensions baggage in their tests. |
| 35 class ExtensionSystem : public ProfileKeyedService { |
| 36 public: |
| 37 ExtensionSystem(); |
| 38 virtual ~ExtensionSystem(); |
| 39 |
| 40 virtual void InitPrefs(bool extensions_enabled, |
| 41 ExtensionPrefValueMap* pref_value_map) = 0; |
| 42 |
| 43 // Initializes extensions machinery. |
| 44 // Component extensions are always enabled, external and user extensions |
| 45 // are controlled by |extensions_enabled|. |
| 46 virtual void Init(bool extensions_enabled) = 0; |
| 47 |
| 48 // The ExtensionService is created at startup. |
| 49 virtual ExtensionService* extension_service() = 0; |
| 50 |
| 51 // The ExtensionDevToolsManager is created at startup. |
| 52 virtual ExtensionDevToolsManager* devtools_manager() = 0; |
| 53 |
| 54 // The UserScriptMaster is created at startup. |
| 55 virtual UserScriptMaster* user_script_master() = 0; |
| 56 |
| 57 // The ExtensionProcessManager is created at startup. |
| 58 virtual ExtensionProcessManager* process_manager() = 0; |
| 59 |
| 60 // Returns the IO-thread-accessible extension data. |
| 61 virtual ExtensionInfoMap* info_map() = 0; |
| 62 |
| 63 // The ExtensionMessageService is created at startup. |
| 64 virtual ExtensionMessageService* message_service() = 0; |
| 65 |
| 66 // The ExtensionEventRouter is created at startup. |
| 67 virtual ExtensionEventRouter* event_router() = 0; |
| 68 |
| 69 // Explicitly remove the ExtensionProcessManager at profile shutdown. |
| 70 virtual void DestroyProcessManager() {} |
| 71 |
| 72 // Called by the ExtensionService that lives in this system. Gives the |
| 73 // info map a chance to react to the load event before the EXTENSION_LOADED |
| 74 // notification has fired. The purpose for handling this event first is to |
| 75 // avoid race conditions by making sure URLRequestContexts learn about new |
| 76 // extensions before anything else needs them to know. |
| 77 virtual void RegisterExtensionWithRequestContexts( |
| 78 const Extension* extension) {} |
| 79 |
| 80 // Called by the ExtensionService that lives in this system. Lets the |
| 81 // info map clean up its RequestContexts once all the listeners to the |
| 82 // EXTENSION_UNLOADED notification have finished running. |
| 83 virtual void UnregisterExtensionWithRequestContexts( |
| 84 const std::string& extension_id, |
| 85 const extension_misc::UnloadedExtensionReason reason) {} |
| 86 }; |
| 87 |
| 88 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. |
| 89 // Implementation details: non-shared services are owned by |
| 90 // ExtensionSystemImpl, a ProfileKeyedService with separate incognito |
| 91 // instances. A private Delegate class (also a ProfileKeyedService, |
| 92 // but with a shared instance for incognito) keeps the common services. |
| 93 class ExtensionSystemImpl : public ExtensionSystem { |
| 94 public: |
| 95 explicit ExtensionSystemImpl(Profile* profile); |
| 96 virtual ~ExtensionSystemImpl(); |
| 97 |
| 98 virtual void InitPrefs(bool extensions_enabled, |
| 99 ExtensionPrefValueMap* pref_value_map); |
| 100 |
| 101 virtual void Init(bool extensions_enabled) OVERRIDE; |
| 102 |
| 103 virtual ExtensionService* extension_service() OVERRIDE; // delegated |
| 104 virtual UserScriptMaster* user_script_master() OVERRIDE; // delegated |
| 105 virtual ExtensionDevToolsManager* devtools_manager() OVERRIDE; |
| 106 virtual ExtensionProcessManager* process_manager() OVERRIDE; |
| 107 virtual ExtensionInfoMap* info_map() OVERRIDE; // delegated |
| 108 virtual ExtensionMessageService* message_service() OVERRIDE; // delegated |
| 109 virtual ExtensionEventRouter* event_router() OVERRIDE; // delegated |
| 110 |
| 111 virtual void DestroyProcessManager() OVERRIDE; |
| 112 |
| 113 virtual void RegisterExtensionWithRequestContexts( |
| 114 const Extension* extension) OVERRIDE; |
| 115 |
| 116 virtual void UnregisterExtensionWithRequestContexts( |
| 117 const std::string& extension_id, |
| 118 const extension_misc::UnloadedExtensionReason reason) OVERRIDE; |
| 119 |
| 120 private: |
| 121 friend class ExtensionSystemDelegateFactory; |
| 122 |
| 123 // Owns the Extension-related systems that have a single instance |
| 124 // shared between normal and incognito profiles. |
| 125 class Delegate : public ProfileKeyedService { |
| 126 public: |
| 127 explicit Delegate(Profile* profile); |
| 128 virtual ~Delegate(); |
| 129 |
| 130 // Initialization takes place in phases. |
| 131 void InitPrefs(bool extensions_enabled, |
| 132 ExtensionPrefValueMap* pref_value_map); |
| 133 void InitInfoMap(); |
| 134 void Init(bool extensions_enabled); |
| 135 |
| 136 ExtensionService* extension_service(); |
| 137 UserScriptMaster* user_script_master(); |
| 138 ExtensionInfoMap* info_map(); |
| 139 ExtensionMessageService* message_service(); |
| 140 ExtensionEventRouter* event_router(); |
| 141 |
| 142 private: |
| 143 Profile* profile_; |
| 144 |
| 145 // The services that are shared between normal and incognito profiles. |
| 146 |
| 147 // Keep extension_prefs_ on top of extension_service_ because the latter |
| 148 // maintains a pointer to the first and shall be destructed first. |
| 149 scoped_ptr<ExtensionPrefs> extension_prefs_; |
| 150 scoped_ptr<ExtensionService> extension_service_; |
| 151 scoped_refptr<UserScriptMaster> user_script_master_; |
| 152 // extension_info_map_ needs to outlive extension_process_manager_. |
| 153 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
| 154 scoped_refptr<ExtensionMessageService> extension_message_service_; |
| 155 scoped_ptr<ExtensionEventRouter> extension_event_router_; |
| 156 scoped_ptr<ExtensionNavigationObserver> extension_navigation_observer_; |
| 157 }; |
| 158 |
| 159 Profile* profile_; |
| 160 |
| 161 Delegate* delegate_; |
| 162 |
| 163 // The services that have their own instances in incognito. |
| 164 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; |
| 165 // |extension_process_manager_| must be destroyed before the Profile's |
| 166 // |io_data_|. While |extension_process_manager_| still lives, we handle |
| 167 // incoming resource requests from extension processes and those require |
| 168 // access to the ResourceContext owned by |io_data_|. |
| 169 scoped_ptr<ExtensionProcessManager> extension_process_manager_; |
| 170 }; |
| 171 |
| 172 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ |
OLD | NEW |