Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / extensions / browser / declarative_user_script_manager.h
blob00779bf066f5558e4b51fc48f755b47b72ee8a2d
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 EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_
6 #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_
8 #include <map>
10 #include "base/macros.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "extensions/browser/extension_registry_observer.h"
15 #include "extensions/common/host_id.h"
17 namespace content {
18 class BrowserContext;
21 namespace extensions {
22 class DeclarativeUserScriptMaster;
24 // Manages a set of DeclarativeUserScriptMaster objects for script injections.
25 class DeclarativeUserScriptManager : public KeyedService,
26 public ExtensionRegistryObserver {
27 public:
28 explicit DeclarativeUserScriptManager(
29 content::BrowserContext* browser_context);
30 ~DeclarativeUserScriptManager() override;
32 // Convenience method to return the DeclarativeUserScriptManager for a given
33 // |context|.
34 static DeclarativeUserScriptManager* Get(content::BrowserContext* context);
36 // Gets the user script master for declarative scripts by the given
37 // HostID; if one does not exist, a new object will be created.
38 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID(
39 const HostID& host_id);
41 private:
42 using UserScriptMasterMap =
43 std::map<HostID, linked_ptr<DeclarativeUserScriptMaster>>;
45 // ExtensionRegistryObserver:
46 void OnExtensionUnloaded(content::BrowserContext* browser_context,
47 const Extension* extension,
48 UnloadedExtensionInfo::Reason reason) override;
50 // Creates a DeclarativeUserScriptMaster object.
51 DeclarativeUserScriptMaster* CreateDeclarativeUserScriptMaster(
52 const HostID& host_id);
54 // A map of DeclarativeUserScriptMasters for each host; each master
55 // is lazily initialized.
56 UserScriptMasterMap declarative_user_script_masters_;
58 content::BrowserContext* browser_context_;
60 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
61 extension_registry_observer_;
63 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager);
66 } // namespace extensions
68 #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_