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 CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_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" |
| 13 #include "extensions/browser/extension_registry_observer.h" |
| 14 #include "extensions/common/host_id.h" |
12 | 15 |
13 class Profile; | 16 class Profile; |
14 | 17 |
15 namespace extensions { | 18 namespace extensions { |
16 class DeclarativeUserScriptMaster; | 19 class DeclarativeUserScriptMaster; |
17 | 20 |
18 // Manages a set of DeclarativeUserScriptMaster objects for script injections. | 21 // Manages a set of DeclarativeUserScriptMaster objects for script injections. |
19 class DeclarativeUserScriptManager { | 22 class DeclarativeUserScriptManager : public ExtensionRegistryObserver { |
20 public: | 23 public: |
21 explicit DeclarativeUserScriptManager(Profile* profile); | 24 explicit DeclarativeUserScriptManager(Profile* profile); |
22 ~DeclarativeUserScriptManager(); | 25 ~DeclarativeUserScriptManager() override; |
23 | 26 |
24 // Get the user script master for declarative scripts; if one does not exist, | 27 // Gets the user script master for declarative scripts by the given |
25 // a new object will be created. | 28 // HostID; if one does not exist, a new object will be created. |
26 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID( | 29 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID( |
27 const std::string& id); | 30 const HostID& host_id); |
28 | 31 |
29 private: | 32 private: |
30 using UserScriptMasterMap = | 33 using UserScriptMasterMap = |
31 std::map<std::string, linked_ptr<DeclarativeUserScriptMaster>>; | 34 std::map<HostID, linked_ptr<DeclarativeUserScriptMaster>>; |
32 | 35 |
33 // A map of DeclarativeUserScriptMasters for ids; each master is lazily | 36 // ExtensionRegistryObserver: |
34 // initialized. | 37 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 38 const Extension* extension, |
| 39 UnloadedExtensionInfo::Reason reason) override; |
| 40 |
| 41 // Creates a DeclarativeUserScriptMaster object. |
| 42 DeclarativeUserScriptMaster* CreateDeclarativeUserScriptMaster( |
| 43 const HostID& host_id); |
| 44 |
| 45 // A map of DeclarativeUserScriptMasters for each host; each master |
| 46 // is lazily initialized. |
35 UserScriptMasterMap declarative_user_script_masters_; | 47 UserScriptMasterMap declarative_user_script_masters_; |
36 | 48 |
37 Profile* profile_; | 49 Profile* profile_; |
38 | 50 |
| 51 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 52 extension_registry_observer_; |
| 53 |
39 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager); | 54 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager); |
40 }; | 55 }; |
41 | 56 |
42 } // extensions | 57 } // namespace extensions |
43 | 58 |
44 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ | 59 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ |
OLD | NEW |