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