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

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

Issue 10116017: Remove EPM::all_hosts_ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup 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 | Annotate | Revision Log
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());
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 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { 381 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) {
377 if (!extension->has_lazy_background_page()) 382 if (!extension->has_lazy_background_page())
378 return 0; 383 return 0;
379 384
380 return background_page_data_[extension->id()].lazy_keepalive_count; 385 return background_page_data_[extension->id()].lazy_keepalive_count;
381 } 386 }
382 387
383 int ExtensionProcessManager::IncrementLazyKeepaliveCount( 388 int ExtensionProcessManager::IncrementLazyKeepaliveCount(
384 const Extension* extension) { 389 const Extension* extension) {
385 if (!extension->has_lazy_background_page()) 390 if (!extension->has_lazy_background_page())
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 CloseBackgroundHost(host); 508 CloseBackgroundHost(host);
504 break; 509 break;
505 } 510 }
506 } 511 }
507 background_page_data_.erase(extension->id()); 512 background_page_data_.erase(extension->id());
508 break; 513 break;
509 } 514 }
510 515
511 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { 516 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
512 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 517 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
513 all_hosts_.erase(host);
514 if (background_hosts_.erase(host)) 518 if (background_hosts_.erase(host))
515 background_page_data_.erase(host->extension()->id()); 519 background_page_data_.erase(host->extension()->id());
516 break; 520 break;
517 } 521 }
518 522
519 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { 523 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: {
520 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 524 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
521 if (host->extension_host_type() == 525 if (host->extension_host_type() ==
522 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 526 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
523 CloseBackgroundHost(host); 527 CloseBackgroundHost(host);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } 580 }
577 } 581 }
578 582
579 Profile* ExtensionProcessManager::GetProfile() const { 583 Profile* ExtensionProcessManager::GetProfile() const {
580 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); 584 return Profile::FromBrowserContext(site_instance_->GetBrowserContext());
581 } 585 }
582 586
583 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 587 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
584 bool is_background) { 588 bool is_background) {
585 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); 589 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile());
586
587 all_hosts_.insert(host);
588 if (is_background) 590 if (is_background)
589 background_hosts_.insert(host); 591 background_hosts_.insert(host);
590 } 592 }
591 593
592 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { 594 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) {
593 CHECK(host->extension_host_type() == 595 CHECK(host->extension_host_type() ==
594 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 596 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
595 delete host; 597 delete host;
596 // |host| should deregister itself from our structures. 598 // |host| should deregister itself from our structures.
597 CHECK(background_hosts_.find(host) == background_hosts_.end()); 599 CHECK(background_hosts_.find(host) == background_hosts_.end());
(...skipping 15 matching lines...) Expand all
613 Profile* profile) 615 Profile* profile)
614 : ExtensionProcessManager(profile), 616 : ExtensionProcessManager(profile),
615 original_manager_(profile->GetOriginalProfile()-> 617 original_manager_(profile->GetOriginalProfile()->
616 GetExtensionProcessManager()) { 618 GetExtensionProcessManager()) {
617 DCHECK(profile->IsOffTheRecord()); 619 DCHECK(profile->IsOffTheRecord());
618 620
619 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 621 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
620 content::NotificationService::AllSources()); 622 content::NotificationService::AllSources());
621 } 623 }
622 624
625 const ExtensionProcessManager::ViewSet
626 ExtensionProcessManager::GetAllViews() const {
627 ViewSet result;
628 for (ExtensionRenderViews::const_iterator iter = all_extension_views_.begin();
629 iter != all_extension_views_.end(); ++iter) {
630 result.insert(iter->first);
631 }
632 return result;
633 }
634
623 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( 635 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost(
624 const Extension* extension, 636 const Extension* extension,
625 const GURL& url, 637 const GURL& url,
626 Browser* browser, 638 Browser* browser,
627 content::ViewType view_type) { 639 content::ViewType view_type) {
628 if (extension->incognito_split_mode()) { 640 if (extension->incognito_split_mode()) {
629 if (IsIncognitoEnabled(extension)) { 641 if (IsIncognitoEnabled(extension)) {
630 return ExtensionProcessManager::CreateViewHost(extension, url, 642 return ExtensionProcessManager::CreateViewHost(extension, url,
631 browser, view_type); 643 browser, view_type);
632 } else { 644 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 if (service && service->is_ready()) 701 if (service && service->is_ready())
690 CreateBackgroundHostsForProfileStartup(this, service->extensions()); 702 CreateBackgroundHostsForProfileStartup(this, service->extensions());
691 } 703 }
692 break; 704 break;
693 } 705 }
694 default: 706 default:
695 ExtensionProcessManager::Observe(type, source, details); 707 ExtensionProcessManager::Observe(type, source, details);
696 break; 708 break;
697 } 709 }
698 } 710 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698