Chromium Code Reviews| Index: chrome/browser/extensions/extension_process_manager.cc |
| diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc |
| index ac453d6182d0aec5ae03f332171aeadcec37c91a..f4607e570eb2eed2f69f37f35eb637e33887466a 100644 |
| --- a/chrome/browser/extensions/extension_process_manager.cc |
| +++ b/chrome/browser/extensions/extension_process_manager.cc |
| @@ -5,6 +5,7 @@ |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| #include "base/message_loop.h" |
| #include "base/metrics/histogram.h" |
| #include "base/string_number_conversions.h" |
| @@ -112,9 +113,9 @@ struct ExtensionProcessManager::BackgroundPageData { |
| int close_sequence_id; |
| // True if the page responded to the ShouldUnload message and is currently |
| - // dispatching the unload event. We use this to ignore any activity |
| - // generated during the unload event that would otherwise keep the |
| - // extension alive. |
| + // dispatching the unload event. During this time any events that arrive will |
| + // cancel the unload process and an onSuspendCanceled event will be dispatched |
| + // to the page. |
| bool is_closing; |
| // Keeps track of when this page was last unloaded. Used for perf metrics. |
| @@ -432,16 +433,12 @@ int ExtensionProcessManager::DecrementLazyKeepaliveCount( |
| int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
| DCHECK_GT(count, 0); |
| if (--count == 0) { |
| - MessageLoop::current()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&ExtensionProcessManager::OnLazyBackgroundPageIdle, |
| - weak_ptr_factory_.GetWeakPtr(), extension->id(), |
| - ++background_page_data_[extension->id()].close_sequence_id), |
| - event_page_idle_time_); |
| + MaybePostOnLazyBackgroundPageIdle(extension->id()); |
| } |
| return count; |
| } |
| + |
| void ExtensionProcessManager::IncrementLazyKeepaliveCountForView( |
| RenderViewHost* render_view_host) { |
| WebContents* web_contents = |
| @@ -456,6 +453,18 @@ void ExtensionProcessManager::IncrementLazyKeepaliveCountForView( |
| } |
| } |
| +void ExtensionProcessManager::MaybePostOnLazyBackgroundPageIdle( |
| + const std::string& extension_id) { |
| + if (background_page_data_[extension_id].lazy_keepalive_count == 0) { |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&ExtensionProcessManager::OnLazyBackgroundPageIdle, |
| + weak_ptr_factory_.GetWeakPtr(), extension_id, |
| + ++background_page_data_[extension_id].close_sequence_id), |
| + event_page_idle_time_); |
| + } |
| +} |
| + |
| void ExtensionProcessManager::OnLazyBackgroundPageIdle( |
| const std::string& extension_id, int sequence_id) { |
| ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| @@ -475,7 +484,13 @@ void ExtensionProcessManager::OnLazyBackgroundPageIdle( |
| void ExtensionProcessManager::OnLazyBackgroundPageActive( |
| const std::string& extension_id) { |
| ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| - if (host && !background_page_data_[extension_id].is_closing) { |
| + if (host) { |
| + bool& is_closing = background_page_data_[extension_id].is_closing; |
| + if (is_closing) { |
| + host->render_view_host()->Send( |
| + new ExtensionMsg_CancelUnload(extension_id)); |
| + is_closing = false; |
| + } |
| // Cancel the current close sequence by changing the close_sequence_id, |
| // which causes us to ignore the next ShouldUnloadAck. |
| ++background_page_data_[extension_id].close_sequence_id; |
| @@ -492,19 +507,24 @@ void ExtensionProcessManager::OnShouldUnloadAck( |
| } |
| void ExtensionProcessManager::OnUnloadAck(const std::string& extension_id) { |
| + background_page_data_[extension_id].is_closing = true; |
| + int sequence_id = background_page_data_[extension_id].close_sequence_id; |
| MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&ExtensionProcessManager::CloseLazyBackgroundPageNow, |
| - weak_ptr_factory_.GetWeakPtr(), extension_id), |
| + weak_ptr_factory_.GetWeakPtr(), extension_id, sequence_id), |
| event_page_unloading_time_); |
| } |
| void ExtensionProcessManager::CloseLazyBackgroundPageNow( |
| - const std::string& extension_id) { |
| - background_page_data_[extension_id].is_closing = true; |
| + const std::string& extension_id, int sequence_id) { |
| ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| - if (host) |
| - CloseBackgroundHost(host); |
| + if (host && |
| + sequence_id == background_page_data_[extension_id].close_sequence_id) { |
| + ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| + if (host) |
| + CloseBackgroundHost(host); |
| + } |
| } |
| void ExtensionProcessManager::OnNetworkRequestStarted( |
| @@ -523,6 +543,11 @@ void ExtensionProcessManager::OnNetworkRequestDone( |
| DecrementLazyKeepaliveCount(host->extension()); |
| } |
| +void ExtensionProcessManager::CancelSuspend(const std::string& extension_id) { |
| + OnLazyBackgroundPageActive(extension_id); |
| + MaybePostOnLazyBackgroundPageIdle(extension_id); |
|
Matt Perry
2012/07/23 19:15:49
This change confuses me. If we're canceling a susp
koz (OOO until 15th September)
2012/07/24 06:49:52
This doesn't transition us to idle straight away,
Matt Perry
2012/07/24 19:25:15
AddPendingTask is often called when the keepalive
koz (OOO until 15th September)
2012/07/25 07:48:31
Done.
|
| +} |
| + |
| void ExtensionProcessManager::Observe( |
| int type, |
| const content::NotificationSource& source, |