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

Side by Side Diff: extensions/browser/process_manager.cc

Issue 434593002: Resubmit: Remove deprecated extension notifications from ProcessManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « extensions/browser/process_manager.h ('k') | extensions/browser/process_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 ProcessManager::ProcessManager(BrowserContext* context, 239 ProcessManager::ProcessManager(BrowserContext* context,
240 BrowserContext* original_context, 240 BrowserContext* original_context,
241 ExtensionRegistry* extension_registry) 241 ExtensionRegistry* extension_registry)
242 : site_instance_(SiteInstance::Create(context)), 242 : site_instance_(SiteInstance::Create(context)),
243 extension_registry_(extension_registry), 243 extension_registry_(extension_registry),
244 startup_background_hosts_created_(false), 244 startup_background_hosts_created_(false),
245 devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged, 245 devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged,
246 base::Unretained(this))), 246 base::Unretained(this))),
247 last_background_close_sequence_id_(0), 247 last_background_close_sequence_id_(0),
248 weak_ptr_factory_(this) { 248 weak_ptr_factory_(this),
249 extension_registry_observer_(this) {
249 // ExtensionRegistry is shared between incognito and regular contexts. 250 // ExtensionRegistry is shared between incognito and regular contexts.
250 DCHECK_EQ(original_context, extension_registry_->browser_context()); 251 DCHECK_EQ(original_context, extension_registry_->browser_context());
251 registrar_.Add(this, 252 registrar_.Add(this,
252 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 253 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
253 content::Source<BrowserContext>(original_context)); 254 content::Source<BrowserContext>(original_context));
254 registrar_.Add(this, 255 registrar_.Add(this,
255 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
256 content::Source<BrowserContext>(original_context));
257 registrar_.Add(this,
258 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
259 content::Source<BrowserContext>(original_context));
260 registrar_.Add(this,
261 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 256 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
262 content::Source<BrowserContext>(context)); 257 content::Source<BrowserContext>(context));
263 registrar_.Add(this, 258 registrar_.Add(this,
264 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 259 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
265 content::Source<BrowserContext>(context)); 260 content::Source<BrowserContext>(context));
266 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 261 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
267 content::NotificationService::AllSources()); 262 content::NotificationService::AllSources());
268 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 263 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
269 content::NotificationService::AllSources()); 264 content::NotificationService::AllSources());
265 extension_registry_observer_.Add(extension_registry_);
270 266
271 // Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than 267 // Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than
272 // kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals. 268 // kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals.
273 event_page_idle_time_ = base::TimeDelta::FromSeconds(10); 269 event_page_idle_time_ = base::TimeDelta::FromSeconds(10);
274 unsigned idle_time_msec = 0; 270 unsigned idle_time_msec = 0;
275 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 271 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
276 extensions::switches::kEventPageIdleTime), &idle_time_msec)) { 272 extensions::switches::kEventPageIdleTime), &idle_time_msec)) {
277 CHECK_GT(idle_time_msec, 0u); // OnKeepaliveImpulseCheck requires non zero. 273 CHECK_GT(idle_time_msec, 0u); // OnKeepaliveImpulseCheck requires non zero.
278 event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec); 274 event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec);
279 } 275 }
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 const content::NotificationSource& source, 653 const content::NotificationSource& source,
658 const content::NotificationDetails& details) { 654 const content::NotificationDetails& details) {
659 switch (type) { 655 switch (type) {
660 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: { 656 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: {
661 // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead 657 // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead
662 // of a notification. 658 // of a notification.
663 MaybeCreateStartupBackgroundHosts(); 659 MaybeCreateStartupBackgroundHosts();
664 break; 660 break;
665 } 661 }
666 662
667 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
668 BrowserContext* context = content::Source<BrowserContext>(source).ptr();
669 ExtensionSystem* system = ExtensionSystem::Get(context);
670 if (system->ready().is_signaled()) {
671 // The extension system is ready, so create the background host.
672 const Extension* extension =
673 content::Details<const Extension>(details).ptr();
674 CreateBackgroundHostForExtensionLoad(this, extension);
675 }
676 break;
677 }
678
679 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
680 const Extension* extension =
681 content::Details<UnloadedExtensionInfo>(details)->extension;
682 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
683 iter != background_hosts_.end(); ++iter) {
684 ExtensionHost* host = *iter;
685 if (host->extension_id() == extension->id()) {
686 CloseBackgroundHost(host);
687 break;
688 }
689 }
690 UnregisterExtension(extension->id());
691 break;
692 }
693
694 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { 663 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
695 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 664 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
696 if (background_hosts_.erase(host)) { 665 if (background_hosts_.erase(host)) {
697 ClearBackgroundPageData(host->extension()->id()); 666 ClearBackgroundPageData(host->extension()->id());
698 background_page_data_[host->extension()->id()].since_suspended.reset( 667 background_page_data_[host->extension()->id()].since_suspended.reset(
699 new base::ElapsedTimer()); 668 new base::ElapsedTimer());
700 } 669 }
701 break; 670 break;
702 } 671 }
703 672
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 content::Source<BrowserContext>(GetBrowserContext()), 718 content::Source<BrowserContext>(GetBrowserContext()),
750 content::Details<RenderViewHost>(contents->GetRenderViewHost())); 719 content::Details<RenderViewHost>(contents->GetRenderViewHost()));
751 break; 720 break;
752 } 721 }
753 722
754 default: 723 default:
755 NOTREACHED(); 724 NOTREACHED();
756 } 725 }
757 } 726 }
758 727
728 void ProcessManager::OnExtensionLoaded(content::BrowserContext* browser_context,
729 const Extension* extension) {
730 if (ExtensionSystem::Get(browser_context)->ready().is_signaled()) {
731 // The extension system is ready, so create the background host.
732 CreateBackgroundHostForExtensionLoad(this, extension);
733 }
734 }
735
736 void ProcessManager::OnExtensionUnloaded(
737 content::BrowserContext* browser_context,
738 const Extension* extension,
739 UnloadedExtensionInfo::Reason reason) {
740 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
741 iter != background_hosts_.end();
742 ++iter) {
743 ExtensionHost* host = *iter;
744 if (host->extension_id() == extension->id()) {
745 CloseBackgroundHost(host);
746 break;
747 }
748 }
749 UnregisterExtension(extension->id());
750 }
751
759 void ProcessManager::OnDevToolsStateChanged( 752 void ProcessManager::OnDevToolsStateChanged(
760 content::DevToolsAgentHost* agent_host, 753 content::DevToolsAgentHost* agent_host,
761 bool attached) { 754 bool attached) {
762 RenderViewHost* rvh = agent_host->GetRenderViewHost(); 755 RenderViewHost* rvh = agent_host->GetRenderViewHost();
763 // Ignore unrelated notifications. 756 // Ignore unrelated notifications.
764 if (!rvh || 757 if (!rvh ||
765 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != 758 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() !=
766 GetBrowserContext()) 759 GetBrowserContext())
767 return; 760 return;
768 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != 761 if (GetViewType(WebContents::FromRenderViewHost(rvh)) !=
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { 916 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) {
924 const Extension* extension = 917 const Extension* extension =
925 extension_registry_->enabled_extensions().GetExtensionOrAppByURL(url); 918 extension_registry_->enabled_extensions().GetExtensionOrAppByURL(url);
926 if (extension && !IncognitoInfo::IsSplitMode(extension)) 919 if (extension && !IncognitoInfo::IsSplitMode(extension))
927 return original_manager_->GetSiteInstanceForURL(url); 920 return original_manager_->GetSiteInstanceForURL(url);
928 921
929 return ProcessManager::GetSiteInstanceForURL(url); 922 return ProcessManager::GetSiteInstanceForURL(url);
930 } 923 }
931 924
932 } // namespace extensions 925 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/process_manager.h ('k') | extensions/browser/process_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698