Bug 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 10 - StorageManager enabled, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 08 Jan 2018 14:05:04 +0100
changeset 449981 ccb06ac64f582189c866ed8ab9834a6353b3cdd3
parent 449980 785e52d7a0fe18043aaa701b2b14429183388015
child 449982 6b6ce0862fd4cd54d2b6fb142efed53cf4bb307e
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1419771
milestone59.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 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 10 - StorageManager enabled, r=asuth
dom/base/DOMPrefs.cpp
dom/base/DOMPrefs.h
dom/quota/StorageManager.cpp
dom/quota/StorageManager.h
dom/webidl/Navigator.webidl
dom/webidl/StorageManager.webidl
dom/workers/WorkerPrefs.h
--- a/dom/base/DOMPrefs.cpp
+++ b/dom/base/DOMPrefs.cpp
@@ -38,28 +38,30 @@ PREF(ImageBitmapExtensionsEnabled, "canv
 PREF(DOMCachesEnabled, "dom.caches.enabled")
 PREF(DOMCachesTestingEnabled, "dom.caches.testing.enabled")
 PREF(PerformanceLoggingEnabled, "dom.performance.enable_user_timing_logging")
 PREF(NotificationEnabled, "dom.webnotifications.enabled")
 PREF(NotificationEnabledInServiceWorkers, "dom.webnotifications.serviceworker.enabled")
 PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled")
 PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled")
 PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled")
+PREF(StorageManagerEnabled, "dom.storageManager.enabled")
 
 #undef PREF
 
 #define PREF_WEBIDL(name)                        \
   /* static */ bool                              \
   DOMPrefs::name(JSContext* aCx, JSObject* aObj) \
   {                                              \
     return DOMPrefs::name();                     \
   }
 
 PREF_WEBIDL(ImageBitmapExtensionsEnabled)
 PREF_WEBIDL(DOMCachesEnabled)
 PREF_WEBIDL(NotificationEnabledInServiceWorkers)
 PREF_WEBIDL(NotificationRIEnabled)
 PREF_WEBIDL(ServiceWorkersEnabled)
+PREF_WEBIDL(StorageManagerEnabled)
 
 #undef PREF_WEBIDL
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPrefs.h
+++ b/dom/base/DOMPrefs.h
@@ -46,14 +46,18 @@ public:
   static bool NotificationRIEnabled(JSContext* aCx, JSObject* aObj);
 
   // Returns true if the dom.serviceWorkers.enabled pref is set.
   static bool ServiceWorkersEnabled();
   static bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aObj);
 
   // Returns true if the dom.serviceWorkers.testing.enabled pref is set.
   static bool ServiceWorkersTestingEnabled();
+
+  // Returns true if the dom.storageManager.enabled pref is set.
+  static bool StorageManagerEnabled();
+  static bool StorageManagerEnabled(JSContext* aCx, JSObject* aObj);
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPrefs_h
--- a/dom/quota/StorageManager.cpp
+++ b/dom/quota/StorageManager.cpp
@@ -1,16 +1,17 @@
 /* -*- 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 "StorageManager.h"
 
+#include "mozilla/dom/DOMPrefs.h"
 #include "mozilla/dom/PromiseWorkerProxy.h"
 #include "mozilla/dom/quota/QuotaManagerService.h"
 #include "mozilla/dom/StorageManagerBinding.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/Telemetry.h"
 #include "nsContentPermissionHelper.h"
@@ -860,30 +861,16 @@ StorageManager::Estimate(ErrorResult& aR
 
   Telemetry::ScalarAdd(Telemetry::ScalarID::NAVIGATOR_STORAGE_ESTIMATE_COUNT,
                        1);
   return ExecuteOpOnMainOrWorkerThread(mOwner,
                                        RequestResolver::Type::Estimate,
                                        aRv);
 }
 
-// static
-bool
-StorageManager::PrefEnabled(JSContext* aCx, JSObject* aObj)
-{
-  if (NS_IsMainThread()) {
-    return Preferences::GetBool("dom.storageManager.enabled");
-  }
-
-  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
-  MOZ_ASSERT(workerPrivate);
-
-  return workerPrivate->StorageManagerEnabled();
-}
-
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StorageManager, mOwner)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(StorageManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(StorageManager)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StorageManager)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
--- a/dom/quota/StorageManager.h
+++ b/dom/quota/StorageManager.h
@@ -20,20 +20,16 @@ struct StorageEstimate;
 
 class StorageManager final
   : public nsISupports
   , public nsWrapperCache
 {
   nsCOMPtr<nsIGlobalObject> mOwner;
 
 public:
-  // Return dom.quota.storageManager.enabled on main/worker thread.
-  static bool
-  PrefEnabled(JSContext* aCx, JSObject* aObj);
-
   explicit
   StorageManager(nsIGlobalObject* aGlobal);
 
   nsIGlobalObject*
   GetParentObject() const
   {
     return mOwner;
   }
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -84,17 +84,17 @@ interface NavigatorContentUtils {
   //DOMString isProtocolHandlerRegistered(DOMString scheme, DOMString url);
   //DOMString isContentHandlerRegistered(DOMString mimeType, DOMString url);
   //void unregisterProtocolHandler(DOMString scheme, DOMString url);
   //void unregisterContentHandler(DOMString mimeType, DOMString url);
 };
 
 [SecureContext, NoInterfaceObject, Exposed=(Window,Worker)]
 interface NavigatorStorage {
-  [Func="mozilla::dom::StorageManager::PrefEnabled"]
+  [Func="mozilla::dom::DOMPrefs::StorageManagerEnabled"]
   readonly attribute StorageManager storage;
 };
 
 [NoInterfaceObject]
 interface NavigatorStorageUtils {
   // NOT IMPLEMENTED
   //void yieldForStorageUpdates();
 };
--- a/dom/webidl/StorageManager.webidl
+++ b/dom/webidl/StorageManager.webidl
@@ -5,17 +5,17 @@
  *
  * The origin of this IDL file is
  * https://storage.spec.whatwg.org/#storagemanager
  *
  */
 
 [SecureContext,
  Exposed=(Window,Worker),
- Func="mozilla::dom::StorageManager::PrefEnabled"]
+ Func="mozilla::dom::DOMPrefs::StorageManagerEnabled"]
 interface StorageManager {
   [Throws]
   Promise<boolean> persisted();
 
   [Exposed=Window, Throws]
   Promise<boolean> persist();
 
   [Throws]
--- a/dom/workers/WorkerPrefs.h
+++ b/dom/workers/WorkerPrefs.h
@@ -16,17 +16,16 @@
 //     macro in Workers.h.
 //   * The name of the function that updates the new value of a pref.
 //
 //   WORKER_PREF("foo.bar", UpdaterFunction)
 //
 //   * First argument is the name of the pref.
 //   * The name of the function that updates the new value of a pref.
 
-WORKER_SIMPLE_PREF("dom.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)
 WORKER_SIMPLE_PREF("dom.promise_rejection_events.enabled", PromiseRejectionEventsEnabled, PROMISE_REJECTION_EVENTS_ENABLED)
 WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
 WORKER_SIMPLE_PREF("dom.streams.enabled", StreamsEnabled, STREAMS_ENABLED)
 WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
 WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
 WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
 WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED)
 WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)