Bug 1361330 - Part 6: Gate SimpleDB behind a preference; r=asuth
authorJan Varga <jan.varga@gmail.com>
Mon, 20 Aug 2018 14:33:17 +0200
changeset 487447 dee7aef26593f4b69163677b5cddfc7a971e323b
parent 487446 481c13a4221b4533b594954abe01f25ffb3c4e36
child 487448 0d8fa976cabda7db3d65efdcb69aa785f5bec9c4
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1361330
milestone63.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 1361330 - Part 6: Gate SimpleDB behind a preference; r=asuth
dom/quota/test/browser_simpledb.js
dom/quota/test/helpers.js
dom/quota/test/unit/head.js
dom/simpledb/ActorsParent.cpp
dom/simpledb/SDBConnection.cpp
dom/simpledb/SDBConnection.h
dom/simpledb/SimpleDBCommon.cpp
dom/simpledb/SimpleDBCommon.h
dom/simpledb/moz.build
layout/build/nsLayoutModule.cpp
--- a/dom/quota/test/browser_simpledb.js
+++ b/dom/quota/test/browser_simpledb.js
@@ -2,16 +2,18 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 add_task(async function testSimpleDB() {
   const name = "data";
   const bufferSize = 100;
 
+  await SpecialPowers.pushPrefEnv({ set: [[ "dom.simpleDB.enabled", true ]] });
+
   let database = getSimpleDatabase();
 
   let request = database.open("data");
   await requestFinished(request);
 
   let buffer1 = getRandomBuffer(bufferSize);
 
   request = database.write(buffer1);
--- a/dom/quota/test/helpers.js
+++ b/dom/quota/test/helpers.js
@@ -44,16 +44,17 @@ function* testHarnessSteps()
 
   info("Pushing preferences");
 
   SpecialPowers.pushPrefEnv(
     {
       "set": [
         ["dom.storageManager.enabled", true],
         ["dom.storageManager.prompt.testing", true],
+        ["dom.simpleDB.enabled", true],
       ]
     },
     nextTestHarnessStep
   );
   yield undefined;
 
   info("Clearing old databases");
 
--- a/dom/quota/test/unit/head.js
+++ b/dom/quota/test/unit/head.js
@@ -61,21 +61,23 @@ function continueToNextStep()
 function continueToNextStepSync()
 {
   testGenerator.next();
 }
 
 function enableTesting()
 {
   SpecialPowers.setBoolPref("dom.quotaManager.testing", true);
+  SpecialPowers.setBoolPref("dom.simpleDB.enabled", true);
 }
 
 function resetTesting()
 {
   SpecialPowers.clearUserPref("dom.quotaManager.testing");
+  SpecialPowers.clearUserPref("dom.simpleDB.enabled");
 }
 
 function init(callback)
 {
   let request = SpecialPowers._getQuotaManager().init();
   request.callback = callback;
 
   return request;
--- a/dom/simpledb/ActorsParent.cpp
+++ b/dom/simpledb/ActorsParent.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/dom/quota/UsageInfo.h"
 #include "mozilla/ipc/BackgroundParent.h"
 #include "mozilla/ipc/PBackgroundParent.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
 #include "nsIFileStreams.h"
 #include "nsISimpleEnumerator.h"
 #include "nsStringStream.h"
 #include "prio.h"
+#include "SimpleDBCommon.h"
 
 #define DISABLE_ASSERTS_FOR_FUZZING 0
 
 #if DISABLE_ASSERTS_FOR_FUZZING
 #define ASSERT_UNLESS_FUZZING(...) do { } while (0)
 #else
 #define ASSERT_UNLESS_FUZZING(...) MOZ_ASSERT(false, __VA_ARGS__)
 #endif
@@ -1194,16 +1195,20 @@ OpenOp::Open()
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mState == State::Initial);
 
   if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
       !OperationMayProceed()) {
     return NS_ERROR_FAILURE;
   }
 
+  if (NS_WARN_IF(!Preferences::GetBool(kPrefSimpleDBEnabled, false))) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
   const PrincipalInfo& principalInfo = GetConnection()->GetPrincipalInfo();
 
   if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
     QuotaManager::GetInfoForChrome(&mSuffix, &mGroup, &mOrigin);
   } else {
     MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);
 
     nsresult rv;
--- a/dom/simpledb/SDBConnection.cpp
+++ b/dom/simpledb/SDBConnection.cpp
@@ -9,16 +9,17 @@
 #include "ActorsChild.h"
 #include "jsfriendapi.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/BackgroundParent.h"
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "nsISDBCallbacks.h"
 #include "SDBRequest.h"
