| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/process_manager.h" | 5 #include "extensions/browser/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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 incognito_context, original_context, original_manager); | 222 incognito_context, original_context, original_manager); |
| 223 } | 223 } |
| 224 | 224 |
| 225 ProcessManager::ProcessManager(BrowserContext* context, | 225 ProcessManager::ProcessManager(BrowserContext* context, |
| 226 BrowserContext* original_context) | 226 BrowserContext* original_context) |
| 227 : site_instance_(SiteInstance::Create(context)), | 227 : site_instance_(SiteInstance::Create(context)), |
| 228 startup_background_hosts_created_(false), | 228 startup_background_hosts_created_(false), |
| 229 devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged, | 229 devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged, |
| 230 base::Unretained(this))), | 230 base::Unretained(this))), |
| 231 last_background_close_sequence_id_(0), | 231 last_background_close_sequence_id_(0), |
| 232 weak_ptr_factory_(this) { | 232 weak_ptr_factory_(this), |
| 233 extension_registry_observer_(this) { |
| 234 extension_registry_observer_.Add(ExtensionRegistry::Get(original_context)); |
| 233 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 235 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 234 content::Source<BrowserContext>(original_context)); | 236 content::Source<BrowserContext>(original_context)); |
| 235 registrar_.Add(this, | |
| 236 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
| 237 content::Source<BrowserContext>(original_context)); | |
| 238 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 239 content::Source<BrowserContext>(original_context)); | |
| 240 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 237 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 241 content::Source<BrowserContext>(context)); | 238 content::Source<BrowserContext>(context)); |
| 242 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 239 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 243 content::Source<BrowserContext>(context)); | 240 content::Source<BrowserContext>(context)); |
| 244 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 241 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 245 content::NotificationService::AllSources()); | 242 content::NotificationService::AllSources()); |
| 246 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 243 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 247 content::NotificationService::AllSources()); | 244 content::NotificationService::AllSources()); |
| 248 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 245 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| 249 content::Source<BrowserContext>(original_context)); | 246 content::Source<BrowserContext>(original_context)); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 // Don't load background hosts now if the loading should be deferred. | 650 // Don't load background hosts now if the loading should be deferred. |
| 654 // Instead they will be loaded when a browser window for this profile | 651 // Instead they will be loaded when a browser window for this profile |
| 655 // (or an incognito profile from this profile) is ready. | 652 // (or an incognito profile from this profile) is ready. |
| 656 if (DeferLoadingBackgroundHosts()) | 653 if (DeferLoadingBackgroundHosts()) |
| 657 break; | 654 break; |
| 658 | 655 |
| 659 CreateBackgroundHostsForProfileStartup(); | 656 CreateBackgroundHostsForProfileStartup(); |
| 660 break; | 657 break; |
| 661 } | 658 } |
| 662 | 659 |
| 663 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | |
| 664 BrowserContext* context = content::Source<BrowserContext>(source).ptr(); | |
| 665 ExtensionSystem* system = ExtensionSystem::Get(context); | |
| 666 if (system->ready().is_signaled()) { | |
| 667 // The extension system is ready, so create the background host. | |
| 668 const Extension* extension = | |
| 669 content::Details<const Extension>(details).ptr(); | |
| 670 CreateBackgroundHostForExtensionLoad(this, extension); | |
| 671 } | |
| 672 break; | |
| 673 } | |
| 674 | |
| 675 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | |
| 676 const Extension* extension = | |
| 677 content::Details<UnloadedExtensionInfo>(details)->extension; | |
| 678 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | |
| 679 iter != background_hosts_.end(); ++iter) { | |
| 680 ExtensionHost* host = *iter; | |
| 681 if (host->extension_id() == extension->id()) { | |
| 682 CloseBackgroundHost(host); | |
| 683 break; | |
| 684 } | |
| 685 } | |
| 686 UnregisterExtension(extension->id()); | |
| 687 break; | |
| 688 } | |
| 689 | |
| 690 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 660 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 691 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 661 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 692 if (background_hosts_.erase(host)) { | 662 if (background_hosts_.erase(host)) { |
| 693 ClearBackgroundPageData(host->extension()->id()); | 663 ClearBackgroundPageData(host->extension()->id()); |
| 694 background_page_data_[host->extension()->id()].since_suspended.reset( | 664 background_page_data_[host->extension()->id()].since_suspended.reset( |
| 695 new base::ElapsedTimer()); | 665 new base::ElapsedTimer()); |
| 696 } | 666 } |
| 697 break; | 667 break; |
| 698 } | 668 } |
| 699 | 669 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 // destructor is called too late in the shutdown sequence. | 723 // destructor is called too late in the shutdown sequence. |
| 754 CloseBackgroundHosts(); | 724 CloseBackgroundHosts(); |
| 755 break; | 725 break; |
| 756 } | 726 } |
| 757 | 727 |
| 758 default: | 728 default: |
| 759 NOTREACHED(); | 729 NOTREACHED(); |
| 760 } | 730 } |
| 761 } | 731 } |
| 762 | 732 |
| 733 void ProcessManager::OnExtensionLoaded(content::BrowserContext* browser_context, |
| 734 const Extension* extension) { |
| 735 if (ExtensionSystem::Get(browser_context)->ready().is_signaled()) { |
| 736 // The extension system is ready, so create the background host. |
| 737 CreateBackgroundHostForExtensionLoad(this, extension); |
| 738 } |
| 739 } |
| 740 |
| 741 void ProcessManager::OnExtensionUnloaded( |
| 742 content::BrowserContext* browser_context, |
| 743 const Extension* extension, |
| 744 UnloadedExtensionInfo::Reason reason) { |
| 745 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 746 iter != background_hosts_.end(); |
| 747 ++iter) { |
| 748 ExtensionHost* host = *iter; |
| 749 if (host->extension_id() == extension->id()) { |
| 750 CloseBackgroundHost(host); |
| 751 break; |
| 752 } |
| 753 } |
| 754 UnregisterExtension(extension->id()); |
| 755 } |
| 756 |
| 763 void ProcessManager::OnDevToolsStateChanged( | 757 void ProcessManager::OnDevToolsStateChanged( |
| 764 content::DevToolsAgentHost* agent_host, | 758 content::DevToolsAgentHost* agent_host, |
| 765 bool attached) { | 759 bool attached) { |
| 766 RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 760 RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
| 767 // Ignore unrelated notifications. | 761 // Ignore unrelated notifications. |
| 768 if (!rvh || | 762 if (!rvh || |
| 769 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != | 763 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != |
| 770 GetBrowserContext()) | 764 GetBrowserContext()) |
| 771 return; | 765 return; |
| 772 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != | 766 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 const Extension* extension = | 931 const Extension* extension = |
| 938 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 932 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
| 939 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 933 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
| 940 return original_manager_->GetSiteInstanceForURL(url); | 934 return original_manager_->GetSiteInstanceForURL(url); |
| 941 } | 935 } |
| 942 } | 936 } |
| 943 return ProcessManager::GetSiteInstanceForURL(url); | 937 return ProcessManager::GetSiteInstanceForURL(url); |
| 944 } | 938 } |
| 945 | 939 |
| 946 } // namespace extensions | 940 } // namespace extensions |
| OLD | NEW |