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