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

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

Issue 13811030: Simplify ExtensionProcessManager to only load extension background pages when a browser window is o… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 16 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
17 #include "chrome/browser/extensions/extension_host.h" 17 #include "chrome/browser/extensions/extension_host.h"
18 #include "chrome/browser/extensions/extension_info_map.h" 18 #include "chrome/browser/extensions/extension_info_map.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/extensions/background_info.h" 25 #include "chrome/common/extensions/background_info.h"
27 #include "chrome/common/extensions/extension.h" 26 #include "chrome/common/extensions/extension.h"
28 #include "chrome/common/extensions/extension_messages.h" 27 #include "chrome/common/extensions/extension_messages.h"
29 #include "chrome/common/extensions/incognito_handler.h" 28 #include "chrome/common/extensions/incognito_handler.h"
30 #include "chrome/common/extensions/manifest_handler.h" 29 #include "chrome/common/extensions/manifest_handler.h"
31 #include "chrome/common/extensions/manifest_url_handler.h" 30 #include "chrome/common/extensions/manifest_url_handler.h"
32 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 new IncognitoExtensionProcessManager(profile) : 130 new IncognitoExtensionProcessManager(profile) :
132 new ExtensionProcessManager(profile); 131 new ExtensionProcessManager(profile);
133 } 132 }
134 133
135 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) 134 ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
136 : site_instance_(SiteInstance::Create(profile)), 135 : site_instance_(SiteInstance::Create(profile)),
137 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 136 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
138 Profile* original_profile = profile->GetOriginalProfile(); 137 Profile* original_profile = profile->GetOriginalProfile();
139 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 138 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
140 content::NotificationService::AllSources()); 139 content::NotificationService::AllSources());
141 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
142 content::Source<Profile>(original_profile));
143 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 140 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
144 content::Source<Profile>(original_profile)); 141 content::Source<Profile>(original_profile));
145 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 142 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
146 content::Source<Profile>(original_profile)); 143 content::Source<Profile>(original_profile));
147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 144 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
148 content::Source<Profile>(profile)); 145 content::Source<Profile>(profile));
149 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 146 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
150 content::Source<Profile>(profile)); 147 content::Source<Profile>(profile));
151 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 148 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
152 content::NotificationService::AllSources()); 149 content::NotificationService::AllSources());
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // If a window for this profile, or this profile's incognito profile, 545 // If a window for this profile, or this profile's incognito profile,
549 // has been opened, make sure this profile's background hosts have 546 // has been opened, make sure this profile's background hosts have
550 // been loaded. 547 // been loaded.
551 Browser* browser = content::Source<Browser>(source).ptr(); 548 Browser* browser = content::Source<Browser>(source).ptr();
552 if (browser->profile() != GetProfile() && 549 if (browser->profile() != GetProfile() &&
553 !(GetProfile()->HasOffTheRecordProfile() && 550 !(GetProfile()->HasOffTheRecordProfile() &&
554 browser->profile() == GetProfile()->GetOffTheRecordProfile())) 551 browser->profile() == GetProfile()->GetOffTheRecordProfile()))
555 break; 552 break;
556 553
557 ExtensionService* service = GetProfile()->GetExtensionService(); 554 ExtensionService* service = GetProfile()->GetExtensionService();
558 if (!service || !service->is_ready()) 555 if (!service || !service->is_ready())
Matt Perry 2013/04/10 19:31:45 Can you move the service->is_ready() part to a CHE
jam 2013/04/10 19:33:39 Done.
559 break; 556 break;
560 557
561 CreateBackgroundHostsForProfileStartup(); 558 CreateBackgroundHostsForProfileStartup();
562 break; 559 break;
563 } 560 }
564 case chrome::NOTIFICATION_EXTENSIONS_READY: {
565 // Don't load background hosts now if the loading should be deferred.
566 // Instead they will be loaded when a browser window for this profile
567 // (or an incognito profile from this profile) is ready.
568 if (DeferLoadingBackgroundHosts())
569 break;
570
571 CreateBackgroundHostsForProfileStartup();
572 break;
573 }
574
575 case chrome::NOTIFICATION_EXTENSION_LOADED: { 561 case chrome::NOTIFICATION_EXTENSION_LOADED: {
576 Profile* profile = content::Source<Profile>(source).ptr(); 562 Profile* profile = content::Source<Profile>(source).ptr();
577 ExtensionService* service = profile->GetExtensionService(); 563 ExtensionService* service = profile->GetExtensionService();
578 if (service->is_ready()) { 564 if (service->is_ready()) {
579 const Extension* extension = 565 const Extension* extension =
580 content::Details<const Extension>(details).ptr(); 566 content::Details<const Extension>(details).ptr();
581 CreateBackgroundHostForExtensionLoad(this, extension); 567 CreateBackgroundHostForExtensionLoad(this, extension);
582 } 568 }
583 break; 569 break;
584 } 570 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 // Re-register all RenderViews for this extension. We do this to restore 751 // Re-register all RenderViews for this extension. We do this to restore
766 // the lazy_keepalive_count (if any) to properly reflect the number of open 752 // the lazy_keepalive_count (if any) to properly reflect the number of open
767 // views. 753 // views.
768 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); 754 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin();
769 it != all_extension_views_.end(); ++it) { 755 it != all_extension_views_.end(); ++it) {
770 if (GetExtensionID(it->first) == extension_id) 756 if (GetExtensionID(it->first) == extension_id)
771 IncrementLazyKeepaliveCountForView(it->first); 757 IncrementLazyKeepaliveCountForView(it->first);
772 } 758 }
773 } 759 }
774 760
775 bool ExtensionProcessManager::DeferLoadingBackgroundHosts() const {
776 #if defined(OS_ANDROID)
777 return false;
778 #else
779 return chrome::GetTotalBrowserCountForProfile(GetProfile()) == 0 &&
780 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList);
781 #endif
782 }
783
784 // 761 //
785 // IncognitoExtensionProcessManager 762 // IncognitoExtensionProcessManager
786 // 763 //
787 764
788 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( 765 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager(
789 Profile* profile) 766 Profile* profile)
790 : ExtensionProcessManager(profile), 767 : ExtensionProcessManager(profile),
791 original_manager_(extensions::ExtensionSystem::Get( 768 original_manager_(extensions::ExtensionSystem::Get(
792 profile->GetOriginalProfile())->process_manager()) { 769 profile->GetOriginalProfile())->process_manager()) {
793 DCHECK(profile->IsOffTheRecord()); 770 DCHECK(profile->IsOffTheRecord());
794
795 // The original profile will have its own ExtensionProcessManager to
796 // load the background pages of the spanning extensions. This process
797 // manager need only worry about the split mode extensions, which is handled
798 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler.
799 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY,
800 content::Source<Profile>(profile->GetOriginalProfile()));
801 } 771 }
802 772
803 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { 773 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() {
804 // TODO(yoz): This cleanup code belongs in the MenuManager. 774 // TODO(yoz): This cleanup code belongs in the MenuManager.
805 // Remove "incognito" "split" mode context menu items. 775 // Remove "incognito" "split" mode context menu items.
806 ExtensionService* service = 776 ExtensionService* service =
807 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); 777 extensions::ExtensionSystem::Get(GetProfile())->extension_service();
808 if (service) 778 if (service)
809 service->menu_manager()->RemoveAllIncognitoContextItems(); 779 service->menu_manager()->RemoveAllIncognitoContextItems();
810 } 780 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 if (service && service->is_ready()) 852 if (service && service->is_ready())
883 CreateBackgroundHostsForProfileStartup(); 853 CreateBackgroundHostsForProfileStartup();
884 } 854 }
885 break; 855 break;
886 } 856 }
887 default: 857 default:
888 ExtensionProcessManager::Observe(type, source, details); 858 ExtensionProcessManager::Observe(type, source, details);
889 break; 859 break;
890 } 860 }
891 } 861 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698