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

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: Simplified, reverted changes to extension_host 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();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (attached) { 703 if (attached) {
693 // Keep the lazy background page alive while it's being inspected. 704 // Keep the lazy background page alive while it's being inspected.
694 CancelSuspend(extension); 705 CancelSuspend(extension);
695 IncrementLazyKeepaliveCount(extension); 706 IncrementLazyKeepaliveCount(extension);
696 } else { 707 } else {
697 DecrementLazyKeepaliveCount(extension); 708 DecrementLazyKeepaliveCount(extension);
698 } 709 }
699 } 710 }
700 711
701 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() { 712 void ExtensionProcessManager::CreateBackgroundHostsForProfileStartup() {
713 if (defer_background_host_creation_)
714 return;
715
702 ExtensionService* service = GetProfile()->GetExtensionService(); 716 ExtensionService* service = GetProfile()->GetExtensionService();
703 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); 717 for (ExtensionSet::const_iterator extension = service->extensions()->begin();
704 extension != service->extensions()->end(); ++extension) { 718 extension != service->extensions()->end(); ++extension) {
705 CreateBackgroundHostForExtensionLoad(this, extension->get()); 719 CreateBackgroundHostForExtensionLoad(this, extension->get());
706 720
707 extensions::RuntimeEventRouter::DispatchOnStartupEvent( 721 extensions::RuntimeEventRouter::DispatchOnStartupEvent(
708 GetProfile(), (*extension)->id()); 722 GetProfile(), (*extension)->id());
709 } 723 }
710 724
711 // Background pages should only be loaded once. To prevent any further loads 725 // Background pages should only be loaded once. To prevent any further loads
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 // Re-register all RenderViews for this extension. We do this to restore 782 // Re-register all RenderViews for this extension. We do this to restore
769 // the lazy_keepalive_count (if any) to properly reflect the number of open 783 // the lazy_keepalive_count (if any) to properly reflect the number of open
770 // views. 784 // views.
771 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); 785 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin();
772 it != all_extension_views_.end(); ++it) { 786 it != all_extension_views_.end(); ++it) {
773 if (GetExtensionID(it->first) == extension_id) 787 if (GetExtensionID(it->first) == extension_id)
774 IncrementLazyKeepaliveCountForView(it->first); 788 IncrementLazyKeepaliveCountForView(it->first);
775 } 789 }
776 } 790 }
777 791
778 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const { 792 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const {
Matt Perry 2013/09/03 19:26:32 could you integrate this method with your new meth
Greg Spencer (Chromium) 2013/09/04 21:17:24 Done. I thought of this too, but was a little hes
779 // The profile may not be valid yet if it is still being initialized. 793 // 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. 794 // In that case, defer loading, since it depends on an initialized profile.
781 // http://crbug.com/222473 795 // http://crbug.com/222473
782 if (!g_browser_process->profile_manager()->IsValidProfile(GetProfile())) 796 if (!g_browser_process->profile_manager()->IsValidProfile(GetProfile()))
783 return true; 797 return true;
784 798
785 #if defined(OS_ANDROID) 799 #if defined(OS_ANDROID)
786 return false; 800 return false;
787 #else 801 #else
788 return chrome::GetTotalBrowserCountForProfile(GetProfile()) == 0 && 802 return chrome::GetTotalBrowserCountForProfile(GetProfile()) == 0 &&
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 if (service && service->is_ready()) 907 if (service && service->is_ready())
894 CreateBackgroundHostsForProfileStartup(); 908 CreateBackgroundHostsForProfileStartup();
895 } 909 }
896 break; 910 break;
897 } 911 }
898 default: 912 default:
899 ExtensionProcessManager::Observe(type, source, details); 913 ExtensionProcessManager::Observe(type, source, details);
900 break; 914 break;
901 } 915 }
902 } 916 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.h ('k') | chrome/browser/extensions/extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698