| 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)); | |
| 235 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 233 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 236 content::Source<BrowserContext>(original_context)); | 234 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)); |
| 237 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 240 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 238 content::Source<BrowserContext>(context)); | 241 content::Source<BrowserContext>(context)); |
| 239 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 242 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 240 content::Source<BrowserContext>(context)); | 243 content::Source<BrowserContext>(context)); |
| 241 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 244 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 242 content::NotificationService::AllSources()); | 245 content::NotificationService::AllSources()); |
| 243 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 246 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 244 content::NotificationService::AllSources()); | 247 content::NotificationService::AllSources()); |
| 245 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 248 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| 246 content::Source<BrowserContext>(original_context)); | 249 content::Source<BrowserContext>(original_context)); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 // Don't load background hosts now if the loading should be deferred. | 653 // Don't load background hosts now if the loading should be deferred. |
| 651 // Instead they will be loaded when a browser window for this profile | 654 // Instead they will be loaded when a browser window for this profile |
| 652 // (or an incognito profile from this profile) is ready. | 655 // (or an incognito profile from this profile) is ready. |
| 653 if (DeferLoadingBackgroundHosts()) | 656 if (DeferLoadingBackgroundHosts()) |
| 654 break; | 657 break; |
| 655 | 658 |
| 656 CreateBackgroundHostsForProfileStartup(); | 659 CreateBackgroundHostsForProfileStartup(); |
| 657 break; | 660 break; |
| 658 } | 661 } |
| 659 | 662 |
| 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 |
| 660 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 690 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 661 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 691 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 662 if (background_hosts_.erase(host)) { | 692 if (background_hosts_.erase(host)) { |
| 663 ClearBackgroundPageData(host->extension()->id()); | 693 ClearBackgroundPageData(host->extension()->id()); |
| 664 background_page_data_[host->extension()->id()].since_suspended.reset( | 694 background_page_data_[host->extension()->id()].since_suspended.reset( |
| 665 new base::ElapsedTimer()); | 695 new base::ElapsedTimer()); |
| 666 } | 696 } |
| 667 break; | 697 break; |
| 668 } | 698 } |
| 669 | 699 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 // destructor is called too late in the shutdown sequence. | 753 // destructor is called too late in the shutdown sequence. |
| 724 CloseBackgroundHosts(); | 754 CloseBackgroundHosts(); |
| 725 break; | 755 break; |
| 726 } | 756 } |
| 727 | 757 |
| 728 default: | 758 default: |
| 729 NOTREACHED(); | 759 NOTREACHED(); |
| 730 } | 760 } |
| 731 } | 761 } |
| 732 | 762 |
| 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 | |
| 757 void ProcessManager::OnDevToolsStateChanged( | 763 void ProcessManager::OnDevToolsStateChanged( |
| 758 content::DevToolsAgentHost* agent_host, | 764 content::DevToolsAgentHost* agent_host, |
| 759 bool attached) { | 765 bool attached) { |
| 760 RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 766 RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
| 761 // Ignore unrelated notifications. | 767 // Ignore unrelated notifications. |
| 762 if (!rvh || | 768 if (!rvh || |
| 763 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != | 769 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != |
| 764 GetBrowserContext()) | 770 GetBrowserContext()) |
| 765 return; | 771 return; |
| 766 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != | 772 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 const Extension* extension = | 937 const Extension* extension = |
| 932 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 938 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
| 933 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 939 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
| 934 return original_manager_->GetSiteInstanceForURL(url); | 940 return original_manager_->GetSiteInstanceForURL(url); |
| 935 } | 941 } |
| 936 } | 942 } |
| 937 return ProcessManager::GetSiteInstanceForURL(url); | 943 return ProcessManager::GetSiteInstanceForURL(url); |
| 938 } | 944 } |
| 939 | 945 |
| 940 } // namespace extensions | 946 } // namespace extensions |
| OLD | NEW |