| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 content::NotificationService::AllSources()); | 196 content::NotificationService::AllSources()); |
| 197 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 197 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| 198 content::Source<BrowserContext>(original_context)); | 198 content::Source<BrowserContext>(original_context)); |
| 199 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 199 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 200 content::Source<BrowserContext>(context)); | 200 content::Source<BrowserContext>(context)); |
| 201 if (context->IsOffTheRecord()) { | 201 if (context->IsOffTheRecord()) { |
| 202 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 202 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 203 content::Source<BrowserContext>(original_context)); | 203 content::Source<BrowserContext>(original_context)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than |
| 207 // kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals. |
| 206 event_page_idle_time_ = base::TimeDelta::FromSeconds(10); | 208 event_page_idle_time_ = base::TimeDelta::FromSeconds(10); |
| 207 unsigned idle_time_msec = 0; | 209 unsigned idle_time_msec = 0; |
| 208 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 210 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 209 extensions::switches::kEventPageIdleTime), &idle_time_msec)) { | 211 extensions::switches::kEventPageIdleTime), &idle_time_msec)) { |
| 210 CHECK(idle_time_msec > 0); // OnKeepaliveImpulseCheck requires non zero. | 212 CHECK(idle_time_msec > 0); // OnKeepaliveImpulseCheck requires non zero. |
| 211 event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec); | 213 event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec); |
| 212 } | 214 } |
| 213 event_page_suspending_time_ = base::TimeDelta::FromSeconds(5); | 215 event_page_suspending_time_ = base::TimeDelta::FromSeconds(5); |
| 214 unsigned suspending_time_msec = 0; | 216 unsigned suspending_time_msec = 0; |
| 215 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 217 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 return; | 414 return; |
| 413 | 415 |
| 414 BackgroundPageData& bd = background_page_data_[extension->id()]; | 416 BackgroundPageData& bd = background_page_data_[extension->id()]; |
| 415 | 417 |
| 416 if (!bd.keepalive_impulse) { | 418 if (!bd.keepalive_impulse) { |
| 417 bd.keepalive_impulse = true; | 419 bd.keepalive_impulse = true; |
| 418 if (!bd.previous_keepalive_impulse) { | 420 if (!bd.previous_keepalive_impulse) { |
| 419 IncrementLazyKeepaliveCount(extension); | 421 IncrementLazyKeepaliveCount(extension); |
| 420 } | 422 } |
| 421 } | 423 } |
| 424 |
| 425 if (!keepalive_impulse_callback_for_testing_.is_null()) |
| 426 keepalive_impulse_callback_for_testing_.Run(extension->id()); |
| 422 } | 427 } |
| 423 | 428 |
| 424 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse | 429 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse |
| 425 // have been made for at least event_page_idle_time_. In the best case an | 430 // have been made for at least event_page_idle_time_. In the best case an |
| 426 // impulse was made just before being cleared, and the decrement will occur | 431 // impulse was made just before being cleared, and the decrement will occur |
| 427 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time | 432 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time |
| 428 // for extension to be shut down based on impulses. Worst case is an impulse | 433 // for extension to be shut down based on impulses. Worst case is an impulse |
| 429 // just after a clear, adding one check cycle and resulting in 3x total time. | 434 // just after a clear, adding one check cycle and resulting in 3x total time. |
| 430 void ProcessManager::OnKeepaliveImpulseCheck() { | 435 void ProcessManager::OnKeepaliveImpulseCheck() { |
| 431 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); | 436 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); |
| 432 i != background_page_data_.end(); | 437 i != background_page_data_.end(); |
| 433 ++i) { | 438 ++i) { |
| 434 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) | 439 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) { |
| 435 DecrementLazyKeepaliveCount(i->first); | 440 DecrementLazyKeepaliveCount(i->first); |
| 441 if (!keepalive_impulse_decrement_callback_for_testing_.is_null()) |
| 442 keepalive_impulse_decrement_callback_for_testing_.Run(i->first); |
| 443 } |
| 436 | 444 |
| 437 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; | 445 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; |
| 438 i->second.keepalive_impulse = false; | 446 i->second.keepalive_impulse = false; |
| 439 } | 447 } |
| 440 | 448 |
| 441 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit | 449 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit |
| 442 // tests there will be no message loop. In that event don't schedule tasks. | 450 // tests there will be no message loop. In that event don't schedule tasks. |
| 443 if (base::MessageLoop::current()) { | 451 if (base::MessageLoop::current()) { |
| 444 base::MessageLoop::current()->PostDelayedTask( | 452 base::MessageLoop::current()->PostDelayedTask( |
| 445 FROM_HERE, | 453 FROM_HERE, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (!service || !service->is_ready()) | 552 if (!service || !service->is_ready()) |
| 545 return; | 553 return; |
| 546 | 554 |
| 547 CreateBackgroundHostsForProfileStartup(); | 555 CreateBackgroundHostsForProfileStartup(); |
| 548 } | 556 } |
| 549 | 557 |
| 550 content::BrowserContext* ProcessManager::GetBrowserContext() const { | 558 content::BrowserContext* ProcessManager::GetBrowserContext() const { |
| 551 return site_instance_->GetBrowserContext(); | 559 return site_instance_->GetBrowserContext(); |
| 552 } | 560 } |
| 553 | 561 |
| 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 |
| 554 void ProcessManager::Observe(int type, | 572 void ProcessManager::Observe(int type, |
| 555 const content::NotificationSource& source, | 573 const content::NotificationSource& source, |
| 556 const content::NotificationDetails& details) { | 574 const content::NotificationDetails& details) { |
| 557 switch (type) { | 575 switch (type) { |
| 558 case chrome::NOTIFICATION_EXTENSIONS_READY: | 576 case chrome::NOTIFICATION_EXTENSIONS_READY: |
| 559 case chrome::NOTIFICATION_PROFILE_CREATED: { | 577 case chrome::NOTIFICATION_PROFILE_CREATED: { |
| 560 // Don't load background hosts now if the loading should be deferred. | 578 // 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 | 579 // Instead they will be loaded when a browser window for this profile |
| 562 // (or an incognito profile from this profile) is ready. | 580 // (or an incognito profile from this profile) is ready. |
| 563 if (DeferLoadingBackgroundHosts()) | 581 if (DeferLoadingBackgroundHosts()) |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 } | 864 } |
| 847 | 865 |
| 848 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { | 866 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { |
| 849 // Keep in sync with duplicate in extension_info_map.cc. | 867 // Keep in sync with duplicate in extension_info_map.cc. |
| 850 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 868 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 851 GetBrowserContext())->extension_service(); | 869 GetBrowserContext())->extension_service(); |
| 852 return extension_util::IsIncognitoEnabled(extension->id(), service); | 870 return extension_util::IsIncognitoEnabled(extension->id(), service); |
| 853 } | 871 } |
| 854 | 872 |
| 855 } // namespace extensions | 873 } // namespace extensions |
| OLD | NEW |