| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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_USER_SCRIPT_MASTER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_MANAGER_H_ |
| 7 |
| 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/scoped_observer.h" |
| 11 #include "chrome/browser/extensions/declarative_user_script_master.h" |
| 12 #include "chrome/browser/extensions/user_script_master.h" |
| 13 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/browser/extension_registry_observer.h" |
| 15 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/user_script.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class BrowserContext; |
| 21 |
| 22 } // namespace content |
| 23 |
| 24 class Profile; |
| 25 |
| 26 namespace extensions { |
| 27 |
| 28 class UserScriptMasterManager : public ExtensionRegistryObserver { |
| 29 public: |
| 30 explicit UserScriptMasterManager(Profile* profile); |
| 31 virtual ~UserScriptMasterManager(); |
| 32 |
| 33 UserScriptMaster* shared_master() { return shared_master_.get(); } |
| 34 |
| 35 DeclarativeUserScriptMaster* GetDeclarativeMasterByExtension( |
| 36 const ExtensionId& extension_id) { |
| 37 if (!declarative_masters_.get(extension_id)) { |
| 38 declarative_masters_.set(extension_id, |
| 39 make_scoped_ptr(new DeclarativeUserScriptMaster( |
| 40 profile_, extension_id))); |
| 41 } |
| 42 return declarative_masters_.get(extension_id); |
| 43 } |
| 44 |
| 45 // ExtensionRegistryObserver implementation. |
| 46 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 47 const Extension* extension) OVERRIDE; |
| 48 virtual void OnExtensionUnloaded( |
| 49 content::BrowserContext* browser_context, |
| 50 const Extension* extension, |
| 51 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 52 |
| 53 private: |
| 54 Profile* profile_; |
| 55 |
| 56 // Shared memory region manager for scripts statically declared in extension |
| 57 // manifests. This region is shared between all extensions. |
| 58 scoped_ptr<UserScriptMaster> shared_master_; |
| 59 |
| 60 // Shared memory region manager for programmatically declared scripts, one per |
| 61 // extension. Managers are instantiated the first time the declarative API is |
| 62 // used by an extension to request content scripts. |
| 63 base::ScopedPtrHashMap<ExtensionId, DeclarativeUserScriptMaster> |
| 64 declarative_masters_; |
| 65 |
| 66 // Listen to extension load, unloaded notifications. |
| 67 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 68 extension_registry_observer_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(UserScriptMasterManager); |
| 71 }; |
| 72 |
| 73 } // namespace extensions |
| 74 |
| 75 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_MANAGER_H_ |
| OLD | NEW |