Commit 2b070294 authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 1597211 - Use EmplaceBack instead of AppendResult, and use return value...

Bug 1597211 - Use EmplaceBack instead of AppendResult, and use return value rather than output parameter. r=dom-workers-and-storage-reviewers,ytausky

Differential Revision: https://phabricator.services.mozilla.com/D53938

--HG--
extra : moz-landing-system : lando
parent 19bcfd87
...@@ -8658,17 +8658,19 @@ bool GetBaseFilename(const nsAString& aFilename, const nsAString& aSuffix, ...@@ -8658,17 +8658,19 @@ bool GetBaseFilename(const nsAString& aFilename, const nsAString& aSuffix,
return true; return true;
} }
   
nsresult SerializeStructuredCloneFiles( mozilla::Result<nsTArray<SerializedStructuredCloneFile>, nsresult>
PBackgroundParent* aBackgroundActor, Database* aDatabase, SerializeStructuredCloneFiles(PBackgroundParent* aBackgroundActor,
const nsTArray<StructuredCloneFile>& aFiles, bool aForPreprocess, Database* aDatabase,
FallibleTArray<SerializedStructuredCloneFile>& aResult) { const nsTArray<StructuredCloneFile>& aFiles,
bool aForPreprocess) {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aBackgroundActor); MOZ_ASSERT(aBackgroundActor);
MOZ_ASSERT(aDatabase); MOZ_ASSERT(aDatabase);
MOZ_ASSERT(aResult.IsEmpty());
nsTArray<SerializedStructuredCloneFile> result;
   
if (aFiles.IsEmpty()) { if (aFiles.IsEmpty()) {
return NS_OK; return result;
} }
   
FileManager* fileManager = aDatabase->GetFileManager(); FileManager* fileManager = aDatabase->GetFileManager();
...@@ -8676,13 +8678,13 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8676,13 +8678,13 @@ nsresult SerializeStructuredCloneFiles(
nsCOMPtr<nsIFile> directory = fileManager->GetCheckedDirectory(); nsCOMPtr<nsIFile> directory = fileManager->GetCheckedDirectory();
if (NS_WARN_IF(!directory)) { if (NS_WARN_IF(!directory)) {
IDB_REPORT_INTERNAL_ERR(); IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
} }
   
const uint32_t count = aFiles.Length(); const uint32_t count = aFiles.Length();
   
if (NS_WARN_IF(!aResult.SetCapacity(count, fallible))) { if (NS_WARN_IF(!result.SetCapacity(count, fallible))) {
return NS_ERROR_OUT_OF_MEMORY; return Err(NS_ERROR_OUT_OF_MEMORY);
} }
   
for (const StructuredCloneFile& file : aFiles) { for (const StructuredCloneFile& file : aFiles) {
...@@ -8698,7 +8700,7 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8698,7 +8700,7 @@ nsresult SerializeStructuredCloneFiles(
fileId); fileId);
if (NS_WARN_IF(!nativeFile)) { if (NS_WARN_IF(!nativeFile)) {
IDB_REPORT_INTERNAL_ERR(); IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
} }
   
switch (file.mType) { switch (file.mType) {
...@@ -8711,15 +8713,10 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8711,15 +8713,10 @@ nsresult SerializeStructuredCloneFiles(
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
// This can only fail if the child has crashed. // This can only fail if the child has crashed.
IDB_REPORT_INTERNAL_ERR(); IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
} }
   
SerializedStructuredCloneFile* serializedFile = result.EmplaceBack(ipcBlob, StructuredCloneFile::eBlob);
aResult.AppendElement(fallible);
MOZ_ASSERT(serializedFile);
serializedFile->file() = ipcBlob;
serializedFile->type() = StructuredCloneFile::eBlob;
   
aDatabase->MapBlob(ipcBlob, file.mFileInfo); aDatabase->MapBlob(ipcBlob, file.mFileInfo);
break; break;
...@@ -8727,17 +8724,13 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8727,17 +8724,13 @@ nsresult SerializeStructuredCloneFiles(
   
case StructuredCloneFile::eMutableFile: { case StructuredCloneFile::eMutableFile: {
if (aDatabase->IsFileHandleDisabled()) { if (aDatabase->IsFileHandleDisabled()) {
SerializedStructuredCloneFile* file = aResult.AppendElement(fallible); result.EmplaceBack(null_t(), StructuredCloneFile::eMutableFile);
MOZ_ASSERT(file);
file->file() = null_t();
file->type() = StructuredCloneFile::eMutableFile;
} else { } else {
RefPtr<MutableFile> actor = RefPtr<MutableFile> actor =
MutableFile::Create(nativeFile, aDatabase, file.mFileInfo); MutableFile::Create(nativeFile, aDatabase, file.mFileInfo);
if (!actor) { if (!actor) {
IDB_REPORT_INTERNAL_ERR(); IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
} }
   
// Transfer ownership to IPDL. // Transfer ownership to IPDL.
...@@ -8747,14 +8740,10 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8747,14 +8740,10 @@ nsresult SerializeStructuredCloneFiles(
actor, EmptyString(), EmptyString())) { actor, EmptyString(), EmptyString())) {
// This can only fail if the child has crashed. // This can only fail if the child has crashed.
IDB_REPORT_INTERNAL_ERR(); IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
} }
   
SerializedStructuredCloneFile* file = aResult.AppendElement(fallible); result.EmplaceBack(actor.get(), StructuredCloneFile::eMutableFile);
MOZ_ASSERT(file);
file->file() = actor;
file->type() = StructuredCloneFile::eMutableFile;
} }
   
break; break;
...@@ -8762,11 +8751,7 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8762,11 +8751,7 @@ nsresult SerializeStructuredCloneFiles(
   
case StructuredCloneFile::eStructuredClone: { case StructuredCloneFile::eStructuredClone: {
if (!aForPreprocess) { if (!aForPreprocess) {
SerializedStructuredCloneFile* file = aResult.AppendElement(fallible); result.EmplaceBack(null_t(), StructuredCloneFile::eStructuredClone);
MOZ_ASSERT(file);
file->file() = null_t();
file->type() = StructuredCloneFile::eStructuredClone;
} else { } else {
RefPtr<FileBlobImpl> impl = new FileBlobImpl(nativeFile); RefPtr<FileBlobImpl> impl = new FileBlobImpl(nativeFile);
impl->SetFileId(file.mFileInfo->Id()); impl->SetFileId(file.mFileInfo->Id());
...@@ -8777,15 +8762,10 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8777,15 +8762,10 @@ nsresult SerializeStructuredCloneFiles(
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
// This can only fail if the child has crashed. // This can only fail if the child has crashed.
IDB_REPORT_INTERNAL_ERR(); IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
} }
   
SerializedStructuredCloneFile* serializedFile = result.EmplaceBack(ipcBlob, StructuredCloneFile::eStructuredClone);
aResult.AppendElement(fallible);
MOZ_ASSERT(serializedFile);
serializedFile->file() = ipcBlob;
serializedFile->type() = StructuredCloneFile::eStructuredClone;
   
aDatabase->MapBlob(ipcBlob, file.mFileInfo); aDatabase->MapBlob(ipcBlob, file.mFileInfo);
} }
...@@ -8795,17 +8775,12 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8795,17 +8775,12 @@ nsresult SerializeStructuredCloneFiles(
   
case StructuredCloneFile::eWasmBytecode: case StructuredCloneFile::eWasmBytecode:
case StructuredCloneFile::eWasmCompiled: { case StructuredCloneFile::eWasmCompiled: {
SerializedStructuredCloneFile* serializedFile =
aResult.AppendElement(fallible);
MOZ_ASSERT(serializedFile);
// Set file() to null, support for storing WebAssembly.Modules has been // Set file() to null, support for storing WebAssembly.Modules has been
// removed in bug 1469395. Support for de-serialization of // removed in bug 1469395. Support for de-serialization of
// WebAssembly.Modules modules has been removed in bug 1561876. Full // WebAssembly.Modules modules has been removed in bug 1561876. Full
// removal is tracked in bug 1487479. // removal is tracked in bug 1487479.
   
serializedFile->file() = null_t(); result.EmplaceBack(null_t(), file.mType);
serializedFile->type() = file.mType;
   
break; break;
} }
...@@ -8815,7 +8790,7 @@ nsresult SerializeStructuredCloneFiles( ...@@ -8815,7 +8790,7 @@ nsresult SerializeStructuredCloneFiles(
} }
} }
   
return NS_OK; return std::move(result);
} }
   
// Idempotently delete a file, decreasing the quota usage as appropriate. If the // Idempotently delete a file, decreasing the quota usage as appropriate. If the
...@@ -15494,12 +15469,11 @@ void Cursor::SendResponseInternal( ...@@ -15494,12 +15469,11 @@ void Cursor::SendResponseInternal(
MOZ_ASSERT(mDatabase); MOZ_ASSERT(mDatabase);
MOZ_ASSERT(mBackgroundParent); MOZ_ASSERT(mBackgroundParent);
   
FallibleTArray<SerializedStructuredCloneFile> serializedFiles; auto res =
nsresult rv = SerializeStructuredCloneFiles( SerializeStructuredCloneFiles(mBackgroundParent, mDatabase, files,
mBackgroundParent, mDatabase, files, /* aForPreprocess */ false);
/* aForPreprocess */ false, serializedFiles); if (NS_WARN_IF(res.isErr())) {
if (NS_WARN_IF(NS_FAILED(rv))) { aResponse = ClampResultCode(res.inspectErr());
aResponse = ClampResultCode(rv);
break; break;
} }
   
...@@ -15526,7 +15500,7 @@ void Cursor::SendResponseInternal( ...@@ -15526,7 +15500,7 @@ void Cursor::SendResponseInternal(
MOZ_ASSERT(serializedInfo); MOZ_ASSERT(serializedInfo);
MOZ_ASSERT(serializedInfo->files().IsEmpty()); MOZ_ASSERT(serializedInfo->files().IsEmpty());
   
serializedInfo->files().SwapElements(serializedFiles); serializedInfo->files() = res.unwrap();
} }
} }
   
...@@ -24984,17 +24958,15 @@ nsresult ObjectStoreGetRequestOp::ConvertResponse( ...@@ -24984,17 +24958,15 @@ nsresult ObjectStoreGetRequestOp::ConvertResponse(
StructuredCloneReadInfo& aInfo, T& aResult) { StructuredCloneReadInfo& aInfo, T& aResult) {
MoveData(aInfo, aResult); MoveData(aInfo, aResult);
   
FallibleTArray<SerializedStructuredCloneFile> serializedFiles; auto res = SerializeStructuredCloneFiles(mBackgroundParent, mDatabase,
nsresult rv = aInfo.mFiles, aForPreprocess);
SerializeStructuredCloneFiles(mBackgroundParent, mDatabase, aInfo.mFiles, if (NS_WARN_IF(res.isErr())) {
aForPreprocess, serializedFiles); return res.unwrapErr();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
} }
   
MOZ_ASSERT(aResult.files().IsEmpty()); MOZ_ASSERT(aResult.files().IsEmpty());
   
aResult.files().SwapElements(serializedFiles); aResult.files() = res.unwrap();
   
return NS_OK; return NS_OK;
} }
...@@ -25683,18 +25655,17 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse, ...@@ -25683,18 +25655,17 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse,
   
serializedInfo.data().data = std::move(info.mData); serializedInfo.data().data = std::move(info.mData);
   
FallibleTArray<SerializedStructuredCloneFile> serializedFiles; auto res = SerializeStructuredCloneFiles(mBackgroundParent, mDatabase,
nsresult rv = SerializeStructuredCloneFiles( info.mFiles,
mBackgroundParent, mDatabase, info.mFiles, /* aForPreprocess */ false);
/* aForPreprocess */ false, serializedFiles); if (NS_WARN_IF(res.isErr())) {
if (NS_WARN_IF(NS_FAILED(rv))) { aResponse = res.unwrapErr();
aResponse = rv;
return; return;
} }
   
MOZ_ASSERT(serializedInfo.files().IsEmpty()); MOZ_ASSERT(serializedInfo.files().IsEmpty());
   
serializedInfo.files().SwapElements(serializedFiles); serializedInfo.files() = res.unwrap();
} }
   
nsTArray<SerializedStructuredCloneReadInfo>& cloneInfos = nsTArray<SerializedStructuredCloneReadInfo>& cloneInfos =
...@@ -25718,18 +25689,17 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse, ...@@ -25718,18 +25689,17 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse,
   
serializedInfo.data().data = std::move(info.mData); serializedInfo.data().data = std::move(info.mData);
   
FallibleTArray<SerializedStructuredCloneFile> serializedFiles; auto res =
nsresult rv = SerializeStructuredCloneFiles( SerializeStructuredCloneFiles(mBackgroundParent, mDatabase, info.mFiles,
mBackgroundParent, mDatabase, info.mFiles, /* aForPreprocess */ false);
/* aForPreprocess */ false, serializedFiles); if (NS_WARN_IF(res.isErr())) {
if (NS_WARN_IF(NS_FAILED(rv))) { aResponse = res.unwrapErr();
aResponse = rv;
return; return;
} }
   
MOZ_ASSERT(serializedInfo.files().IsEmpty()); MOZ_ASSERT(serializedInfo.files().IsEmpty());
   
serializedInfo.files().SwapElements(serializedFiles); serializedInfo.files() = res.unwrap();
} }
} }
   
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment