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_SHARED_USER_SCRIPT_MASTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_USER_SCRIPT_LOADER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SHARED_USER_SCRIPT_MASTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_USER_SCRIPT_LOADER_H_ |
7 | 7 |
8 #include <set> | 8 #include "base/memory/shared_memory.h" |
9 | |
10 #include "base/scoped_observer.h" | |
11 #include "chrome/browser/extensions/user_script_loader.h" | 9 #include "chrome/browser/extensions/user_script_loader.h" |
10 #include "content/public/browser/notification_observer.h" | |
11 #include "content/public/browser/notification_registrar.h" | |
12 #include "extensions/browser/extension_registry_observer.h" | 12 #include "extensions/browser/extension_registry_observer.h" |
13 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
14 #include "extensions/common/extension_set.h" | |
14 #include "extensions/common/user_script.h" | 15 #include "extensions/common/user_script.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class BrowserContext; | 18 class BrowserContext; |
18 } | 19 } |
19 | 20 |
20 class Profile; | 21 class Profile; |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
25 class ContentVerifier; | |
24 class ExtensionRegistry; | 26 class ExtensionRegistry; |
25 | 27 |
26 // Manages statically-defined user scripts for all extensions. Owns a | 28 // UserScriptLoader for extensions. |
27 // UserScriptLoader to which file loading and shared memory management | 29 class ExtensionUserScriptLoader : public UserScriptLoader, |
28 // operations are delegated. | 30 public ExtensionRegistryObserver { |
29 class SharedUserScriptMaster : public ExtensionRegistryObserver { | |
30 public: | 31 public: |
31 explicit SharedUserScriptMaster(Profile* profile); | 32 ExtensionUserScriptLoader(Profile* profile, |
32 ~SharedUserScriptMaster() override; | 33 const ConsumerID& consumer_id, |
33 | 34 bool listen_for_extension_system_loaded); |
34 // Provides access to loader state method: scripts_ready(). | 35 ~ExtensionUserScriptLoader() override; |
35 bool scripts_ready() const { return loader_.scripts_ready(); } | |
36 | 36 |
37 private: | 37 private: |
38 // UserScriptLoader implementation. | |
39 void UpdateConsumersInfo() override; | |
40 bool ready() override; | |
41 ContentVerifier* GetContentVerifier() override; | |
42 LoadUserScriptsFunctionCallback GetLoadUserScriptsFunction() override; | |
43 static bool LoadScriptContent(const ConsumerID& consumer_id, | |
Fady Samuel
2014/12/22 21:48:46
Move this above // UserScriptLoader implementation
Xi Han
2014/12/22 22:58:59
Moved.
| |
44 UserScript::File* script_file, | |
45 const SubstitutionMap* localization_messages, | |
46 scoped_refptr<ContentVerifier> verifier); | |
47 void SendUpdate(content::RenderProcessHost* process, | |
48 base::SharedMemoryHandle handle_for_process, | |
49 const std::set<ConsumerID>& changed_consumers) override; | |
50 | |
38 // ExtensionRegistryObserver implementation. | 51 // ExtensionRegistryObserver implementation. |
39 void OnExtensionLoaded(content::BrowserContext* browser_context, | |
40 const Extension* extension) override; | |
41 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 52 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
42 const Extension* extension, | 53 const Extension* extension, |
43 UnloadedExtensionInfo::Reason reason) override; | 54 UnloadedExtensionInfo::Reason reason) override; |
44 | 55 |
45 // Gets an extension's scripts' metadata; i.e., gets a list of UserScript | 56 // Initiates script load when we have been waiting for the extension system |
46 // objects that contains script info, but not the contents of the scripts. | 57 // to be ready. |
47 const std::set<UserScript> GetScriptsMetadata(const Extension* extension); | 58 void OnExtensionSystemReady(); |
48 | 59 |
49 // Script loader that handles loading contents of scripts into shared memory | 60 // If the extensions service has finished loading its initial set of |
50 // and notifying renderers of scripts in shared memory. | 61 // extensions. |
51 UserScriptLoader loader_; | 62 bool extension_system_ready_; |
52 | |
53 // The profile for which the scripts managed here are installed. | |
54 Profile* profile_; | |
55 | 63 |
56 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 64 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
57 extension_registry_observer_; | 65 extension_registry_observer_; |
58 | 66 |
59 DISALLOW_COPY_AND_ASSIGN(SharedUserScriptMaster); | 67 base::WeakPtrFactory<ExtensionUserScriptLoader> weak_factory_; |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(ExtensionUserScriptLoader); | |
60 }; | 70 }; |
61 | 71 |
62 } // namespace extensions | 72 } // namespace extensions |
63 | 73 |
64 #endif // CHROME_BROWSER_EXTENSIONS_SHARED_USER_SCRIPT_MASTER_H_ | 74 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_USER_SCRIPT_LOADER_H_ |
OLD | NEW |