Bug 1623278 - Use MovingNotNull in ActorsParent. r=dom-workers-and-storage-reviewers,janv
authorSimon Giesecke <sgiesecke@mozilla.com>
Thu, 14 May 2020 09:14:17 +0000
changeset 593593 fddd01727ad2f5c097b4d750bba958d0cdfc1340
parent 593592 5f5964262d18844fcd64f2730f36e230bda18a41
child 593594 7e01603c26005b763f0596ecba7c6993ec84a2da
push id13186
push userffxbld-merge
push dateMon, 01 Jun 2020 09:52:46 +0000
treeherdermozilla-beta@3e7c70a1e4a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-workers-and-storage-reviewers, janv
bugs1623278
milestone78.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 1623278 - Use MovingNotNull in ActorsParent. r=dom-workers-and-storage-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D73033
dom/indexedDB/ActorsParent.cpp
dom/indexedDB/FileManager.h
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -916,122 +916,120 @@ nsresult ReadCompressedIndexDataValues(m
 
 nsresult ReadCompressedIndexDataValues(mozIStorageValueArray* aValues,
                                        uint32_t aColumnIndex,
                                        nsTArray<IndexDataValue>& aIndexValues) {
   return ReadCompressedIndexDataValuesFromSource(aValues, aColumnIndex,
                                                  aIndexValues);
 }
 
-nsresult CreateFileTables(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+nsresult CreateFileTables(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("CreateFileTables", DOM);
 
   // Table `file`
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE file ("
                          "id INTEGER PRIMARY KEY, "
                          "refcount INTEGER NOT NULL"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_insert_trigger "
                          "AFTER INSERT ON object_data "
                          "FOR EACH ROW "
                          "WHEN NEW.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(NULL, NEW.file_ids); "
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TRIGGER object_data_update_trigger "
       "AFTER UPDATE OF file_ids ON object_data "
       "FOR EACH ROW "
       "WHEN OLD.file_ids IS NOT NULL OR NEW.file_ids IS NOT NULL "
       "BEGIN "
       "SELECT update_refcount(OLD.file_ids, NEW.file_ids); "
       "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_delete_trigger "
                          "AFTER DELETE ON object_data "
                          "FOR EACH ROW WHEN OLD.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(OLD.file_ids, NULL); "
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER file_update_trigger "
                          "AFTER UPDATE ON file "
                          "FOR EACH ROW WHEN NEW.refcount = 0 "
                          "BEGIN "
                          "DELETE FROM file WHERE id = OLD.id; "
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
-nsresult CreateTables(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+nsresult CreateTables(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("CreateTables", DOM);
 
   // Table `database`
 
   // There are two reasons for having the origin column.
   // First, we can ensure that we don't have collisions in the origin hash we
   // use for the path because when we open the db we can make sure that the
   // origins exactly match. Second, chrome code crawling through the idb
   // directory can figure out the origin of every db without having to
   // reverse-engineer our hash scheme.
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE database"
                          "( name TEXT PRIMARY KEY"
                          ", origin TEXT NOT NULL"
                          ", version INTEGER NOT NULL DEFAULT 0"
                          ", last_vacuum_time INTEGER NOT NULL DEFAULT 0"
                          ", last_analyze_time INTEGER NOT NULL DEFAULT 0"
                          ", last_vacuum_size INTEGER NOT NULL DEFAULT 0"
                          ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Table `object_store`
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE object_store"
                          "( id INTEGER PRIMARY KEY"
                          ", auto_increment INTEGER NOT NULL DEFAULT 0"
                          ", name TEXT NOT NULL"
                          ", key_path TEXT"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Table `object_store_index`
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE object_store_index"
                          "( id INTEGER PRIMARY KEY"
                          ", object_store_id INTEGER NOT NULL"
                          ", name TEXT NOT NULL"
                          ", key_path TEXT NOT NULL"
                          ", unique_index INTEGER NOT NULL"
                          ", multientry INTEGER NOT NULL"
                          ", locale TEXT"
@@ -1039,108 +1037,107 @@ nsresult CreateTables(mozIStorageConnect
                          ", FOREIGN KEY (object_store_id) "
                          "REFERENCES object_store(id) "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Table `object_data`
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE object_data"
                          "( object_store_id INTEGER NOT NULL"
                          ", key BLOB NOT NULL"
                          ", index_data_values BLOB DEFAULT NULL"
                          ", file_ids TEXT"
                          ", data BLOB NOT NULL"
                          ", PRIMARY KEY (object_store_id, key)"
                          ", FOREIGN KEY (object_store_id) "
                          "REFERENCES object_store(id) "
                          ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Table `index_data`
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE index_data"
                          "( index_id INTEGER NOT NULL"
                          ", value BLOB NOT NULL"
                          ", object_data_key BLOB NOT NULL"
                          ", object_store_id INTEGER NOT NULL"
                          ", value_locale BLOB"
                          ", PRIMARY KEY (index_id, value, object_data_key)"
                          ", FOREIGN KEY (index_id) "
                          "REFERENCES object_store_index(id) "
                          ", FOREIGN KEY (object_store_id, object_data_key) "
                          "REFERENCES object_data(object_store_id, key) "
                          ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE INDEX index_data_value_locale_index "
       "ON index_data (index_id, value_locale, object_data_key, value) "
       "WHERE value_locale IS NOT NULL;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Table `unique_index_data`
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE unique_index_data"
                          "( index_id INTEGER NOT NULL"
                          ", value BLOB NOT NULL"
                          ", object_store_id INTEGER NOT NULL"
                          ", object_data_key BLOB NOT NULL"
                          ", value_locale BLOB"
                          ", PRIMARY KEY (index_id, value)"
                          ", FOREIGN KEY (index_id) "
                          "REFERENCES object_store_index(id) "
                          ", FOREIGN KEY (object_store_id, object_data_key) "
                          "REFERENCES object_data(object_store_id, key) "
                          ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE INDEX unique_index_data_value_locale_index "
       "ON unique_index_data (index_id, value_locale, object_data_key, value) "
       "WHERE value_locale IS NOT NULL;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = CreateFileTables(aConnection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(kSQLiteSchemaVersion);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom4To5(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.SetSchemaVersion(kSQLiteSchemaVersion);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom4To5(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom4To5", DOM);
 
   nsresult rv;
 
   // All we changed is the type of the version column, so lets try to
   // convert that to an integer, and if we fail, set it to 0.
   nsCOMPtr<mozIStorageStatement> stmt;
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("SELECT name, version, dataVersion "
                          "FROM database"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsString name;
@@ -1176,34 +1173,34 @@ nsresult UpgradeSchemaFrom4To5(mozIStora
     }
 
     rv = stmt->GetInt64(2, &dataVersion);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DROP TABLE database"));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING("DROP TABLE database"));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE database ("
                          "name TEXT NOT NULL, "
                          "version INTEGER NOT NULL DEFAULT 0, "
                          "dataVersion INTEGER NOT NULL"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // The parameter names are not used, parameters are bound by index only
   // locally in the same function.
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("INSERT INTO database (name, version, dataVersion) "
                          "VALUES (:name, :version, :dataVersion)"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   {
@@ -1225,526 +1222,523 @@ nsresult UpgradeSchemaFrom4To5(mozIStora
     }
 
     rv = stmt->Execute();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  rv = aConnection->SetSchemaVersion(5);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom5To6(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.SetSchemaVersion(5);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom5To6(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom5To6", DOM);
 
   // First, drop all the indexes we're no longer going to use.
-  nsresult rv = aConnection->ExecuteSimpleSQL(
-      NS_LITERAL_CSTRING("DROP INDEX key_index;"));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv =
+      aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING("DROP INDEX key_index;"));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP INDEX ai_key_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP INDEX value_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP INDEX ai_value_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Now, reorder the columns of object_data to put the blob data last. We do
   // this by copying into a temporary table, dropping the original, then copying
   // back into a newly created table.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "id INTEGER PRIMARY KEY, "
                          "object_store_id, "
                          "key_value, "
                          "data "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT id, object_store_id, key_value, data "
                          "FROM object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE object_data ("
       "id INTEGER PRIMARY KEY, "
       "object_store_id INTEGER NOT NULL, "
       "key_value DEFAULT NULL, "
       "data BLOB NOT NULL, "
       "UNIQUE (object_store_id, key_value), "
       "FOREIGN KEY (object_store_id) REFERENCES object_store(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO object_data "
                          "SELECT id, object_store_id, key_value, data "
                          "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // We need to add a unique constraint to our ai_object_data table. Copy all
   // the data out of it using a temporary table as before.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "id INTEGER PRIMARY KEY, "
                          "object_store_id, "
                          "data "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT id, object_store_id, data "
                          "FROM ai_object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE ai_object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE ai_object_data ("
       "id INTEGER PRIMARY KEY AUTOINCREMENT, "
       "object_store_id INTEGER NOT NULL, "
       "data BLOB NOT NULL, "
       "UNIQUE (object_store_id, id), "
       "FOREIGN KEY (object_store_id) REFERENCES object_store(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO ai_object_data "
                          "SELECT id, object_store_id, data "
                          "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Fix up the index_data table. We're reordering the columns as well as
   // changing the primary key from being a simple id to being a composite.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "index_id, "
                          "value, "
                          "object_data_key, "
                          "object_data_id "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO temp_upgrade "
       "SELECT index_id, value, object_data_key, object_data_id "
       "FROM index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE index_data ("
       "index_id INTEGER NOT NULL, "
       "value NOT NULL, "
       "object_data_key NOT NULL, "
       "object_data_id INTEGER NOT NULL, "
       "PRIMARY KEY (index_id, value, object_data_key), "
       "FOREIGN KEY (index_id) REFERENCES object_store_index(id) ON DELETE "
       "CASCADE, "
       "FOREIGN KEY (object_data_id) REFERENCES object_data(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT OR IGNORE INTO index_data "
       "SELECT index_id, value, object_data_key, object_data_id "
       "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE INDEX index_data_object_data_id_index "
                          "ON index_data (object_data_id);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Fix up the unique_index_data table. We're reordering the columns as well as
   // changing the primary key from being a simple id to being a composite.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "index_id, "
                          "value, "
                          "object_data_key, "
                          "object_data_id "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO temp_upgrade "
       "SELECT index_id, value, object_data_key, object_data_id "
       "FROM unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE unique_index_data ("
       "index_id INTEGER NOT NULL, "
       "value NOT NULL, "
       "object_data_key NOT NULL, "
       "object_data_id INTEGER NOT NULL, "
       "PRIMARY KEY (index_id, value, object_data_key), "
       "UNIQUE (index_id, value), "
       "FOREIGN KEY (index_id) REFERENCES object_store_index(id) ON DELETE "
       "CASCADE "
       "FOREIGN KEY (object_data_id) REFERENCES object_data(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO unique_index_data "
       "SELECT index_id, value, object_data_key, object_data_id "
       "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE INDEX unique_index_data_object_data_id_index "
                          "ON unique_index_data (object_data_id);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Fix up the ai_index_data table. We're reordering the columns as well as
   // changing the primary key from being a simple id to being a composite.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "index_id, "
                          "value, "
                          "ai_object_data_id "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT index_id, value, ai_object_data_id "
                          "FROM ai_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE ai_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE ai_index_data ("
       "index_id INTEGER NOT NULL, "
       "value NOT NULL, "
       "ai_object_data_id INTEGER NOT NULL, "
       "PRIMARY KEY (index_id, value, ai_object_data_id), "
       "FOREIGN KEY (index_id) REFERENCES object_store_index(id) ON DELETE "
       "CASCADE, "
       "FOREIGN KEY (ai_object_data_id) REFERENCES ai_object_data(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT OR IGNORE INTO ai_index_data "
                          "SELECT index_id, value, ai_object_data_id "
                          "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE INDEX ai_index_data_ai_object_data_id_index "
                          "ON ai_index_data (ai_object_data_id);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Fix up the ai_unique_index_data table. We're reordering the columns as well
   // as changing the primary key from being a simple id to being a composite.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "index_id, "
                          "value, "
                          "ai_object_data_id "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT index_id, value, ai_object_data_id "
                          "FROM ai_unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE ai_unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE ai_unique_index_data ("
       "index_id INTEGER NOT NULL, "
       "value NOT NULL, "
       "ai_object_data_id INTEGER NOT NULL, "
       "UNIQUE (index_id, value), "
       "PRIMARY KEY (index_id, value, ai_object_data_id), "
       "FOREIGN KEY (index_id) REFERENCES object_store_index(id) ON DELETE "
       "CASCADE, "
       "FOREIGN KEY (ai_object_data_id) REFERENCES ai_object_data(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO ai_unique_index_data "
                          "SELECT index_id, value, ai_object_data_id "
                          "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE INDEX ai_unique_index_data_ai_object_data_id_index "
       "ON ai_unique_index_data (ai_object_data_id);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(6);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom6To7(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.SetSchemaVersion(6);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom6To7(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom6To7", DOM);
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "id, "
                          "name, "
                          "key_path, "
                          "auto_increment"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT id, name, key_path, auto_increment "
                          "FROM object_store;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_store;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE object_store ("
                          "id INTEGER PRIMARY KEY, "
                          "auto_increment INTEGER NOT NULL DEFAULT 0, "
                          "name TEXT NOT NULL, "
                          "key_path TEXT, "
                          "UNIQUE (name)"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO object_store "
       "SELECT id, auto_increment, name, nullif(key_path, '') "
       "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(7);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom7To8(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.SetSchemaVersion(7);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom7To8(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom7To8", DOM);
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "id, "
                          "object_store_id, "
                          "name, "
                          "key_path, "
                          "unique_index, "
                          "object_store_autoincrement"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT id, object_store_id, name, key_path, "
                          "unique_index, object_store_autoincrement "
                          "FROM object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE object_store_index ("
       "id INTEGER, "
       "object_store_id INTEGER NOT NULL, "
       "name TEXT NOT NULL, "
       "key_path TEXT NOT NULL, "
       "unique_index INTEGER NOT NULL, "
       "multientry INTEGER NOT NULL, "
       "object_store_autoincrement INTERGER NOT NULL, "
@@ -1752,32 +1746,32 @@ nsresult UpgradeSchemaFrom7To8(mozIStora
       "UNIQUE (object_store_id, name), "
       "FOREIGN KEY (object_store_id) REFERENCES object_store(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO object_store_index "
                          "SELECT id, object_store_id, name, key_path, "
                          "unique_index, 0, object_store_autoincrement "
                          "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(8);
+  rv = aConnection.SetSchemaVersion(8);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 class CompressDataBlobsFunction final : public mozIStorageFunction {
@@ -1840,243 +1834,240 @@ class CompressDataBlobsFunction final : 
     nsCOMPtr<nsIVariant> result =
         new mozilla::storage::AdoptedBlobVariant(data);
 
     result.forget(aResult);
     return NS_OK;
   }
 };
 
-nsresult UpgradeSchemaFrom8To9_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+nsresult UpgradeSchemaFrom8To9_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom8To9_0", DOM);
 
   // We no longer use the dataVersion column.
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("UPDATE database SET dataVersion = 0;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsCOMPtr<mozIStorageFunction> compressor = new CompressDataBlobsFunction();
 
   NS_NAMED_LITERAL_CSTRING(compressorName, "compress");
 
-  rv = aConnection->CreateFunction(compressorName, 1, compressor);
+  rv = aConnection.CreateFunction(compressorName, 1, compressor);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Turn off foreign key constraints before we do anything here.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("UPDATE object_data SET data = compress(data);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("UPDATE ai_object_data SET data = compress(data);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->RemoveFunction(compressorName);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(9, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom9_0To10_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.RemoveFunction(compressorName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(9, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom9_0To10_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom9_0To10_0", DOM);
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE object_data ADD COLUMN file_ids TEXT;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "ALTER TABLE ai_object_data ADD COLUMN file_ids TEXT;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = CreateFileTables(aConnection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(10, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom10_0To11_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(10, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom10_0To11_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom10_0To11_0", DOM);
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "id, "
                          "object_store_id, "
                          "name, "
                          "key_path, "
                          "unique_index, "
                          "multientry"
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO temp_upgrade "
                          "SELECT id, object_store_id, name, key_path, "
                          "unique_index, multientry "
                          "FROM object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE object_store_index ("
       "id INTEGER PRIMARY KEY, "
       "object_store_id INTEGER NOT NULL, "
       "name TEXT NOT NULL, "
       "key_path TEXT NOT NULL, "
       "unique_index INTEGER NOT NULL, "
       "multientry INTEGER NOT NULL, "
       "UNIQUE (object_store_id, name), "
       "FOREIGN KEY (object_store_id) REFERENCES object_store(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO object_store_index "
                          "SELECT id, object_store_id, name, key_path, "
                          "unique_index, multientry "
                          "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TRIGGER object_data_insert_trigger;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO object_data (object_store_id, key_value, data, file_ids) "
       "SELECT object_store_id, id, data, file_ids "
       "FROM ai_object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_insert_trigger "
                          "AFTER INSERT ON object_data "
                          "FOR EACH ROW "
                          "WHEN NEW.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(NULL, NEW.file_ids); "
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO index_data (index_id, value, object_data_key, "
       "object_data_id) "
       "SELECT ai_index_data.index_id, ai_index_data.value, "
       "ai_index_data.ai_object_data_id, object_data.id "
       "FROM ai_index_data "
       "INNER JOIN object_store_index ON "
       "object_store_index.id = ai_index_data.index_id "
       "INNER JOIN object_data ON "
       "object_data.object_store_id = object_store_index.object_store_id AND "
       "object_data.key_value = ai_index_data.ai_object_data_id;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO unique_index_data (index_id, value, object_data_key, "
       "object_data_id) "
       "SELECT ai_unique_index_data.index_id, ai_unique_index_data.value, "
       "ai_unique_index_data.ai_object_data_id, object_data.id "
       "FROM ai_unique_index_data "
       "INNER JOIN object_store_index ON "
       "object_store_index.id = ai_unique_index_data.index_id "
       "INNER JOIN object_data ON "
       "object_data.object_store_id = object_store_index.object_store_id AND "
       "object_data.key_value = ai_unique_index_data.ai_object_data_id;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "UPDATE object_store "
       "SET auto_increment = (SELECT max(id) FROM ai_object_data) + 1 "
       "WHERE auto_increment;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE ai_unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE ai_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE ai_object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(11, 0));
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(11, 0));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 class EncodeKeysFunction final : public mozIStorageFunction {
@@ -2137,352 +2128,349 @@ class EncodeKeysFunction final : public 
 
     nsCOMPtr<nsIVariant> result = new mozilla::storage::BlobVariant(data);
 
     result.forget(aResult);
     return NS_OK;
   }
 };
 
-nsresult UpgradeSchemaFrom11_0To12_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+nsresult UpgradeSchemaFrom11_0To12_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom11_0To12_0", DOM);
 
   NS_NAMED_LITERAL_CSTRING(encoderName, "encode");
 
   nsCOMPtr<mozIStorageFunction> encoder = new EncodeKeysFunction();
 
-  nsresult rv = aConnection->CreateFunction(encoderName, 1, encoder);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.CreateFunction(encoderName, 1, encoder);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "id INTEGER PRIMARY KEY, "
                          "object_store_id, "
                          "key_value, "
                          "data, "
                          "file_ids "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO temp_upgrade "
       "SELECT id, object_store_id, encode(key_value), data, file_ids "
       "FROM object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE object_data ("
       "id INTEGER PRIMARY KEY, "
       "object_store_id INTEGER NOT NULL, "
       "key_value BLOB DEFAULT NULL, "
       "file_ids TEXT, "
       "data BLOB NOT NULL, "
       "UNIQUE (object_store_id, key_value), "
       "FOREIGN KEY (object_store_id) REFERENCES object_store(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO object_data "
       "SELECT id, object_store_id, key_value, file_ids, data "
       "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_insert_trigger "
                          "AFTER INSERT ON object_data "
                          "FOR EACH ROW "
                          "WHEN NEW.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(NULL, NEW.file_ids); "
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TRIGGER object_data_update_trigger "
       "AFTER UPDATE OF file_ids ON object_data "
       "FOR EACH ROW "
       "WHEN OLD.file_ids IS NOT NULL OR NEW.file_ids IS NOT NULL "
       "BEGIN "
       "SELECT update_refcount(OLD.file_ids, NEW.file_ids); "
       "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_delete_trigger "
                          "AFTER DELETE ON object_data "
                          "FOR EACH ROW WHEN OLD.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(OLD.file_ids, NULL); "
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "index_id, "
                          "value, "
                          "object_data_key, "
                          "object_data_id "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO temp_upgrade "
       "SELECT index_id, encode(value), encode(object_data_key), object_data_id "
       "FROM index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE index_data ("
       "index_id INTEGER NOT NULL, "
       "value BLOB NOT NULL, "
       "object_data_key BLOB NOT NULL, "
       "object_data_id INTEGER NOT NULL, "
       "PRIMARY KEY (index_id, value, object_data_key), "
       "FOREIGN KEY (index_id) REFERENCES object_store_index(id) ON DELETE "
       "CASCADE, "
       "FOREIGN KEY (object_data_id) REFERENCES object_data(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO index_data "
       "SELECT index_id, value, object_data_key, object_data_id "
       "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE INDEX index_data_object_data_id_index "
                          "ON index_data (object_data_id);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TEMPORARY TABLE temp_upgrade ("
                          "index_id, "
                          "value, "
                          "object_data_key, "
                          "object_data_id "
                          ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO temp_upgrade "
       "SELECT index_id, encode(value), encode(object_data_key), object_data_id "
       "FROM unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TABLE unique_index_data ("
       "index_id INTEGER NOT NULL, "
       "value BLOB NOT NULL, "
       "object_data_key BLOB NOT NULL, "
       "object_data_id INTEGER NOT NULL, "
       "PRIMARY KEY (index_id, value, object_data_key), "
       "UNIQUE (index_id, value), "
       "FOREIGN KEY (index_id) REFERENCES object_store_index(id) ON DELETE "
       "CASCADE "
       "FOREIGN KEY (object_data_id) REFERENCES object_data(id) ON DELETE "
       "CASCADE"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "INSERT INTO unique_index_data "
       "SELECT index_id, value, object_data_key, object_data_id "
       "FROM temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE temp_upgrade;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE INDEX unique_index_data_object_data_id_index "
                          "ON unique_index_data (object_data_id);"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->RemoveFunction(encoderName);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(12, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom12_0To13_0(mozIStorageConnection* aConnection,
+  rv = aConnection.RemoveFunction(encoderName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(12, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom12_0To13_0(mozIStorageConnection& aConnection,
                                      bool* aVacuumNeeded) {
   AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom12_0To13_0", DOM);
 
   nsresult rv;
 
 #ifdef IDB_MOBILE
   int32_t defaultPageSize;
-  rv = aConnection->GetDefaultPageSize(&defaultPageSize);
+  rv = aConnection.GetDefaultPageSize(&defaultPageSize);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Enable auto_vacuum mode and update the page size to the platform default.
   nsAutoCString upgradeQuery("PRAGMA auto_vacuum = FULL; PRAGMA page_size = ");
   upgradeQuery.AppendInt(defaultPageSize);
 
-  rv = aConnection->ExecuteSimpleSQL(upgradeQuery);
+  rv = aConnection.ExecuteSimpleSQL(upgradeQuery);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   *aVacuumNeeded = true;
 #endif
 
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(13, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom13_0To14_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(13, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom13_0To14_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   // The only change between 13 and 14 was a different structured
   // clone format, but it's backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(14, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom14_0To15_0(mozIStorageConnection* aConnection) {
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(14, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom14_0To15_0(mozIStorageConnection& aConnection) {
   // The only change between 14 and 15 was a different structured
   // clone format, but it's backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(15, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom15_0To16_0(mozIStorageConnection* aConnection) {
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(15, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom15_0To16_0(mozIStorageConnection& aConnection) {
   // The only change between 15 and 16 was a different structured
   // clone format, but it's backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(16, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom16_0To17_0(mozIStorageConnection* aConnection) {
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(16, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom16_0To17_0(mozIStorageConnection& aConnection) {
   // The only change between 16 and 17 was a different structured
   // clone format, but it's backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(17, 0));
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(17, 0));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 class UpgradeSchemaFrom17_0To18_0Helper final {
   class InsertIndexDataValuesFunction;
   class UpgradeKeyFunction;
 
  public:
-  static nsresult DoUpgrade(mozIStorageConnection* aConnection,
+  static nsresult DoUpgrade(mozIStorageConnection& aConnection,
                             const nsACString& aOrigin);
 
  private:
-  static nsresult DoUpgradeInternal(mozIStorageConnection* aConnection,
+  static nsresult DoUpgradeInternal(mozIStorageConnection& aConnection,
                                     const nsACString& aOrigin);
 
   UpgradeSchemaFrom17_0To18_0Helper() = delete;
   ~UpgradeSchemaFrom17_0To18_0Helper() = delete;
 };
 
 class UpgradeSchemaFrom17_0To18_0Helper::InsertIndexDataValuesFunction final
     : public mozIStorageFunction {
@@ -2788,188 +2776,186 @@ UpgradeSchemaFrom17_0To18_0Helper::Upgra
   nsCOMPtr<nsIVariant> result = new mozilla::storage::AdoptedBlobVariant(data);
 
   result.forget(_retval);
   return NS_OK;
 }
 
 // static
 nsresult UpgradeSchemaFrom17_0To18_0Helper::DoUpgrade(
-    mozIStorageConnection* aConnection, const nsACString& aOrigin) {
-  MOZ_ASSERT(aConnection);
+    mozIStorageConnection& aConnection, const nsACString& aOrigin) {
   MOZ_ASSERT(!aOrigin.IsEmpty());
 
   // Register the |upgrade_key| function.
   RefPtr<UpgradeKeyFunction> updateFunction = new UpgradeKeyFunction();
 
   NS_NAMED_LITERAL_CSTRING(upgradeKeyFunctionName, "upgrade_key");
 
   nsresult rv =
-      aConnection->CreateFunction(upgradeKeyFunctionName, 1, updateFunction);
+      aConnection.CreateFunction(upgradeKeyFunctionName, 1, updateFunction);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Register the |insert_idv| function.
   RefPtr<InsertIndexDataValuesFunction> insertIDVFunction =
       new InsertIndexDataValuesFunction();
 
   NS_NAMED_LITERAL_CSTRING(insertIDVFunctionName, "insert_idv");
 
-  rv = aConnection->CreateFunction(insertIDVFunctionName, 4, insertIDVFunction);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    MOZ_ALWAYS_SUCCEEDS(aConnection->RemoveFunction(upgradeKeyFunctionName));
+  rv = aConnection.CreateFunction(insertIDVFunctionName, 4, insertIDVFunction);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    MOZ_ALWAYS_SUCCEEDS(aConnection.RemoveFunction(upgradeKeyFunctionName));
     return rv;
   }
 
   rv = DoUpgradeInternal(aConnection, aOrigin);
 
-  MOZ_ALWAYS_SUCCEEDS(aConnection->RemoveFunction(upgradeKeyFunctionName));
-  MOZ_ALWAYS_SUCCEEDS(aConnection->RemoveFunction(insertIDVFunctionName));
+  MOZ_ALWAYS_SUCCEEDS(aConnection.RemoveFunction(upgradeKeyFunctionName));
+  MOZ_ALWAYS_SUCCEEDS(aConnection.RemoveFunction(insertIDVFunctionName));
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 // static
 nsresult UpgradeSchemaFrom17_0To18_0Helper::DoUpgradeInternal(
-    mozIStorageConnection* aConnection, const nsACString& aOrigin) {
-  MOZ_ASSERT(aConnection);
+    mozIStorageConnection& aConnection, const nsACString& aOrigin) {
   MOZ_ASSERT(!aOrigin.IsEmpty());
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  nsresult rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Drop these triggers to avoid unnecessary work during the upgrade
       // process.
       "DROP TRIGGER object_data_insert_trigger;"
       "DROP TRIGGER object_data_update_trigger;"
       "DROP TRIGGER object_data_delete_trigger;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Drop these indexes before we do anything else to free disk space.
       "DROP INDEX index_data_object_data_id_index;"
       "DROP INDEX unique_index_data_object_data_id_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Create the new tables and triggers first.
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // This will eventually become the |database| table.
       "CREATE TABLE database_upgrade "
       "( name TEXT PRIMARY KEY"
       ", origin TEXT NOT NULL"
       ", version INTEGER NOT NULL DEFAULT 0"
       ", last_vacuum_time INTEGER NOT NULL DEFAULT 0"
       ", last_analyze_time INTEGER NOT NULL DEFAULT 0"
       ", last_vacuum_size INTEGER NOT NULL DEFAULT 0"
       ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // This will eventually become the |object_store| table.
       "CREATE TABLE object_store_upgrade"
       "( id INTEGER PRIMARY KEY"
       ", auto_increment INTEGER NOT NULL DEFAULT 0"
       ", name TEXT NOT NULL"
       ", key_path TEXT"
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // This will eventually become the |object_store_index| table.
       "CREATE TABLE object_store_index_upgrade"
       "( id INTEGER PRIMARY KEY"
       ", object_store_id INTEGER NOT NULL"
       ", name TEXT NOT NULL"
       ", key_path TEXT NOT NULL"
       ", unique_index INTEGER NOT NULL"
       ", multientry INTEGER NOT NULL"
       ", FOREIGN KEY (object_store_id) "
       "REFERENCES object_store(id) "
       ");"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // This will eventually become the |object_data| table.
       "CREATE TABLE object_data_upgrade"
       "( object_store_id INTEGER NOT NULL"
       ", key BLOB NOT NULL"
       ", index_data_values BLOB DEFAULT NULL"
       ", file_ids TEXT"
       ", data BLOB NOT NULL"
       ", PRIMARY KEY (object_store_id, key)"
       ", FOREIGN KEY (object_store_id) "
       "REFERENCES object_store(id) "
       ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // This will eventually become the |index_data| table.
       "CREATE TABLE index_data_upgrade"
       "( index_id INTEGER NOT NULL"
       ", value BLOB NOT NULL"
       ", object_data_key BLOB NOT NULL"
       ", object_store_id INTEGER NOT NULL"
       ", PRIMARY KEY (index_id, value, object_data_key)"
       ", FOREIGN KEY (index_id) "
       "REFERENCES object_store_index(id) "
       ", FOREIGN KEY (object_store_id, object_data_key) "
       "REFERENCES object_data(object_store_id, key) "
       ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // This will eventually become the |unique_index_data| table.
       "CREATE TABLE unique_index_data_upgrade"
       "( index_id INTEGER NOT NULL"
       ", value BLOB NOT NULL"
       ", object_store_id INTEGER NOT NULL"
       ", object_data_key BLOB NOT NULL"
       ", PRIMARY KEY (index_id, value)"
       ", FOREIGN KEY (index_id) "
       "REFERENCES object_store_index(id) "
       ", FOREIGN KEY (object_store_id, object_data_key) "
       "REFERENCES object_data(object_store_id, key) "
       ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Temporarily store |index_data_values| that we build during the upgrade
       // of the index tables. We will later move this to the |object_data|
       // table.
       "CREATE TEMPORARY TABLE temp_index_data_values "
       "( object_store_id INTEGER NOT NULL"
       ", key BLOB NOT NULL"
       ", index_data_values BLOB DEFAULT NULL"
       ", PRIMARY KEY (object_store_id, key)"
       ") WITHOUT ROWID;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // These two triggers help build the |index_data_values| blobs. The nested
       // SELECT statements help us achieve an "INSERT OR UPDATE"-like behavior.
       "CREATE TEMPORARY TRIGGER unique_index_data_upgrade_insert_trigger "
       "AFTER INSERT ON unique_index_data_upgrade "
       "BEGIN "
       "INSERT OR REPLACE INTO temp_index_data_values "
       "VALUES "
       "( NEW.object_store_id"
@@ -2984,17 +2970,17 @@ nsresult UpgradeSchemaFrom17_0To18_0Help
       ", NEW.value"
       ")"
       ");"
       "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TEMPORARY TRIGGER index_data_upgrade_insert_trigger "
       "AFTER INSERT ON index_data_upgrade "
       "BEGIN "
       "INSERT OR REPLACE INTO temp_index_data_values "
       "VALUES "
       "( NEW.object_store_id"
       ", NEW.object_data_key"
       ", insert_idv("
@@ -3010,96 +2996,96 @@ nsresult UpgradeSchemaFrom17_0To18_0Help
       ");"
       "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Update the |unique_index_data| table to change the column order, remove the
   // ON DELETE CASCADE clauses, and to apply the WITHOUT ROWID optimization.
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Insert all the data.
       "INSERT INTO unique_index_data_upgrade "
       "SELECT "
       "unique_index_data.index_id, "
       "upgrade_key(unique_index_data.value), "
       "object_data.object_store_id, "
       "upgrade_key(unique_index_data.object_data_key) "
       "FROM unique_index_data "
       "JOIN object_data "
       "ON unique_index_data.object_data_id = object_data.id;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // The trigger is no longer needed.
       "DROP TRIGGER unique_index_data_upgrade_insert_trigger;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // The old table is no longer needed.
       "DROP TABLE unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Rename the table.
       "ALTER TABLE unique_index_data_upgrade "
       "RENAME TO unique_index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Update the |index_data| table to change the column order, remove the ON
   // DELETE CASCADE clauses, and to apply the WITHOUT ROWID optimization.
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Insert all the data.
       "INSERT INTO index_data_upgrade "
       "SELECT "
       "index_data.index_id, "
       "upgrade_key(index_data.value), "
       "upgrade_key(index_data.object_data_key), "
       "object_data.object_store_id "
       "FROM index_data "
       "JOIN object_data "
       "ON index_data.object_data_id = object_data.id;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // The trigger is no longer needed.
       "DROP TRIGGER index_data_upgrade_insert_trigger;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // The old table is no longer needed.
       "DROP TABLE index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Rename the table.
       "ALTER TABLE index_data_upgrade "
       "RENAME TO index_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Update the |object_data| table to add the |index_data_values| column,
   // remove the ON DELETE CASCADE clause, and apply the WITHOUT ROWID
   // optimization.
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Insert all the data.
       "INSERT INTO object_data_upgrade "
       "SELECT "
       "object_data.object_store_id, "
       "upgrade_key(object_data.key_value), "
       "temp_index_data_values.index_data_values, "
       "object_data.file_ids, "
       "object_data.data "
@@ -3108,90 +3094,90 @@ nsresult UpgradeSchemaFrom17_0To18_0Help
       "ON object_data.object_store_id = "
       "temp_index_data_values.object_store_id "
       "AND upgrade_key(object_data.key_value) = "
       "temp_index_data_values.key;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // The temporary table is no longer needed.
       "DROP TABLE temp_index_data_values;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // The old table is no longer needed.
       "DROP TABLE object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       // Rename the table.
       "ALTER TABLE object_data_upgrade "
       "RENAME TO object_data;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Update the |object_store_index| table to remove the UNIQUE constraint and
   // the ON DELETE CASCADE clause.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO object_store_index_upgrade "
                          "SELECT * "
                          "FROM object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE object_store_index_upgrade "
                          "RENAME TO object_store_index;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Update the |object_store| table to remove the UNIQUE constraint.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("INSERT INTO object_store_upgrade "
                          "SELECT * "
                          "FROM object_store;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TABLE object_store;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE object_store_upgrade "
                          "RENAME TO object_store;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Update the |database| table to include the origin, vacuum information, and
   // apply the WITHOUT ROWID optimization.
   nsCOMPtr<mozIStorageStatement> stmt;
 
   // The parameter names are not used, parameters are bound by index only
   // locally in the same function.
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("INSERT INTO database_upgrade "
                          "SELECT name, :origin, version, 0, 0, 0 "
                          "FROM database;"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
@@ -3200,180 +3186,177 @@ nsresult UpgradeSchemaFrom17_0To18_0Help
     return rv;
   }
 
   rv = stmt->Execute();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv =
-      aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DROP TABLE database;"));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING("DROP TABLE database;"));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE database_upgrade "
                          "RENAME TO database;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
 #ifdef DEBUG
   {
     // Make sure there's only one entry in the |database| table.
     nsCOMPtr<mozIStorageStatement> stmt;
     MOZ_ASSERT(NS_SUCCEEDED(
-        aConnection->CreateStatement(NS_LITERAL_CSTRING("SELECT COUNT(*) "
-                                                        "FROM database;"),
-                                     getter_AddRefs(stmt))));
+        aConnection.CreateStatement(NS_LITERAL_CSTRING("SELECT COUNT(*) "
+                                                       "FROM database;"),
+                                    getter_AddRefs(stmt))));
 
     bool hasResult;
     MOZ_ASSERT(NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)));
 
     int64_t count;
     MOZ_ASSERT(NS_SUCCEEDED(stmt->GetInt64(0, &count)));
 
     MOZ_ASSERT(count == 1);
   }
 #endif
 
   // Recreate file table triggers.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_insert_trigger "
                          "AFTER INSERT ON object_data "
                          "WHEN NEW.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(NULL, NEW.file_ids);"
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TRIGGER object_data_update_trigger "
       "AFTER UPDATE OF file_ids ON object_data "
       "WHEN OLD.file_ids IS NOT NULL OR NEW.file_ids IS NOT NULL "
       "BEGIN "
       "SELECT update_refcount(OLD.file_ids, NEW.file_ids);"
       "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TRIGGER object_data_delete_trigger "
                          "AFTER DELETE ON object_data "
                          "WHEN OLD.file_ids IS NOT NULL "
                          "BEGIN "
                          "SELECT update_refcount(OLD.file_ids, NULL);"
                          "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Finally, turn on auto_vacuum mode. We use full auto_vacuum mode to reclaim
   // disk space on mobile devices (at the cost of some COMMIT speed), and
   // incremental auto_vacuum mode on desktop builds.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
 #ifdef IDB_MOBILE
       NS_LITERAL_CSTRING("PRAGMA auto_vacuum = FULL;")
 #else
       NS_LITERAL_CSTRING("PRAGMA auto_vacuum = INCREMENTAL;")
 #endif
   );
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(18, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom17_0To18_0(mozIStorageConnection* aConnection,
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(18, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom17_0To18_0(mozIStorageConnection& aConnection,
                                      const nsACString& aOrigin) {
-  MOZ_ASSERT(aConnection);
   MOZ_ASSERT(!aOrigin.IsEmpty());
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom17_0To18_0", DOM);
 
   return UpgradeSchemaFrom17_0To18_0Helper::DoUpgrade(aConnection, aOrigin);
 }
 
-nsresult UpgradeSchemaFrom18_0To19_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+nsresult UpgradeSchemaFrom18_0To19_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   nsresult rv;
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom18_0To19_0", DOM);
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE object_store_index "
                          "ADD COLUMN locale TEXT;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE object_store_index "
                          "ADD COLUMN is_auto_locale BOOLEAN;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE index_data "
                          "ADD COLUMN value_locale BLOB;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("ALTER TABLE unique_index_data "
                          "ADD COLUMN value_locale BLOB;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE INDEX index_data_value_locale_index "
       "ON index_data (index_id, value_locale, object_data_key, value) "
       "WHERE value_locale IS NOT NULL;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE INDEX unique_index_data_value_locale_index "
       "ON unique_index_data (index_id, value_locale, object_data_key, value) "
       "WHERE value_locale IS NOT NULL;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(19, 0));
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(19, 0));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 class UpgradeFileIdsFunction final : public mozIStorageFunction {
   SafeRefPtr<FileManager> mFileManager;
 
  public:
   UpgradeFileIdsFunction() { AssertIsOnIOThread(); }
 
-  nsresult Init(nsIFile* aFMDirectory, mozIStorageConnection* aConnection);
+  nsresult Init(nsIFile* aFMDirectory, mozIStorageConnection& aConnection);
 
   NS_DECL_ISUPPORTS
 
  private:
   ~UpgradeFileIdsFunction() {
     AssertIsOnIOThread();
 
     if (mFileManager) {
@@ -3382,24 +3365,23 @@ class UpgradeFileIdsFunction final : pub
   }
 
   NS_IMETHOD
   OnFunctionCall(mozIStorageValueArray* aArguments,
                  nsIVariant** aResult) override;
 };
 
 nsresult UpgradeSchemaFrom19_0To20_0(nsIFile* aFMDirectory,
-                                     mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+                                     mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom19_0To20_0", DOM);
 
   nsCOMPtr<mozIStorageStatement> stmt;
-  nsresult rv = aConnection->CreateStatement(
+  nsresult rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("SELECT count(*) "
                          "FROM object_data "
                          "WHERE file_ids IS NOT NULL"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
@@ -3423,72 +3405,72 @@ nsresult UpgradeSchemaFrom19_0To20_0(nsI
     if (NS_WARN_IF(count < 0)) {
       MOZ_ASSERT(false, "This should never be possible!");
       return NS_ERROR_FAILURE;
     }
   }
 
   if (count == 0) {
     // Nothing to upgrade.
-    rv = aConnection->SetSchemaVersion(MakeSchemaVersion(20, 0));
+    rv = aConnection.SetSchemaVersion(MakeSchemaVersion(20, 0));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     return NS_OK;
   }
 
   RefPtr<UpgradeFileIdsFunction> function = new UpgradeFileIdsFunction();
 
   rv = function->Init(aFMDirectory, aConnection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   NS_NAMED_LITERAL_CSTRING(functionName, "upgrade");
 
-  rv = aConnection->CreateFunction(functionName, 2, function);
+  rv = aConnection.CreateFunction(functionName, 2, function);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Disable update trigger.
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("DROP TRIGGER object_data_update_trigger;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->ExecuteSimpleSQL(
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("UPDATE object_data "
                          "SET file_ids = upgrade(file_ids, data) "
                          "WHERE file_ids IS NOT NULL;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Enable update trigger.
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE TRIGGER object_data_update_trigger "
       "AFTER UPDATE OF file_ids ON object_data "
       "FOR EACH ROW "
       "WHEN OLD.file_ids IS NOT NULL OR NEW.file_ids IS NOT NULL "
       "BEGIN "
       "SELECT update_refcount(OLD.file_ids, NEW.file_ids); "
       "END;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->RemoveFunction(functionName);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(20, 0));
+  rv = aConnection.RemoveFunction(functionName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(20, 0));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 class UpgradeIndexDataValuesFunction final : public mozIStorageFunction {
@@ -3637,121 +3619,120 @@ UpgradeIndexDataValuesFunction::OnFuncti
   std::pair<uint8_t*, int> data(newIdv.release(), newIdvLength);
 
   nsCOMPtr<nsIVariant> result = new storage::AdoptedBlobVariant(data);
 
   result.forget(aResult);
   return NS_OK;
 }
 
-nsresult UpgradeSchemaFrom20_0To21_0(mozIStorageConnection* aConnection) {
+nsresult UpgradeSchemaFrom20_0To21_0(mozIStorageConnection& aConnection) {
   // This should have been part of the 18 to 19 upgrade, where we changed the
   // layout of the index_data_values blobs but didn't upgrade the existing data.
   // See bug 1202788.
 
   AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom20_0To21_0", DOM);
 
   RefPtr<UpgradeIndexDataValuesFunction> function =
       new UpgradeIndexDataValuesFunction();
 
   NS_NAMED_LITERAL_CSTRING(functionName, "upgrade_idv");
 
-  nsresult rv = aConnection->CreateFunction(functionName, 1, function);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  nsresult rv = aConnection.CreateFunction(functionName, 1, function);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "UPDATE object_data "
       "SET index_data_values = upgrade_idv(index_data_values) "
       "WHERE index_data_values IS NOT NULL;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->RemoveFunction(functionName);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(21, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom21_0To22_0(mozIStorageConnection* aConnection) {
+  rv = aConnection.RemoveFunction(functionName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(21, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom21_0To22_0(mozIStorageConnection& aConnection) {
   // The only change between 21 and 22 was a different structured clone format,
   // but it's backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(22, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom22_0To23_0(mozIStorageConnection* aConnection,
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(22, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom22_0To23_0(mozIStorageConnection& aConnection,
                                      const nsACString& aOrigin) {
   AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+
   MOZ_ASSERT(!aOrigin.IsEmpty());
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom22_0To23_0", DOM);
 
   nsCOMPtr<mozIStorageStatement> stmt;
   // The parameter names are not used, parameters are bound by index only
   // locally in the same function.
   nsresult rv =
-      aConnection->CreateStatement(NS_LITERAL_CSTRING("UPDATE database "
-                                                      "SET origin = :origin;"),
-                                   getter_AddRefs(stmt));
+      aConnection.CreateStatement(NS_LITERAL_CSTRING("UPDATE database "
+                                                     "SET origin = :origin;"),
+                                  getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = stmt->BindUTF8StringByIndex(0, aOrigin);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = stmt->Execute();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(23, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom23_0To24_0(mozIStorageConnection* aConnection) {
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(23, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom23_0To24_0(mozIStorageConnection& aConnection) {
   // The only change between 23 and 24 was a different structured clone format,
   // but it's backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(24, 0));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult UpgradeSchemaFrom24_0To25_0(mozIStorageConnection* aConnection) {
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(24, 0));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult UpgradeSchemaFrom24_0To25_0(mozIStorageConnection& aConnection) {
   // The changes between 24 and 25 were an upgraded snappy library, a different
   // structured clone format and a different file_ds format. But everything is
   // backwards-compatible.
-  nsresult rv = aConnection->SetSchemaVersion(MakeSchemaVersion(25, 0));
+  nsresult rv = aConnection.SetSchemaVersion(MakeSchemaVersion(25, 0));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 class StripObsoleteOriginAttributesFunction final : public mozIStorageFunction {
@@ -3804,48 +3785,47 @@ class StripObsoleteOriginAttributesFunct
     nsCOMPtr<nsIVariant> result =
         new mozilla::storage::UTF8TextVariant(originNoSuffix + suffix);
 
     result.forget(aResult);
     return NS_OK;
   }
 };
 
-nsresult UpgradeSchemaFrom25_0To26_0(mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+nsresult UpgradeSchemaFrom25_0To26_0(mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
 
   AUTO_PROFILER_LABEL("UpgradeSchemaFrom25_0To26_0", DOM);
 
   NS_NAMED_LITERAL_CSTRING(functionName, "strip_obsolete_attributes");
 
   nsCOMPtr<mozIStorageFunction> stripObsoleteAttributes =
       new StripObsoleteOriginAttributesFunction();
 
-  nsresult rv = aConnection->CreateFunction(functionName,
-                                            /* aNumArguments */ 1,
-                                            stripObsoleteAttributes);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.CreateFunction(functionName,
+                                           /* aNumArguments */ 1,
+                                           stripObsoleteAttributes);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("UPDATE DATABASE "
                          "SET origin = strip_obsolete_attributes(origin) "
                          "WHERE origin LIKE '%^%';"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = aConnection->RemoveFunction(functionName);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = aConnection->SetSchemaVersion(MakeSchemaVersion(26, 0));
+  rv = aConnection.RemoveFunction(functionName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = aConnection.SetSchemaVersion(MakeSchemaVersion(26, 0));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 Result<nsCOMPtr<nsIFileURL>, nsresult> GetDatabaseFileURL(
@@ -3897,19 +3877,18 @@ Result<nsCOMPtr<nsIFileURL>, nsresult> G
            .Finalize(result);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return Err(rv);
   }
 
   return result;
 }
 
-nsresult SetDefaultPragmas(mozIStorageConnection* aConnection) {
+nsresult SetDefaultPragmas(mozIStorageConnection& aConnection) {
   MOZ_ASSERT(!NS_IsMainThread());
-  MOZ_ASSERT(aConnection);
 
   static constexpr auto kBuiltInPragmas = NS_LITERAL_CSTRING(
       // We use foreign keys in DEBUG builds only because there is a performance
       // cost to using them.
       "PRAGMA foreign_keys = "
 #ifdef DEBUG
       "ON"
 #else
@@ -3923,62 +3902,60 @@ nsresult SetDefaultPragmas(mozIStorageCo
       // triggers, so the statement fires the delete trigger first and then the
       // insert trigger.
       "PRAGMA recursive_triggers = ON;"
 
       // We aggressively truncate the database file when idle so don't bother
       // overwriting the WAL with 0 during active periods.
       "PRAGMA secure_delete = OFF;");
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(kBuiltInPragmas);
+  nsresult rv = aConnection.ExecuteSimpleSQL(kBuiltInPragmas);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsAutoCString pragmaStmt;
   pragmaStmt.AssignLiteral("PRAGMA synchronous = ");
 
   if (IndexedDatabaseManager::FullSynchronous()) {
     pragmaStmt.AppendLiteral("FULL");
   } else {
     pragmaStmt.AppendLiteral("NORMAL");
   }
   pragmaStmt.Append(';');
 
-  rv = aConnection->ExecuteSimpleSQL(pragmaStmt);
+  rv = aConnection.ExecuteSimpleSQL(pragmaStmt);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
 #ifndef IDB_MOBILE
   if (kSQLiteGrowthIncrement) {
     // This is just an optimization so ignore the failure if the disk is
     // currently too full.
-    rv =
-        aConnection->SetGrowthIncrement(kSQLiteGrowthIncrement, EmptyCString());
+    rv = aConnection.SetGrowthIncrement(kSQLiteGrowthIncrement, EmptyCString());
     if (rv != NS_ERROR_FILE_TOO_BIG && NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 #endif  // IDB_MOBILE
 
   return NS_OK;
 }
 
-nsresult SetJournalMode(mozIStorageConnection* aConnection) {
+nsresult SetJournalMode(mozIStorageConnection& aConnection) {
   MOZ_ASSERT(!NS_IsMainThread());
-  MOZ_ASSERT(aConnection);
 
   // Try enabling WAL mode. This can fail in various circumstances so we have to
   // check the results here.
   NS_NAMED_LITERAL_CSTRING(journalModeQueryStart, "PRAGMA journal_mode = ");
   NS_NAMED_LITERAL_CSTRING(journalModeWAL, "wal");
 
   nsCOMPtr<mozIStorageStatement> stmt;
-  nsresult rv = aConnection->CreateStatement(
+  nsresult rv = aConnection.CreateStatement(
       journalModeQueryStart + journalModeWAL, getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   bool hasResult;
   rv = stmt->ExecuteStep(&hasResult);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -3994,64 +3971,65 @@ nsresult SetJournalMode(mozIStorageConne
   }
 
   if (journalMode.Equals(journalModeWAL)) {
     // WAL mode successfully enabled. Maybe set limits on its size here.
     if (kMaxWALPages >= 0) {
       nsAutoCString pageCount;
       pageCount.AppendInt(kMaxWALPages);
 
-      rv = aConnection->ExecuteSimpleSQL(
+      rv = aConnection.ExecuteSimpleSQL(
           NS_LITERAL_CSTRING("PRAGMA wal_autocheckpoint = ") + pageCount);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
   } else {
     NS_WARNING("Failed to set WAL mode, falling back to normal journal mode.");
 #ifdef IDB_MOBILE
-    rv = aConnection->ExecuteSimpleSQL(journalModeQueryStart +
-                                       NS_LITERAL_CSTRING("truncate"));
+    rv = aConnection.ExecuteSimpleSQL(journalModeQueryStart +
+                                      NS_LITERAL_CSTRING("truncate"));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 #endif
   }
 
   return NS_OK;
 }
 
 template <typename V>
-auto ValOrErr(V&& aVal, const nsresult aRv) {
-  return NS_SUCCEEDED(aRv) ? aVal : Result<V, nsresult>{Err(aRv)};
+auto ValOrErr(V aVal, const nsresult aRv) {
+  return NS_SUCCEEDED(aRv) ? WrapMovingNotNull(std::move(aVal))
+                           : Result<MovingNotNull<V>, nsresult>{Err(aRv)};
 }
 
 template <class FileOrURLType>
 struct StorageOpenTraits;
 
 template <>
 struct StorageOpenTraits<nsIFileURL> {
-  static Result<nsCOMPtr<mozIStorageConnection>, nsresult> Open(
+  static Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult> Open(
       mozIStorageService& aStorageService, nsIFileURL& aFileURL) {
     nsCOMPtr<mozIStorageConnection> connection;
     nsresult rv = aStorageService.OpenDatabaseWithFileURL(
         &aFileURL, getter_AddRefs(connection));
     return ValOrErr(std::move(connection), rv);
   }
 
 #ifdef DEBUG
   static void GetPath(nsIFileURL& aFileURL, nsCString& aPath) {
     MOZ_ALWAYS_SUCCEEDS(aFileURL.GetFileName(aPath));
   }
 #endif
 };
 
 template <>
 struct StorageOpenTraits<nsIFile> {
-  static Result<nsCOMPtr<mozIStorageConnection>, nsresult> Open(
+  static Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult> Open(
       mozIStorageService& aStorageService, nsIFile& aFile) {
     nsCOMPtr<mozIStorageConnection> connection;
     nsresult rv = aStorageService.OpenUnsharedDatabase(
         &aFile, getter_AddRefs(connection));
     return ValOrErr(std::move(connection), rv);
   }
 
 #ifdef DEBUG
@@ -4060,18 +4038,19 @@ struct StorageOpenTraits<nsIFile> {
     MOZ_ALWAYS_SUCCEEDS(aFile.GetPath(path));
 
     LossyCopyUTF16toASCII(path, aPath);
   }
 #endif
 };
 
 template <class FileOrURLType>
-Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDatabaseAndHandleBusy(
-    mozIStorageService& aStorageService, FileOrURLType& aFileOrURL) {
+Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult>
+OpenDatabaseAndHandleBusy(mozIStorageService& aStorageService,
+                          FileOrURLType& aFileOrURL) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
 
   auto connectionOrErr =
       StorageOpenTraits<FileOrURLType>::Open(aStorageService, aFileOrURL);
 
   if (connectionOrErr.isErr() &&
       connectionOrErr.inspectErr() == NS_ERROR_STORAGE_BUSY) {
@@ -4108,20 +4087,21 @@ Result<nsCOMPtr<mozIStorageConnection>, 
 
   if (NS_WARN_IF(connectionOrErr.isErr())) {
     return Err(connectionOrErr.unwrapErr());
   }
 
   return connectionOrErr;
 }
 
-Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
-    nsIFile& aDBFile, nsIFile& aFMDirectory, const nsAString& aName,
-    const nsACString& aOrigin, const int64_t aDirectoryLockId,
-    const uint32_t aTelemetryId) {
+Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult>
+CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
+                        const nsAString& aName, const nsACString& aOrigin,
+                        const int64_t aDirectoryLockId,
+                        const uint32_t aTelemetryId) {
   AssertIsOnIOThread();
   MOZ_ASSERT(aDirectoryLockId >= -1);
 
   AUTO_PROFILER_LABEL("CreateStorageConnection", DOM);
 
   bool exists;
 
   auto dbFileUrlOrErr =
@@ -4180,19 +4160,19 @@ Result<nsCOMPtr<mozIStorageConnection>, 
       connectionOrErr = OpenDatabaseAndHandleBusy(*ss, *dbFileUrl);
     }
 
     if (NS_WARN_IF(connectionOrErr.isErr())) {
       return Err(connectionOrErr.unwrapErr());
     }
   }
 
-  auto connection = connectionOrErr.unwrap();
-
-  rv = SetDefaultPragmas(connection);
+  auto connection = connectionOrErr.unwrap().unwrapBasePtr();
+
+  rv = SetDefaultPragmas(*connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return Err(rv);
   }
 
   rv = connection->EnableModule(NS_LITERAL_CSTRING("filesystem"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return Err(rv);
   }
@@ -4245,17 +4225,17 @@ Result<nsCOMPtr<mozIStorageConnection>, 
         // mozstorage translates SQLITE_FULL to NS_ERROR_FILE_NO_DEVICE_SPACE,
         // which we know better as NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR.
         rv = NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
       }
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return Err(rv);
       }
 
-      rv = SetJournalMode(connection);
+      rv = SetJournalMode(*connection);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return Err(rv);
       }
 
       journalModeSet = true;
     } else {
 #ifdef DEBUG
       // Disable foreign key support while upgrading. This has to be done before
@@ -4263,20 +4243,20 @@ Result<nsCOMPtr<mozIStorageConnection>, 
       MOZ_ALWAYS_SUCCEEDS(connection->ExecuteSimpleSQL(
           NS_LITERAL_CSTRING("PRAGMA foreign_keys = OFF;")));
 #endif
     }
 
     bool vacuumNeeded = false;
 
     mozStorageTransaction transaction(
-        connection, false, mozIStorageConnection::TRANSACTION_IMMEDIATE);
+        connection.get(), false, mozIStorageConnection::TRANSACTION_IMMEDIATE);
 
     if (newDatabase) {
-      rv = CreateTables(connection);
+      rv = CreateTables(*connection);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return Err(rv);
       }
 
       MOZ_ASSERT(NS_SUCCEEDED(connection->GetSchemaVersion(&schemaVersion)));
       MOZ_ASSERT(schemaVersion == kSQLiteSchemaVersion);
 
       nsCOMPtr<mozIStorageStatement> stmt;
@@ -4307,82 +4287,82 @@ Result<nsCOMPtr<mozIStorageConnection>, 
     } else {
       // This logic needs to change next time we change the schema!
       static_assert(kSQLiteSchemaVersion == int32_t((26 << 4) + 0),
                     "Upgrade function needed due to schema version increase.");
 
       while (schemaVersion != kSQLiteSchemaVersion) {
         switch (schemaVersion) {
           case 4:
-            rv = UpgradeSchemaFrom4To5(connection);
+            rv = UpgradeSchemaFrom4To5(*connection);
             break;
           case 5:
-            rv = UpgradeSchemaFrom5To6(connection);
+            rv = UpgradeSchemaFrom5To6(*connection);
             break;
           case 6:
-            rv = UpgradeSchemaFrom6To7(connection);
+            rv = UpgradeSchemaFrom6To7(*connection);
             break;
           case 7:
-            rv = UpgradeSchemaFrom7To8(connection);
+            rv = UpgradeSchemaFrom7To8(*connection);
             break;
           case 8:
-            rv = UpgradeSchemaFrom8To9_0(connection);
+            rv = UpgradeSchemaFrom8To9_0(*connection);
             vacuumNeeded = true;
             break;
           case MakeSchemaVersion(9, 0):
-            rv = UpgradeSchemaFrom9_0To10_0(connection);
+            rv = UpgradeSchemaFrom9_0To10_0(*connection);
             break;
           case MakeSchemaVersion(10, 0):
-            rv = UpgradeSchemaFrom10_0To11_0(connection);
+            rv = UpgradeSchemaFrom10_0To11_0(*connection);
             break;
           case MakeSchemaVersion(11, 0):
-            rv = UpgradeSchemaFrom11_0To12_0(connection);
+            rv = UpgradeSchemaFrom11_0To12_0(*connection);
             break;
           case MakeSchemaVersion(12, 0):
-            rv = UpgradeSchemaFrom12_0To13_0(connection, &vacuumNeeded);
+            rv = UpgradeSchemaFrom12_0To13_0(*connection, &vacuumNeeded);
             break;
           case MakeSchemaVersion(13, 0):
-            rv = UpgradeSchemaFrom13_0To14_0(connection);
+            rv = UpgradeSchemaFrom13_0To14_0(*connection);
             break;
           case MakeSchemaVersion(14, 0):
-            rv = UpgradeSchemaFrom14_0To15_0(connection);
+            rv = UpgradeSchemaFrom14_0To15_0(*connection);
             break;
           case MakeSchemaVersion(15, 0):
-            rv = UpgradeSchemaFrom15_0To16_0(connection);
+            rv = UpgradeSchemaFrom15_0To16_0(*connection);
             break;
           case MakeSchemaVersion(16, 0):
-            rv = UpgradeSchemaFrom16_0To17_0(connection);
+            rv = UpgradeSchemaFrom16_0To17_0(*connection);
             break;
           case MakeSchemaVersion(17, 0):
-            rv = UpgradeSchemaFrom17_0To18_0(connection, aOrigin);
+            rv = UpgradeSchemaFrom17_0To18_0(*connection, aOrigin);
             vacuumNeeded = true;
             break;
           case MakeSchemaVersion(18, 0):
-            rv = UpgradeSchemaFrom18_0To19_0(connection);
+            rv = UpgradeSchemaFrom18_0To19_0(*connection);
             break;
           case MakeSchemaVersion(19, 0):
-            rv = UpgradeSchemaFrom19_0To20_0(&aFMDirectory, connection);
+            rv = UpgradeSchemaFrom19_0To20_0(&aFMDirectory, *connection);
             break;
           case MakeSchemaVersion(20, 0):
-            rv = UpgradeSchemaFrom20_0To21_0(connection);
+            rv = UpgradeSchemaFrom20_0To21_0(*connection);
             break;
           case MakeSchemaVersion(21, 0):
-            rv = UpgradeSchemaFrom21_0To22_0(connection);
+            rv = UpgradeSchemaFrom21_0To22_0(*connection);
             break;
           case MakeSchemaVersion(22, 0):
-            rv = UpgradeSchemaFrom22_0To23_0(connection, aOrigin);
+            rv = UpgradeSchemaFrom22_0To23_0(*connection, aOrigin);
             break;
           case MakeSchemaVersion(23, 0):
-            rv = UpgradeSchemaFrom23_0To24_0(connection);
+            rv = UpgradeSchemaFrom23_0To24_0(*connection);
             break;
           case MakeSchemaVersion(24, 0):
-            rv = UpgradeSchemaFrom24_0To25_0(connection);
+            rv = UpgradeSchemaFrom24_0To25_0(*connection);
             break;
           case MakeSchemaVersion(25, 0):
-            rv = UpgradeSchemaFrom25_0To26_0(connection);
+            rv = UpgradeSchemaFrom25_0To26_0(*connection);
             break;
           default:
             IDB_WARNING(
                 "Unable to open IndexedDB database, no upgrade path is "
                 "available!");
             return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
         }
 
@@ -4549,39 +4529,39 @@ Result<nsCOMPtr<mozIStorageConnection>, 
       rv = vacuumTimeStmt->Execute();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return Err(rv);
       }
     }
   }
 
   if (!journalModeSet) {
-    rv = SetJournalMode(connection);
+    rv = SetJournalMode(*connection);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return Err(rv);
     }
   }
 
-  return connection;
+  return WrapMovingNotNullUnchecked(std::move(connection));
 }
 
 nsCOMPtr<nsIFile> GetFileForPath(const nsAString& aPath) {
   MOZ_ASSERT(!aPath.IsEmpty());
 
   auto fileOrErr = QM_NewLocalFile(aPath);
   if (NS_WARN_IF(fileOrErr.isErr())) {
     return nullptr;
   }
 
   return fileOrErr.unwrap();
 }
 
-Result<nsCOMPtr<mozIStorageConnection>, nsresult> GetStorageConnection(
-    nsIFile& aDatabaseFile, const int64_t aDirectoryLockId,
-    const uint32_t aTelemetryId) {
+Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult>
+GetStorageConnection(nsIFile& aDatabaseFile, const int64_t aDirectoryLockId,
+                     const uint32_t aTelemetryId) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
   MOZ_ASSERT(aDirectoryLockId >= 0);
 
   AUTO_PROFILER_LABEL("GetStorageConnection", DOM);
 
   bool exists;
   nsresult rv = aDatabaseFile.Exists(&exists);
@@ -4607,34 +4587,35 @@ Result<nsCOMPtr<mozIStorageConnection>, 
   }
 
   auto connectionOrErr =
       OpenDatabaseAndHandleBusy(*ss, *dbFileUrlOrErr.inspect());
   if (NS_WARN_IF(connectionOrErr.isErr())) {
     return Err(connectionOrErr.unwrapErr());
   }
 
-  auto connection = connectionOrErr.unwrap();
-
-  rv = SetDefaultPragmas(connection);
+  auto connection = connectionOrErr.unwrap().unwrapBasePtr();
+
+  rv = SetDefaultPragmas(*connection);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return Err(rv);
+  }
+
+  rv = SetJournalMode(*connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return Err(rv);
   }
 
-  rv = SetJournalMode(connection);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return Err(rv);
-  }
-
-  return connection;
-}
-
-Result<nsCOMPtr<mozIStorageConnection>, nsresult> GetStorageConnection(
-    const nsAString& aDatabaseFilePath, const int64_t aDirectoryLockId,
-    const uint32_t aTelemetryId) {
+  return WrapMovingNotNullUnchecked(std::move(connection));
+}
+
+Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult>
+GetStorageConnection(const nsAString& aDatabaseFilePath,
+                     const int64_t aDirectoryLockId,
+                     const uint32_t aTelemetryId) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
   MOZ_ASSERT(!aDatabaseFilePath.IsEmpty());
   MOZ_ASSERT(StringEndsWith(aDatabaseFilePath, kSQLiteSuffix));
   MOZ_ASSERT(aDirectoryLockId >= 0);
 
   nsCOMPtr<nsIFile> dbFile = GetFileForPath(aDatabaseFilePath);
   if (NS_WARN_IF(!dbFile)) {
@@ -4734,18 +4715,19 @@ class DatabaseConnection final {
 
   void Close();
 
   nsresult DisableQuotaChecks();
 
   void EnableQuotaChecks();
 
  private:
-  DatabaseConnection(nsCOMPtr<mozIStorageConnection> aStorageConnection,
-                     SafeRefPtr<FileManager> aFileManager);
+  DatabaseConnection(
+      MovingNotNull<nsCOMPtr<mozIStorageConnection>> aStorageConnection,
+      MovingNotNull<SafeRefPtr<FileManager>> aFileManager);
 
   ~DatabaseConnection();
 
   nsresult Init();
 
   nsresult CheckpointInternal(CheckpointMode aMode);
 
   nsresult GetFreelistCount(CachedStatement& aCachedStatement,
@@ -5908,19 +5890,18 @@ class Database final
   uint32_t TelemetryId() const { return mTelemetryId; }
 
   PersistenceType Type() const { return mPersistenceType; }
 
   const nsString& FilePath() const { return mFilePath; }
 
   FileManager& GetFileManager() const { return *mFileManager; }
 
-  SafeRefPtr<FileManager> GetFileManagerPtr() const {
-    MOZ_ASSERT(mFileManager);
-    return mFileManager.clonePtr();
+  MovingNotNull<SafeRefPtr<FileManager>> GetFileManagerPtr() const {
+    return WrapMovingNotNull(mFileManager.clonePtr());
   }
 
   const FullDatabaseMetadata& Metadata() const {
     MOZ_ASSERT(mMetadata);
     return *mMetadata;
   }
 
   SafeRefPtr<FullDatabaseMetadata> MetadataPtr() const {
@@ -6949,17 +6930,17 @@ class OpenDatabaseOp final : public Fact
  public:
   OpenDatabaseOp(SafeRefPtr<Factory> aFactory,
                  RefPtr<ContentParent> aContentParent,
                  const CommonFactoryRequestParams& aParams);
 
  private:
   ~OpenDatabaseOp() override { MOZ_ASSERT(!mVersionChangeOp); }
 
-  nsresult LoadDatabaseInformation(mozIStorageConnection* aConnection);
+  nsresult LoadDatabaseInformation(mozIStorageConnection& aConnection);
 
   nsresult SendUpgradeNeeded();
 
   void EnsureDatabaseActor();
 
   nsresult EnsureDatabaseActorIsAlive();
 
   mozilla::Result<DatabaseSpec, nsresult> MetadataToSpec() const;
@@ -6985,17 +6966,17 @@ class OpenDatabaseOp final : public Fact
   bool AreActorsAlive() override;
 
   void SendBlockedNotification() override;
 
   nsresult DispatchToWorkThread() override;
 
   void SendResults() override;
 
-  static nsresult UpdateLocaleAwareIndex(mozIStorageConnection* aConnection,
+  static nsresult UpdateLocaleAwareIndex(mozIStorageConnection& aConnection,
                                          const IndexMetadata& aIndexMetadata,
                                          const nsCString& aLocale);
 };
 
 class OpenDatabaseOp::VersionChangeOp final
     : public TransactionDatabaseOperationBase {
   friend class OpenDatabaseOp;
 
@@ -8065,25 +8046,24 @@ class ValueCursorBase {
   friend struct ValuePopulateResponseHelper<false>;
 
  protected:
   explicit ValueCursorBase(TransactionBase* const aTransaction)
       : mDatabase(aTransaction->GetDatabasePtr()),
         mFileManager(mDatabase->GetFileManagerPtr()),
         mBackgroundParent(WrapNotNull(aTransaction->GetBackgroundParent())) {
     MOZ_ASSERT(mDatabase);
-    MOZ_ASSERT(mFileManager);
   }
 
   void ProcessFiles(CursorResponse& aResponse, const FilesArray& aFiles);
 
   ~ValueCursorBase() { MOZ_ASSERT(!mBackgroundParent); }
 
   const SafeRefPtr<Database> mDatabase;
-  const SafeRefPtr<FileManager> mFileManager;
+  const NotNull<SafeRefPtr<FileManager>> mFileManager;
 
   InitializedOnce<const NotNull<PBackgroundParent*>> mBackgroundParent;
 };
 
 class KeyCursorBase {
  protected:
   explicit KeyCursorBase(TransactionBase* const /*aTransaction*/) {}
 
@@ -8959,59 +8939,59 @@ class DatabaseMaintenance final : public
 
  private:
   ~DatabaseMaintenance() override = default;
 
   // Runs on maintenance thread pool. Does maintenance on the database.
   void PerformMaintenanceOnDatabase();
 
   // Runs on maintenance thread pool as part of PerformMaintenanceOnDatabase.
-  nsresult CheckIntegrity(mozIStorageConnection* aConnection, bool* aOk);
+  nsresult CheckIntegrity(mozIStorageConnection& aConnection, bool* aOk);
 
   // Runs on maintenance thread pool as part of PerformMaintenanceOnDatabase.
-  nsresult DetermineMaintenanceAction(mozIStorageConnection* aConnection,
+  nsresult DetermineMaintenanceAction(mozIStorageConnection& aConnection,
                                       nsIFile* aDatabaseFile,
                                       MaintenanceAction* aMaintenanceAction);
 
   // Runs on maintenance thread pool as part of PerformMaintenanceOnDatabase.
-  void IncrementalVacuum(mozIStorageConnection* aConnection);
+  void IncrementalVacuum(mozIStorageConnection& aConnection);
 
   // Runs on maintenance thread pool as part of PerformMaintenanceOnDatabase.
-  void FullVacuum(mozIStorageConnection* aConnection, nsIFile* aDatabaseFile);
+  void FullVacuum(mozIStorageConnection& aConnection, nsIFile* aDatabaseFile);
 
   // Runs on the PBackground thread. It dispatches a complete callback and
   // unregisters from Maintenance.
   void RunOnOwningThread();
 
   // Runs on maintenance thread pool. Once it performs database maintenance
   // it will dispatch to the PBackground thread on which RunOnOwningThread()
   // is called.
   void RunOnConnectionThread();
 
   NS_DECL_NSIRUNNABLE
 };
 
 class MOZ_STACK_CLASS DatabaseMaintenance::AutoProgressHandler final
     : public mozIStorageProgressHandler {
   Maintenance* mMaintenance;
-  mozIStorageConnection* mConnection;
+  LazyInitializedOnce<const NotNull<mozIStorageConnection*>> mConnection;
 
   NS_DECL_OWNINGTHREAD
 
 #ifdef DEBUG
   // This class is stack-based so we never actually allow AddRef/Release to do
   // anything. But we need to know if any consumer *thinks* that they have a
   // reference to this object so we track the reference countin DEBUG builds.
   nsrefcnt mDEBUGRefCnt;
 #endif
 
  public:
   explicit AutoProgressHandler(Maintenance* aMaintenance)
       : mMaintenance(aMaintenance),
-        mConnection(nullptr)
+        mConnection()
 #ifdef DEBUG
         ,
         mDEBUGRefCnt(0)
 #endif
   {
     MOZ_ASSERT(!NS_IsMainThread());
     MOZ_ASSERT(!IsOnBackgroundThread());
     NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler);
@@ -9023,17 +9003,17 @@ class MOZ_STACK_CLASS DatabaseMaintenanc
 
     if (mConnection) {
       Unregister();
     }
 
     MOZ_ASSERT(!mDEBUGRefCnt);
   }
 
-  nsresult Register(mozIStorageConnection* aConnection);
+  nsresult Register(NotNull<mozIStorageConnection*> aConnection);
 
   // We don't want the mRefCnt member but this class does not "inherit"
   // nsISupports.
   NS_DECL_ISUPPORTS_INHERITED
 
  private:
   void Unregister();
 
@@ -10101,18 +10081,16 @@ struct KeyPopulateResponseHelper {
     return 0;
   }
 };
 
 template <bool StatementHasIndexKeyBindings>
 struct ValuePopulateResponseHelper {
   nsresult MaybeGetCloneInfo(mozIStorageStatement* const aStmt,
                              const ValueCursorBase& aCursor) {
-    MOZ_ASSERT(aCursor.mFileManager);
-
     constexpr auto offset = StatementHasIndexKeyBindings ? 2 : 0;
 
     auto cloneInfoOrErr =
         DatabaseOperationBase::GetStructuredCloneReadInfoFromStatement(
             aStmt, 2 + offset, 1 + offset, *aCursor.mFileManager);
     if (NS_WARN_IF(cloneInfoOrErr.isErr())) {
       return cloneInfoOrErr.unwrapErr();
     }
@@ -10673,29 +10651,28 @@ nsresult FileManager::AsyncDeleteFile(in
   return NS_OK;
 }
 
 /*******************************************************************************
  * DatabaseConnection implementation
  ******************************************************************************/
 
 DatabaseConnection::DatabaseConnection(
-    nsCOMPtr<mozIStorageConnection> aStorageConnection,
-    SafeRefPtr<FileManager> aFileManager)
-    : mStorageConnection(WrapNotNull(std::move(aStorageConnection))),
-      mFileManager(WrapNotNull(std::move(aFileManager))),
+    MovingNotNull<nsCOMPtr<mozIStorageConnection>> aStorageConnection,
+    MovingNotNull<SafeRefPtr<FileManager>> aFileManager)
+    : mStorageConnection(std::move(aStorageConnection)),
+      mFileManager(std::move(aFileManager)),
       mInReadTransaction(false),
       mInWriteTransaction(false)
 #ifdef DEBUG
       ,
       mDEBUGSavepointCount(0)
 #endif
 {
   AssertIsOnConnectionThread();
-  MOZ_ASSERT(mStorageConnection);
   MOZ_ASSERT(mFileManager);
 }
 
 DatabaseConnection::~DatabaseConnection() {
   MOZ_ASSERT(!mStorageConnection);
   MOZ_ASSERT(!mFileManager);
   MOZ_ASSERT(!mCachedStatements.Count());
   MOZ_ASSERT(!mUpdateRefcountFunction);
@@ -16423,20 +16400,19 @@ FileManager::FileManager(PersistenceType
                          const nsAString& aDatabaseName, bool aEnforcingQuota)
     : mPersistenceType(aPersistenceType),
       mGroup(aGroup),
       mOrigin(aOrigin),
       mDatabaseName(aDatabaseName),
       mEnforcingQuota(aEnforcingQuota) {}
 
 nsresult FileManager::Init(nsIFile* aDirectory,
-                           mozIStorageConnection* aConnection) {
+                           mozIStorageConnection& aConnection) {
   AssertIsOnIOThread();
   MOZ_ASSERT(aDirectory);
-  MOZ_ASSERT(aConnection);
 
   bool exists;
   nsresult rv = aDirectory->Exists(&exists);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (exists) {
@@ -16498,19 +16474,19 @@ nsresult FileManager::Init(nsIFile* aDir
     rv = journalDirectory->GetPath(journalDirectoryPath);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     mJournalDirectoryPath.init(std::move(journalDirectoryPath));
   }
 
   nsCOMPtr<mozIStorageStatement> stmt;
-  rv = aConnection->CreateStatement(NS_LITERAL_CSTRING("SELECT id, refcount "
-                                                       "FROM file"),
-                                    getter_AddRefs(stmt));
+  rv = aConnection.CreateStatement(NS_LITERAL_CSTRING("SELECT id, refcount "
+                                                      "FROM file"),
+                                   getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   bool hasResult;
   while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
     int64_t id;
     rv = stmt->GetInt64(0, &id);
@@ -16717,19 +16693,19 @@ nsresult FileManager::InitDirectory(nsIF
     if (hasElements) {
       auto connectionOrErr = CreateStorageConnection(
           aDatabaseFile, aDirectory, VoidString(), aOrigin,
           /* aDirectoryLockId */ -1, aTelemetryId);
       if (NS_WARN_IF(connectionOrErr.isErr())) {
         return connectionOrErr.unwrapErr();
       }
 
-      auto connection = connectionOrErr.unwrap();
-
-      mozStorageTransaction transaction(connection, false);
+      auto connection = connectionOrErr.unwrap().unwrap();
+
+      mozStorageTransaction transaction(connection.get(), false);
 
       rv = connection->ExecuteSimpleSQL(
           NS_LITERAL_CSTRING("CREATE VIRTUAL TABLE fs USING filesystem;"));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
       nsCOMPtr<mozIStorageStatement> stmt;
@@ -18649,109 +18625,104 @@ void DatabaseMaintenance::PerformMainten
   MOZ_ASSERT(mMaintenance);
   MOZ_ASSERT(mMaintenance->StartTime());
   MOZ_ASSERT(mDirectoryLock);
   MOZ_ASSERT(!mDatabasePath.IsEmpty());
   MOZ_ASSERT(!mGroup.IsEmpty());
   MOZ_ASSERT(!mOrigin.IsEmpty());
 
   class MOZ_STACK_CLASS AutoClose final {
-    nsCOMPtr<mozIStorageConnection> mConnection;
+    NotNull<nsCOMPtr<mozIStorageConnection>> mConnection;
 
    public:
-    explicit AutoClose(mozIStorageConnection* aConnection)
-        : mConnection(aConnection) {
-      MOZ_ASSERT(aConnection);
-    }
-
-    ~AutoClose() {
-      MOZ_ASSERT(mConnection);
-
-      MOZ_ALWAYS_SUCCEEDS(mConnection->Close());
-    }
+    explicit AutoClose(
+        MovingNotNull<nsCOMPtr<mozIStorageConnection>> aConnection)
+        : mConnection(std::move(aConnection)) {}
+
+    ~AutoClose() { MOZ_ALWAYS_SUCCEEDS(mConnection->Close()); }
   };
 
   if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
       mMaintenance->IsAborted()) {
     return;
   }
 
   const nsCOMPtr<nsIFile> databaseFile = GetFileForPath(mDatabasePath);
   MOZ_ASSERT(databaseFile);
 
   auto connectionOrErr = GetStorageConnection(*databaseFile, mDirectoryLockId,
                                               TelemetryIdForFile(databaseFile));
   if (NS_WARN_IF(connectionOrErr.isErr())) {
     return;
   }
 
-  const auto connection = connectionOrErr.unwrap();
+  const auto connection = connectionOrErr.unwrap().unwrap();
 
   AutoClose autoClose(connection);
 
   AutoProgressHandler progressHandler(mMaintenance);
   if (NS_WARN_IF(NS_FAILED(progressHandler.Register(connection)))) {
     return;
   }
 
   bool databaseIsOk;
-  nsresult rv = CheckIntegrity(connection, &databaseIsOk);
+  nsresult rv = CheckIntegrity(*connection, &databaseIsOk);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   if (NS_WARN_IF(!databaseIsOk)) {
     // XXX Handle this somehow! Probably need to clear all storage for the
     //     origin. Needs followup.
     MOZ_ASSERT(false, "Database corruption detected!");
     return;
   }
 
   MaintenanceAction maintenanceAction;
-  rv = DetermineMaintenanceAction(connection, databaseFile, &maintenanceAction);
+  rv =
+      DetermineMaintenanceAction(*connection, databaseFile, &maintenanceAction);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   switch (maintenanceAction) {
     case MaintenanceAction::Nothing:
       break;
 
     case MaintenanceAction::IncrementalVacuum:
-      IncrementalVacuum(connection);
+      IncrementalVacuum(*connection);
       break;
 
     case MaintenanceAction::FullVacuum:
-      FullVacuum(connection, databaseFile);
+      FullVacuum(*connection, databaseFile);
       break;
 
     default:
       MOZ_CRASH("Unknown MaintenanceAction!");
   }
 }
 
-nsresult DatabaseMaintenance::CheckIntegrity(mozIStorageConnection* aConnection,
+nsresult DatabaseMaintenance::CheckIntegrity(mozIStorageConnection& aConnection,
                                              bool* aOk) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
-  MOZ_ASSERT(aConnection);
   MOZ_ASSERT(aOk);
 
   if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
       mMaintenance->IsAborted()) {
     return NS_ERROR_ABORT;
   }
 
   nsresult rv;
 
   // First do a full integrity_check. Scope statements tightly here because
   // later operations require zero live statements.
   {
     nsCOMPtr<mozIStorageStatement> stmt;
-    rv = aConnection->CreateStatement(
+    rv = aConnection.CreateStatement(
         NS_LITERAL_CSTRING("PRAGMA integrity_check(1);"), getter_AddRefs(stmt));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     bool hasResult;
     rv = stmt->ExecuteStep(&hasResult);
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -18772,17 +18743,17 @@ nsresult DatabaseMaintenance::CheckInteg
     }
   }
 
   // Now enable and check for foreign key constraints.
   {
     int32_t foreignKeysWereEnabled;
     {
       nsCOMPtr<mozIStorageStatement> stmt;
-      rv = aConnection->CreateStatement(
+      rv = aConnection.CreateStatement(
           NS_LITERAL_CSTRING("PRAGMA foreign_keys;"), getter_AddRefs(stmt));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
       bool hasResult;
       rv = stmt->ExecuteStep(&hasResult);
       if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -18793,27 +18764,27 @@ nsresult DatabaseMaintenance::CheckInteg
 
       rv = stmt->GetInt32(0, &foreignKeysWereEnabled);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     if (!foreignKeysWereEnabled) {
-      rv = aConnection->ExecuteSimpleSQL(
+      rv = aConnection.ExecuteSimpleSQL(
           NS_LITERAL_CSTRING("PRAGMA foreign_keys = ON;"));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     bool foreignKeyError;
     {
       nsCOMPtr<mozIStorageStatement> stmt;
-      rv = aConnection->CreateStatement(
+      rv = aConnection.CreateStatement(
           NS_LITERAL_CSTRING("PRAGMA foreign_key_check;"),
           getter_AddRefs(stmt));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
       rv = stmt->ExecuteStep(&foreignKeyError);
       if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -18822,68 +18793,67 @@ nsresult DatabaseMaintenance::CheckInteg
     }
 
     if (!foreignKeysWereEnabled) {
       nsAutoCString stmtSQL;
       stmtSQL.AssignLiteral("PRAGMA foreign_keys = ");
       stmtSQL.AppendLiteral("OFF");
       stmtSQL.Append(';');
 
-      rv = aConnection->ExecuteSimpleSQL(stmtSQL);
+      rv = aConnection.ExecuteSimpleSQL(stmtSQL);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     if (foreignKeyError) {
       *aOk = false;
       return NS_OK;
     }
   }
 
   *aOk = true;
   return NS_OK;
 }
 
 nsresult DatabaseMaintenance::DetermineMaintenanceAction(
-    mozIStorageConnection* aConnection, nsIFile* aDatabaseFile,
+    mozIStorageConnection& aConnection, nsIFile* aDatabaseFile,
     MaintenanceAction* aMaintenanceAction) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
-  MOZ_ASSERT(aConnection);
   MOZ_ASSERT(aDatabaseFile);
   MOZ_ASSERT(aMaintenanceAction);
 
   if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
       mMaintenance->IsAborted()) {
     return NS_ERROR_ABORT;
   }
 
   int32_t schemaVersion;
-  nsresult rv = aConnection->GetSchemaVersion(&schemaVersion);
+  nsresult rv = aConnection.GetSchemaVersion(&schemaVersion);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Don't do anything if the schema version is less than 18; before that
   // version no databases had |auto_vacuum == INCREMENTAL| set and we didn't
   // track the values needed for the heuristics below.
   if (schemaVersion < MakeSchemaVersion(18, 0)) {
     *aMaintenanceAction = MaintenanceAction::Nothing;
     return NS_OK;
   }
 
   // This method shouldn't make any permanent changes to the database, so make
   // sure everything gets rolled back when we leave.
-  mozStorageTransaction transaction(aConnection,
+  mozStorageTransaction transaction(&aConnection,
                                     /* aCommitOnComplete */ false);
 
   // Check to see when we last vacuumed this database.
   nsCOMPtr<mozIStorageStatement> stmt;
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("SELECT last_vacuum_time, last_vacuum_size "
                          "FROM database;"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   bool hasResult;
@@ -18923,26 +18893,26 @@ nsresult DatabaseMaintenance::DetermineM
     return NS_OK;
   }
 
   // It has been more than a week since the database was vacuumed, so gather
   // statistics on its usage to see if vacuuming is worthwhile.
 
   // Create a temporary copy of the dbstat table to speed up the queries that
   // come later.
-  rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
+  rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING(
       "CREATE VIRTUAL TABLE __stats__ USING dbstat;"
       "CREATE TEMP TABLE __temp_stats__ AS SELECT * FROM __stats__;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Calculate the percentage of the database pages that are not in contiguous
   // order.
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING(
           "SELECT SUM(__ts1__.pageno != __ts2__.pageno + 1) * 100.0 / COUNT(*) "
           "FROM __temp_stats__ AS __ts1__, __temp_stats__ AS __ts2__ "
           "WHERE __ts1__.name = __ts2__.name "
           "AND __ts1__.rowid = __ts2__.rowid + 1;"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
@@ -18979,18 +18949,18 @@ nsresult DatabaseMaintenance::DetermineM
   if (currentFileSize <= lastVacuumSize ||
       (((currentFileSize - lastVacuumSize) * 100 / currentFileSize) <
        kPercentFileSizeGrowthThreshold)) {
     *aMaintenanceAction = MaintenanceAction::IncrementalVacuum;
     return NS_OK;
   }
 
   // See if there are any free pages that we can reclaim.
-  rv = aConnection->CreateStatement(
-      NS_LITERAL_CSTRING("PRAGMA freelist_count;"), getter_AddRefs(stmt));
+  rv = aConnection.CreateStatement(NS_LITERAL_CSTRING("PRAGMA freelist_count;"),
+                                   getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = stmt->ExecuteStep(&hasResult);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
@@ -19008,17 +18978,17 @@ nsresult DatabaseMaintenance::DetermineM
   // If we have too many free pages then we should try an incremental vacuum. If
   // that causes too much fragmentation then we'll try a full vacuum later.
   if (freelistCount > kMaxFreelistThreshold) {
     *aMaintenanceAction = MaintenanceAction::IncrementalVacuum;
     return NS_OK;
   }
 
   // Calculate the percentage of unused bytes on pages in the database.
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("SELECT SUM(unused) * 100.0 / SUM(pgsize) "
                          "FROM __temp_stats__;"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = stmt->ExecuteStep(&hasResult);
@@ -19039,46 +19009,44 @@ nsresult DatabaseMaintenance::DetermineM
 
   *aMaintenanceAction = percentUnused >= kPercentUnusedThreshold
                             ? MaintenanceAction::FullVacuum
                             : MaintenanceAction::IncrementalVacuum;
   return NS_OK;
 }
 
 void DatabaseMaintenance::IncrementalVacuum(
-    mozIStorageConnection* aConnection) {
+    mozIStorageConnection& aConnection) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
-  MOZ_ASSERT(aConnection);
 
   if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
       mMaintenance->IsAborted()) {
     return;
   }
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(
+  nsresult rv = aConnection.ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("PRAGMA incremental_vacuum;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 }
 
-void DatabaseMaintenance::FullVacuum(mozIStorageConnection* aConnection,
+void DatabaseMaintenance::FullVacuum(mozIStorageConnection& aConnection,
                                      nsIFile* aDatabaseFile) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
-  MOZ_ASSERT(aConnection);
   MOZ_ASSERT(aDatabaseFile);
 
   if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
       mMaintenance->IsAborted()) {
     return;
   }
 
-  nsresult rv = aConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING("VACUUM;"));
+  nsresult rv = aConnection.ExecuteSimpleSQL(NS_LITERAL_CSTRING("VACUUM;"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   PRTime vacuumTime = PR_Now();
   MOZ_ASSERT(vacuumTime > 0);
 
   int64_t fileSize;
@@ -19087,17 +19055,17 @@ void DatabaseMaintenance::FullVacuum(moz
     return;
   }
 
   MOZ_ASSERT(fileSize > 0);
 
   nsCOMPtr<mozIStorageStatement> stmt;
   // The parameter names are not used, parameters are bound by index only
   // locally in the same function.
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("UPDATE database "
                          "SET last_vacuum_time = :time"
                          ", last_vacuum_size = :size;"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
@@ -19146,45 +19114,45 @@ DatabaseMaintenance::Run() {
   } else {
     RunOnConnectionThread();
   }
 
   return NS_OK;
 }
 
 nsresult DatabaseMaintenance::AutoProgressHandler::Register(
-    mozIStorageConnection* aConnection) {
+    NotNull<mozIStorageConnection*> aConnection) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
-  MOZ_ASSERT(aConnection);
 
   // We want to quickly bail out of any operation if the user becomes active, so
   // use a small granularity here since database performance isn't critical.
   static const int32_t kProgressGranularity = 50;
 
   nsCOMPtr<mozIStorageProgressHandler> oldHandler;
   nsresult rv = aConnection->SetProgressHandler(kProgressGranularity, this,
                                                 getter_AddRefs(oldHandler));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   MOZ_ASSERT(!oldHandler);
-  mConnection = aConnection;
+  mConnection.init(aConnection);
 
   return NS_OK;
 }
 
 void DatabaseMaintenance::AutoProgressHandler::Unregister() {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
   MOZ_ASSERT(mConnection);
 
   nsCOMPtr<mozIStorageProgressHandler> oldHandler;
-  nsresult rv = mConnection->RemoveProgressHandler(getter_AddRefs(oldHandler));
+  nsresult rv =
+      mConnection->get()->RemoveProgressHandler(getter_AddRefs(oldHandler));
   Unused << NS_WARN_IF(NS_FAILED(rv));
 
   MOZ_ASSERT_IF(NS_SUCCEEDED(rv), oldHandler == this);
 }
 
 NS_IMETHODIMP_(MozExternalRefCountType)
 DatabaseMaintenance::AutoProgressHandler::AddRef() {
   NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler);
@@ -19207,18 +19175,17 @@ DatabaseMaintenance::AutoProgressHandler
 
 NS_IMPL_QUERY_INTERFACE(DatabaseMaintenance::AutoProgressHandler,
                         mozIStorageProgressHandler)
 
 NS_IMETHODIMP
 DatabaseMaintenance::AutoProgressHandler::OnProgress(
     mozIStorageConnection* aConnection, bool* _retval) {
   NS_ASSERT_OWNINGTHREAD(DatabaseMaintenance::AutoProgressHandler);
-  MOZ_ASSERT(aConnection);
-  MOZ_ASSERT(mConnection == aConnection);
+  MOZ_ASSERT(*mConnection == aConnection);
   MOZ_ASSERT(_retval);
 
   *_retval = QuotaClient::IsShuttingDownOnNonBackgroundThread() ||
              mMaintenance->IsAborted();
 
   return NS_OK;
 }
 
@@ -19226,17 +19193,17 @@ DatabaseMaintenance::AutoProgressHandler
  * Local class implementations
  ******************************************************************************/
 
 NS_IMPL_ISUPPORTS(CompressDataBlobsFunction, mozIStorageFunction)
 NS_IMPL_ISUPPORTS(EncodeKeysFunction, mozIStorageFunction)
 NS_IMPL_ISUPPORTS(StripObsoleteOriginAttributesFunction, mozIStorageFunction);
 
 nsresult UpgradeFileIdsFunction::Init(nsIFile* aFMDirectory,
-                                      mozIStorageConnection* aConnection) {
+                                      mozIStorageConnection& aConnection) {
   // This file manager doesn't need real origin info, etc. The only purpose is
   // to store file ids without adding more complexity or code duplication.
   auto fileManager =
       MakeSafeRefPtr<FileManager>(PERSISTENCE_TYPE_INVALID, EmptyCString(),
                                   EmptyCString(), EmptyString(), false);
 
   nsresult rv = fileManager->Init(aFMDirectory, aConnection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -20143,17 +20110,16 @@ nsresult DatabaseOperationBase::ObjectSt
 
 NS_IMPL_ISUPPORTS_INHERITED(DatabaseOperationBase, Runnable,
                             mozIStorageProgressHandler)
 
 NS_IMETHODIMP
 DatabaseOperationBase::OnProgress(mozIStorageConnection* aConnection,
                                   bool* _retval) {
   MOZ_ASSERT(!IsOnBackgroundThread());
-  MOZ_ASSERT(aConnection);
   MOZ_ASSERT(_retval);
 
   // This is intentionally racy.
   *_retval = QuotaClient::IsShuttingDownOnNonBackgroundThread() ||
              !OperationMayProceed();
   return NS_OK;
 }
 
@@ -21367,25 +21333,25 @@ nsresult OpenDatabaseOp::DoDatabaseWork(
 
   auto connectionOrErr =
       CreateStorageConnection(*dbFile, *fmDirectory, databaseName, mOrigin,
                               mDirectoryLockId, mTelemetryId);
   if (NS_WARN_IF(connectionOrErr.isErr())) {
     return connectionOrErr.unwrapErr();
   }
 
-  auto connection = connectionOrErr.unwrap();
+  auto connection = connectionOrErr.unwrap().unwrap();
 
   AutoSetProgressHandler asph;
   rv = asph.Register(*connection, this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = LoadDatabaseInformation(connection);
+  rv = LoadDatabaseInformation(*connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   MOZ_ASSERT(mMetadata->mNextObjectStoreId > mMetadata->mObjectStores.Count());
   MOZ_ASSERT(mMetadata->mNextIndexId > 0);
 
   // See if we need to do a versionchange transaction
@@ -21410,17 +21376,17 @@ nsresult OpenDatabaseOp::DoDatabaseWork(
   MOZ_ASSERT(mgr);
 
   SafeRefPtr<FileManager> fileManager =
       mgr->GetFileManager(persistenceType, mOrigin, databaseName);
   if (!fileManager) {
     fileManager = MakeSafeRefPtr<FileManager>(persistenceType, mGroup, mOrigin,
                                               databaseName, mEnforcingQuota);
 
-    rv = fileManager->Init(fmDirectory, connection);
+    rv = fileManager->Init(fmDirectory, *connection);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     mgr->AddFileManager(fileManager.clonePtr());
   }
 
   mFileManager = std::move(fileManager);
@@ -21441,24 +21407,23 @@ nsresult OpenDatabaseOp::DoDatabaseWork(
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 nsresult OpenDatabaseOp::LoadDatabaseInformation(
-    mozIStorageConnection* aConnection) {
-  AssertIsOnIOThread();
-  MOZ_ASSERT(aConnection);
+    mozIStorageConnection& aConnection) {
+  AssertIsOnIOThread();
   MOZ_ASSERT(mMetadata);
 
   // Load version information.
   nsCOMPtr<mozIStorageStatement> stmt;
-  nsresult rv = aConnection->CreateStatement(
+  nsresult rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("SELECT name, origin, version "
                          "FROM database"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   bool hasResult;
@@ -21498,17 +21463,17 @@ nsresult OpenDatabaseOp::LoadDatabaseInf
     return rv;
   }
 
   mMetadata->mCommonMetadata.version() = uint64_t(version);
 
   ObjectStoreTable& objectStores = mMetadata->mObjectStores;
 
   // Load object store names and ids.
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING("SELECT id, auto_increment, name, key_path "
                          "FROM object_store"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   Maybe<nsTHashtable<nsUint64HashKey>> usedIds;
@@ -21603,17 +21568,17 @@ nsresult OpenDatabaseOp::LoadDatabaseInf
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   usedIds.reset();
   usedNames.reset();
 
   // Load index information
-  rv = aConnection->CreateStatement(
+  rv = aConnection.CreateStatement(
       NS_LITERAL_CSTRING(
           "SELECT "
           "id, object_store_id, name, key_path, unique_index, multientry, "
           "locale, is_auto_locale "
           "FROM object_store_index"),
       getter_AddRefs(stmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
@@ -21767,34 +21732,34 @@ nsresult OpenDatabaseOp::LoadDatabaseInf
   mMetadata->mNextObjectStoreId = lastObjectStoreId + 1;
   mMetadata->mNextIndexId = lastIndexId + 1;
 
   return NS_OK;
 }
 
 /* static */
 nsresult OpenDatabaseOp::UpdateLocaleAwareIndex(
-    mozIStorageConnection* aConnection, const IndexMetadata& aIndexMetadata,
+    mozIStorageConnection& aConnection, const IndexMetadata& aIndexMetadata,
     const nsCString& aLocale) {
   nsresult rv;
 
   nsCString indexTable;
   if (aIndexMetadata.unique()) {
     indexTable.AssignLiteral("unique_index_data");
   } else {
     indexTable.AssignLiteral("index_data");
   }
 
   // The parameter names are not used, parameters are bound by index only
   // locally in the same function.
   nsCString readQuery =
       NS_LITERAL_CSTRING("SELECT value, object_data_key FROM ") + indexTable +
       NS_LITERAL_CSTRING(" WHERE index_id = :index_id");
   nsCOMPtr<mozIStorageStatement> readStmt;
-  rv = aConnection->CreateStatement(readQuery, getter_AddRefs(readStmt));
+  rv = aConnection.CreateStatement(readQuery, getter_AddRefs(readStmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = readStmt->BindInt64ByIndex(0, aIndexMetadata.id());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
@@ -21808,17 +21773,17 @@ nsresult OpenDatabaseOp::UpdateLocaleAwa
       nsCString writeQuery =
           NS_LITERAL_CSTRING("UPDATE ") + indexTable +
           NS_LITERAL_CSTRING("SET value_locale = :") +
           kStmtParamNameValueLocale +
           NS_LITERAL_CSTRING(" WHERE index_id = :") + kStmtParamNameIndexId +
           NS_LITERAL_CSTRING(" AND value = :") + kStmtParamNameValue +
           NS_LITERAL_CSTRING(" AND object_data_key = :") +
           kStmtParamNameObjectDataKey;
-      rv = aConnection->CreateStatement(writeQuery, getter_AddRefs(writeStmt));
+      rv = aConnection.CreateStatement(writeQuery, getter_AddRefs(writeStmt));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     mozStorageStatementScoper scoper(writeStmt);
     rv = writeStmt->BindInt64ByName(kStmtParamNameIndexId, aIndexMetadata.id());
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -21867,17 +21832,17 @@ nsresult OpenDatabaseOp::UpdateLocaleAwa
   }
 
   // The parameter names are not used, parameters are bound by index only
   // locally in the same function.
   nsCString metaQuery = NS_LITERAL_CSTRING(
       "UPDATE object_store_index SET "
       "locale = :locale WHERE id = :id");
   nsCOMPtr<mozIStorageStatement> metaStmt;
-  rv = aConnection->CreateStatement(metaQuery, getter_AddRefs(metaStmt));
+  rv = aConnection.CreateStatement(metaQuery, getter_AddRefs(metaStmt));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsString locale;
   CopyASCIItoUTF16(aLocale, locale);
   rv = metaStmt->BindStringByIndex(0, locale);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -22485,17 +22450,17 @@ void DeleteDatabaseOp::LoadPreviousVersi
     return;
   }
 
   auto connectionOrErr = OpenDatabaseAndHandleBusy(*ss, aDatabaseFile);
   if (NS_WARN_IF(connectionOrErr.isErr())) {
     return;
   }
 
-  const auto connection = connectionOrErr.unwrap();
+  const auto connection = connectionOrErr.unwrap().unwrap();
 
 #ifdef DEBUG
   {
     nsCOMPtr<mozIStorageStatement> stmt;
     rv = connection->CreateStatement(NS_LITERAL_CSTRING("SELECT name "
                                                         "FROM database"),
                                      getter_AddRefs(stmt));
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -26958,17 +26923,16 @@ nsresult CommonOpenOpHelper<CursorType>:
                                 optPreviousKey);
 }
 
 nsresult OpenOpHelper<IDBCursorType::ObjectStore>::DoDatabaseWork(
     DatabaseConnection* aConnection) {
   MOZ_ASSERT(aConnection);
   aConnection->AssertIsOnConnectionThread();
   MOZ_ASSERT(GetCursor().mObjectStoreId);
-  MOZ_ASSERT(GetCursor().mFileManager);
 
   AUTO_PROFILER_LABEL("Cursor::OpenOp::DoObjectStoreDatabaseWork", DOM);
 
   const bool usingKeyRange = GetOptionalKeyRange().isSome();
 
   nsCString queryStart = NS_LITERAL_CSTRING("SELECT ") + kColumnNameKey +
                          NS_LITERAL_CSTRING(
                              ", file_ids, data "
--- a/dom/indexedDB/FileManager.h
+++ b/dom/indexedDB/FileManager.h
@@ -63,17 +63,17 @@ class FileManager final : public FileMan
   const nsACString& Group() const { return mGroup; }
 
   const nsACString& Origin() const { return mOrigin; }
 
   const nsAString& DatabaseName() const { return mDatabaseName; }
 
   bool EnforcingQuota() const { return mEnforcingQuota; }
 
-  nsresult Init(nsIFile* aDirectory, mozIStorageConnection* aConnection);
+  nsresult Init(nsIFile* aDirectory, mozIStorageConnection& aConnection);
 
   [[nodiscard]] nsCOMPtr<nsIFile> GetDirectory();
 
   [[nodiscard]] nsCOMPtr<nsIFile> GetCheckedDirectory();
 
   [[nodiscard]] nsCOMPtr<nsIFile> GetJournalDirectory();
 
   [[nodiscard]] nsCOMPtr<nsIFile> EnsureJournalDirectory();