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