Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 10 - StorageManager enabled, r=asuth
☠☠ backed out by ccd7b237c433 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Dec 2017 14:02:45 -0600
changeset 396300 5e44aeda4196494f6ac6114faa38d8091a136329
parent 396299 601b49f51b41ca478019cb28d9ac0c7f1c780f56
child 396301 b9d674bdc72366f0adf272c6a1c619503fd0b657
push id56975
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:59:07 +0000
treeherderautoland@16bcfaad13e1 [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 DOMPreferences, a thread-safe access to preferences for DOM - part 10 - StorageManager enabled, r=asuth
dom/base/DOMPreferences.cpp
dom/base/DOMPreferences.h
dom/quota/StorageManager.cpp
dom/quota/StorageManager.h
dom/webidl/Navigator.webidl
dom/webidl/StorageManager.webidl
dom/workers/WorkerPrefs.h
--- a/dom/base/DOMPreferences.cpp
+++ b/dom/base/DOMPreferences.cpp
@@ -39,28 +39,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                                    \
   DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
   {                                                    \
     return DOMPreferences::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/DOMPreferences.h
+++ b/dom/base/DOMPreferences.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_DOMPreferences_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/DOMPreferences.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::DOMPreferences::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::DOMPreferences::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)