diff options
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/browser/process_manager.cc | 18 | ||||
-rw-r--r-- | extensions/browser/process_manager.h | 11 |
2 files changed, 28 insertions, 1 deletions
diff --git a/extensions/browser/process_manager.cc b/extensions/browser/process_manager.cc index 7a362e3..b4e7357 100644 --- a/extensions/browser/process_manager.cc +++ b/extensions/browser/process_manager.cc @@ -442,6 +442,9 @@ void ProcessManager::KeepaliveImpulse(const Extension* extension) { IncrementLazyKeepaliveCount(extension); } } + + if (!keepalive_impulse_callback_for_testing_.is_null()) + keepalive_impulse_callback_for_testing_.Run(extension->id()); } // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse @@ -454,8 +457,11 @@ void ProcessManager::OnKeepaliveImpulseCheck() { for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); i != background_page_data_.end(); ++i) { - if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) + if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) { DecrementLazyKeepaliveCount(i->first); + if (!keepalive_impulse_decrement_callback_for_testing_.is_null()) + keepalive_impulse_decrement_callback_for_testing_.Run(i->first); + } i->second.previous_keepalive_impulse = i->second.keepalive_impulse; i->second.keepalive_impulse = false; @@ -576,6 +582,16 @@ content::BrowserContext* ProcessManager::GetBrowserContext() const { return site_instance_->GetBrowserContext(); } +void ProcessManager::SetKeepaliveImpulseCallbackForTesting( + const ImpulseCallbackForTesting& callback) { + keepalive_impulse_callback_for_testing_ = callback; +} + +void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting( + const ImpulseCallbackForTesting& callback) { + keepalive_impulse_decrement_callback_for_testing_ = callback; +} + void ProcessManager::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { diff --git a/extensions/browser/process_manager.h b/extensions/browser/process_manager.h index 8b48aab..f283c79 100644 --- a/extensions/browser/process_manager.h +++ b/extensions/browser/process_manager.h @@ -121,6 +121,14 @@ class ProcessManager : public content::NotificationObserver { // related SiteInstances. content::BrowserContext* GetBrowserContext() const; + // Sets callbacks for testing keepalive impulse behavior. + typedef base::Callback<void(const std::string& extension_id)> + ImpulseCallbackForTesting; + void SetKeepaliveImpulseCallbackForTesting( + const ImpulseCallbackForTesting& callback); + void SetKeepaliveImpulseDecrementCallbackForTesting( + const ImpulseCallbackForTesting& callback); + protected: // If |context| is incognito pass the master context as |original_context|. // Otherwise pass the same context for both. @@ -216,6 +224,9 @@ class ProcessManager : public content::NotificationObserver { base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; + ImpulseCallbackForTesting keepalive_impulse_callback_for_testing_; + ImpulseCallbackForTesting keepalive_impulse_decrement_callback_for_testing_; + base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(ProcessManager); |