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

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

Issue 443623002: Revert of 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) {
250 // ExtensionRegistry is shared between incognito and regular contexts. 249 // ExtensionRegistry is shared between incognito and regular contexts.
251 DCHECK_EQ(original_context, extension_registry_->browser_context()); 250 DCHECK_EQ(original_context, extension_registry_->browser_context());
252 registrar_.Add(this, 251 registrar_.Add(this,
253 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 252 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
254 content::Source<BrowserContext>(original_context)); 253 content::Source<BrowserContext>(original_context));
255 registrar_.Add(this, 254 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,
256 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 261 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
257 content::Source<BrowserContext>(context)); 262 content::Source<BrowserContext>(context));
258 registrar_.Add(this, 263 registrar_.Add(this,
259 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 264 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
260 content::Source<BrowserContext>(context)); 265 content::Source<BrowserContext>(context));
261 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 266 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
262 content::NotificationService::AllSources()); 267 content::NotificationService::AllSources());
263 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 268 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
264 content::NotificationService::AllSources()); 269 content::NotificationService::AllSources());
265 extension_registry_observer_.Add(extension_registry_);
266 270
267 // Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than 271 // Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than
268 // kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals. 272 // kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals.
269 event_page_idle_time_ = base::TimeDelta::FromSeconds(10); 273 event_page_idle_time_ = base::TimeDelta::FromSeconds(10);
270 unsigned idle_time_msec = 0; 274 unsigned idle_time_msec = 0;
271 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 275 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
272 extensions::switches::kEventPageIdleTime), &idle_time_msec)) { 276 extensions::switches::kEventPageIdleTime), &idle_time_msec)) {
273 CHECK_GT(idle_time_msec, 0u); // OnKeepaliveImpulseCheck requires non zero. 277 CHECK_GT(idle_time_msec, 0u); // OnKeepaliveImpulseCheck requires non zero.
274 event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec); 278 event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec);
275 } 279 }
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 const content::NotificationSource& source, 657 const content::NotificationSource& source,
654 const content::NotificationDetails& details) { 658 const content::NotificationDetails& details) {
655 switch (type) { 659 switch (type) {
656 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: { 660 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: {
657 // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead 661 // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead
658 // of a notification. 662 // of a notification.
659 MaybeCreateStartupBackgroundHosts(); 663 MaybeCreateStartupBackgroundHosts();
660 break; 664 break;
661 } 665 }
662 666
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
663 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { 694 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
664 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 695 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
665 if (background_hosts_.erase(host)) { 696 if (background_hosts_.erase(host)) {
666 ClearBackgroundPageData(host->extension()->id()); 697 ClearBackgroundPageData(host->extension()->id());
667 background_page_data_[host->extension()->id()].since_suspended.reset( 698 background_page_data_[host->extension()->id()].since_suspended.reset(
668 new base::ElapsedTimer()); 699 new base::ElapsedTimer());
669 } 700 }
670 break; 701 break;
671 } 702 }
672 703
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 content::Source<BrowserContext>(GetBrowserContext()), 749 content::Source<BrowserContext>(GetBrowserContext()),
719 content::Details<RenderViewHost>(contents->GetRenderViewHost())); 750 content::Details<RenderViewHost>(contents->GetRenderViewHost()));
720 break; 751 break;
721 } 752 }
722 753
723 default: 754 default:
724 NOTREACHED(); 755 NOTREACHED();
725 } 756 }
726 } 757 }
727 758
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
752 void ProcessManager::OnDevToolsStateChanged( 759 void ProcessManager::OnDevToolsStateChanged(
753 content::DevToolsAgentHost* agent_host, 760 content::DevToolsAgentHost* agent_host,
754 bool attached) { 761 bool attached) {
755 RenderViewHost* rvh = agent_host->GetRenderViewHost(); 762 RenderViewHost* rvh = agent_host->GetRenderViewHost();
756 // Ignore unrelated notifications. 763 // Ignore unrelated notifications.
757 if (!rvh || 764 if (!rvh ||
758 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != 765 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() !=
759 GetBrowserContext()) 766 GetBrowserContext())
760 return; 767 return;
761 if (GetViewType(WebContents::FromRenderViewHost(rvh)) != 768 if (GetViewType(WebContents::FromRenderViewHost(rvh)) !=
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { 923 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) {
917 const Extension* extension = 924 const Extension* extension =
918 extension_registry_->enabled_extensions().GetExtensionOrAppByURL(url); 925 extension_registry_->enabled_extensions().GetExtensionOrAppByURL(url);
919 if (extension && !IncognitoInfo::IsSplitMode(extension)) 926 if (extension && !IncognitoInfo::IsSplitMode(extension))
920 return original_manager_->GetSiteInstanceForURL(url); 927 return original_manager_->GetSiteInstanceForURL(url);
921 928
922 return ProcessManager::GetSiteInstanceForURL(url); 929 return ProcessManager::GetSiteInstanceForURL(url);
923 } 930 }
924 931
925 } // namespace extensions 932 } // 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