Index: extensions/browser/user_script_loader.h |
diff --git a/extensions/browser/user_script_loader.h b/extensions/browser/user_script_loader.h |
index c800933cf775d64962eef73abf50b5593788ce83..72b04618054b62e43e4f5694546e5c7b41f4c1e2 100644 |
--- a/extensions/browser/user_script_loader.h |
+++ b/extensions/browser/user_script_loader.h |
@@ -44,33 +44,32 @@ class UserScriptLoader : public content::NotificationObserver { |
using HostsInfo = std::map<HostID, PathAndDefaultLocale>; |
using SubstitutionMap = std::map<std::string, std::string>; |
- using LoadUserScriptsContentFunction = |
- base::Callback<bool(const HostID&, |
- UserScript::File*, |
- const SubstitutionMap*, |
- const scoped_refptr<ContentVerifier>&)>; |
// Parses the includes out of |script| and returns them in |includes|. |
static bool ParseMetadataHeader(const base::StringPiece& script_text, |
UserScript* script); |
UserScriptLoader(content::BrowserContext* browser_context, |
- const HostID& host_id, |
- const scoped_refptr<ContentVerifier>& content_verifier); |
+ const HostID& host_id); |
~UserScriptLoader() override; |
- // A wrapper around the method to load user scripts, which is normally run on |
- // the file thread. Exposed only for tests. |
- void LoadScriptsForTest(UserScriptList* user_scripts); |
- |
// Add |scripts| to the set of scripts managed by this loader. |
void AddScripts(const std::set<UserScript>& scripts); |
+ // Add |scripts| to the set of scripts managed by this loader. |
+ // The fetch of the content of the script starts URL request |
+ // to the associated render specified by |
+ // |render_process_id, render_view_id|. |
+ virtual void AddScripts(const std::set<UserScript>& scripts, |
+ int render_process_id, |
+ int render_view_id); |
+ |
// Remove |scripts| from the set of scripts managed by this loader. |
void RemoveScripts(const std::set<UserScript>& scripts); |
// Clears the set of scripts managed by this loader. |
- void ClearScripts(); |
+ // If |is_clear| is true, will attempt to load scripts. |
+ void ClearScripts(bool is_clear); |
Devlin
2015/04/20 23:48:25
Do we still need this bool?
Xi Han
2015/04/21 21:18:58
Yes, it is also called by DeclarativeUserScriptMas
|
// Initiates procedure to start loading scripts on the file thread. |
void StartLoad(); |
@@ -78,32 +77,29 @@ class UserScriptLoader : public content::NotificationObserver { |
// Returns true if we have any scripts ready. |
bool scripts_ready() const { return shared_memory_.get() != NULL; } |
- protected: |
- // Updates |hosts_info_| to contain info for each element of |
- // |changed_hosts_|. |
- virtual void UpdateHostsInfo(const std::set<HostID>& changed_hosts) = 0; |
- |
- // Returns a function pointer of a static funcion to load user scripts. |
- // Derived classes can specify their ways to load scripts in the static |
- // function they return. |
- // Note: It has to be safe to call multiple times. |
- virtual LoadUserScriptsContentFunction GetLoadUserScriptsFunction() = 0; |
- |
- // Adds the |host_id, location| to the |hosts_info_| map. |
- // Only inserts the entry to the map when the given host_id doesn't |
- // exists. |
- void AddHostInfo(const HostID& host_id, const PathAndDefaultLocale& location); |
+ // Pickle user scripts and return pointer to the shared memory. |
+ static scoped_ptr<base::SharedMemory> Serialize( |
+ const extensions::UserScriptList& scripts); |
- // Removes the entries with the given host_id from the |hosts_info_| map. |
- void RemoveHostInfo(const HostID& host_id); |
+ protected: |
+ // Allows the derived classes have different ways to load user scripts. |
+ virtual void LoadScripts(const std::set<HostID>& changed_hosts, |
+ const std::set<int>& added_script_ids) = 0; |
// Sets the flag if the initial set of hosts has finished loading; if it's |
// set to be true, calls AttempLoad() to bootstrap. |
void SetReady(bool ready); |
+ // Called once we have finished loading the scripts on the file thread. |
+ void OnScriptsLoaded(scoped_ptr<UserScriptList> user_scripts, |
+ scoped_ptr<base::SharedMemory> shared_memory); |
+ |
content::BrowserContext* browser_context() const { return browser_context_; } |
const HostID& host_id() const { return host_id_; } |
+ // List of scripts from currently-installed extensions we should load. |
+ scoped_ptr<UserScriptList> user_scripts_; |
+ |
private: |
// content::NotificationObserver implementation. |
void Observe(int type, |
@@ -118,10 +114,6 @@ class UserScriptLoader : public content::NotificationObserver { |
// Attempts to initiate a load. |
void AttemptLoad(); |
- // Called once we have finished loading the scripts on the file thread. |
- void OnScriptsLoaded(scoped_ptr<UserScriptList> user_scripts, |
- scoped_ptr<base::SharedMemory> shared_memory); |
- |
// Sends the renderer process a new set of user scripts. If |
// |changed_hosts| is not empty, this signals that only the scripts from |
// those hosts should be updated. Otherwise, all hosts will be |
@@ -141,12 +133,6 @@ class UserScriptLoader : public content::NotificationObserver { |
// Contains the scripts that were found the last time scripts were updated. |
scoped_ptr<base::SharedMemory> shared_memory_; |
- // List of scripts from currently-installed extensions we should load. |
- scoped_ptr<UserScriptList> user_scripts_; |
- |
- // Maps host info needed for localization to a host ID. |
- HostsInfo hosts_info_; |
- |
// The mutually-exclusive sets of scripts that were added or removed since the |
// last script load. |
std::set<UserScript> added_scripts_; |
@@ -178,11 +164,6 @@ class UserScriptLoader : public content::NotificationObserver { |
// non-empty value for declarative user script shared memory regions. |
HostID host_id_; |
- // Manages content verification of the loaded user scripts. |
- scoped_refptr<ContentVerifier> content_verifier_; |
- |
- base::WeakPtrFactory<UserScriptLoader> weak_factory_; |
- |
DISALLOW_COPY_AND_ASSIGN(UserScriptLoader); |
}; |