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

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

Issue 10113005: Remove EPM:all_hosts_ and use all_extension_views_ instead. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comments addressed Created 8 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/extension_event_router.h" 8 #include "chrome/browser/extensions/extension_event_router.h"
9 #include "chrome/browser/extensions/extension_process_manager.h" 9 #include "chrome/browser/extensions/extension_process_manager.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
11 #include "chrome/browser/extensions/extension_info_map.h" 11 #include "chrome/browser/extensions/extension_info_map.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/chrome_view_type.h" 19 #include "chrome/common/chrome_view_type.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_messages.h" 21 #include "chrome/common/extensions/extension_messages.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
(...skipping 13 matching lines...) Expand all
36 using content::OpenURLParams; 37 using content::OpenURLParams;
37 using content::Referrer; 38 using content::Referrer;
38 using content::RenderViewHost; 39 using content::RenderViewHost;
39 using content::SiteInstance; 40 using content::SiteInstance;
40 41
41 namespace { 42 namespace {
42 43
43 std::string GetExtensionID(RenderViewHost* render_view_host) { 44 std::string GetExtensionID(RenderViewHost* render_view_host) {
44 // This works for both apps and extensions because the site has been 45 // This works for both apps and extensions because the site has been
45 // normalized to the extension URL for apps. 46 // normalized to the extension URL for apps.
47 if (!render_view_host->GetSiteInstance())
48 return "";
49
46 return render_view_host->GetSiteInstance()->GetSite().host(); 50 return render_view_host->GetSiteInstance()->GetSite().host();
47 } 51 }
48 52
49 // Incognito profiles use this process manager. It is mostly a shim that decides 53 // Incognito profiles use this process manager. It is mostly a shim that decides
50 // whether to fall back on the original profile's ExtensionProcessManager based 54 // whether to fall back on the original profile's ExtensionProcessManager based
51 // on whether a given extension uses "split" or "spanning" incognito behavior. 55 // on whether a given extension uses "split" or "spanning" incognito behavior.
52 class IncognitoExtensionProcessManager : public ExtensionProcessManager { 56 class IncognitoExtensionProcessManager : public ExtensionProcessManager {
53 public: 57 public:
54 explicit IncognitoExtensionProcessManager(Profile* profile); 58 explicit IncognitoExtensionProcessManager(Profile* profile);
55 virtual ~IncognitoExtensionProcessManager() {} 59 virtual ~IncognitoExtensionProcessManager() {}
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Gather up all the views for that site. 313 // Gather up all the views for that site.
310 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); 314 for (ExtensionRenderViews::iterator view = all_extension_views_.begin();
311 view != all_extension_views_.end(); ++view) { 315 view != all_extension_views_.end(); ++view) {
312 if (view->first->GetSiteInstance() == site_instance) 316 if (view->first->GetSiteInstance() == site_instance)
313 result.insert(view->first); 317 result.insert(view->first);
314 } 318 }
315 319
316 return result; 320 return result;
317 } 321 }
318 322
323 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost(
324 content::RenderViewHost* render_view_host) {
325 if (!render_view_host->GetSiteInstance())
326 return NULL;
327
328 ExtensionService* service =
329 ExtensionSystem::Get(GetProfile())->extension_service();
330 return service->extensions()->GetByID(
331 render_view_host->GetSiteInstance()->GetSite().host());
332 }
333
319 void ExtensionProcessManager::RegisterRenderViewHost( 334 void ExtensionProcessManager::RegisterRenderViewHost(
320 RenderViewHost* render_view_host, 335 RenderViewHost* render_view_host,
321 const Extension* extension) { 336 const Extension* extension) {
322 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID; 337 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID;
323 } 338 }
324 339
325 void ExtensionProcessManager::UnregisterRenderViewHost( 340 void ExtensionProcessManager::UnregisterRenderViewHost(
326 RenderViewHost* render_view_host) { 341 RenderViewHost* render_view_host) {
327 ExtensionRenderViews::iterator view = 342 ExtensionRenderViews::iterator view =
328 all_extension_views_.find(render_view_host); 343 all_extension_views_.find(render_view_host);
329 if (view == all_extension_views_.end()) 344 if (view == all_extension_views_.end())
330 return; 345 return;
331 346
332 content::ViewType view_type = view->second; 347 content::ViewType view_type = view->second;
333 all_extension_views_.erase(view); 348 all_extension_views_.erase(view);
334 349
335 // Keepalive count, balanced in UpdateRegisteredRenderView. 350 // Keepalive count, balanced in UpdateRegisteredRenderView.
336 if (view_type != content::VIEW_TYPE_INVALID && 351 if (view_type != content::VIEW_TYPE_INVALID &&
337 view_type != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 352 view_type != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
338 const Extension* extension = 353 const Extension* extension = GetExtensionForRenderViewHost(
339 GetProfile()->GetExtensionService()->extensions()->GetByID( 354 render_view_host);
340 GetExtensionID(render_view_host));
341 if (extension) 355 if (extension)
342 DecrementLazyKeepaliveCount(extension); 356 DecrementLazyKeepaliveCount(extension);
343 } 357 }
344 } 358 }
345 359
346 void ExtensionProcessManager::UpdateRegisteredRenderView( 360 void ExtensionProcessManager::UpdateRegisteredRenderView(
347 RenderViewHost* render_view_host) { 361 RenderViewHost* render_view_host) {
348 ExtensionRenderViews::iterator view = 362 ExtensionRenderViews::iterator view =
349 all_extension_views_.find(render_view_host); 363 all_extension_views_.find(render_view_host);
350 if (view == all_extension_views_.end()) 364 if (view == all_extension_views_.end())
351 return; 365 return;
352 366
353 view->second = render_view_host->GetDelegate()->GetRenderViewType(); 367 view->second = render_view_host->GetDelegate()->GetRenderViewType();
354 368
355 // Keep the lazy background page alive as long as any non-background-page 369 // Keep the lazy background page alive as long as any non-background-page
356 // extension views are visible. Keepalive count balanced in 370 // extension views are visible. Keepalive count balanced in
357 // UnregisterRenderViewHost. 371 // UnregisterRenderViewHost.
358 if (view->second != content::VIEW_TYPE_INVALID && 372 if (view->second != content::VIEW_TYPE_INVALID &&
359 view->second != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 373 view->second != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
360 const Extension* extension = 374 const Extension* extension = GetExtensionForRenderViewHost(
361 GetProfile()->GetExtensionService()->extensions()->GetByID( 375 render_view_host);
362 GetExtensionID(render_view_host));
363 if (extension) 376 if (extension)
364 IncrementLazyKeepaliveCount(extension); 377 IncrementLazyKeepaliveCount(extension);
365 } 378 }
366 } 379 }
367 380
368 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { 381 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
369 return site_instance_->GetRelatedSiteInstance(url); 382 return site_instance_->GetRelatedSiteInstance(url);
370 } 383 }
371 384
372 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const {
373 return all_hosts_.find(host) != all_hosts_.end();
374 }
375
376 bool ExtensionProcessManager::IsBackgroundHostClosing( 385 bool ExtensionProcessManager::IsBackgroundHostClosing(
377 const std::string& extension_id) { 386 const std::string& extension_id) {
378 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); 387 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
379 return (host && background_page_data_[extension_id].is_closing); 388 return (host && background_page_data_[extension_id].is_closing);
380 } 389 }
381 390
382 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { 391 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) {
383 if (!extension->has_lazy_background_page()) 392 if (!extension->has_lazy_background_page())
384 return 0; 393 return 0;
385 394
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 CloseBackgroundHost(host); 508 CloseBackgroundHost(host);
500 break; 509 break;
501 } 510 }
502 } 511 }
503 background_page_data_.erase(extension->id()); 512 background_page_data_.erase(extension->id());
504 break; 513 break;
505 } 514 }
506 515
507 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { 516 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
508 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 517 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
509 all_hosts_.erase(host);
510 if (background_hosts_.erase(host)) 518 if (background_hosts_.erase(host))
511 background_page_data_.erase(host->extension()->id()); 519 background_page_data_.erase(host->extension()->id());
520 platform_app_hosts_.erase(host);
512 break; 521 break;
513 } 522 }
514 523
515 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { 524 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: {
516 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 525 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
517 if (host->extension_host_type() == 526 if (host->extension_host_type() ==
518 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 527 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
519 CloseBackgroundHost(host); 528 CloseBackgroundHost(host);
520 } 529 }
521 break; 530 break;
(...skipping 14 matching lines...) Expand all
536 break; 545 break;
537 } 546 }
538 547
539 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: { 548 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: {
540 RenderViewHost* render_view_host = 549 RenderViewHost* render_view_host =
541 content::Details<RenderViewHost>(details).ptr(); 550 content::Details<RenderViewHost>(details).ptr();
542 // Keep the lazy background page alive while it's being inspected. 551 // Keep the lazy background page alive while it's being inspected.
543 // Balanced in response to the CLOSING notification. 552 // Balanced in response to the CLOSING notification.
544 if (render_view_host->GetDelegate()->GetRenderViewType() == 553 if (render_view_host->GetDelegate()->GetRenderViewType() ==
545 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 554 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
546 const Extension* extension = 555 const Extension* extension = GetExtensionForRenderViewHost(
Aaron Boodman 2012/04/25 21:27:06 Thanks for cleaning all these up!
547 GetProfile()->GetExtensionService()->extensions()->GetByID( 556 render_view_host);
548 GetExtensionID(render_view_host));
549 if (extension) 557 if (extension)
550 IncrementLazyKeepaliveCount(extension); 558 IncrementLazyKeepaliveCount(extension);
551 } 559 }
552 break; 560 break;
553 } 561 }
554 562
555 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: { 563 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: {
556 RenderViewHost* render_view_host = 564 RenderViewHost* render_view_host =
557 content::Details<RenderViewHost>(details).ptr(); 565 content::Details<RenderViewHost>(details).ptr();
558 // Balanced in response to the OPENING notification. 566 // Balanced in response to the OPENING notification.
559 if (render_view_host->GetDelegate()->GetRenderViewType() == 567 if (render_view_host->GetDelegate()->GetRenderViewType() ==
560 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 568 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
561 const Extension* extension = 569 const Extension* extension = GetExtensionForRenderViewHost(
562 GetProfile()->GetExtensionService()->extensions()->GetByID( 570 render_view_host);
563 GetExtensionID(render_view_host));
564 if (extension) 571 if (extension)
565 DecrementLazyKeepaliveCount(extension); 572 DecrementLazyKeepaliveCount(extension);
566 } 573 }
567 break; 574 break;
568 } 575 }
569 576
570 default: 577 default:
571 NOTREACHED(); 578 NOTREACHED();
572 } 579 }
573 } 580 }
574 581
575 Profile* ExtensionProcessManager::GetProfile() const { 582 Profile* ExtensionProcessManager::GetProfile() const {
576 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); 583 return Profile::FromBrowserContext(site_instance_->GetBrowserContext());
577 } 584 }
578 585
579 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 586 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
580 bool is_background) { 587 bool is_background) {
581 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); 588 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile());
582
583 all_hosts_.insert(host);
584 if (is_background) 589 if (is_background)
585 background_hosts_.insert(host); 590 background_hosts_.insert(host);
591 if (host->extension()->is_platform_app())
592 platform_app_hosts_.insert(host);
586 } 593 }
587 594
588 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { 595 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) {
589 CHECK(host->extension_host_type() == 596 CHECK(host->extension_host_type() ==
590 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 597 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
591 delete host; 598 delete host;
592 // |host| should deregister itself from our structures. 599 // |host| should deregister itself from our structures.
593 CHECK(background_hosts_.find(host) == background_hosts_.end()); 600 CHECK(background_hosts_.find(host) == background_hosts_.end());
594 } 601 }
595 602
(...skipping 13 matching lines...) Expand all
609 Profile* profile) 616 Profile* profile)
610 : ExtensionProcessManager(profile), 617 : ExtensionProcessManager(profile),
611 original_manager_(profile->GetOriginalProfile()-> 618 original_manager_(profile->GetOriginalProfile()->
612 GetExtensionProcessManager()) { 619 GetExtensionProcessManager()) {
613 DCHECK(profile->IsOffTheRecord()); 620 DCHECK(profile->IsOffTheRecord());
614 621
615 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 622 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
616 content::NotificationService::AllSources()); 623 content::NotificationService::AllSources());
617 } 624 }
618 625
626 const ExtensionProcessManager::ViewSet
627 ExtensionProcessManager::GetAllViews() const {
628 ViewSet result;
629 for (ExtensionRenderViews::const_iterator iter =
630 all_extension_views_.begin();
631 iter != all_extension_views_.end(); ++iter) {
632 result.insert(iter->first);
633 }
634 return result;
635 }
636
619 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( 637 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost(
620 const Extension* extension, 638 const Extension* extension,
621 const GURL& url, 639 const GURL& url,
622 Browser* browser, 640 Browser* browser,
623 content::ViewType view_type) { 641 content::ViewType view_type) {
624 if (extension->incognito_split_mode()) { 642 if (extension->incognito_split_mode()) {
625 if (IsIncognitoEnabled(extension)) { 643 if (IsIncognitoEnabled(extension)) {
626 return ExtensionProcessManager::CreateViewHost(extension, url, 644 return ExtensionProcessManager::CreateViewHost(extension, url,
627 browser, view_type); 645 browser, view_type);
628 } else { 646 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (service && service->is_ready()) 703 if (service && service->is_ready())
686 CreateBackgroundHostsForProfileStartup(this, service->extensions()); 704 CreateBackgroundHostsForProfileStartup(this, service->extensions());
687 } 705 }
688 break; 706 break;
689 } 707 }
690 default: 708 default:
691 ExtensionProcessManager::Observe(type, source, details); 709 ExtensionProcessManager::Observe(type, source, details);
692 break; 710 break;
693 } 711 }
694 } 712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698