| 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 LazyBackgroundTaskQueue; | 
 |   27 class Profile; | 
 |   28 class UserScriptMaster; | 
 |   29  | 
 |   30 // The ExtensionSystem manages the creation and destruction of services | 
 |   31 // related to extensions. Most objects are shared between normal | 
 |   32 // and incognito Profiles, except as called out in comments. | 
 |   33 // This interface supports using TestExtensionSystem for TestingProfiles | 
 |   34 // that don't want all of the extensions baggage in their tests. | 
 |   35 class ExtensionSystem : public ProfileKeyedService { | 
 |   36  public: | 
 |   37   ExtensionSystem(); | 
 |   38   virtual ~ExtensionSystem(); | 
 |   39  | 
 |   40   // ProfileKeyedService implementation. | 
 |   41   virtual void Shutdown() OVERRIDE {} | 
 |   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 LazyBackgroundTaskQueue is created at startup. | 
 |   64   virtual LazyBackgroundTaskQueue* lazy_background_task_queue() = 0; | 
 |   65  | 
 |   66   // The ExtensionMessageService is created at startup. | 
 |   67   virtual ExtensionMessageService* message_service() = 0; | 
 |   68  | 
 |   69   // The ExtensionEventRouter is created at startup. | 
 |   70   virtual ExtensionEventRouter* event_router() = 0; | 
 |   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 Shared 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   // ProfileKeyedService implementation. | 
 |   99   virtual void Shutdown() OVERRIDE; | 
 |  100  | 
 |  101   virtual void Init(bool extensions_enabled) OVERRIDE; | 
 |  102  | 
 |  103   virtual ExtensionService* extension_service() OVERRIDE;  // shared | 
 |  104   virtual UserScriptMaster* user_script_master() OVERRIDE;  // shared | 
 |  105   virtual ExtensionDevToolsManager* devtools_manager() OVERRIDE; | 
 |  106   virtual ExtensionProcessManager* process_manager() OVERRIDE; | 
 |  107   virtual LazyBackgroundTaskQueue* lazy_background_task_queue() | 
 |  108       OVERRIDE;  // shared | 
 |  109   virtual ExtensionInfoMap* info_map() OVERRIDE;  // shared | 
 |  110   virtual ExtensionMessageService* message_service() OVERRIDE;  // shared | 
 |  111   virtual ExtensionEventRouter* event_router() OVERRIDE;  // shared | 
 |  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 ExtensionSystemSharedFactory; | 
 |  122  | 
 |  123   // Owns the Extension-related systems that have a single instance | 
 |  124   // shared between normal and incognito profiles. | 
 |  125   class Shared : public ProfileKeyedService { | 
 |  126    public: | 
 |  127     explicit Shared(Profile* profile); | 
 |  128     virtual ~Shared(); | 
 |  129  | 
 |  130     // Initialization takes place in phases. | 
 |  131     virtual void InitPrefs(); | 
 |  132     void InitInfoMap(); | 
 |  133     void Init(bool extensions_enabled); | 
 |  134  | 
 |  135     ExtensionService* extension_service(); | 
 |  136     UserScriptMaster* user_script_master(); | 
 |  137     ExtensionInfoMap* info_map(); | 
 |  138     LazyBackgroundTaskQueue* lazy_background_task_queue(); | 
 |  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     // This is a dependency of ExtensionMessageService and ExtensionEventRouter. | 
 |  155     scoped_ptr<LazyBackgroundTaskQueue> lazy_background_task_queue_; | 
 |  156     scoped_ptr<ExtensionMessageService> extension_message_service_; | 
 |  157     scoped_ptr<ExtensionEventRouter> extension_event_router_; | 
 |  158     scoped_ptr<ExtensionNavigationObserver> extension_navigation_observer_; | 
 |  159   }; | 
 |  160  | 
 |  161   Profile* profile_; | 
 |  162  | 
 |  163   Shared* shared_; | 
 |  164  | 
 |  165   // The services that have their own instances in incognito. | 
 |  166   scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; | 
 |  167   // |extension_process_manager_| must be destroyed before the Profile's | 
 |  168   // |io_data_|. While |extension_process_manager_| still lives, we handle | 
 |  169   // incoming resource requests from extension processes and those require | 
 |  170   // access to the ResourceContext owned by |io_data_|. | 
 |  171   scoped_ptr<ExtensionProcessManager> extension_process_manager_; | 
 |  172 }; | 
 |  173  | 
 |  174 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ | 
| OLD | NEW |