Bug 1600283 - Remove uses of plain pointers. r=#dom-workers-and-storage draft
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 04 Dec 2019 16:49:52 +0000
changeset 2516001 d177bd8ff076c8dcd22dd8eeb54ff4ff4a6d3b6d
parent 2516000 3cd460937c359d6e699cc038f4cc223b58c98ef4
child 2516002 ed3d43b1b88aad10373376230a507a8d7b6d9835
push id460090
push userreviewbot
push dateWed, 04 Dec 2019 16:51:29 +0000
treeherdertry@35d310cdd9cf [default view] [failures only]
bugs1600283
milestone73.0a1
Bug 1600283 - Remove uses of plain pointers. r=#dom-workers-and-storage Differential Revision: https://phabricator.services.mozilla.com/D55506 Differential Diff: PHID-DIFF-vtmi775oxxor2tkdws4j
dom/indexedDB/ActorsParent.cpp
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -4071,32 +4071,34 @@ nsresult SetJournalMode(mozIStorageConne
 
 template <class FileOrURLType>
 struct StorageOpenTraits;
 
 template <>
 struct StorageOpenTraits<nsIFileURL*> {
   static nsresult Open(mozIStorageService* aStorageService,
                        nsIFileURL* aFileURL,
-                       mozIStorageConnection** aConnection) {
-    return aStorageService->OpenDatabaseWithFileURL(aFileURL, aConnection);
+                       nsCOMPtr<mozIStorageConnection>* aConnection) {
+    return aStorageService->OpenDatabaseWithFileURL(
+        aFileURL, getter_AddRefs(*aConnection));
   }
 
 #ifdef DEBUG
   static void GetPath(nsIFileURL* aFileURL, nsCString& aPath) {
     MOZ_ALWAYS_SUCCEEDS(aFileURL->GetFileName(aPath));
   }
 #endif
 };
 
 template <>
 struct StorageOpenTraits<nsIFile*> {
   static nsresult Open(mozIStorageService* aStorageService, nsIFile* aFile,
-                       mozIStorageConnection** aConnection) {
-    return aStorageService->OpenUnsharedDatabase(aFile, aConnection);
+                       nsCOMPtr<mozIStorageConnection>* aConnection) {
+    return aStorageService->OpenUnsharedDatabase(aFile,
+                                                 getter_AddRefs(*aConnection));
   }
 
 #ifdef DEBUG
   static void GetPath(nsIFile* aFile, nsCString& aPath) {
     nsString path;
     MOZ_ALWAYS_SUCCEEDS(aFile->GetPath(path));
 
     LossyCopyUTF16toASCII(path, aPath);
@@ -4104,28 +4106,28 @@ struct StorageOpenTraits<nsIFile*> {
 #endif
 };
 
 template <template <class> class SmartPtr, class FileOrURLType>
 struct StorageOpenTraits<SmartPtr<FileOrURLType>>
     : public StorageOpenTraits<FileOrURLType*> {};
 
 template <class FileOrURLType>
-nsresult OpenDatabaseAndHandleBusy(mozIStorageService* aStorageService,
-                                   FileOrURLType aFileOrURL,
-                                   mozIStorageConnection** aConnection) {
+nsresult OpenDatabaseAndHandleBusy(
+    mozIStorageService* aStorageService, FileOrURLType aFileOrURL,
+    nsCOMPtr<mozIStorageConnection>* aConnection) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!IsOnBackgroundThread());
   MOZ_ASSERT(aStorageService);
   MOZ_ASSERT(aFileOrURL);
   MOZ_ASSERT(aConnection);
 
   nsCOMPtr<mozIStorageConnection> connection;
-  nsresult rv = StorageOpenTraits<FileOrURLType>::Open(
-      aStorageService, aFileOrURL, getter_AddRefs(connection));
+  nsresult rv = StorageOpenTraits<FileOrURLType>::Open(aStorageService,
+                                                       aFileOrURL, &connection);
 
   if (rv == NS_ERROR_STORAGE_BUSY) {
 #ifdef DEBUG
     {
       nsCString path;
       StorageOpenTraits<FileOrURLType>::GetPath(aFileOrURL, path);
 
       nsPrintfCString message(
@@ -4140,29 +4142,29 @@ nsresult OpenDatabaseAndHandleBusy(mozIS
     // Another thread must be checkpointing the WAL. Wait up to 10 seconds for
     // that to complete.
     const TimeStamp start = TimeStamp::NowLoRes();
 
     while (true) {
       PR_Sleep(PR_MillisecondsToInterval(100));
 
       rv = StorageOpenTraits<FileOrURLType>::Open(aStorageService, aFileOrURL,
-                                                  getter_AddRefs(connection));
+                                                  &connection);
       if (rv != NS_ERROR_STORAGE_BUSY ||
           TimeStamp::NowLoRes() - start > TimeDuration::FromSeconds(10)) {
         break;
       }
     }
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  connection.forget(aConnection);
+  *aConnection = std::move(connection);
   return NS_OK;
 }
 
 nsresult CreateStorageConnection(nsIFile* aDBFile, nsIFile* aFMDirectory,
                                  const nsAString& aName,
                                  const nsACString& aOrigin,
                                  int64_t aDirectoryLockId,
                                  uint32_t aTelemetryId,
@@ -4186,17 +4188,17 @@ nsresult CreateStorageConnection(nsIFile
 
   nsCOMPtr<mozIStorageService> ss =
       do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsCOMPtr<mozIStorageConnection> connection;
-  rv = OpenDatabaseAndHandleBusy(ss, dbFileUrl, getter_AddRefs(connection));
+  rv = OpenDatabaseAndHandleBusy(ss, dbFileUrl, &connection);
   if (rv == NS_ERROR_FILE_CORRUPTED) {
     // If we're just opening the database during origin initialization, then
     // we don't want to erase any files. The failure here will fail origin
     // initialization too.
     if (aName.IsVoid()) {
       return rv;
     }
 
@@ -4223,17 +4225,17 @@ nsresult CreateStorageConnection(nsIFile
       }
 
       rv = aFMDirectory->Remove(true);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
-    rv = OpenDatabaseAndHandleBusy(ss, dbFileUrl, getter_AddRefs(connection));
+    rv = OpenDatabaseAndHandleBusy(ss, dbFileUrl, &connection);
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = SetDefaultPragmas(connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -4655,17 +4657,17 @@ nsresult GetStorageConnection(nsIFile* a
 
   nsCOMPtr<mozIStorageService> ss =
       do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsCOMPtr<mozIStorageConnection> connection;
-  rv = OpenDatabaseAndHandleBusy(ss, dbFileUrl, getter_AddRefs(connection));
+  rv = OpenDatabaseAndHandleBusy(ss, dbFileUrl, &connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = SetDefaultPragmas(connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
@@ -21682,17 +21684,17 @@ void DeleteDatabaseOp::LoadPreviousVersi
 
   nsCOMPtr<mozIStorageService> ss =
       do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   nsCOMPtr<mozIStorageConnection> connection;
-  rv = OpenDatabaseAndHandleBusy(ss, aDatabaseFile, getter_AddRefs(connection));
+  rv = OpenDatabaseAndHandleBusy(ss, aDatabaseFile, &connection);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
 #ifdef DEBUG
   {
     nsCOMPtr<mozIStorageStatement> stmt;
     rv = connection->CreateStatement(NS_LITERAL_CSTRING("SELECT name "