| OLD | NEW |
| 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" |
| 23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/extensions/background_info.h" | 26 #include "chrome/common/extensions/background_info.h" |
| 26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/extensions/extension_messages.h" | 28 #include "chrome/common/extensions/extension_messages.h" |
| 28 #include "chrome/common/extensions/incognito_handler.h" | 29 #include "chrome/common/extensions/incognito_handler.h" |
| 29 #include "chrome/common/extensions/manifest_handler.h" | 30 #include "chrome/common/extensions/manifest_handler.h" |
| 30 #include "chrome/common/extensions/manifest_url_handler.h" | 31 #include "chrome/common/extensions/manifest_url_handler.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 new IncognitoExtensionProcessManager(profile) : | 131 new IncognitoExtensionProcessManager(profile) : |
| 131 new ExtensionProcessManager(profile); | 132 new ExtensionProcessManager(profile); |
| 132 } | 133 } |
| 133 | 134 |
| 134 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) | 135 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) |
| 135 : site_instance_(SiteInstance::Create(profile)), | 136 : site_instance_(SiteInstance::Create(profile)), |
| 136 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 137 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 137 Profile* original_profile = profile->GetOriginalProfile(); | 138 Profile* original_profile = profile->GetOriginalProfile(); |
| 138 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 139 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 139 content::NotificationService::AllSources()); | 140 content::NotificationService::AllSources()); |
| 141 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 142 content::Source<Profile>(original_profile)); |
| 140 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 143 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 141 content::Source<Profile>(original_profile)); | 144 content::Source<Profile>(original_profile)); |
| 142 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 145 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 143 content::Source<Profile>(original_profile)); | 146 content::Source<Profile>(original_profile)); |
| 144 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 145 content::Source<Profile>(profile)); | 148 content::Source<Profile>(profile)); |
| 146 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 149 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 147 content::Source<Profile>(profile)); | 150 content::Source<Profile>(profile)); |
| 148 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 151 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 149 content::NotificationService::AllSources()); | 152 content::NotificationService::AllSources()); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 // If a window for this profile, or this profile's incognito profile, | 548 // If a window for this profile, or this profile's incognito profile, |
| 546 // has been opened, make sure this profile's background hosts have | 549 // has been opened, make sure this profile's background hosts have |
| 547 // been loaded. | 550 // been loaded. |
| 548 Browser* browser = content::Source<Browser>(source).ptr(); | 551 Browser* browser = content::Source<Browser>(source).ptr(); |
| 549 if (browser->profile() != GetProfile() && | 552 if (browser->profile() != GetProfile() && |
| 550 !(GetProfile()->HasOffTheRecordProfile() && | 553 !(GetProfile()->HasOffTheRecordProfile() && |
| 551 browser->profile() == GetProfile()->GetOffTheRecordProfile())) | 554 browser->profile() == GetProfile()->GetOffTheRecordProfile())) |
| 552 break; | 555 break; |
| 553 | 556 |
| 554 ExtensionService* service = GetProfile()->GetExtensionService(); | 557 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 555 if (!service) | 558 if (!service || !service->is_ready()) |
| 556 break; | 559 break; |
| 557 | 560 |
| 558 CHECK(service->is_ready()); | |
| 559 CreateBackgroundHostsForProfileStartup(); | 561 CreateBackgroundHostsForProfileStartup(); |
| 560 break; | 562 break; |
| 561 } | 563 } |
| 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 |
| 562 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 575 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 563 Profile* profile = content::Source<Profile>(source).ptr(); | 576 Profile* profile = content::Source<Profile>(source).ptr(); |
| 564 ExtensionService* service = profile->GetExtensionService(); | 577 ExtensionService* service = profile->GetExtensionService(); |
| 565 if (service->is_ready()) { | 578 if (service->is_ready()) { |
| 566 const Extension* extension = | 579 const Extension* extension = |
| 567 content::Details<const Extension>(details).ptr(); | 580 content::Details<const Extension>(details).ptr(); |
| 568 CreateBackgroundHostForExtensionLoad(this, extension); | 581 CreateBackgroundHostForExtensionLoad(this, extension); |
| 569 } | 582 } |
| 570 break; | 583 break; |
| 571 } | 584 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 // Re-register all RenderViews for this extension. We do this to restore | 765 // Re-register all RenderViews for this extension. We do this to restore |
| 753 // the lazy_keepalive_count (if any) to properly reflect the number of open | 766 // the lazy_keepalive_count (if any) to properly reflect the number of open |
| 754 // views. | 767 // views. |
| 755 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); | 768 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); |
| 756 it != all_extension_views_.end(); ++it) { | 769 it != all_extension_views_.end(); ++it) { |
| 757 if (GetExtensionID(it->first) == extension_id) | 770 if (GetExtensionID(it->first) == extension_id) |
| 758 IncrementLazyKeepaliveCountForView(it->first); | 771 IncrementLazyKeepaliveCountForView(it->first); |
| 759 } | 772 } |
| 760 } | 773 } |
| 761 | 774 |
| 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 |
| 762 // | 784 // |
| 763 // IncognitoExtensionProcessManager | 785 // IncognitoExtensionProcessManager |
| 764 // | 786 // |
| 765 | 787 |
| 766 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( | 788 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( |
| 767 Profile* profile) | 789 Profile* profile) |
| 768 : ExtensionProcessManager(profile), | 790 : ExtensionProcessManager(profile), |
| 769 original_manager_(extensions::ExtensionSystem::Get( | 791 original_manager_(extensions::ExtensionSystem::Get( |
| 770 profile->GetOriginalProfile())->process_manager()) { | 792 profile->GetOriginalProfile())->process_manager()) { |
| 771 DCHECK(profile->IsOffTheRecord()); | 793 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())); |
| 772 } | 801 } |
| 773 | 802 |
| 774 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { | 803 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { |
| 775 // TODO(yoz): This cleanup code belongs in the MenuManager. | 804 // TODO(yoz): This cleanup code belongs in the MenuManager. |
| 776 // Remove "incognito" "split" mode context menu items. | 805 // Remove "incognito" "split" mode context menu items. |
| 777 ExtensionService* service = | 806 ExtensionService* service = |
| 778 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 807 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); |
| 779 if (service) | 808 if (service) |
| 780 service->menu_manager()->RemoveAllIncognitoContextItems(); | 809 service->menu_manager()->RemoveAllIncognitoContextItems(); |
| 781 } | 810 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 if (service && service->is_ready()) | 882 if (service && service->is_ready()) |
| 854 CreateBackgroundHostsForProfileStartup(); | 883 CreateBackgroundHostsForProfileStartup(); |
| 855 } | 884 } |
| 856 break; | 885 break; |
| 857 } | 886 } |
| 858 default: | 887 default: |
| 859 ExtensionProcessManager::Observe(type, source, details); | 888 ExtensionProcessManager::Observe(type, source, details); |
| 860 break; | 889 break; |
| 861 } | 890 } |
| 862 } | 891 } |
| OLD | NEW |