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

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 23618014: This defers starting background extension page RenderViews (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged logic into DeferLoadingBackgroundHosts Created 7 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_process_manager.h" 5 #include "chrome/browser/extensions/extension_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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // static 131 // static
132 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { 132 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) {
133 return (profile->IsOffTheRecord()) ? 133 return (profile->IsOffTheRecord()) ?
134 new IncognitoExtensionProcessManager(profile) : 134 new IncognitoExtensionProcessManager(profile) :
135 new ExtensionProcessManager(profile); 135 new ExtensionProcessManager(profile);
136 } 136 }
137 137
138 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) 138 ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
139 : site_instance_(SiteInstance::Create(profile)), 139 : site_instance_(SiteInstance::Create(profile)),
140 defer_background_host_creation_(false),
140 weak_ptr_factory_(this), 141 weak_ptr_factory_(this),
141 devtools_callback_(base::Bind( 142 devtools_callback_(base::Bind(
142 &ExtensionProcessManager::OnDevToolsStateChanged, 143 &ExtensionProcessManager::OnDevToolsStateChanged,
143 base::Unretained(this))) { 144 base::Unretained(this))) {
144 Profile* original_profile = profile->GetOriginalProfile(); 145 Profile* original_profile = profile->GetOriginalProfile();
145 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 146 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
146 content::NotificationService::AllSources()); 147 content::NotificationService::AllSources());
147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 148 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
148 content::Source<Profile>(original_profile)); 149 content::Source<Profile>(original_profile));
149 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 150 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 new ExtensionMsg_CancelSuspend(extension->id())); 538 new ExtensionMsg_CancelSuspend(extension->id()));
538 // This increment / decrement is to simulate an instantaneous event. This 539 // This increment / decrement is to simulate an instantaneous event. This
539 // has the effect of invalidating close_sequence_id, preventing any in 540 // has the effect of invalidating close_sequence_id, preventing any in
540 // progress closes from completing and starting a new close process if 541 // progress closes from completing and starting a new close process if
541 // necessary. 542 // necessary.
542 IncrementLazyKeepaliveCount(extension); 543 IncrementLazyKeepaliveCount(extension);
543 DecrementLazyKeepaliveCount(extension); 544 DecrementLazyKeepaliveCount(extension);
544 } 545 }
545 } 546 }
546 547
548 void ExtensionProcessManager::DeferBackgroundHostCreation(bool defer) {
549 bool previous = defer_background_host_creation_;
550 defer_background_host_creation_ = defer;
551
552 // If we were deferred, and we switch to non-deferred, then create the
553 // background hosts.
554 if (previous && !defer_background_host_creation_)
555 CreateBackgroundHostsForProfileStartup();
556 }
557
547 void ExtensionProcessManager::Observe( 558 void ExtensionProcessManager::Observe(
548 int type, 559 int type,
549 const content::NotificationSource& source, 560 const content::NotificationSource& source,
550 const content::NotificationDetails& details) { 561 const content::NotificationDetails& details) {
551 switch (type) { 562 switch (type) {
552 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { 563 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
553 // If a window for this profile, or this profile's incognito profile, 564 // If a window for this profile, or this profile's incognito profile,
554 // has been opened, make sure this profile's background hosts have 565 // has been opened, make sure this profile's background hosts have
555 // been loaded. 566 // been loaded.
556 Browser* browser = content::Source<Browser>(source).ptr(); 567 Browser* browser = content::Source<Browser>(source).ptr();
557 if (browser->profile() != GetProfile() && 568 if (browser->profile() != GetProfile() &&
558 !(GetProfile()->HasOffTheRecordProfile() && 569 !(GetProfile()->HasOffTheRecordProfile() &&
559 browser->profile() == GetProfile()->GetOffTheRecordProfile())) 570 browser->profile() == GetProfile()->GetOffTheRecordProfile()))
560 break; 571 break;
561 572
562 ExtensionService* service = GetProfile()->GetExtensionService(); 573 ExtensionService* service = GetProfile()->GetExtensionService();
563 if (!service || !service->is_ready()) 574 if (!service || !service->is_ready())
564 break; 575 break;
565 576
566 CreateBackgroundHostsForProfileStartup(); 577 CreateBackgroundHostsForProfileStartup();
567 break; 578 break;
568 } 579 }
569 case chrome::NOTIFICATION_EXTENSIONS_READY: 580 case chrome::NOTIFICATION_EXTENSIONS_READY:
570 case chrome::NOTIFICATION_PROFILE_CREATED: { 581 case chrome::NOTIFICATION_PROFILE_CREATED: {
571 // Don't load background hosts now if the loading should be deferred.
572 // Instead they will be loaded when a browser window for this profile
573 // (or an incognito profile from this profile) is ready.
574 if (DeferLoadingBackgroundHosts())
575 break;
576
577 CreateBackgroundHostsForProfileStartup(); 582 CreateBackgroundHostsForProfileStartup();
578 break; 583 break;
579 } 584 }
580 585
581 case chrome::NOTIFICATION_EXTENSION_LOADED: { 586 case chrome::NOTIFICATION_EXTENSION_LOADED: {
582 Profile* profile = content::Source<Profile>(source).ptr(); 587 Profile* profile = content::Source<Profile>(source).ptr();
583 ExtensionService* service = 588 ExtensionService* service =
584 extensions::ExtensionSystem::Get(profile)->extension_service(); 589 extensions::ExtensionSystem::Get(profile)->extension_service();
585 if (service->is_ready()) { 590 if (service->is_ready()) {
586 const Extension* extension = 591 const Extension* extension =
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (attached) { 697 if (attached) {
693 // Keep the lazy background page alive while it's being inspected. 698 // Keep the lazy background page alive while it's being inspected.
694 CancelSuspend(extension); 699 CancelSuspend(extension);
695 IncrementLazyKeepaliveCount(extension); 700 IncrementLazyKeepaliveCount(extension);
696 } else { 701 } else {
697 DecrementLazyKeepaliveCount(extension); 702 DecrementLazyKeepaliveCount(extension);
698 } 703 }
699 } 704 }
700 705
701 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() { 706 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() {
707 // Don't load background hosts now if the loading should be deferred.
708 // Instead they will be loaded when a browser window for this profile
709 // (or an incognito profile from this profile) is ready, or when
710 // DeferBackgroundHostCreation is called with false.
711 if (DeferLoadingBackgroundHosts())
712 return;
713
702 ExtensionService* service = GetProfile()->GetExtensionService(); 714 ExtensionService* service = GetProfile()->GetExtensionService();
703 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); 715 for (ExtensionSet::const_iterator extension = service->extensions()->begin();
704 extension != service->extensions()->end(); ++extension) { 716 extension != service->extensions()->end(); ++extension) {
705 CreateBackgroundHostForExtensionLoad(this, extension->get()); 717 CreateBackgroundHostForExtensionLoad(this, extension->get());
706 718
707 extensions::RuntimeEventRouter::DispatchOnStartupEvent( 719 extensions::RuntimeEventRouter::DispatchOnStartupEvent(
708 GetProfile(), (*extension)->id()); 720 GetProfile(), (*extension)->id());
709 } 721 }
710 722
711 // Background pages should only be loaded once. To prevent any further loads 723 // Background pages should only be loaded once. To prevent any further loads
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 // the lazy_keepalive_count (if any) to properly reflect the number of open 781 // the lazy_keepalive_count (if any) to properly reflect the number of open
770 // views. 782 // views.
771 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); 783 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin();
772 it != all_extension_views_.end(); ++it) { 784 it != all_extension_views_.end(); ++it) {
773 if (GetExtensionID(it->first) == extension_id) 785 if (GetExtensionID(it->first) == extension_id)
774 IncrementLazyKeepaliveCountForView(it->first); 786 IncrementLazyKeepaliveCountForView(it->first);
775 } 787 }
776 } 788 }
777 789
778 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { 790 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const {
791 // Don't load background hosts now if the loading should be deferred.
792 if (defer_background_host_creation_)
793 return true;
794
779 // The profile may not be valid yet if it is still being initialized. 795 // The profile may not be valid yet if it is still being initialized.
780 // In that case, defer loading, since it depends on an initialized profile. 796 // In that case, defer loading, since it depends on an initialized profile.
781 // http://crbug.com/222473 797 // http://crbug.com/222473
782 if (!g_browser_process->profile_manager()->IsValidProfile(GetProfile())) 798 if (!g_browser_process->profile_manager()->IsValidProfile(GetProfile()))
783 return true; 799 return true;
784 800
785 #if defined(OS_ANDROID) 801 #if defined(OS_ANDROID)
786 return false; 802 return false;
787 #else 803 #else
788 return chrome::GetTotalBrowserCountForProfile(GetProfile()) == 0 && 804 return chrome::GetTotalBrowserCountForProfile(GetProfile()) == 0 &&
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 if (service && service->is_ready()) 909 if (service && service->is_ready())
894 CreateBackgroundHostsForProfileStartup(); 910 CreateBackgroundHostsForProfileStartup();
895 } 911 }
896 break; 912 break;
897 } 913 }
898 default: 914 default:
899 ExtensionProcessManager::Observe(type, source, details); 915 ExtensionProcessManager::Observe(type, source, details);
900 break; 916 break;
901 } 917 }
902 } 918 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698