+#include "SimpleDBCommon.h"
 
 namespace mozilla {
 namespace dom {
 
 using namespace mozilla::ipc;
 
 namespace {
 
@@ -71,16 +72,40 @@ SDBConnection::~SDBConnection()
   AssertIsOnOwningThread();
 
   if (mBackgroundActor) {
     mBackgroundActor->SendDeleteMeInternal();
     MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
   }
 }
 
+// static
+nsresult
+SDBConnection::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
+{
+  MOZ_ASSERT(aResult);
+
+  if (NS_WARN_IF(!Preferences::GetBool(kPrefSimpleDBEnabled, false))) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
+  if (aOuter) {
+    return NS_ERROR_NO_AGGREGATION;
+  }
+
+  RefPtr<SDBConnection> connection = new SDBConnection();
+
+  nsresult rv = connection->QueryInterface(aIID, aResult);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
 void
 SDBConnection::ClearBackgroundActor()
 {
   AssertIsOnOwningThread();
 
   mBackgroundActor = nullptr;
 }
 
--- a/dom/simpledb/SDBConnection.h
+++ b/dom/simpledb/SDBConnection.h
@@ -43,17 +43,18 @@ class SDBConnection final
 
   SDBConnectionChild* mBackgroundActor;
 
   bool mRunningRequest;
   bool mOpen;
   bool mAllowedToClose;
 
 public:
-  SDBConnection();
+  static nsresult
+  Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
   void
   AssertIsOnOwningThread() const
   {
     NS_ASSERT_OWNINGTHREAD(SDBConnection);
   }
 
   void
@@ -70,16 +71,18 @@ public:
 
   void
   OnClose(bool aAbnormal);
 
   void
   AllowToClose();
 
 private:
+  SDBConnection();
+
   ~SDBConnection();
 
   nsresult
   CheckState();
 
   nsresult
   EnsureBackgroundActor();
 
new file mode 100644
--- /dev/null
+++ b/dom/simpledb/SimpleDBCommon.cpp
@@ -0,0 +1,15 @@
+/* -*- 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 "SimpleDBCommon.h"
+
+namespace mozilla {
+namespace dom {
+
+const char* kPrefSimpleDBEnabled = "dom.simpleDB.enabled";
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/simpledb/SimpleDBCommon.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_simpledb_SimpledbCommon_h
+#define mozilla_dom_simpledb_SimpledbCommon_h
+
+namespace mozilla {
+namespace dom {
+
+extern const char* kPrefSimpleDBEnabled;
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_simpledb_SimpledbCommon_h
--- a/dom/simpledb/moz.build
+++ b/dom/simpledb/moz.build
@@ -22,16 +22,17 @@ EXPORTS.mozilla.dom += [
 ]
 
 UNIFIED_SOURCES += [
     'ActorsChild.cpp',
     'ActorsParent.cpp',
     'SDBConnection.cpp',
     'SDBRequest.cpp',
     'SDBResults.cpp',
+    'SimpleDBCommon.cpp',
 ]
 
 IPDL_SOURCES += [
     'PBackgroundSDBConnection.ipdl',
     'PBackgroundSDBRequest.ipdl',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -193,17 +193,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(HTMLEdito
 #define PRESENTATION_TCP_SESSION_TRANSPORT_CID \
 { 0xc9d023f4, 0x6228, 0x4c07, { 0x8b, 0x1d, 0x9c, 0x19, 0x57, 0x3f, 0xaa, 0x27 } }
 
 already_AddRefed<nsIPresentationService> NS_CreatePresentationService();
 
 // Factory Constructor
 typedef mozilla::dom::BlobURL::Mutator BlobURLMutator;
 NS_GENERIC_FACTORY_CONSTRUCTOR(BlobURLMutator)
-NS_GENERIC_FACTORY_CONSTRUCTOR(SDBConnection)
 NS_GENERIC_FACTORY_CONSTRUCTOR(LocalStorageManager)
 NS_GENERIC_FACTORY_CONSTRUCTOR(SessionStorageManager)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(DOMRequestService,
                                          DOMRequestService::FactoryCreate)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(QuotaManagerService,
                                          QuotaManagerService::FactoryCreate)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ServiceWorkerManager,
                                          ServiceWorkerManager::GetInstance)
@@ -769,17 +768,17 @@ static const mozilla::Module::CIDEntry k
   { &kNS_WINDOWCOMMANDTABLE_CID, false, nullptr, CreateWindowCommandTableConstructor },
   { &kNS_WINDOWCONTROLLER_CID, false, nullptr, CreateWindowControllerWithSingletonCommandTable },
   { &kNS_PLUGINDOCLOADERFACTORY_CID, false, nullptr, CreateContentDLF },
   { &kNS_PLUGINDOCUMENT_CID, false, nullptr, CreatePluginDocument },
   { &kNS_VIDEODOCUMENT_CID, false, nullptr, CreateVideoDocument },
   { &kNS_STYLESHEETSERVICE_CID, false, nullptr, nsStyleSheetServiceConstructor },
   { &kNS_HOSTOBJECTURI_CID, false, nullptr, BlobURLMutatorConstructor }, // do_CreateInstance returns mutator
   { &kNS_HOSTOBJECTURIMUTATOR_CID, false, nullptr, BlobURLMutatorConstructor },
-  { &kNS_SDBCONNECTION_CID, false, nullptr, SDBConnectionConstructor },
+  { &kNS_SDBCONNECTION_CID, false, nullptr, SDBConnection::Create },
   { &kNS_DOMSESSIONSTORAGEMANAGER_CID, false, nullptr, SessionStorageManagerConstructor },
   { &kNS_DOMLOCALSTORAGEMANAGER_CID, false, nullptr, LocalStorageManagerConstructor },
   { &kNS_TEXTEDITOR_CID, false, nullptr, TextEditorConstructor },
   { &kDOMREQUEST_SERVICE_CID, false, nullptr, DOMRequestServiceConstructor },
   { &kQUOTAMANAGER_SERVICE_CID, false, nullptr, QuotaManagerServiceConstructor },
   { &kSERVICEWORKERMANAGER_CID, false, nullptr, ServiceWorkerManagerConstructor },
   { &kSTORAGEACTIVITYSERVICE_CID, false, nullptr, StorageActivityServiceConstructor },
   { &kNOTIFICATIONTELEMETRYSERVICE_CID, false, nullptr, NotificationTelemetryServiceConstructor },