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

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: Make tests work 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Gather up all the views for that site. 310 // Gather up all the views for that site.
310 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); 311 for (ExtensionRenderViews::iterator view = all_extension_views_.begin();
311 view != all_extension_views_.end(); ++view) { 312 view != all_extension_views_.end(); ++view) {
312 if (view->first->GetSiteInstance() == site_instance) 313 if (view->first->GetSiteInstance() == site_instance)
313 result.insert(view->first); 314 result.insert(view->first);
314 } 315 }
315 316
316 return result; 317 return result;
317 } 318 }
318 319
320 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost(
321 content::RenderViewHost* render_view_host) {
322 ExtensionService* service =
323 ExtensionSystem::Get(GetProfile())->extension_service();
324 return service->extensions()->GetByID(
325 render_view_host->GetSiteInstance()->GetSite().host());
Charlie Reis 2012/04/23 20:21:49 I think this is correct for extensions. A SiteIns
benwells 2012/04/24 04:31:27 OK, SiteInstance is checked here and in GetExtensi
326 }
327
319 void ExtensionProcessManager::RegisterRenderViewHost( 328 void ExtensionProcessManager::RegisterRenderViewHost(
320 RenderViewHost* render_view_host, 329 RenderViewHost* render_view_host,
321 const Extension* extension) { 330 const Extension* extension) {
322 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID; 331 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID;
323 } 332 }
324 333
325 void ExtensionProcessManager::UnregisterRenderViewHost( 334 void ExtensionProcessManager::UnregisterRenderViewHost(
326 RenderViewHost* render_view_host) { 335 RenderViewHost* render_view_host) {
327 ExtensionRenderViews::iterator view = 336 ExtensionRenderViews::iterator view =
328 all_extension_views_.find(render_view_host); 337 all_extension_views_.find(render_view_host);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 GetExtensionID(render_view_host)); 371 GetExtensionID(render_view_host));
363 if (extension) 372 if (extension)
364 IncrementLazyKeepaliveCount(extension); 373 IncrementLazyKeepaliveCount(extension);
365 } 374 }
366 } 375 }
367 376
368 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { 377 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
369 return site_instance_->GetRelatedSiteInstance(url); 378 return site_instance_->GetRelatedSiteInstance(url);
370 } 379 }
371 380
372 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const {
373 return all_hosts_.find(host) != all_hosts_.end();
374 }
375
376 bool ExtensionProcessManager::IsBackgroundHostClosing( 381 bool ExtensionProcessManager::IsBackgroundHostClosing(
377 const std::string& extension_id) { 382 const std::string& extension_id) {
378 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); 383 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
379 return (host && background_page_data_[extension_id].is_closing); 384 return (host && background_page_data_[extension_id].is_closing);
380 } 385 }
381 386
382 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { 387 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) {
383 if (!extension->has_lazy_background_page()) 388 if (!extension->has_lazy_background_page())
384 return 0; 389 return 0;
385 390
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 CloseBackgroundHost(host); 509 CloseBackgroundHost(host);
505 break; 510 break;
506 } 511 }
507 } 512 }
508 background_page_data_.erase(extension->id()); 513 background_page_data_.erase(extension->id());
509 break; 514 break;
510 } 515 }
511 516
512 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { 517 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
513 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 518 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
514 all_hosts_.erase(host);
515 if (background_hosts_.erase(host)) 519 if (background_hosts_.erase(host))
516 background_page_data_.erase(host->extension()->id()); 520 background_page_data_.erase(host->extension()->id());
521 platform_app_hosts_.erase(host);
517 break; 522 break;
518 } 523 }
519 524
520 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { 525 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: {
521 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 526 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
522 if (host->extension_host_type() == 527 if (host->extension_host_type() ==
523 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 528 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
524 CloseBackgroundHost(host); 529 CloseBackgroundHost(host);
525 } 530 }
526 break; 531 break;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 } 582 }
578 } 583 }
579 584
580 Profile* ExtensionProcessManager::GetProfile() const { 585 Profile* ExtensionProcessManager::GetProfile() const {
581 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); 586 return Profile::FromBrowserContext(site_instance_->GetBrowserContext());
582 } 587 }
583 588
584 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 589 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
585 bool is_background) { 590 bool is_background) {
586 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); 591 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile());
587
588 all_hosts_.insert(host);
589 if (is_background) 592 if (is_background)
590 background_hosts_.insert(host); 593 background_hosts_.insert(host);
594 if (host->extension()->is_platform_app())
595 platform_app_hosts_.insert(host);
591 } 596 }
592 597
593 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { 598 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) {
594 CHECK(host->extension_host_type() == 599 CHECK(host->extension_host_type() ==
595 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 600 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
596 delete host; 601 delete host;
597 // |host| should deregister itself from our structures. 602 // |host| should deregister itself from our structures.
598 CHECK(background_hosts_.find(host) == background_hosts_.end()); 603 CHECK(background_hosts_.find(host) == background_hosts_.end());
599 } 604 }
600 605
(...skipping 13 matching lines...) Expand all
614 Profile* profile) 619 Profile* profile)
615 : ExtensionProcessManager(profile), 620 : ExtensionProcessManager(profile),
616 original_manager_(profile->GetOriginalProfile()-> 621 original_manager_(profile->GetOriginalProfile()->
617 GetExtensionProcessManager()) { 622 GetExtensionProcessManager()) {
618 DCHECK(profile->IsOffTheRecord()); 623 DCHECK(profile->IsOffTheRecord());
619 624
620 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 625 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
621 content::NotificationService::AllSources()); 626 content::NotificationService::AllSources());
622 } 627 }
623 628
629 const ExtensionProcessManager::ViewSet
630 ExtensionProcessManager::GetAllViews() const {
631 ViewSet result;
632 for (ExtensionRenderViews::const_iterator iter =
633 all_extension_views_.begin();
634 iter != all_extension_views_.end(); ++iter) {
635 result.insert(iter->first);
636 }
637 return result;
638 }
639
624 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( 640 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost(
625 const Extension* extension, 641 const Extension* extension,
626 const GURL& url, 642 const GURL& url,
627 Browser* browser, 643 Browser* browser,
628 content::ViewType view_type) { 644 content::ViewType view_type) {
629 if (extension->incognito_split_mode()) { 645 if (extension->incognito_split_mode()) {
630 if (IsIncognitoEnabled(extension)) { 646 if (IsIncognitoEnabled(extension)) {
631 return ExtensionProcessManager::CreateViewHost(extension, url, 647 return ExtensionProcessManager::CreateViewHost(extension, url,
632 browser, view_type); 648 browser, view_type);
633 } else { 649 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (service && service->is_ready()) 706 if (service && service->is_ready())
691 CreateBackgroundHostsForProfileStartup(this, service->extensions()); 707 CreateBackgroundHostsForProfileStartup(this, service->extensions());
692 } 708 }
693 break; 709 break;
694 } 710 }
695 default: 711 default:
696 ExtensionProcessManager::Observe(type, source, details); 712 ExtensionProcessManager::Observe(type, source, details);
697 break; 713 break;
698 } 714 }
699 } 715 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698