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

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

Issue 381283002: Refactor code that defers extension background page loading (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: larger DeferLoadingBackgroundHosts Created 6 years, 5 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 | Annotate | Revision Log
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 220 }
221 221
222 ProcessManager::ProcessManager(BrowserContext* context, 222 ProcessManager::ProcessManager(BrowserContext* context,
223 BrowserContext* original_context) 223 BrowserContext* original_context)
224 : site_instance_(SiteInstance::Create(context)), 224 : site_instance_(SiteInstance::Create(context)),
225 startup_background_hosts_created_(false), 225 startup_background_hosts_created_(false),
226 devtools_callback_(base::Bind( 226 devtools_callback_(base::Bind(
227 &ProcessManager::OnDevToolsStateChanged, 227 &ProcessManager::OnDevToolsStateChanged,
228 base::Unretained(this))), 228 base::Unretained(this))),
229 weak_ptr_factory_(this) { 229 weak_ptr_factory_(this) {
230 LOG(ERROR) << "JAMES new ProcessManager";
230 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 231 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
231 content::Source<BrowserContext>(original_context)); 232 content::Source<BrowserContext>(original_context));
232 registrar_.Add(this, 233 registrar_.Add(this,
233 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 234 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
234 content::Source<BrowserContext>(original_context)); 235 content::Source<BrowserContext>(original_context));
235 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 236 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
236 content::Source<BrowserContext>(original_context)); 237 content::Source<BrowserContext>(original_context));
237 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 238 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
238 content::Source<BrowserContext>(context)); 239 content::Source<BrowserContext>(context));
239 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 240 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // This increment / decrement is to simulate an instantaneous event. This 609 // This increment / decrement is to simulate an instantaneous event. This
609 // has the effect of invalidating close_sequence_id, preventing any in 610 // has the effect of invalidating close_sequence_id, preventing any in
610 // progress closes from completing and starting a new close process if 611 // progress closes from completing and starting a new close process if
611 // necessary. 612 // necessary.
612 IncrementLazyKeepaliveCount(extension); 613 IncrementLazyKeepaliveCount(extension);
613 DecrementLazyKeepaliveCount(extension); 614 DecrementLazyKeepaliveCount(extension);
614 } 615 }
615 } 616 }
616 617
617 void ProcessManager::OnBrowserWindowReady() { 618 void ProcessManager::OnBrowserWindowReady() {
619 LOG(ERROR) << "JAMES OnBrowserWindowReady";
618 // If the extension system isn't ready yet the background hosts will be 620 // If the extension system isn't ready yet the background hosts will be
619 // created via NOTIFICATION_EXTENSIONS_READY below. 621 // created via NOTIFICATION_EXTENSIONS_READY below.
620 ExtensionSystem* system = ExtensionSystem::Get(GetBrowserContext()); 622 ExtensionSystem* system = ExtensionSystem::Get(GetBrowserContext());
621 if (!system->ready().is_signaled()) 623 if (!system->ready().is_signaled())
622 return; 624 return;
623 625
624 CreateBackgroundHostsForProfileStartup(); 626 MaybeCreateBackgroundHostsForStartup();
625 } 627 }
626 628
627 content::BrowserContext* ProcessManager::GetBrowserContext() const { 629 content::BrowserContext* ProcessManager::GetBrowserContext() const {
628 return site_instance_->GetBrowserContext(); 630 return site_instance_->GetBrowserContext();
629 } 631 }
630 632
631 void ProcessManager::SetKeepaliveImpulseCallbackForTesting( 633 void ProcessManager::SetKeepaliveImpulseCallbackForTesting(
632 const ImpulseCallbackForTesting& callback) { 634 const ImpulseCallbackForTesting& callback) {
633 keepalive_impulse_callback_for_testing_ = callback; 635 keepalive_impulse_callback_for_testing_ = callback;
634 } 636 }
635 637
636 void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting( 638 void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting(
637 const ImpulseCallbackForTesting& callback) { 639 const ImpulseCallbackForTesting& callback) {
638 keepalive_impulse_decrement_callback_for_testing_ = callback; 640 keepalive_impulse_decrement_callback_for_testing_ = callback;
639 } 641 }
640 642
641 void ProcessManager::Observe(int type, 643 void ProcessManager::Observe(int type,
642 const content::NotificationSource& source, 644 const content::NotificationSource& source,
643 const content::NotificationDetails& details) { 645 const content::NotificationDetails& details) {
644 switch (type) { 646 switch (type) {
645 case chrome::NOTIFICATION_EXTENSIONS_READY: 647 case chrome::NOTIFICATION_EXTENSIONS_READY:
646 case chrome::NOTIFICATION_PROFILE_CREATED: { 648 case chrome::NOTIFICATION_PROFILE_CREATED: {
647 // Don't load background hosts now if the loading should be deferred. 649 if (type == chrome::NOTIFICATION_EXTENSIONS_READY)
648 // Instead they will be loaded when a browser window for this profile 650 LOG(ERROR) << "JAMES got extensions_ready";
649 // (or an incognito profile from this profile) is ready. 651 else
650 if (DeferLoadingBackgroundHosts()) 652 LOG(ERROR) << "JAMES got profile_created";
651 break;
652 653
653 CreateBackgroundHostsForProfileStartup(); 654 MaybeCreateBackgroundHostsForStartup();
654 break; 655 break;
655 } 656 }
656 657
657 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { 658 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
658 BrowserContext* context = content::Source<BrowserContext>(source).ptr(); 659 BrowserContext* context = content::Source<BrowserContext>(source).ptr();
659 ExtensionSystem* system = ExtensionSystem::Get(context); 660 ExtensionSystem* system = ExtensionSystem::Get(context);
660 if (system->ready().is_signaled()) { 661 if (system->ready().is_signaled()) {
661 // The extension system is ready, so create the background host. 662 // The extension system is ready, so create the background host.
662 const Extension* extension = 663 const Extension* extension =
663 content::Details<const Extension>(details).ptr(); 664 content::Details<const Extension>(details).ptr();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // RegisterRenderViewHost is called too early (before the process is 736 // RegisterRenderViewHost is called too early (before the process is
736 // available), so we need to wait until now to notify. 737 // available), so we need to wait until now to notify.
737 content::NotificationService::current()->Notify( 738 content::NotificationService::current()->Notify(
738 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, 739 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED,
739 content::Source<BrowserContext>(GetBrowserContext()), 740 content::Source<BrowserContext>(GetBrowserContext()),
740 content::Details<RenderViewHost>(contents->GetRenderViewHost())); 741 content::Details<RenderViewHost>(contents->GetRenderViewHost()));
741 break; 742 break;
742 } 743 }
743 744
744 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 745 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
746 LOG(ERROR) << "JAMES got profile_destroyed";
745 // Close background hosts when the last browser is closed so that they 747 // Close background hosts when the last browser is closed so that they
746 // have time to shutdown various objects on different threads. Our 748 // have time to shutdown various objects on different threads. Our
747 // destructor is called too late in the shutdown sequence. 749 // destructor is called too late in the shutdown sequence.
748 CloseBackgroundHosts(); 750 CloseBackgroundHosts();
749 break; 751 break;
750 } 752 }
751 753
752 default: 754 default:
753 NOTREACHED(); 755 NOTREACHED();
754 } 756 }
(...skipping 16 matching lines...) Expand all
771 return; 773 return;
772 if (attached) { 774 if (attached) {
773 // Keep the lazy background page alive while it's being inspected. 775 // Keep the lazy background page alive while it's being inspected.
774 CancelSuspend(extension); 776 CancelSuspend(extension);
775 IncrementLazyKeepaliveCount(extension); 777 IncrementLazyKeepaliveCount(extension);
776 } else { 778 } else {
777 DecrementLazyKeepaliveCount(extension); 779 DecrementLazyKeepaliveCount(extension);
778 } 780 }
779 } 781 }
780 782
781 void ProcessManager::CreateBackgroundHostsForProfileStartup() { 783 void ProcessManager::MaybeCreateBackgroundHostsForStartup() {
782 if (startup_background_hosts_created_ || 784 if (startup_background_hosts_created_)
783 !ExtensionsBrowserClient::Get()->
784 IsBackgroundPageAllowed(GetBrowserContext())) {
785 return; 785 return;
786 } 786
787 // The embedder might want to defer background page loading. For example,
788 // Chrome defers background page loading when it is launched to show the app
789 // list, then triggers a load later via OnBrowserWindowReady().
790 if (ExtensionsBrowserClient::Get()->DeferLoadingBackgroundHosts(
791 GetBrowserContext()))
792 return;
787 793
788 const ExtensionSet& enabled_extensions = 794 const ExtensionSet& enabled_extensions =
789 ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions(); 795 ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions();
790 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); 796 for (ExtensionSet::const_iterator extension = enabled_extensions.begin();
791 extension != enabled_extensions.end(); 797 extension != enabled_extensions.end();
792 ++extension) { 798 ++extension) {
793 CreateBackgroundHostForExtensionLoad(this, extension->get()); 799 CreateBackgroundHostForExtensionLoad(this, extension->get());
794 800
795 FOR_EACH_OBSERVER(ProcessManagerObserver, 801 FOR_EACH_OBSERVER(ProcessManagerObserver,
796 observer_list_, 802 observer_list_,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698