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

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 8361021: Track all extension processes in ExtensionInfoMap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: argh Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
316 } 312
317 if (site_instance->HasProcess()) { 313 int render_process_id = ClearSiteInstanceID(site_instance_id);
318 int render_process_id = site_instance->GetProcess()->id(); 314 if (render_process_id == -1)
319 ProcessIDMap::iterator host = process_ids_.find(render_process_id); 315 return;
320 if (host != process_ids_.end()) { 316
321 host->second.erase(site_instance_id); 317 Profile* profile = Profile::FromBrowserContext(
322 if (host->second.empty()) { 318 browsing_instance_->browser_context());
323 process_ids_.erase(host); 319 BrowserThread::PostTask(
324 Profile* profile = Profile::FromBrowserContext( 320 BrowserThread::IO, FROM_HERE,
325 site_instance->GetProcess()->browser_context()); 321 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
326 BrowserThread::PostTask( 322 profile->GetExtensionInfoMap(),
327 BrowserThread::IO, FROM_HERE, 323 extension_id,
328 base::Bind(&ExtensionInfoMap::BindingsDisabledForProcess, 324 render_process_id));
329 profile->GetExtensionInfoMap(), 325 }
330 render_process_id)); 326
327 int ExtensionProcessManager::ClearSiteInstanceID(int site_instance_id) {
328 for (ProcessIDMap::iterator i = process_ids_.begin();
329 i != process_ids_.end(); ++i) {
330 SiteInstanceIDSet& site_instance_id_set = i->second;
331 for (SiteInstanceIDSet::iterator j = site_instance_id_set.begin();
332 j != site_instance_id_set.end(); ++j) {
333 if (*j == site_instance_id) {
334 int render_process_id = i->first;
335 site_instance_id_set.erase(j);
336 if (site_instance_id_set.empty())
337 process_ids_.erase(i);
338 return render_process_id;
331 } 339 }
332 } 340 }
333 } 341 }
342 return -1;
334 } 343 }
335 344
336 bool ExtensionProcessManager::IsExtensionProcess(int render_process_id) { 345 bool ExtensionProcessManager::IsExtensionProcess(int render_process_id) {
337 return process_ids_.find(render_process_id) != process_ids_.end(); 346 return process_ids_.find(render_process_id) != process_ids_.end();
338 } 347 }
339 348
340 bool ExtensionProcessManager::AreBindingsEnabledForProcess( 349 bool ExtensionProcessManager::AreBindingsEnabledForProcess(
341 int render_process_id) { 350 int render_process_id) {
342 // Must behave logically the same as AreBindingsEnabledForProcess() in 351 // Must behave logically the same as AreBindingsEnabledForProcess() in
343 // extension_info_map.cc. 352 // extension_info_map.cc.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 if (service && service->is_ready()) 670 if (service && service->is_ready())
662 CreateBackgroundHostsForProfileStartup(this, service->extensions()); 671 CreateBackgroundHostsForProfileStartup(this, service->extensions());
663 } 672 }
664 break; 673 break;
665 } 674 }
666 default: 675 default:
667 ExtensionProcessManager::Observe(type, source, details); 676 ExtensionProcessManager::Observe(type, source, details);
668 break; 677 break;
669 } 678 }
670 } 679 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698