Bug 1651016 - Convert remaining NS_ENSURE_SUCCESS to QM_TRY in ActorsParent.cpp; r=dom-workers-and-storage-reviewers,ttung,sg
☠☠ backed out by ded0022e1004 ☠ ☠
authorJan Varga <jvarga@mozilla.com>
Thu, 23 Jul 2020 09:18:05 +0000
changeset 541804 2f4529e62cd3bf1d3e6d8fec16006fc1180d8e6e
parent 541803 8f2aa854a083d3b5dd6b32b72a7cb6241e22c749
child 541805 aed04f32eb91b2d98e1ad6b2344028b29bd9b63a
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-workers-and-storage-reviewers, ttung, sg
bugs1651016
milestone80.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 1651016 - Convert remaining NS_ENSURE_SUCCESS to QM_TRY in ActorsParent.cpp; r=dom-workers-and-storage-reviewers,ttung,sg Differential Revision: https://phabricator.services.mozilla.com/D83958
dom/quota/ActorsParent.cpp
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -4701,23 +4701,22 @@ already_AddRefed<QuotaObject> QuotaManag
     *aFileSizeOut = 0;
   }
 
   if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
     return nullptr;
   }
 
   nsString path;
-  nsresult rv = aFile->GetPath(path);
-  NS_ENSURE_SUCCESS(rv, nullptr);
+  QM_TRY(aFile->GetPath(path), nullptr);
 
 #ifdef DEBUG
   nsCOMPtr<nsIFile> directory;
-  rv = GetDirectoryForOrigin(aPersistenceType, aOrigin,
-                             getter_AddRefs(directory));
+  nsresult rv = GetDirectoryForOrigin(aPersistenceType, aOrigin,
+                                      getter_AddRefs(directory));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return nullptr;
   }
 
   nsAutoString clientType;
   bool ok = Client::TypeToText(aClientType, clientType, fallible);
   if (NS_WARN_IF(!ok)) {
     return nullptr;
@@ -4736,22 +4735,20 @@ already_AddRefed<QuotaObject> QuotaManag
 
   MOZ_ASSERT(StringBeginsWith(path, directoryPath));
 #endif
 
   int64_t fileSize;
 
   if (aFileSize == -1) {
     bool exists;
-    rv = aFile->Exists(&exists);
-    NS_ENSURE_SUCCESS(rv, nullptr);
+    QM_TRY(aFile->Exists(&exists), nullptr);
 
     if (exists) {
-      rv = aFile->GetFileSize(&fileSize);
-      NS_ENSURE_SUCCESS(rv, nullptr);
+      QM_TRY(aFile->GetFileSize(&fileSize), nullptr);
     } else {
       fileSize = 0;
     }
   } else {
     fileSize = aFileSize;
   }
 
   RefPtr<QuotaObject> result;
@@ -4895,18 +4892,17 @@ nsresult QuotaManager::GetDirectoryForOr
     return directoryOrErr.unwrapErr();
   }
 
   nsCOMPtr<nsIFile> directory = directoryOrErr.unwrap();
 
   nsAutoCString originSanitized(aASCIIOrigin);
   SanitizeOriginString(originSanitized);
 
-  nsresult rv = directory->Append(NS_ConvertASCIItoUTF16(originSanitized));
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(directory->Append(NS_ConvertASCIItoUTF16(originSanitized)));
 
   directory.forget(aDirectory);
   return NS_OK;
 }
 
 nsresult QuotaManager::RestoreDirectoryMetadata2(nsIFile* aDirectory,
                                                  bool aPersistent) {
   AssertIsOnIOThread();
@@ -4929,27 +4925,25 @@ nsresult QuotaManager::GetDirectoryMetad
     nsACString& aSuffix, nsACString& aGroup, nsACString& aOrigin) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(aDirectory);
   MOZ_ASSERT(aTimestamp);
   MOZ_ASSERT(aPersisted);
   MOZ_ASSERT(mStorageConnection);
 
   nsCOMPtr<nsIBinaryInputStream> binaryStream;
-  nsresult rv =
-      GetBinaryInputStream(aDirectory, nsLiteralString(METADATA_V2_FILE_NAME),
-                           getter_AddRefs(binaryStream));
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(GetBinaryInputStream(aDirectory,
+                              nsLiteralString(METADATA_V2_FILE_NAME),
+                              getter_AddRefs(binaryStream)));
 
   uint64_t timestamp;
-  rv = binaryStream->Read64(&timestamp);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(binaryStream->Read64(&timestamp));
 
   bool persisted;
-  rv = binaryStream->ReadBoolean(&persisted);
+  nsresult rv = binaryStream->ReadBoolean(&persisted);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   uint32_t reservedData1;
   rv = binaryStream->Read32(&reservedData1);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
@@ -4963,22 +4957,20 @@ nsresult QuotaManager::GetDirectoryMetad
 
   nsCString suffix;
   rv = binaryStream->ReadCString(suffix);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsCString group;
-  rv = binaryStream->ReadCString(group);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(binaryStream->ReadCString(group));
 
   nsCString origin;
-  rv = binaryStream->ReadCString(origin);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(binaryStream->ReadCString(origin));
 
   // Currently unused (used to be isApp).
   bool dummy;
   rv = binaryStream->ReadBoolean(&dummy);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
