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_USER_SCRIPT_LOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 static bool ParseMetadataHeader(const base::StringPiece& script_text, | 52 static bool ParseMetadataHeader(const base::StringPiece& script_text, |
53 UserScript* script); | 53 UserScript* script); |
54 | 54 |
55 // A wrapper around the method to load user scripts, which is normally run on | 55 // A wrapper around the method to load user scripts, which is normally run on |
56 // the file thread. Exposed only for tests. | 56 // the file thread. Exposed only for tests. |
57 static void LoadScriptsForTest(UserScriptList* user_scripts); | 57 static void LoadScriptsForTest(UserScriptList* user_scripts); |
58 | 58 |
59 UserScriptLoader(Profile* profile, | 59 UserScriptLoader(Profile* profile, |
60 const ExtensionId& owner_extension_id, | 60 const ExtensionId& owner_extension_id, |
61 bool listen_for_extension_system_loaded); | 61 bool listen_for_extension_system_loaded); |
62 virtual ~UserScriptLoader(); | 62 ~UserScriptLoader() override; |
63 | 63 |
64 // Add |scripts| to the set of scripts managed by this loader. | 64 // Add |scripts| to the set of scripts managed by this loader. |
65 void AddScripts(const std::set<UserScript>& scripts); | 65 void AddScripts(const std::set<UserScript>& scripts); |
66 | 66 |
67 // Remove |scripts| from the set of scripts managed by this loader. | 67 // Remove |scripts| from the set of scripts managed by this loader. |
68 void RemoveScripts(const std::set<UserScript>& scripts); | 68 void RemoveScripts(const std::set<UserScript>& scripts); |
69 | 69 |
70 // Clears the set of scripts managed by this loader. | 70 // Clears the set of scripts managed by this loader. |
71 void ClearScripts(); | 71 void ClearScripts(); |
72 | 72 |
73 // Initiates procedure to start loading scripts on the file thread. | 73 // Initiates procedure to start loading scripts on the file thread. |
74 void StartLoad(); | 74 void StartLoad(); |
75 | 75 |
76 // Return true if we have any scripts ready. | 76 // Return true if we have any scripts ready. |
77 bool scripts_ready() const { return shared_memory_.get() != NULL; } | 77 bool scripts_ready() const { return shared_memory_.get() != NULL; } |
78 | 78 |
79 private: | 79 private: |
80 // content::NotificationObserver implementation. | 80 // content::NotificationObserver implementation. |
81 virtual void Observe(int type, | 81 void Observe(int type, |
82 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) override; | 83 const content::NotificationDetails& details) override; |
84 | 84 |
85 // ExtensionRegistryObserver implementation. | 85 // ExtensionRegistryObserver implementation. |
86 virtual void OnExtensionUnloaded( | 86 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
87 content::BrowserContext* browser_context, | 87 const Extension* extension, |
88 const Extension* extension, | 88 UnloadedExtensionInfo::Reason reason) override; |
89 UnloadedExtensionInfo::Reason reason) override; | |
90 | 89 |
91 // Initiates script load when we have been waiting for the extension system | 90 // Initiates script load when we have been waiting for the extension system |
92 // to be ready. | 91 // to be ready. |
93 void OnExtensionSystemReady(); | 92 void OnExtensionSystemReady(); |
94 | 93 |
95 // Returns whether or not it is possible that calls to AddScripts(), | 94 // Returns whether or not it is possible that calls to AddScripts(), |
96 // RemoveScripts(), and/or ClearScripts() have caused any real change in the | 95 // RemoveScripts(), and/or ClearScripts() have caused any real change in the |
97 // set of scripts to be loaded. | 96 // set of scripts to be loaded. |
98 bool ScriptsMayHaveChanged() const; | 97 bool ScriptsMayHaveChanged() const; |
99 | 98 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 extension_registry_observer_; | 171 extension_registry_observer_; |
173 | 172 |
174 base::WeakPtrFactory<UserScriptLoader> weak_factory_; | 173 base::WeakPtrFactory<UserScriptLoader> weak_factory_; |
175 | 174 |
176 DISALLOW_COPY_AND_ASSIGN(UserScriptLoader); | 175 DISALLOW_COPY_AND_ASSIGN(UserScriptLoader); |
177 }; | 176 }; |
178 | 177 |
179 } // namespace extensions | 178 } // namespace extensions |
180 | 179 |
181 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_ | 180 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_ |
OLD | NEW |