| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 return; | 435 return; |
| 436 | 436 |
| 437 BackgroundPageData& bd = background_page_data_[extension->id()]; | 437 BackgroundPageData& bd = background_page_data_[extension->id()]; |
| 438 | 438 |
| 439 if (!bd.keepalive_impulse) { | 439 if (!bd.keepalive_impulse) { |
| 440 bd.keepalive_impulse = true; | 440 bd.keepalive_impulse = true; |
| 441 if (!bd.previous_keepalive_impulse) { | 441 if (!bd.previous_keepalive_impulse) { |
| 442 IncrementLazyKeepaliveCount(extension); | 442 IncrementLazyKeepaliveCount(extension); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | |
| 446 if (!keepalive_impulse_callback_for_testing_.is_null()) | |
| 447 keepalive_impulse_callback_for_testing_.Run(extension->id()); | |
| 448 } | 445 } |
| 449 | 446 |
| 450 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse | 447 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse |
| 451 // have been made for at least event_page_idle_time_. In the best case an | 448 // have been made for at least event_page_idle_time_. In the best case an |
| 452 // impulse was made just before being cleared, and the decrement will occur | 449 // impulse was made just before being cleared, and the decrement will occur |
| 453 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time | 450 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time |
| 454 // for extension to be shut down based on impulses. Worst case is an impulse | 451 // for extension to be shut down based on impulses. Worst case is an impulse |
| 455 // just after a clear, adding one check cycle and resulting in 3x total time. | 452 // just after a clear, adding one check cycle and resulting in 3x total time. |
| 456 void ProcessManager::OnKeepaliveImpulseCheck() { | 453 void ProcessManager::OnKeepaliveImpulseCheck() { |
| 457 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); | 454 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); |
| 458 i != background_page_data_.end(); | 455 i != background_page_data_.end(); |
| 459 ++i) { | 456 ++i) { |
| 460 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) { | 457 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) |
| 461 DecrementLazyKeepaliveCount(i->first); | 458 DecrementLazyKeepaliveCount(i->first); |
| 462 if (!keepalive_impulse_decrement_callback_for_testing_.is_null()) | |
| 463 keepalive_impulse_decrement_callback_for_testing_.Run(i->first); | |
| 464 } | |
| 465 | 459 |
| 466 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; | 460 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; |
| 467 i->second.keepalive_impulse = false; | 461 i->second.keepalive_impulse = false; |
| 468 } | 462 } |
| 469 | 463 |
| 470 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit | 464 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit |
| 471 // tests there will be no message loop. In that event don't schedule tasks. | 465 // tests there will be no message loop. In that event don't schedule tasks. |
| 472 if (base::MessageLoop::current()) { | 466 if (base::MessageLoop::current()) { |
| 473 base::MessageLoop::current()->PostDelayedTask( | 467 base::MessageLoop::current()->PostDelayedTask( |
| 474 FROM_HERE, | 468 FROM_HERE, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 if (!service || !service->is_ready()) | 569 if (!service || !service->is_ready()) |
| 576 return; | 570 return; |
| 577 | 571 |
| 578 CreateBackgroundHostsForProfileStartup(); | 572 CreateBackgroundHostsForProfileStartup(); |
| 579 } | 573 } |
| 580 | 574 |
| 581 content::BrowserContext* ProcessManager::GetBrowserContext() const { | 575 content::BrowserContext* ProcessManager::GetBrowserContext() const { |
| 582 return site_instance_->GetBrowserContext(); | 576 return site_instance_->GetBrowserContext(); |
| 583 } | 577 } |
| 584 | 578 |
| 585 void ProcessManager::SetKeepaliveImpulseCallbackForTesting( | |
| 586 const ImpulseCallbackForTesting& callback) { | |
| 587 keepalive_impulse_callback_for_testing_ = callback; | |
| 588 } | |
| 589 | |
| 590 void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting( | |
| 591 const ImpulseCallbackForTesting& callback) { | |
| 592 keepalive_impulse_decrement_callback_for_testing_ = callback; | |
| 593 } | |
| 594 | |
| 595 void ProcessManager::Observe(int type, | 579 void ProcessManager::Observe(int type, |
| 596 const content::NotificationSource& source, | 580 const content::NotificationSource& source, |
| 597 const content::NotificationDetails& details) { | 581 const content::NotificationDetails& details) { |
| 598 switch (type) { | 582 switch (type) { |
| 599 case chrome::NOTIFICATION_EXTENSIONS_READY: | 583 case chrome::NOTIFICATION_EXTENSIONS_READY: |
| 600 case chrome::NOTIFICATION_PROFILE_CREATED: { | 584 case chrome::NOTIFICATION_PROFILE_CREATED: { |
| 601 // Don't load background hosts now if the loading should be deferred. | 585 // Don't load background hosts now if the loading should be deferred. |
| 602 // Instead they will be loaded when a browser window for this profile | 586 // Instead they will be loaded when a browser window for this profile |
| 603 // (or an incognito profile from this profile) is ready. | 587 // (or an incognito profile from this profile) is ready. |
| 604 if (DeferLoadingBackgroundHosts()) | 588 if (DeferLoadingBackgroundHosts()) |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 } | 873 } |
| 890 | 874 |
| 891 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { | 875 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { |
| 892 // Keep in sync with duplicate in extension_info_map.cc. | 876 // Keep in sync with duplicate in extension_info_map.cc. |
| 893 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 877 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 894 GetBrowserContext())->extension_service(); | 878 GetBrowserContext())->extension_service(); |
| 895 return extension_util::IsIncognitoEnabled(extension->id(), service); | 879 return extension_util::IsIncognitoEnabled(extension->id(), service); |
| 896 } | 880 } |
| 897 | 881 |
| 898 } // namespace extensions | 882 } // namespace extensions |
| OLD | NEW |