OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "extensions/browser/extension_user_script_loader.h" | 5 #include "extensions/browser/extension_user_script_loader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <map> |
| 10 #include <memory> |
9 #include <set> | 11 #include <set> |
10 #include <string> | 12 #include <string> |
| 13 #include <utility> |
11 | 14 |
12 #include "base/bind.h" | 15 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
14 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
16 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
17 #include "base/version.h" | 20 #include "base/version.h" |
18 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const ExtensionUserScriptLoader::HostsInfo& hosts_info, | 159 const ExtensionUserScriptLoader::HostsInfo& hosts_info, |
157 const std::set<int>& added_script_ids, | 160 const std::set<int>& added_script_ids, |
158 const scoped_refptr<ContentVerifier>& verifier, | 161 const scoped_refptr<ContentVerifier>& verifier, |
159 UserScriptLoader::LoadScriptsCallback callback) { | 162 UserScriptLoader::LoadScriptsCallback callback) { |
160 DCHECK(user_scripts.get()); | 163 DCHECK(user_scripts.get()); |
161 LoadUserScripts(user_scripts.get(), hosts_info, added_script_ids, verifier); | 164 LoadUserScripts(user_scripts.get(), hosts_info, added_script_ids, verifier); |
162 std::unique_ptr<base::SharedMemory> memory = | 165 std::unique_ptr<base::SharedMemory> memory = |
163 UserScriptLoader::Serialize(*user_scripts); | 166 UserScriptLoader::Serialize(*user_scripts); |
164 content::BrowserThread::PostTask( | 167 content::BrowserThread::PostTask( |
165 content::BrowserThread::UI, FROM_HERE, | 168 content::BrowserThread::UI, FROM_HERE, |
166 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory))); | 169 base::BindOnce(std::move(callback), std::move(user_scripts), |
| 170 std::move(memory))); |
167 } | 171 } |
168 | 172 |
169 } // namespace | 173 } // namespace |
170 | 174 |
171 ExtensionUserScriptLoader::ExtensionUserScriptLoader( | 175 ExtensionUserScriptLoader::ExtensionUserScriptLoader( |
172 BrowserContext* browser_context, | 176 BrowserContext* browser_context, |
173 const HostID& host_id, | 177 const HostID& host_id, |
174 bool listen_for_extension_system_loaded) | 178 bool listen_for_extension_system_loaded) |
175 : UserScriptLoader(browser_context, host_id), | 179 : UserScriptLoader(browser_context, host_id), |
176 content_verifier_( | 180 content_verifier_( |
(...skipping 28 matching lines...) Expand all Loading... |
205 | 209 |
206 void ExtensionUserScriptLoader::LoadScripts( | 210 void ExtensionUserScriptLoader::LoadScripts( |
207 std::unique_ptr<UserScriptList> user_scripts, | 211 std::unique_ptr<UserScriptList> user_scripts, |
208 const std::set<HostID>& changed_hosts, | 212 const std::set<HostID>& changed_hosts, |
209 const std::set<int>& added_script_ids, | 213 const std::set<int>& added_script_ids, |
210 LoadScriptsCallback callback) { | 214 LoadScriptsCallback callback) { |
211 UpdateHostsInfo(changed_hosts); | 215 UpdateHostsInfo(changed_hosts); |
212 | 216 |
213 content::BrowserThread::PostTask( | 217 content::BrowserThread::PostTask( |
214 content::BrowserThread::FILE, FROM_HERE, | 218 content::BrowserThread::FILE, FROM_HERE, |
215 base::Bind(&LoadScriptsOnFileThread, base::Passed(&user_scripts), | 219 base::BindOnce(&LoadScriptsOnFileThread, std::move(user_scripts), |
216 hosts_info_, added_script_ids, content_verifier_, callback)); | 220 hosts_info_, added_script_ids, content_verifier_, |
| 221 std::move(callback))); |
217 } | 222 } |
218 | 223 |
219 void ExtensionUserScriptLoader::UpdateHostsInfo( | 224 void ExtensionUserScriptLoader::UpdateHostsInfo( |
220 const std::set<HostID>& changed_hosts) { | 225 const std::set<HostID>& changed_hosts) { |
221 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); | 226 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); |
222 for (const HostID& host_id : changed_hosts) { | 227 for (const HostID& host_id : changed_hosts) { |
223 const Extension* extension = | 228 const Extension* extension = |
224 registry->GetExtensionById(host_id.id(), ExtensionRegistry::ENABLED); | 229 registry->GetExtensionById(host_id.id(), ExtensionRegistry::ENABLED); |
225 // |changed_hosts_| may include hosts that have been removed, | 230 // |changed_hosts_| may include hosts that have been removed, |
226 // which leads to the above lookup failing. In this case, just continue. | 231 // which leads to the above lookup failing. In this case, just continue. |
(...skipping 11 matching lines...) Expand all Loading... |
238 const Extension* extension, | 243 const Extension* extension, |
239 UnloadedExtensionReason reason) { | 244 UnloadedExtensionReason reason) { |
240 hosts_info_.erase(HostID(HostID::EXTENSIONS, extension->id())); | 245 hosts_info_.erase(HostID(HostID::EXTENSIONS, extension->id())); |
241 } | 246 } |
242 | 247 |
243 void ExtensionUserScriptLoader::OnExtensionSystemReady() { | 248 void ExtensionUserScriptLoader::OnExtensionSystemReady() { |
244 SetReady(true); | 249 SetReady(true); |
245 } | 250 } |
246 | 251 |
247 } // namespace extensions | 252 } // namespace extensions |
OLD | NEW |