Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2610)

Unified Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 10804020: Introduce runtime.onSuspendCanceled() event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0338fc0523a78cf0751cae45352bce416f315311 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.
@@ -413,17 +414,31 @@ int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) {
}
int ExtensionProcessManager::IncrementLazyKeepaliveCount(
- const Extension* extension) {
+ const Extension* extension, bool cancel_suspend) {
if (!extension->has_lazy_background_page())
return 0;
int& count = background_page_data_[extension->id()].lazy_keepalive_count;
- if (++count == 1)
+ bool& is_closing = background_page_data_[extension->id()].is_closing;
+ if (++count == 1) {
+ if (cancel_suspend && is_closing) {
+ is_closing = false;
+ ExtensionHost* host = GetBackgroundHostForExtension(extension->id());
+ if (host)
+ host->render_view_host()->Send(
+ new ExtensionMsg_CancelUnload(extension->id()));
benwells 2012/07/20 10:57:00 Nit: braces around the if body as there is more th
+ }
OnLazyBackgroundPageActive(extension->id());
+ }
return count;
}
+int ExtensionProcessManager::IncrementLazyKeepaliveCount(
+ const Extension* extension) {
+ return IncrementLazyKeepaliveCount(extension, false);
+}
+
int ExtensionProcessManager::DecrementLazyKeepaliveCount(
const Extension* extension) {
if (!extension->has_lazy_background_page())
@@ -442,6 +457,7 @@ int ExtensionProcessManager::DecrementLazyKeepaliveCount(
return count;
}
+
void ExtensionProcessManager::IncrementLazyKeepaliveCountForView(
RenderViewHost* render_view_host) {
WebContents* web_contents =
@@ -492,19 +508,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(
@@ -608,7 +629,7 @@ void ExtensionProcessManager::Observe(
const Extension* extension = GetExtensionForRenderViewHost(
render_view_host);
if (extension)
- IncrementLazyKeepaliveCount(extension);
+ IncrementLazyKeepaliveCount(extension, true);
}
break;
}

Powered by Google App Engine
This is Rietveld 408576698