| 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_MASTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ |
| 6 #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ | 6 #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
| 13 #include "extensions/common/host_id.h" | 13 #include "extensions/common/host_id.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class BrowserContext; | 16 class BrowserContext; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 class BrowserUserScript; |
| 21 class UserScript; | 22 class UserScript; |
| 22 class UserScriptLoader; | 23 class UserScriptLoader; |
| 23 | 24 |
| 24 struct UserScriptIDPair; | 25 struct UserScriptIDPair; |
| 25 | 26 |
| 26 // Manages declarative user scripts for a single extension. Owns a | 27 // Manages declarative user scripts for a single extension. Owns a |
| 27 // UserScriptLoader to which file loading and shared memory management | 28 // UserScriptLoader to which file loading and shared memory management |
| 28 // operations are delegated, and provides an interface for adding, removing, | 29 // operations are delegated, and provides an interface for adding, removing, |
| 29 // and clearing scripts. | 30 // and clearing scripts. |
| 30 class DeclarativeUserScriptMaster { | 31 class DeclarativeUserScriptMaster { |
| 31 public: | 32 public: |
| 32 DeclarativeUserScriptMaster(content::BrowserContext* browser_context, | 33 DeclarativeUserScriptMaster(content::BrowserContext* browser_context, |
| 33 const HostID& host_id); | 34 const HostID& host_id); |
| 34 ~DeclarativeUserScriptMaster(); | 35 ~DeclarativeUserScriptMaster(); |
| 35 | 36 |
| 36 // Adds script to shared memory region. This may not happen right away if a | 37 // Adds script to shared memory region. This may not happen right away if a |
| 37 // script load is in progress. | 38 // script load is in progress. |
| 38 void AddScript(const UserScript& script); | 39 void AddScript(std::unique_ptr<BrowserUserScript> script); |
| 39 | 40 |
| 40 // Adds a set of scripts to shared meomory region. The fetch of the content | 41 // Adds a set of scripts to shared meomory region. The fetch of the content |
| 41 // of the script on WebUI requires to start URL request to the associated | 42 // of the script on WebUI requires to start URL request to the associated |
| 42 // render specified by |render_process_id, render_view_id|. | 43 // render specified by |render_process_id, render_view_id|. |
| 43 // This may not happen right away if a script load is in progress. | 44 // This may not happen right away if a script load is in progress. |
| 44 void AddScripts(const std::vector<UserScript>& scripts, | 45 void AddScripts(std::vector<std::unique_ptr<BrowserUserScript>>& scripts, |
| 45 int render_process_id, | 46 int render_process_id, |
| 46 int render_view_id); | 47 int render_view_id); |
| 47 | 48 |
| 48 // Removes script from shared memory region. This may not happen right away if | 49 // Removes script from shared memory region. This may not happen right away if |
| 49 // a script load is in progress. | 50 // a script load is in progress. |
| 50 void RemoveScript(const UserScript& script); | 51 void RemoveScript(const UserScriptIDPair& script); |
| 51 | 52 |
| 52 // Removes a set of scripts from shared memory region. This may not happen | 53 // Removes a set of scripts from shared memory region. This may not happen |
| 53 // right away if a script load is in progress. | 54 // right away if a script load is in progress. |
| 54 void RemoveScripts(const std::set<UserScriptIDPair>& scripts); | 55 void RemoveScripts(const std::set<UserScriptIDPair>& scripts); |
| 55 | 56 |
| 56 // Removes all scripts from shared memory region. This may not happen right | 57 // Removes all scripts from shared memory region. This may not happen right |
| 57 // away if a script load is in progress. | 58 // away if a script load is in progress. |
| 58 void ClearScripts(); | 59 void ClearScripts(); |
| 59 | 60 |
| 60 const HostID& host_id() const { return host_id_; } | 61 const HostID& host_id() const { return host_id_; } |
| 61 | 62 |
| 62 UserScriptLoader* loader() { return loader_.get(); } | 63 UserScriptLoader* loader() { return loader_.get(); } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 // ID of host that owns scripts that this component manages. | 66 // ID of host that owns scripts that this component manages. |
| 66 HostID host_id_; | 67 HostID host_id_; |
| 67 | 68 |
| 68 // Script loader that handles loading contents of scripts into shared memory | 69 // Script loader that handles loading contents of scripts into shared memory |
| 69 // and notifying renderers of script updates. | 70 // and notifying renderers of script updates. |
| 70 std::unique_ptr<UserScriptLoader> loader_; | 71 std::unique_ptr<UserScriptLoader> loader_; |
| 71 | 72 |
| 72 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster); | 73 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 } // namespace extensions | 76 } // namespace extensions |
| 76 | 77 |
| 77 #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ | 78 #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ |
| OLD | NEW |