| 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 return; | 414 return; |
| 415 | 415 |
| 416 BackgroundPageData& bd = background_page_data_[extension->id()]; | 416 BackgroundPageData& bd = background_page_data_[extension->id()]; |
| 417 | 417 |
| 418 if (!bd.keepalive_impulse) { | 418 if (!bd.keepalive_impulse) { |
| 419 bd.keepalive_impulse = true; | 419 bd.keepalive_impulse = true; |
| 420 if (!bd.previous_keepalive_impulse) { | 420 if (!bd.previous_keepalive_impulse) { |
| 421 IncrementLazyKeepaliveCount(extension); | 421 IncrementLazyKeepaliveCount(extension); |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 | |
| 425 if (!keepalive_impulse_callback_for_testing_.is_null()) | |
| 426 keepalive_impulse_callback_for_testing_.Run(extension->id()); | |
| 427 } | 424 } |
| 428 | 425 |
| 429 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse | 426 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse |
| 430 // have been made for at least event_page_idle_time_. In the best case an | 427 // have been made for at least event_page_idle_time_. In the best case an |
| 431 // impulse was made just before being cleared, and the decrement will occur | 428 // impulse was made just before being cleared, and the decrement will occur |
| 432 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time | 429 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time |
| 433 // for extension to be shut down based on impulses. Worst case is an impulse | 430 // for extension to be shut down based on impulses. Worst case is an impulse |
| 434 // just after a clear, adding one check cycle and resulting in 3x total time. | 431 // just after a clear, adding one check cycle and resulting in 3x total time. |
| 435 void ProcessManager::OnKeepaliveImpulseCheck() { | 432 void ProcessManager::OnKeepaliveImpulseCheck() { |
| 436 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); | 433 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); |
| 437 i != background_page_data_.end(); | 434 i != background_page_data_.end(); |
| 438 ++i) { | 435 ++i) { |
| 439 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) { | 436 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) |
| 440 DecrementLazyKeepaliveCount(i->first); | 437 DecrementLazyKeepaliveCount(i->first); |
| 441 if (!keepalive_impulse_decrement_callback_for_testing_.is_null()) | |
| 442 keepalive_impulse_decrement_callback_for_testing_.Run(i->first); | |
| 443 } | |
| 444 | 438 |
| 445 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; | 439 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; |
| 446 i->second.keepalive_impulse = false; | 440 i->second.keepalive_impulse = false; |
| 447 } | 441 } |
| 448 | 442 |
| 449 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit | 443 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit |
| 450 // tests there will be no message loop. In that event don't schedule tasks. | 444 // tests there will be no message loop. In that event don't schedule tasks. |
| 451 if (base::MessageLoop::current()) { | 445 if (base::MessageLoop::current()) { |
| 452 base::MessageLoop::current()->PostDelayedTask( | 446 base::MessageLoop::current()->PostDelayedTask( |
| 453 FROM_HERE, | 447 FROM_HERE, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (!service || !service->is_ready()) | 546 if (!service || !service->is_ready()) |
| 553 return; | 547 return; |
| 554 | 548 |
| 555 CreateBackgroundHostsForProfileStartup(); | 549 CreateBackgroundHostsForProfileStartup(); |
| 556 } | 550 } |
| 557 | 551 |
| 558 content::BrowserContext* ProcessManager::GetBrowserContext() const { | 552 content::BrowserContext* ProcessManager::GetBrowserContext() const { |
| 559 return site_instance_->GetBrowserContext(); | 553 return site_instance_->GetBrowserContext(); |
| 560 } | 554 } |
| 561 | 555 |
| 562 void ProcessManager::SetKeepaliveImpulseCallbackForTesting( | |
| 563 const ImpulseCallbackForTesting& callback) { | |
| 564 keepalive_impulse_callback_for_testing_ = callback; | |
| 565 } | |
| 566 | |
| 567 void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting( | |
| 568 const ImpulseCallbackForTesting& callback) { | |
| 569 keepalive_impulse_decrement_callback_for_testing_ = callback; | |
| 570 } | |
| 571 | |
| 572 void ProcessManager::Observe(int type, | 556 void ProcessManager::Observe(int type, |
| 573 const content::NotificationSource& source, | 557 const content::NotificationSource& source, |
| 574 const content::NotificationDetails& details) { | 558 const content::NotificationDetails& details) { |
| 575 switch (type) { | 559 switch (type) { |
| 576 case chrome::NOTIFICATION_EXTENSIONS_READY: | 560 case chrome::NOTIFICATION_EXTENSIONS_READY: |
| 577 case chrome::NOTIFICATION_PROFILE_CREATED: { | 561 case chrome::NOTIFICATION_PROFILE_CREATED: { |
| 578 // Don't load background hosts now if the loading should be deferred. | 562 // Don't load background hosts now if the loading should be deferred. |
| 579 // Instead they will be loaded when a browser window for this profile | 563 // Instead they will be loaded when a browser window for this profile |
| 580 // (or an incognito profile from this profile) is ready. | 564 // (or an incognito profile from this profile) is ready. |
| 581 if (DeferLoadingBackgroundHosts()) | 565 if (DeferLoadingBackgroundHosts()) |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 } | 848 } |
| 865 | 849 |
| 866 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { | 850 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { |
| 867 // Keep in sync with duplicate in extension_info_map.cc. | 851 // Keep in sync with duplicate in extension_info_map.cc. |
| 868 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 852 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 869 GetBrowserContext())->extension_service(); | 853 GetBrowserContext())->extension_service(); |
| 870 return extension_util::IsIncognitoEnabled(extension->id(), service); | 854 return extension_util::IsIncognitoEnabled(extension->id(), service); |
| 871 } | 855 } |
| 872 | 856 |
| 873 } // namespace extensions | 857 } // namespace extensions |
| OLD | NEW |