Chromium Code Reviews| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 incognito_context, original_context, original_manager); | 223 incognito_context, original_context, original_manager); |
| 224 } | 224 } |
| 225 | 225 |
| 226 ProcessManager::ProcessManager(BrowserContext* context, | 226 ProcessManager::ProcessManager(BrowserContext* context, |
| 227 BrowserContext* original_context) | 227 BrowserContext* original_context) |
| 228 : site_instance_(SiteInstance::Create(context)), | 228 : site_instance_(SiteInstance::Create(context)), |
| 229 startup_background_hosts_created_(false), | 229 startup_background_hosts_created_(false), |
| 230 devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged, | 230 devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged, |
| 231 base::Unretained(this))), | 231 base::Unretained(this))), |
| 232 last_background_close_sequence_id_(0), | 232 last_background_close_sequence_id_(0), |
| 233 weak_ptr_factory_(this) { | 233 weak_ptr_factory_(this), |
| 234 extension_registry_observer_(this) { | |
| 235 extension_registry_observer_.Add(ExtensionRegistry::Get(original_context)); | |
| 234 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 236 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 235 content::Source<BrowserContext>(original_context)); | 237 content::Source<BrowserContext>(original_context)); |
| 236 registrar_.Add(this, | |
| 237 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
| 238 content::Source<BrowserContext>(original_context)); | |
| 239 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 240 content::Source<BrowserContext>(original_context)); | |
| 241 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 238 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 242 content::Source<BrowserContext>(context)); | 239 content::Source<BrowserContext>(context)); |
| 243 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 240 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 244 content::Source<BrowserContext>(context)); | 241 content::Source<BrowserContext>(context)); |
| 245 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 242 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 246 content::NotificationService::AllSources()); | 243 content::NotificationService::AllSources()); |
| 247 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 244 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 248 content::NotificationService::AllSources()); | 245 content::NotificationService::AllSources()); |
| 249 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 246 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 250 content::Source<BrowserContext>(context)); | 247 content::Source<BrowserContext>(context)); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 const content::NotificationSource& source, | 637 const content::NotificationSource& source, |
| 641 const content::NotificationDetails& details) { | 638 const content::NotificationDetails& details) { |
| 642 switch (type) { | 639 switch (type) { |
| 643 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 640 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
| 644 // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead | 641 // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead |
| 645 // of a notification. | 642 // of a notification. |
| 646 MaybeCreateStartupBackgroundHosts(); | 643 MaybeCreateStartupBackgroundHosts(); |
| 647 break; | 644 break; |
| 648 } | 645 } |
| 649 | 646 |
| 650 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | |
| 651 BrowserContext* context = content::Source<BrowserContext>(source).ptr(); | |
| 652 ExtensionSystem* system = ExtensionSystem::Get(context); | |
| 653 if (system->ready().is_signaled()) { | |
| 654 // The extension system is ready, so create the background host. | |
| 655 const Extension* extension = | |
| 656 content::Details<const Extension>(details).ptr(); | |
| 657 CreateBackgroundHostForExtensionLoad(this, extension); | |
| 658 } | |
| 659 break; | |
| 660 } | |
| 661 | |
| 662 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | |
| 663 const Extension* extension = | |
| 664 content::Details<UnloadedExtensionInfo>(details)->extension; | |
| 665 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | |
| 666 iter != background_hosts_.end(); ++iter) { | |
| 667 ExtensionHost* host = *iter; | |
| 668 if (host->extension_id() == extension->id()) { | |
| 669 CloseBackgroundHost(host); | |
| 670 break; | |
| 671 } | |
| 672 } | |
| 673 UnregisterExtension(extension->id()); | |
| 674 break; | |
| 675 } | |
| 676 | |
| 677 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 647 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 678 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 648 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 679 if (background_hosts_.erase(host)) { | 649 if (background_hosts_.erase(host)) { |
| 680 ClearBackgroundPageData(host->extension()->id()); | 650 ClearBackgroundPageData(host->extension()->id()); |
| 681 background_page_data_[host->extension()->id()].since_suspended.reset( | 651 background_page_data_[host->extension()->id()].since_suspended.reset( |
| 682 new base::ElapsedTimer()); | 652 new base::ElapsedTimer()); |
| 683 } | 653 } |
| 684 break; | 654 break; |
| 685 } | 655 } |
| 686 | 656 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 // destructor is called too late in the shutdown sequence. | 710 // destructor is called too late in the shutdown sequence. |
| 741 CloseBackgroundHosts(); | 711 CloseBackgroundHosts(); |
| 742 break; | 712 break; |
| 743 } | 713 } |
| 744 | 714 |
| 745 default: | 715 default: |
| 746 NOTREACHED(); | 716 NOTREACHED(); |
| 747 } | 717 } |
| 748 } | 718 } |
| 749 | 719 |
| 720 void ProcessManager::OnExtensionLoaded(content::BrowserContext* browser_context, | |
| 721 const Extension* extension) { | |
| 722 ExtensionSystem* system = ExtensionSystem::Get(browser_context); | |
| 723 if (system->ready().is_signaled()) { | |
|
Devlin
2014/07/17 20:13:11
Let's go ahead and inline system here:
if (Extensi
limasdf
2014/07/20 05:24:28
Done.
| |
| 724 // The extension system is ready, so create the background host. | |
| 725 CreateBackgroundHostForExtensionLoad(this, extension); | |
| 726 } | |
| 727 } | |
| 728 | |
| 729 void ProcessManager::OnExtensionUnloaded( | |
| 730 content::BrowserContext* browser_context, | |
| 731 const Extension* extension, | |
| 732 UnloadedExtensionInfo::Reason reason) { | |
| 733 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | |
| 734 iter != background_hosts_.end(); | |
| 735 ++iter) { | |
| 736 ExtensionHost* host = *iter; | |
| 737 if (host->extension_id() == extension->id()) { | |
| 738 CloseBackgroundHost(host); | |
| 739 break; | |
| 740 } | |
| 741 } | |
| 742 UnregisterExtension(extension->id()); | |
| 743 } | |
| 744 | |
| 750 void ProcessManager::OnDevToolsStateChanged( | 745 void ProcessManager::OnDevToolsStateChanged( |
| 751 content::DevToolsAgentHost* agent_host, | 746 content::DevToolsAgentHost* agent_host, |
| 752 bool attached) { | 747 bool attached) { |
| 753 RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 748 RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
| 754 // Ignore unrelated notifications. | 749 // Ignore unrelated notifications. |
| 755 if (!rvh || | 750 if (!rvh || |
| 756 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != | 751 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != |
| 757 GetBrowserContext()) | 752 GetBrowserContext()) |
| 758 return; | 753 return; |
| 759 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != | 754 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 const Extension* extension = | 918 const Extension* extension = |
| 924 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 919 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
| 925 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 920 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
| 926 return original_manager_->GetSiteInstanceForURL(url); | 921 return original_manager_->GetSiteInstanceForURL(url); |
| 927 } | 922 } |
| 928 } | 923 } |
| 929 return ProcessManager::GetSiteInstanceForURL(url); | 924 return ProcessManager::GetSiteInstanceForURL(url); |
| 930 } | 925 } |
| 931 | 926 |
| 932 } // namespace extensions | 927 } // namespace extensions |
| OLD | NEW |