@@ -5347,62 +5339,58 @@ nsresult QuotaManager::InitializeOrigin(
 
 nsresult
 QuotaManager::UpgradeFromIndexedDBDirectoryToPersistentStorageDirectory(
     nsIFile* aIndexedDBDir) {
   AssertIsOnIOThread();
   MOZ_ASSERT(aIndexedDBDir);
 
   bool isDirectory;
-  nsresult rv = aIndexedDBDir->IsDirectory(&isDirectory);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(aIndexedDBDir->IsDirectory(&isDirectory));
 
   if (!isDirectory) {
     NS_WARNING("indexedDB entry is not a directory!");
     return NS_OK;
   }
 
   auto persistentStorageDirOrErr = QM_NewLocalFile(mStoragePath);
   if (NS_WARN_IF(persistentStorageDirOrErr.isErr())) {
     return persistentStorageDirOrErr.unwrapErr();
   }
 
   nsCOMPtr<nsIFile> persistentStorageDir = persistentStorageDirOrErr.unwrap();
 
-  rv = persistentStorageDir->Append(nsLiteralString(PERSISTENT_DIRECTORY_NAME));
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(
+      persistentStorageDir->Append(nsLiteralString(PERSISTENT_DIRECTORY_NAME)));
 
   bool exists;
-  rv = persistentStorageDir->Exists(&exists);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(persistentStorageDir->Exists(&exists));
 
   if (exists) {
     QM_WARNING("Deleting old <profile>/indexedDB directory!");
 
-    rv = aIndexedDBDir->Remove(/* aRecursive */ true);
+    nsresult rv = aIndexedDBDir->Remove(/* aRecursive */ true);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     return NS_OK;
   }
 
   nsCOMPtr<nsIFile> storageDir;
-  rv = persistentStorageDir->GetParent(getter_AddRefs(storageDir));
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(persistentStorageDir->GetParent(getter_AddRefs(storageDir)));
 
   // MoveTo() is atomic if the move happens on the same volume which should
   // be our case, so even if we crash in the middle of the operation nothing
   // breaks next time we try to initialize.
   // However there's a theoretical possibility that the indexedDB directory
   // is on different volume, but it should be rare enough that we don't have
   // to worry about it.
-  rv = aIndexedDBDir->MoveTo(storageDir,
-                             nsLiteralString(PERSISTENT_DIRECTORY_NAME));
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(aIndexedDBDir->MoveTo(storageDir,
+                               nsLiteralString(PERSISTENT_DIRECTORY_NAME)));
 
   return NS_OK;
 }
 
 nsresult
 QuotaManager::UpgradeFromPersistentStorageDirectoryToDefaultStorageDirectory(
     nsIFile* aPersistentStorageDir) {
   AssertIsOnIOThread();
@@ -7422,35 +7410,33 @@ nsresult QuotaManager::GetInfoFromPrinci
   }
 
   if (aPrincipal->GetIsNullPrincipal()) {
     NS_WARNING("IndexedDB not supported from this principal!");
     return NS_ERROR_FAILURE;
   }
 
   nsCString origin;
-  nsresult rv = aPrincipal->GetOrigin(origin);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(aPrincipal->GetOrigin(origin));
 
   if (origin.EqualsLiteral(kChromeOrigin)) {
     NS_WARNING("Non-chrome principal can't use chrome origin!");
     return NS_ERROR_FAILURE;
   }
 
   nsCString suffix;
   aPrincipal->OriginAttributesRef().CreateSuffix(suffix);
 
   if (aSuffix) {
     aSuffix->Assign(suffix);
   }
 
   if (aGroup) {
     nsCString baseDomain;
-    rv = aPrincipal->GetBaseDomain(baseDomain);
-    NS_ENSURE_SUCCESS(rv, rv);
+    QM_TRY(aPrincipal->GetBaseDomain(baseDomain));
 
     MOZ_ASSERT(!baseDomain.IsEmpty());
 
     aGroup->Assign(baseDomain + suffix);
   }
 
   if (aOrigin) {
     aOrigin->Assign(origin);
@@ -7468,18 +7454,17 @@ nsresult QuotaManager::GetInfoFromWindow
   MOZ_ASSERT(aWindow);
 
   nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
   QM_TRY(OkIf(sop), NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
   QM_TRY(OkIf(principal), NS_ERROR_FAILURE);
 
-  nsresult rv = GetInfoFromPrincipal(principal, aSuffix, aGroup, aOrigin);
-  NS_ENSURE_SUCCESS(rv, rv);
+  QM_TRY(GetInfoFromPrincipal(principal, aSuffix, aGroup, aOrigin));
 
   return NS_OK;
 }
 
 // static
 void QuotaManager::GetInfoForChrome(nsACString* aSuffix, nsACString* aGroup,
                                     nsACString* aOrigin) {
   if (aSuffix) {
@@ -7785,21 +7770,21 @@ void QuotaManager::CheckTemporaryStorage
     // If disk space is still low after origin clear, notify storage pressure.
     NotifyStoragePressure(mTemporaryStorageUsage);
   }
 }
 
 void QuotaManager::DeleteFilesForOrigin(PersistenceType aPersistenceType,
                                         const nsACString& aOrigin) {
   nsCOMPtr<nsIFile> directory;
-  nsresult rv = GetDirectoryForOrigin(aPersistenceType, aOrigin,
-                                      getter_AddRefs(directory));
-  NS_ENSURE_SUCCESS_VOID(rv);
-
-  rv = directory->Remove(true);
+  QM_TRY(GetDirectoryForOrigin(aPersistenceType, aOrigin,
+                               getter_AddRefs(directory)),
+         QM_VOID);
+
+  nsresult rv = directory->Remove(true);
   if (rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST &&
       rv != NS_ERROR_FILE_NOT_FOUND && NS_FAILED(rv)) {
     // This should never fail if we've closed all storage connections
     // correctly...
     NS_ERROR("Failed to remove directory!");
   }
 }