OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "chrome/browser/extensions/extension_process_manager.h" | 7 #include "chrome/browser/extensions/extension_process_manager.h" |
8 | 8 |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 void ExtensionProcessManager::RegisterExtensionSiteInstance( | 273 void ExtensionProcessManager::RegisterExtensionSiteInstance( |
274 SiteInstance* site_instance, | 274 SiteInstance* site_instance, |
275 const Extension* extension) { | 275 const Extension* extension) { |
276 if (!site_instance->HasProcess()) { | 276 if (!site_instance->HasProcess()) { |
277 NOTREACHED(); | 277 NOTREACHED(); |
278 return; | 278 return; |
279 } | 279 } |
280 | 280 |
281 int site_instance_id = site_instance->id(); | 281 int site_instance_id = site_instance->id(); |
282 int render_process_id = site_instance->GetProcess()->id(); | 282 int render_process_id = site_instance->GetProcess()->id(); |
283 process_ids_[render_process_id].insert(site_instance_id); | 283 if (process_ids_[render_process_id].insert(site_instance_id).second) { |
284 | 284 // Register process hosting extensions that have access to extension |
285 // Register process hosting extensions that have access to extension bindings | 285 // bindings with the ExtensionInfoMap on the IO thread. |
286 // with the ExtensionInfoMap on the IO thread. | 286 Profile* profile = |
287 Profile* profile = | 287 Profile::FromBrowserContext(browsing_instance_->browser_context()); |
288 Profile::FromBrowserContext(browsing_instance_->browser_context()); | |
289 ExtensionService* service = profile->GetExtensionService(); | |
290 if (service->ExtensionBindingsAllowed(extension->url())) { | |
291 Profile* profile = Profile::FromBrowserContext( | |
292 site_instance->GetProcess()->browser_context()); | |
293 BrowserThread::PostTask( | 288 BrowserThread::PostTask( |
294 BrowserThread::IO, FROM_HERE, | 289 BrowserThread::IO, FROM_HERE, |
295 base::Bind(&ExtensionInfoMap::BindingsEnabledForProcess, | 290 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, |
296 profile->GetExtensionInfoMap(), | 291 profile->GetExtensionInfoMap(), |
292 extension->id(), | |
297 render_process_id)); | 293 render_process_id)); |
298 } | 294 } |
299 | 295 |
300 SiteInstanceIDMap::const_iterator it = extension_ids_.find(site_instance_id); | 296 SiteInstanceIDMap::const_iterator it = extension_ids_.find(site_instance_id); |
301 if (it != extension_ids_.end() && (*it).second == extension->id()) | 297 if (it != extension_ids_.end() && (*it).second == extension->id()) |
302 return; | 298 return; |
303 | 299 |
304 // SiteInstance ids should get removed from the map before the extension ids | 300 // SiteInstance ids should get removed from the map before the extension ids |
305 // get used for a new SiteInstance. | 301 // get used for a new SiteInstance. |
306 DCHECK(it == extension_ids_.end()); | 302 DCHECK(it == extension_ids_.end()); |
307 extension_ids_[site_instance_id] = extension->id(); | 303 extension_ids_[site_instance_id] = extension->id(); |
308 } | 304 } |
309 | 305 |
310 void ExtensionProcessManager::UnregisterExtensionSiteInstance( | 306 void ExtensionProcessManager::UnregisterExtensionSiteInstance( |
311 SiteInstance* site_instance) { | 307 SiteInstance* site_instance) { |
312 int site_instance_id = site_instance->id(); | 308 int site_instance_id = site_instance->id(); |
313 SiteInstanceIDMap::iterator it = extension_ids_.find(site_instance_id); | 309 std::string extension_id = extension_ids_[site_instance_id]; |
314 if (it != extension_ids_.end()) { | 310 if (!extension_id.empty()) |
315 extension_ids_.erase(it++); | 311 extension_ids_.erase(site_instance_id); |
312 | |
313 int render_process_id = GetProcessIDBySiteInstanceID(site_instance_id); | |
314 if (render_process_id == -1) | |
315 return; | |
316 | |
317 ProcessIDMap::iterator iter = process_ids_.find(render_process_id); | |
Matt Perry
2011/10/21 18:28:51
This code might be cleaner if the helper was inste
| |
318 if (iter != process_ids_.end()) { | |
319 SiteInstanceIDSet& site_instance_id_set = iter->second; | |
320 site_instance_id_set.erase(site_instance_id); | |
321 if (site_instance_id_set.empty()) | |
322 process_ids_.erase(iter); | |
316 } | 323 } |
317 if (site_instance->HasProcess()) { | 324 |
318 int render_process_id = site_instance->GetProcess()->id(); | 325 Profile* profile = Profile::FromBrowserContext( |
319 ProcessIDMap::iterator host = process_ids_.find(render_process_id); | 326 site_instance->GetProcess()->browser_context()); |
Matt Perry
2011/10/21 18:28:51
Is GetProcess guaranteed to be non-NULL? The old c
Aaron Boodman
2011/10/22 04:02:42
Done.
| |
320 if (host != process_ids_.end()) { | 327 BrowserThread::PostTask( |
321 host->second.erase(site_instance_id); | 328 BrowserThread::IO, FROM_HERE, |
322 if (host->second.empty()) { | 329 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, |
323 process_ids_.erase(host); | 330 profile->GetExtensionInfoMap(), |
324 Profile* profile = Profile::FromBrowserContext( | 331 extension_id, |
325 site_instance->GetProcess()->browser_context()); | 332 render_process_id)); |
326 BrowserThread::PostTask( | 333 } |
327 BrowserThread::IO, FROM_HERE, | 334 |
328 base::Bind(&ExtensionInfoMap::BindingsDisabledForProcess, | 335 int ExtensionProcessManager::GetProcessIDBySiteInstanceID( |
329 profile->GetExtensionInfoMap(), | 336 int site_instance_id) const { |
330 render_process_id)); | 337 for (ProcessIDMap::const_iterator i = process_ids_.begin(); |
331 } | 338 i != process_ids_.end(); ++i) { |
339 const SiteInstanceIDSet& site_instance_id_set = i->second; | |
340 for (SiteInstanceIDSet::const_iterator j = site_instance_id_set.begin(); | |
341 j != site_instance_id_set.end(); ++j) { | |
342 if (*j == site_instance_id) | |
343 return i->first; | |
332 } | 344 } |
333 } | 345 } |
346 return -1; | |
334 } | 347 } |
335 | 348 |
336 bool ExtensionProcessManager::IsExtensionProcess(int render_process_id) { | 349 bool ExtensionProcessManager::IsExtensionProcess(int render_process_id) { |
337 return process_ids_.find(render_process_id) != process_ids_.end(); | 350 return process_ids_.find(render_process_id) != process_ids_.end(); |
338 } | 351 } |
339 | 352 |
340 bool ExtensionProcessManager::AreBindingsEnabledForProcess( | 353 bool ExtensionProcessManager::AreBindingsEnabledForProcess( |
341 int render_process_id) { | 354 int render_process_id) { |
342 // Must behave logically the same as AreBindingsEnabledForProcess() in | 355 // Must behave logically the same as AreBindingsEnabledForProcess() in |
343 // extension_info_map.cc. | 356 // extension_info_map.cc. |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 if (service && service->is_ready()) | 674 if (service && service->is_ready()) |
662 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 675 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
663 } | 676 } |
664 break; | 677 break; |
665 } | 678 } |
666 default: | 679 default: |
667 ExtensionProcessManager::Observe(type, source, details); | 680 ExtensionProcessManager::Observe(type, source, details); |
668 break; | 681 break; |
669 } | 682 } |
670 } | 683 } |
OLD | NEW |