Bug 1431847 P3 Add ServiceWorkerParentInterceptEnabled() method and backing pref. r=asuth
authorBen Kelly <ben@wanderview.com>
Wed, 24 Jan 2018 12:47:16 -0500
changeset 400701 c540f53d730b090123a37d1171f2d55e94a7153c
parent 400700 9274ff8934e03db9822d34f2c2581e3eb43dd8f3
child 400702 f4f3e57a1de6e9fda7cc6b31e9ce46da1f2f01ee
push id33313
push userncsoregi@mozilla.com
push dateThu, 25 Jan 2018 10:14:49 +0000
treeherdermozilla-central@040afea6562f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1431847
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1431847 P3 Add ServiceWorkerParentInterceptEnabled() method and backing pref. r=asuth
dom/workers/ServiceWorkerUtils.cpp
dom/workers/ServiceWorkerUtils.h
dom/workers/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/workers/ServiceWorkerUtils.cpp
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ServiceWorkerUtils.h"
+
+#include "mozilla/Preferences.h"
+
+namespace mozilla {
+namespace dom {
+
+bool
+ServiceWorkerParentInterceptEnabled()
+{
+  // For right now we only support main thread.  In the future we could make
+  // this use an atomic bool if we need to support worker threads.
+  MOZ_ASSERT(NS_IsMainThread());
+
+  static bool sInit = false;
+  static bool sEnabled;
+
+  if (!sInit) {
+    MOZ_ASSERT(NS_IsMainThread());
+    Preferences::AddBoolVarCache(&sEnabled,
+                                 "dom.serviceWorkers.parent_intercept",
+                                 false);
+    sInit = true;
+  }
+
+  return sEnabled;
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/workers/ServiceWorkerUtils.h
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef _mozilla_dom_ServiceWorkerUtils_h
+#define _mozilla_dom_ServiceWorkerUtils_h
+
+namespace mozilla {
+namespace dom {
+
+bool
+ServiceWorkerParentInterceptEnabled();
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // _mozilla_dom_ServiceWorkerUtils_h
--- a/dom/workers/moz.build
+++ b/dom/workers/moz.build
@@ -13,16 +13,17 @@ EXPORTS.mozilla.dom += [
     'ServiceWorkerCommon.h',
     'ServiceWorkerContainer.h',
     'ServiceWorkerDescriptor.h',
     'ServiceWorkerEvents.h',
     'ServiceWorkerInterceptController.h',
     'ServiceWorkerIPCUtils.h',
     'ServiceWorkerRegistrar.h',
     'ServiceWorkerRegistration.h',
+    'ServiceWorkerUtils.h',
     'WorkerLocation.h',
     'WorkerNavigator.h',
     'WorkerPrivate.h',
     'WorkerRunnable.h',
     'WorkerScope.h',
 ]
 
 EXPORTS.mozilla.dom.workers += [
@@ -73,16 +74,17 @@ UNIFIED_SOURCES += [
     'ServiceWorkerRegistrar.cpp',
     'ServiceWorkerRegistration.cpp',
     'ServiceWorkerRegistrationInfo.cpp',
     'ServiceWorkerScriptCache.cpp',
     'ServiceWorkerUnregisterJob.cpp',
     'ServiceWorkerUpdateJob.cpp',
     'ServiceWorkerUpdaterChild.cpp',
     'ServiceWorkerUpdaterParent.cpp',
+    'ServiceWorkerUtils.cpp',
     'SharedWorker.cpp',
     'WorkerDebuggerManager.cpp',
     'WorkerHolder.cpp',
     'WorkerHolderToken.cpp',
     'WorkerLocation.cpp',
     'WorkerNavigator.cpp',
     'WorkerPrivate.cpp',
     'WorkerRunnable.cpp',