| OLD | NEW |
| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 BrowserContext* original_context = | 168 BrowserContext* original_context = |
| 169 ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 169 ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
| 170 return new IncognitoProcessManager(context, original_context); | 170 return new IncognitoProcessManager(context, original_context); |
| 171 } | 171 } |
| 172 return new ProcessManager(context, context); | 172 return new ProcessManager(context, context); |
| 173 } | 173 } |
| 174 | 174 |
| 175 ProcessManager::ProcessManager(BrowserContext* context, | 175 ProcessManager::ProcessManager(BrowserContext* context, |
| 176 BrowserContext* original_context) | 176 BrowserContext* original_context) |
| 177 : site_instance_(SiteInstance::Create(context)), | 177 : site_instance_(SiteInstance::Create(context)), |
| 178 defer_background_host_creation_(false), | |
| 179 startup_background_hosts_created_(false), | 178 startup_background_hosts_created_(false), |
| 180 devtools_callback_(base::Bind( | 179 devtools_callback_(base::Bind( |
| 181 &ProcessManager::OnDevToolsStateChanged, | 180 &ProcessManager::OnDevToolsStateChanged, |
| 182 base::Unretained(this))), | 181 base::Unretained(this))), |
| 183 weak_ptr_factory_(this) { | 182 weak_ptr_factory_(this) { |
| 184 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 183 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 185 content::Source<BrowserContext>(original_context)); | 184 content::Source<BrowserContext>(original_context)); |
| 186 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 185 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 187 content::Source<BrowserContext>(original_context)); | 186 content::Source<BrowserContext>(original_context)); |
| 188 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 187 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 new ExtensionMsg_CancelSuspend(extension->id())); | 528 new ExtensionMsg_CancelSuspend(extension->id())); |
| 530 // This increment / decrement is to simulate an instantaneous event. This | 529 // This increment / decrement is to simulate an instantaneous event. This |
| 531 // has the effect of invalidating close_sequence_id, preventing any in | 530 // has the effect of invalidating close_sequence_id, preventing any in |
| 532 // progress closes from completing and starting a new close process if | 531 // progress closes from completing and starting a new close process if |
| 533 // necessary. | 532 // necessary. |
| 534 IncrementLazyKeepaliveCount(extension); | 533 IncrementLazyKeepaliveCount(extension); |
| 535 DecrementLazyKeepaliveCount(extension); | 534 DecrementLazyKeepaliveCount(extension); |
| 536 } | 535 } |
| 537 } | 536 } |
| 538 | 537 |
| 539 void ProcessManager::DeferBackgroundHostCreation(bool defer) { | |
| 540 bool previous = defer_background_host_creation_; | |
| 541 defer_background_host_creation_ = defer; | |
| 542 | |
| 543 // If we were deferred, and we switch to non-deferred, then create the | |
| 544 // background hosts. | |
| 545 if (previous && !defer_background_host_creation_) | |
| 546 CreateBackgroundHostsForProfileStartup(); | |
| 547 } | |
| 548 | |
| 549 void ProcessManager::OnBrowserWindowReady() { | 538 void ProcessManager::OnBrowserWindowReady() { |
| 550 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 539 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 551 GetBrowserContext())->extension_service(); | 540 GetBrowserContext())->extension_service(); |
| 552 // On Chrome OS, a login screen is implemented as a browser. | 541 // On Chrome OS, a login screen is implemented as a browser. |
| 553 // This browser has no extension service. In this case, | 542 // This browser has no extension service. In this case, |
| 554 // service will be NULL. | 543 // service will be NULL. |
| 555 if (!service || !service->is_ready()) | 544 if (!service || !service->is_ready()) |
| 556 return; | 545 return; |
| 557 | 546 |
| 558 CreateBackgroundHostsForProfileStartup(); | 547 CreateBackgroundHostsForProfileStartup(); |
| 559 } | 548 } |
| 560 | 549 |
| 561 content::BrowserContext* ProcessManager::GetBrowserContext() const { | 550 content::BrowserContext* ProcessManager::GetBrowserContext() const { |
| 562 return site_instance_->GetBrowserContext(); | 551 return site_instance_->GetBrowserContext(); |
| 563 } | 552 } |
| 564 | 553 |
| 565 void ProcessManager::Observe(int type, | 554 void ProcessManager::Observe(int type, |
| 566 const content::NotificationSource& source, | 555 const content::NotificationSource& source, |
| 567 const content::NotificationDetails& details) { | 556 const content::NotificationDetails& details) { |
| 568 switch (type) { | 557 switch (type) { |
| 569 case chrome::NOTIFICATION_EXTENSIONS_READY: | 558 case chrome::NOTIFICATION_EXTENSIONS_READY: |
| 570 case chrome::NOTIFICATION_PROFILE_CREATED: { | 559 case chrome::NOTIFICATION_PROFILE_CREATED: { |
| 560 // Don't load background hosts now if the loading should be deferred. |
| 561 // Instead they will be loaded when a browser window for this profile |
| 562 // (or an incognito profile from this profile) is ready. |
| 563 if (DeferLoadingBackgroundHosts()) |
| 564 break; |
| 565 |
| 571 CreateBackgroundHostsForProfileStartup(); | 566 CreateBackgroundHostsForProfileStartup(); |
| 572 break; | 567 break; |
| 573 } | 568 } |
| 574 | 569 |
| 575 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 570 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 576 BrowserContext* context = content::Source<BrowserContext>(source).ptr(); | 571 BrowserContext* context = content::Source<BrowserContext>(source).ptr(); |
| 577 ExtensionService* service = | 572 ExtensionService* service = |
| 578 ExtensionSystem::GetForBrowserContext(context)->extension_service(); | 573 ExtensionSystem::GetForBrowserContext(context)->extension_service(); |
| 579 if (service->is_ready()) { | 574 if (service->is_ready()) { |
| 580 const Extension* extension = | 575 const Extension* extension = |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 IncrementLazyKeepaliveCount(extension); | 687 IncrementLazyKeepaliveCount(extension); |
| 693 } else { | 688 } else { |
| 694 DecrementLazyKeepaliveCount(extension); | 689 DecrementLazyKeepaliveCount(extension); |
| 695 } | 690 } |
| 696 } | 691 } |
| 697 | 692 |
| 698 void ProcessManager::CreateBackgroundHostsForProfileStartup() { | 693 void ProcessManager::CreateBackgroundHostsForProfileStartup() { |
| 699 if (startup_background_hosts_created_) | 694 if (startup_background_hosts_created_) |
| 700 return; | 695 return; |
| 701 | 696 |
| 702 // Don't load background hosts now if the loading should be deferred. | |
| 703 // Instead they will be loaded when a browser window for this profile | |
| 704 // (or an incognito profile from this profile) is ready, or when | |
| 705 // DeferBackgroundHostCreation is called with false. | |
| 706 if (DeferLoadingBackgroundHosts()) | |
| 707 return; | |
| 708 | |
| 709 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 697 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 710 GetBrowserContext())->extension_service(); | 698 GetBrowserContext())->extension_service(); |
| 711 DCHECK(service); | 699 DCHECK(service); |
| 712 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); | 700 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); |
| 713 extension != service->extensions()->end(); ++extension) { | 701 extension != service->extensions()->end(); ++extension) { |
| 714 CreateBackgroundHostForExtensionLoad(this, extension->get()); | 702 CreateBackgroundHostForExtensionLoad(this, extension->get()); |
| 715 | 703 |
| 716 RuntimeEventRouter::DispatchOnStartupEvent(GetBrowserContext(), | 704 RuntimeEventRouter::DispatchOnStartupEvent(GetBrowserContext(), |
| 717 (*extension)->id()); | 705 (*extension)->id()); |
| 718 } | 706 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 // the lazy_keepalive_count (if any) to properly reflect the number of open | 786 // the lazy_keepalive_count (if any) to properly reflect the number of open |
| 799 // views. | 787 // views. |
| 800 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); | 788 for (ExtensionRenderViews::const_iterator it = all_extension_views_.begin(); |
| 801 it != all_extension_views_.end(); ++it) { | 789 it != all_extension_views_.end(); ++it) { |
| 802 if (GetExtensionID(it->first) == extension_id) | 790 if (GetExtensionID(it->first) == extension_id) |
| 803 IncrementLazyKeepaliveCountForView(it->first); | 791 IncrementLazyKeepaliveCountForView(it->first); |
| 804 } | 792 } |
| 805 } | 793 } |
| 806 | 794 |
| 807 bool ProcessManager::DeferLoadingBackgroundHosts() const { | 795 bool ProcessManager::DeferLoadingBackgroundHosts() const { |
| 808 // Don't load background hosts now if the loading should be deferred. | |
| 809 if (defer_background_host_creation_) | |
| 810 return true; | |
| 811 | |
| 812 // The extensions embedder may have special rules about background hosts. | 796 // The extensions embedder may have special rules about background hosts. |
| 813 return ExtensionsBrowserClient::Get()->DeferLoadingBackgroundHosts( | 797 return ExtensionsBrowserClient::Get()->DeferLoadingBackgroundHosts( |
| 814 GetBrowserContext()); | 798 GetBrowserContext()); |
| 815 } | 799 } |
| 816 | 800 |
| 817 // | 801 // |
| 818 // IncognitoProcessManager | 802 // IncognitoProcessManager |
| 819 // | 803 // |
| 820 | 804 |
| 821 IncognitoProcessManager::IncognitoProcessManager( | 805 IncognitoProcessManager::IncognitoProcessManager( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 } | 846 } |
| 863 | 847 |
| 864 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { | 848 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { |
| 865 // Keep in sync with duplicate in extension_info_map.cc. | 849 // Keep in sync with duplicate in extension_info_map.cc. |
| 866 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 850 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 867 GetBrowserContext())->extension_service(); | 851 GetBrowserContext())->extension_service(); |
| 868 return extension_util::IsIncognitoEnabled(extension->id(), service); | 852 return extension_util::IsIncognitoEnabled(extension->id(), service); |
| 869 } | 853 } |
| 870 | 854 |
| 871 } // namespace extensions | 855 } // namespace extensions |
| OLD | NEW |