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

Unified Diff: extensions/browser/extension_function.cc

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: send increment/decrement request from renderer/ process Created 4 years, 3 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: extensions/browser/extension_function.cc
diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc
index e734dee7e8699e31f7f27ca9e813a853eeb2bc05..a44d4b2406e8e35aad52b9f0e9213c2521dce27e 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -13,6 +13,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/synchronization/lock.h"
+#include "content/common/service_worker/service_worker_types.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
@@ -470,12 +471,15 @@ void ExtensionFunction::OnRespondingLater(ResponseValue value) {
UIThreadExtensionFunction::UIThreadExtensionFunction()
: context_(nullptr),
render_frame_host_(nullptr),
- is_from_service_worker_(false),
+ service_worker_version_id_(content::kInvalidServiceWorkerVersionId),
delegate_(nullptr) {}
UIThreadExtensionFunction::~UIThreadExtensionFunction() {
- if (dispatcher() && render_frame_host())
- dispatcher()->OnExtensionFunctionCompleted(extension());
+ if (dispatcher() && (render_frame_host() || IsFromServiceWorker())) {
+ dispatcher()->OnExtensionFunctionCompleted(extension(),
+ service_worker_version_id_);
+ }
+
// The extension function should always respond to avoid leaks in the
// renderer, dangling callbacks, etc. The exception is if the system is
// shutting down.
@@ -521,10 +525,14 @@ void UIThreadExtensionFunction::Destruct() const {
BrowserThread::DeleteOnUIThread::Destruct(this);
}
+bool UIThreadExtensionFunction::IsFromServiceWorker() const {
michaeln 2016/09/24 01:46:51 style nit: maybe inline and rename is_from_service
lazyboy 2016/09/27 21:26:45 Done.
+ return content::kInvalidServiceWorkerVersionId != service_worker_version_id_;
+}
+
void UIThreadExtensionFunction::SetRenderFrameHost(
content::RenderFrameHost* render_frame_host) {
// An extension function from Service Worker does not have a RenderFrameHost.
- if (is_from_service_worker_) {
+ if (IsFromServiceWorker()) {
DCHECK(!render_frame_host);
return;
}

Powered by Google App Engine
This is Rietveld 408576698