Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/extensions/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); | 388 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| 389 all_extension_views_[render_view_host] = | 389 all_extension_views_[render_view_host] = |
| 390 extensions::GetViewType(web_contents); | 390 extensions::GetViewType(web_contents); |
| 391 | 391 |
| 392 // Keep the lazy background page alive as long as any non-background-page | 392 // Keep the lazy background page alive as long as any non-background-page |
| 393 // extension views are visible. Keepalive count balanced in | 393 // extension views are visible. Keepalive count balanced in |
| 394 // UnregisterRenderViewHost. | 394 // UnregisterRenderViewHost. |
| 395 IncrementLazyKeepaliveCountForView(render_view_host); | 395 IncrementLazyKeepaliveCountForView(render_view_host); |
| 396 } | 396 } |
| 397 | 397 |
| 398 void ExtensionProcessManager::ReregisterRenderViewHosts( | |
| 399 const std::string& extension_id) { | |
| 400 // Re-register all RenderViews for this extension. We do this to restore | |
| 401 // the lazy_keepalive_count (if any) to properly reflect the number of open | |
| 402 // views. | |
| 403 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); | |
| 404 it != all_extension_views_.end(); ++it) { | |
| 405 if (GetExtensionID(it->first) == extension_id) | |
| 406 IncrementLazyKeepaliveCountForView(it->first); | |
| 407 } | |
| 408 } | |
| 409 | |
| 398 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 410 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { |
| 399 return site_instance_->GetRelatedSiteInstance(url); | 411 return site_instance_->GetRelatedSiteInstance(url); |
| 400 } | 412 } |
| 401 | 413 |
| 402 bool ExtensionProcessManager::IsBackgroundHostClosing( | 414 bool ExtensionProcessManager::IsBackgroundHostClosing( |
| 403 const std::string& extension_id) { | 415 const std::string& extension_id) { |
| 404 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 416 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| 405 return (host && background_page_data_[extension_id].is_closing); | 417 return (host && background_page_data_[extension_id].is_closing); |
| 406 } | 418 } |
| 407 | 419 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 } | 596 } |
| 585 | 597 |
| 586 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 598 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 587 Profile* profile = content::Source<Profile>(source).ptr(); | 599 Profile* profile = content::Source<Profile>(source).ptr(); |
| 588 ExtensionService* service = | 600 ExtensionService* service = |
| 589 extensions::ExtensionSystem::Get(profile)->extension_service(); | 601 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 590 if (service->is_ready()) { | 602 if (service->is_ready()) { |
| 591 const Extension* extension = | 603 const Extension* extension = |
| 592 content::Details<const Extension>(details).ptr(); | 604 content::Details<const Extension>(details).ptr(); |
| 593 CreateBackgroundHostForExtensionLoad(this, extension); | 605 CreateBackgroundHostForExtensionLoad(this, extension); |
| 606 | |
| 607 if (extension->is_platform_app() && | |
| 608 service->IsBeingReloaded(extension->id())) | |
| 609 ReregisterRenderViewHosts(extension->id()); | |
|
benwells
2013/09/20 07:35:31
This makes me uncomfortable. The render view hosts
tmdiep
2013/09/20 11:07:36
Incrementing the render view hosts actually preven
benwells
2013/09/20 11:22:47
That was the conclusion I came to today as well. L
| |
| 594 } | 610 } |
| 595 break; | 611 break; |
| 596 } | 612 } |
| 597 | 613 |
| 598 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 614 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 599 const Extension* extension = | 615 const Extension* extension = |
| 600 content::Details<extensions::UnloadedExtensionInfo>( | 616 content::Details<extensions::UnloadedExtensionInfo>( |
| 601 details)->extension; | 617 details)->extension; |
| 602 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 618 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 603 iter != background_hosts_.end(); ++iter) { | 619 iter != background_hosts_.end(); ++iter) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 785 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 770 iter != background_hosts_.end(); ) { | 786 iter != background_hosts_.end(); ) { |
| 771 ExtensionHostSet::iterator current = iter++; | 787 ExtensionHostSet::iterator current = iter++; |
| 772 delete *current; | 788 delete *current; |
| 773 } | 789 } |
| 774 } | 790 } |
| 775 | 791 |
| 776 void ExtensionProcessManager::ClearBackgroundPageData( | 792 void ExtensionProcessManager::ClearBackgroundPageData( |
| 777 const std::string& extension_id) { | 793 const std::string& extension_id) { |
| 778 background_page_data_.erase(extension_id); | 794 background_page_data_.erase(extension_id); |
| 779 | 795 ReregisterRenderViewHosts(extension_id); |
| 780 // Re-register all RenderViews for this extension. We do this to restore | |
| 781 // the lazy_keepalive_count (if any) to properly reflect the number of open | |
| 782 // views. | |
| 783 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); | |
| 784 it != all_extension_views_.end(); ++it) { | |
| 785 if (GetExtensionID(it->first) == extension_id) | |
| 786 IncrementLazyKeepaliveCountForView(it->first); | |
| 787 } | |
| 788 } | 796 } |
| 789 | 797 |
| 790 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { | 798 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { |
| 791 // Don't load background hosts now if the loading should be deferred. | 799 // Don't load background hosts now if the loading should be deferred. |
| 792 if (defer_background_host_creation_) | 800 if (defer_background_host_creation_) |
| 793 return true; | 801 return true; |
| 794 | 802 |
| 795 // The profile may not be valid yet if it is still being initialized. | 803 // The profile may not be valid yet if it is still being initialized. |
| 796 // In that case, defer loading, since it depends on an initialized profile. | 804 // In that case, defer loading, since it depends on an initialized profile. |
| 797 // http://crbug.com/222473 | 805 // http://crbug.com/222473 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 if (service && service->is_ready()) | 917 if (service && service->is_ready()) |
| 910 CreateBackgroundHostsForProfileStartup(); | 918 CreateBackgroundHostsForProfileStartup(); |
| 911 } | 919 } |
| 912 break; | 920 break; |
| 913 } | 921 } |
| 914 default: | 922 default: |
| 915 ExtensionProcessManager::Observe(type, source, details); | 923 ExtensionProcessManager::Observe(type, source, details); |
| 916 break; | 924 break; |
| 917 } | 925 } |
| 918 } | 926 } |
| OLD | NEW |