Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: extensions/browser/user_script_loader.h

Issue 2228743002: Rework some UserScriptLoader logic in preparation to removing UserScript copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix DCHECK Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_USER_SCRIPT_LOADER_H_ 5 #ifndef EXTENSIONS_BROWSER_USER_SCRIPT_LOADER_H_
6 #define EXTENSIONS_BROWSER_USER_SCRIPT_LOADER_H_ 6 #define EXTENSIONS_BROWSER_USER_SCRIPT_LOADER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Parses the includes out of |script| and returns them in |includes|. 52 // Parses the includes out of |script| and returns them in |includes|.
53 static bool ParseMetadataHeader(const base::StringPiece& script_text, 53 static bool ParseMetadataHeader(const base::StringPiece& script_text,
54 UserScript* script); 54 UserScript* script);
55 55
56 UserScriptLoader(content::BrowserContext* browser_context, 56 UserScriptLoader(content::BrowserContext* browser_context,
57 const HostID& host_id); 57 const HostID& host_id);
58 ~UserScriptLoader() override; 58 ~UserScriptLoader() override;
59 59
60 // Add |scripts| to the set of scripts managed by this loader. 60 // Add |scripts| to the set of scripts managed by this loader.
61 void AddScripts(const std::set<UserScript>& scripts); 61 void AddScripts(const UserScriptList& scripts);
62 62
63 // Add |scripts| to the set of scripts managed by this loader. 63 // Add |scripts| to the set of scripts managed by this loader.
64 // The fetch of the content of the script starts URL request 64 // The fetch of the content of the script starts URL request
65 // to the associated render specified by 65 // to the associated render specified by
66 // |render_process_id, render_view_id|. 66 // |render_process_id, render_view_id|.
67 // TODO(hanxi): The renderer information doesn't really belong in this base 67 // TODO(hanxi): The renderer information doesn't really belong in this base
68 // class, but it's not an easy fix. 68 // class, but it's not an easy fix.
69 virtual void AddScripts(const std::set<UserScript>& scripts, 69 virtual void AddScripts(const UserScriptList& scripts,
70 int render_process_id, 70 int render_process_id,
71 int render_view_id); 71 int render_view_id);
72 72
73 // Remove |scripts| from the set of scripts managed by this loader. 73 // Removes scripts with ids specified in |scripts| from the set of scripts
74 void RemoveScripts(const std::set<UserScript>& scripts); 74 // managed by this loader.
75 // TODO(lazyboy): Likely we can make |scripts| a std::vector, but
76 // WebViewContentScriptManager makes this non-trivial.
77 void RemoveScripts(const std::set<UserScriptIDPair>& scripts);
75 78
76 // Clears the set of scripts managed by this loader. 79 // Clears the set of scripts managed by this loader.
77 void ClearScripts(); 80 void ClearScripts();
78 81
79 // Initiates procedure to start loading scripts on the file thread. 82 // Initiates procedure to start loading scripts on the file thread.
80 void StartLoad(); 83 void StartLoad();
81 84
82 // Returns true if we have any scripts ready. 85 // Returns true if we have any scripts ready.
83 bool scripts_ready() const { return shared_memory_.get() != NULL; } 86 bool scripts_ready() const { return shared_memory_.get() != NULL; }
84 87
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // Sends the renderer process a new set of user scripts. If 128 // Sends the renderer process a new set of user scripts. If
126 // |changed_hosts| is not empty, this signals that only the scripts from 129 // |changed_hosts| is not empty, this signals that only the scripts from
127 // those hosts should be updated. Otherwise, all hosts will be 130 // those hosts should be updated. Otherwise, all hosts will be
128 // updated. 131 // updated.
129 void SendUpdate(content::RenderProcessHost* process, 132 void SendUpdate(content::RenderProcessHost* process,
130 base::SharedMemory* shared_memory, 133 base::SharedMemory* shared_memory,
131 const std::set<HostID>& changed_hosts); 134 const std::set<HostID>& changed_hosts);
132 135
133 bool is_loading() const { 136 bool is_loading() const {
134 // Ownership of |user_scripts_| is passed to the file thread when loading. 137 // Ownership of |user_scripts_| is passed to the file thread when loading.
135 return user_scripts_.get() == NULL; 138 return user_scripts_.get() == nullptr;
136 } 139 }
137 140
138 // Manages our notification registrations. 141 // Manages our notification registrations.
139 content::NotificationRegistrar registrar_; 142 content::NotificationRegistrar registrar_;
140 143
141 // Contains the scripts that were found the last time scripts were updated. 144 // Contains the scripts that were found the last time scripts were updated.
142 std::unique_ptr<base::SharedMemory> shared_memory_; 145 std::unique_ptr<base::SharedMemory> shared_memory_;
143 146
144 // List of scripts from currently-installed extensions we should load. 147 // List of scripts from currently-installed extensions we should load.
145 std::unique_ptr<UserScriptList> user_scripts_; 148 std::unique_ptr<UserScriptList> user_scripts_;
146 149
147 // The mutually-exclusive sets of scripts that were added or removed since the 150 // The mutually-exclusive information about sets of scripts that were added or
148 // last script load. 151 // removed since the last script load. These maps are keyed by script's id.
Devlin 2016/08/11 01:09:27 Nit: "keyed by script ids" maybe?
lazyboy 2016/08/11 01:51:06 Done.
149 std::set<UserScript> added_scripts_; 152 // Note that we only need HostID information for removal.
150 std::set<UserScript> removed_scripts_; 153 std::map<int, UserScript> added_scripts_map_;
154 std::set<UserScriptIDPair> removed_script_hosts_;
151 155
152 // Indicates whether the the collection of scripts should be cleared before 156 // Indicates whether the the collection of scripts should be cleared before
153 // additions and removals on the next script load. 157 // additions and removals on the next script load.
154 bool clear_scripts_; 158 bool clear_scripts_;
155 159
156 // The IDs of the extensions which changed in the last update sent to the 160 // The IDs of the extensions which changed in the last update sent to the
157 // renderer. 161 // renderer.
158 std::set<HostID> changed_hosts_; 162 std::set<HostID> changed_hosts_;
159 163
160 // If the initial set of hosts has finished loading. 164 // If the initial set of hosts has finished loading.
(...skipping 15 matching lines...) Expand all
176 base::ObserverList<Observer> observers_; 180 base::ObserverList<Observer> observers_;
177 181
178 base::WeakPtrFactory<UserScriptLoader> weak_factory_; 182 base::WeakPtrFactory<UserScriptLoader> weak_factory_;
179 183
180 DISALLOW_COPY_AND_ASSIGN(UserScriptLoader); 184 DISALLOW_COPY_AND_ASSIGN(UserScriptLoader);
181 }; 185 };
182 186
183 } // namespace extensions 187 } // namespace extensions
184 188
185 #endif // EXTENSIONS_BROWSER_USER_SCRIPT_LOADER_H_ 189 #endif // EXTENSIONS_BROWSER_USER_SCRIPT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698