OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
| 13 #include "components/keyed_service/core/keyed_service.h" |
13 #include "extensions/browser/extension_registry_observer.h" | 14 #include "extensions/browser/extension_registry_observer.h" |
14 #include "extensions/common/host_id.h" | 15 #include "extensions/common/host_id.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class BrowserContext; | 18 class BrowserContext; |
18 } | 19 } |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 class DeclarativeUserScriptMaster; | 22 class DeclarativeUserScriptMaster; |
22 | 23 |
23 // Manages a set of DeclarativeUserScriptMaster objects for script injections. | 24 // Manages a set of DeclarativeUserScriptMaster objects for script injections. |
24 class DeclarativeUserScriptManager : public ExtensionRegistryObserver { | 25 class DeclarativeUserScriptManager : public KeyedService, |
| 26 public ExtensionRegistryObserver { |
25 public: | 27 public: |
26 explicit DeclarativeUserScriptManager( | 28 explicit DeclarativeUserScriptManager( |
27 content::BrowserContext* browser_context); | 29 content::BrowserContext* browser_context); |
28 ~DeclarativeUserScriptManager() override; | 30 ~DeclarativeUserScriptManager() override; |
29 | 31 |
| 32 // Convenience method to return the DeclarativeUserScriptManager for a given |
| 33 // |context|. |
| 34 static DeclarativeUserScriptManager* Get(content::BrowserContext* context); |
| 35 |
30 // Gets the user script master for declarative scripts by the given | 36 // Gets the user script master for declarative scripts by the given |
31 // HostID; if one does not exist, a new object will be created. | 37 // HostID; if one does not exist, a new object will be created. |
32 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID( | 38 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID( |
33 const HostID& host_id); | 39 const HostID& host_id); |
34 | 40 |
35 private: | 41 private: |
36 using UserScriptMasterMap = | 42 using UserScriptMasterMap = |
37 std::map<HostID, linked_ptr<DeclarativeUserScriptMaster>>; | 43 std::map<HostID, linked_ptr<DeclarativeUserScriptMaster>>; |
38 | 44 |
39 // ExtensionRegistryObserver: | 45 // ExtensionRegistryObserver: |
(...skipping 13 matching lines...) Expand all Loading... |
53 | 59 |
54 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 60 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
55 extension_registry_observer_; | 61 extension_registry_observer_; |
56 | 62 |
57 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager); | 63 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager); |
58 }; | 64 }; |
59 | 65 |
60 } // namespace extensions | 66 } // namespace extensions |
61 | 67 |
62 #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_ | 68 #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MANAGER_H_ |
OLD | NEW |