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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MASTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MASTER_H_
8 #include "base/scoped_observer.h"
9 #include "chrome/browser/extensions/user_script_loader.h"
10 #include "extensions/browser/extension_registry_observer.h"
11 #include "extensions/common/extension.h"
15 namespace extensions
{
17 class ExtensionRegistry
;
20 // Manages declarative user scripts for a single extension. Owns a
21 // UserScriptLoader to which file loading and shared memory management
22 // operations are delegated, and provides an interface for adding, removing,
23 // and clearing scripts.
24 class DeclarativeUserScriptMaster
: public ExtensionRegistryObserver
{
26 DeclarativeUserScriptMaster(Profile
* profile
,
27 const ExtensionId
& extension_id
);
28 virtual ~DeclarativeUserScriptMaster();
30 // Adds script to shared memory region. This may not happen right away if a
31 // script load is in progress.
32 void AddScript(const UserScript
& script
);
34 // Removes script from shared memory region. This may not happen right away if
35 // a script load is in progress.
36 void RemoveScript(const UserScript
& script
);
38 // Removes all scripts from shared memory region. This may not happen right
39 // away if a script load is in progress.
42 const ExtensionId
& extension_id() const { return extension_id_
; }
45 // ExtensionRegistryObserver implementation.
46 virtual void OnExtensionUnloaded(
47 content::BrowserContext
* browser_context
,
48 const Extension
* extension
,
49 UnloadedExtensionInfo::Reason reason
) override
;
51 // ID of extension that owns scripts that this component manages.
52 ExtensionId extension_id_
;
54 // Script loader that handles loading contents of scripts into shared memory
55 // and notifying renderers of script updates.
56 UserScriptLoader loader_
;
58 ScopedObserver
<ExtensionRegistry
, ExtensionRegistryObserver
>
59 extension_registry_observer_
;
61 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster
);
64 } // namespace extensions
66 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MASTER_H_