Bug 1607791 - Get rid of IDBMutableFile.getFile() - part 1, r=asuth,janv

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2020-01-15 09:58:39 +00:00
Родитель 22aa29f8b3
Коммит 6c05c922e3
28 изменённых файлов: 1 добавлений и 995 удалений

Просмотреть файл

@ -483,12 +483,6 @@ bool WriteBlob(JSStructuredCloneWriter* aWriter, Blob* aBlob,
MOZ_ASSERT(aBlob);
MOZ_ASSERT(aHolder);
if (JS_GetStructuredCloneScope(aWriter) !=
JS::StructuredCloneScope::SameProcessSameThread &&
!aBlob->Impl()->MayBeClonedToOtherThreads()) {
return false;
}
RefPtr<BlobImpl> blobImpl = aBlob->Impl();
// We store the position of the blobImpl in the array as index.

Просмотреть файл

@ -60,7 +60,6 @@ attribute OfflineResourceList.onobsolete
// Non-standard IndexedDB API
method IDBDatabase.createMutableFile
method IDBMutableFile.open
method IDBMutableFile.getFile
// DataTransfer API (gecko-only methods)
method DataTransfer.addElement

Просмотреть файл

@ -310,8 +310,7 @@ class ConsoleRunnable : public StructuredCloneHolderBase {
bool CustomWriteHandler(JSContext* aCx, JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj) override {
RefPtr<Blob> blob;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) &&
blob->Impl()->MayBeClonedToOtherThreads()) {
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
if (NS_WARN_IF(!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB,
mClonedData.mBlobs.Length()))) {
return false;

Просмотреть файл

@ -105,9 +105,6 @@ class BlobImpl : public nsISupports {
// file is a directory.
virtual bool IsDirectory() const { return false; }
// True if this implementation can be sent to other threads.
virtual bool MayBeClonedToOtherThreads() const { return true; }
protected:
virtual ~BlobImpl() {}
};

Просмотреть файл

@ -283,16 +283,6 @@ void MultipartBlobImpl::SetLengthAndModifiedDate(ErrorResult& aRv) {
}
}
bool MultipartBlobImpl::MayBeClonedToOtherThreads() const {
for (uint32_t i = 0; i < mBlobImpls.Length(); ++i) {
if (!mBlobImpls[i]->MayBeClonedToOtherThreads()) {
return false;
}
}
return true;
}
size_t MultipartBlobImpl::GetAllocationSize() const {
FallibleTArray<BlobImpl*> visitedBlobs;

Просмотреть файл

@ -61,8 +61,6 @@ class MultipartBlobImpl final : public BaseBlobImpl {
void SetName(const nsAString& aName) { mName = aName; }
virtual bool MayBeClonedToOtherThreads() const override;
size_t GetAllocationSize() const override;
size_t GetAllocationSize(
FallibleTArray<BlobImpl*>& aVisitedBlobImpls) const override;

Просмотреть файл

@ -1,42 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include IPCBlob;
namespace mozilla {
namespace dom {
// IndexedDB and FileHandle do not know all the Blob/File properties when they
// create a IPCBlob. For this reason, they need to use this simple protocol.
// When the information is known, they send a __delete__ message with the
// pending data.
// This contains any extra bit for making a File out of a Blob.
struct PendingIPCFileData
{
nsString name;
int64_t lastModified;
};
struct PendingIPCBlobData
{
nsString type;
uint64_t size;
// Nothing() is used for Blob
PendingIPCFileData? file;
};
protocol PPendingIPCBlob
{
manager PBackground;
parent:
async __delete__(PendingIPCBlobData aData);
};
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -1,48 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PendingIPCBlobChild.h"
namespace mozilla {
namespace dom {
PendingIPCBlobChild::PendingIPCBlobChild(const IPCBlob& aBlob) {
mBlobImpl = IPCBlobUtils::Deserialize(aBlob);
MOZ_ASSERT(mBlobImpl);
}
PendingIPCBlobChild::~PendingIPCBlobChild() {}
already_AddRefed<BlobImpl> PendingIPCBlobChild::SetPendingInfoAndDeleteActor(
const nsString& aName, const nsString& aContentType, uint64_t aLength,
int64_t aLastModifiedDate) {
RefPtr<BlobImpl> blobImpl;
blobImpl.swap(mBlobImpl);
blobImpl->SetLazyData(aName, aContentType, aLength, aLastModifiedDate);
PendingIPCFileData fileData(nsString(aName), aLastModifiedDate);
PendingIPCBlobData blobData(nsString(aContentType), aLength, Some(fileData));
Unused << Send__delete__(this, blobData);
return blobImpl.forget();
}
already_AddRefed<BlobImpl> PendingIPCBlobChild::SetPendingInfoAndDeleteActor(
const nsString& aContentType, uint64_t aLength) {
RefPtr<BlobImpl> blobImpl;
blobImpl.swap(mBlobImpl);
blobImpl->SetLazyData(VoidString(), aContentType, aLength, INT64_MAX);
PendingIPCBlobData data(nsString(aContentType), aLength, Nothing());
Unused << Send__delete__(this, data);
return blobImpl.forget();
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -1,42 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_PendingIPCBlobChild_h
#define mozilla_dom_PendingIPCBlobChild_h
#include "mozilla/dom/PPendingIPCBlob.h"
#include "mozilla/dom/PPendingIPCBlobChild.h"
namespace mozilla {
namespace dom {
class BlobImpl;
class PendingIPCBlobChild final : public PPendingIPCBlobChild {
public:
explicit PendingIPCBlobChild(const IPCBlob& aBlob);
// After calling one of the following method, the actor will be deleted.
// For File.
already_AddRefed<BlobImpl> SetPendingInfoAndDeleteActor(
const nsString& aName, const nsString& aContentType, uint64_t aLength,
int64_t aLastModifiedDate);
// For Blob.
already_AddRefed<BlobImpl> SetPendingInfoAndDeleteActor(
const nsString& aContentType, uint64_t aLength);
private:
~PendingIPCBlobChild();
RefPtr<BlobImpl> mBlobImpl;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PendingIPCBlobChild_h

Просмотреть файл

@ -1,54 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PendingIPCBlobParent.h"
#include "mozilla/ipc/PBackgroundParent.h"
namespace mozilla {
using namespace ipc;
namespace dom {
/* static */
PendingIPCBlobParent* PendingIPCBlobParent::Create(PBackgroundParent* aManager,
BlobImpl* aBlobImpl) {
MOZ_ASSERT(aManager);
MOZ_ASSERT(aBlobImpl);
IPCBlob ipcBlob;
nsresult rv = IPCBlobUtils::Serialize(aBlobImpl, aManager, ipcBlob);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
PendingIPCBlobParent* actor = new PendingIPCBlobParent(aBlobImpl);
if (!aManager->SendPPendingIPCBlobConstructor(actor, ipcBlob)) {
// The actor will be deleted by the manager.
return nullptr;
}
return actor;
}
PendingIPCBlobParent::PendingIPCBlobParent(BlobImpl* aBlobImpl)
: mBlobImpl(aBlobImpl) {}
IPCResult PendingIPCBlobParent::Recv__delete__(
const PendingIPCBlobData& aData) {
if (aData.file().isNothing()) {
mBlobImpl->SetLazyData(VoidString(), aData.type(), aData.size(), INT64_MAX);
} else {
const PendingIPCFileData& fileData = aData.file().ref();
mBlobImpl->SetLazyData(fileData.name(), aData.type(), aData.size(),
fileData.lastModified());
}
return IPC_OK();
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -1,41 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_PendingIPCBlobParent_h
#define mozilla_dom_PendingIPCBlobParent_h
#include "mozilla/dom/PPendingIPCBlobParent.h"
namespace mozilla {
namespace ipc {
class PBackgroundParent;
}
namespace dom {
class BlobImpl;
class PendingIPCBlobParent final : public PPendingIPCBlobParent {
public:
static PendingIPCBlobParent* Create(PBackgroundParent* aManager,
BlobImpl* aBlobImpl);
void ActorDestroy(ActorDestroyReason aWhy) override {}
mozilla::ipc::IPCResult Recv__delete__(
const PendingIPCBlobData& aData) override;
private:
explicit PendingIPCBlobParent(BlobImpl* aBlobImpl);
RefPtr<BlobImpl> mBlobImpl;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PendingIPCBlobParent_h

Просмотреть файл

@ -21,8 +21,6 @@ EXPORTS.mozilla.dom += [
'IPCBlobInputStreamParent.h',
'IPCBlobInputStreamStorage.h',
'IPCBlobUtils.h',
'PendingIPCBlobChild.h',
'PendingIPCBlobParent.h',
'TemporaryIPCBlobChild.h',
'TemporaryIPCBlobParent.h',
]
@ -36,8 +34,6 @@ UNIFIED_SOURCES += [
'IPCBlobInputStreamStorage.cpp',
'IPCBlobInputStreamThread.cpp',
'IPCBlobUtils.cpp',
'PendingIPCBlobChild.cpp',
'PendingIPCBlobParent.cpp',
'TemporaryIPCBlobChild.cpp',
'TemporaryIPCBlobParent.cpp',
]
@ -47,7 +43,6 @@ IPDL_SOURCES += [
'IPCBlob.ipdlh',
'PFileCreator.ipdl',
'PIPCBlobInputStream.ipdl',
'PPendingIPCBlob.ipdl',
'PTemporaryIPCBlob.ipdl',
]

Просмотреть файл

@ -16,7 +16,6 @@
#include "mozilla/dom/indexedDB/ActorsParent.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseParent.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/PendingIPCBlobParent.h"
#include "mozilla/dom/quota/MemoryOutputStream.h"
#include "nsAutoPtr.h"
#include "nsComponentManagerUtils.h"
@ -572,20 +571,6 @@ class FlushOp final : public NormalFileHandleOp {
virtual void GetResponse(FileRequestResponse& aResponse) override;
};
class GetFileOp final : public GetMetadataOp {
friend class FileHandle;
PBackgroundParent* mBackgroundParent;
private:
// Only created by FileHandle.
GetFileOp(FileHandle* aFileHandle, const FileRequestParams& aParams);
~GetFileOp() {}
virtual void GetResponse(FileRequestResponse& aResponse) override;
};
namespace {
/*******************************************************************************
@ -1471,10 +1456,6 @@ bool FileHandle::VerifyRequestParams(const FileRequestParams& aParams) const {
break;
}
case FileRequestParams::TFileRequestGetFileParams: {
break;
}
default:
MOZ_CRASH("Should never get here!");
}
@ -1631,10 +1612,6 @@ PBackgroundFileRequestParent* FileHandle::AllocPBackgroundFileRequestParent(
actor = new FlushOp(this, aParams);
break;
case FileRequestParams::TFileRequestGetFileParams:
actor = new GetFileOp(this, aParams);
break;
default:
MOZ_CRASH("Should never get here!");
}
@ -2187,33 +2164,5 @@ void FlushOp::GetResponse(FileRequestResponse& aResponse) {
aResponse = FileRequestFlushResponse();
}
GetFileOp::GetFileOp(FileHandle* aFileHandle, const FileRequestParams& aParams)
: GetMetadataOp(aFileHandle, FileRequestGetMetadataParams(true, true)),
mBackgroundParent(aFileHandle->GetBackgroundParent()) {
MOZ_ASSERT(aParams.type() == FileRequestParams::TFileRequestGetFileParams);
MOZ_ASSERT(mBackgroundParent);
}
void GetFileOp::GetResponse(FileRequestResponse& aResponse) {
AssertIsOnOwningThread();
RefPtr<BlobImpl> blobImpl = mFileHandle->GetMutableFile()->CreateBlobImpl();
MOZ_ASSERT(blobImpl);
PendingIPCBlobParent* actor =
PendingIPCBlobParent::Create(mBackgroundParent, blobImpl);
if (NS_WARN_IF(!actor)) {
// This can only fail if the child has crashed.
aResponse = NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
return;
}
FileRequestGetFileResponse response;
response.fileParent() = actor;
response.metadata() = mMetadata;
aResponse = response;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -58,10 +58,6 @@ struct FileRequestFlushParams
{
};
struct FileRequestGetFileParams
{
};
union FileRequestParams
{
FileRequestGetMetadataParams;
@ -69,7 +65,6 @@ union FileRequestParams
FileRequestWriteParams;
FileRequestTruncateParams;
FileRequestFlushParams;
FileRequestGetFileParams;
};
protocol PBackgroundFileHandle

Просмотреть файл

@ -3,7 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackgroundFileHandle;
include protocol PPendingIPCBlob;
using struct mozilla::void_t
from "ipc/IPCMessageUtils.h";
@ -39,12 +38,6 @@ struct FileRequestFlushResponse
{
};
struct FileRequestGetFileResponse
{
PPendingIPCBlob file;
FileRequestMetadata metadata;
};
union FileRequestResponse
{
nsresult;
@ -53,7 +46,6 @@ union FileRequestResponse
FileRequestWriteResponse;
FileRequestTruncateResponse;
FileRequestFlushResponse;
FileRequestGetFileResponse;
};
protocol PBackgroundFileRequest

Просмотреть файл

@ -7,7 +7,6 @@
#include "ActorsChild.h"
#include "BackgroundChildImpl.h"
#include "FileSnapshot.h"
#include "IDBDatabase.h"
#include "IDBEvents.h"
#include "IDBFactory.h"
@ -32,7 +31,6 @@
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/PendingIPCBlobChild.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/Encoding.h"
@ -1209,32 +1207,6 @@ class MOZ_STACK_CLASS FileHandleResultHelper final
}
};
MOZ_MUST_USE RefPtr<File> ConvertActorToFile(
IDBFileHandle* aFileHandle, const FileRequestGetFileResponse& aResponse) {
auto* const actor = static_cast<PendingIPCBlobChild*>(aResponse.fileChild());
IDBMutableFile* mutableFile = aFileHandle->GetMutableFile();
MOZ_ASSERT(mutableFile);
const FileRequestMetadata& metadata = aResponse.metadata();
const Maybe<uint64_t>& size = metadata.size();
MOZ_ASSERT(size.isSome());
const Maybe<int64_t>& lastModified = metadata.lastModified();
MOZ_ASSERT(lastModified.isSome());
const RefPtr<BlobImpl> blobImpl = actor->SetPendingInfoAndDeleteActor(
mutableFile->Name(), mutableFile->Type(), size.value(),
lastModified.value());
MOZ_ASSERT(blobImpl);
const RefPtr<BlobImpl> blobImplSnapshot =
new BlobImplSnapshot(blobImpl, static_cast<IDBFileHandle*>(aFileHandle));
return File::Create(mutableFile->GetOwnerGlobal(), blobImplSnapshot);
}
void DispatchFileHandleErrorEvent(IDBFileRequest* aFileRequest,
nsresult aErrorCode,
IDBFileHandle* aFileHandle) {
@ -3959,17 +3931,6 @@ void BackgroundFileRequestChild::HandleResponse(nsresult aResponse) {
DispatchFileHandleErrorEvent(mFileRequest, aResponse, mFileHandle);
}
void BackgroundFileRequestChild::HandleResponse(
const FileRequestGetFileResponse& aResponse) {
AssertIsOnOwningThread();
RefPtr<File> file = ConvertActorToFile(mFileHandle, aResponse);
FileHandleResultHelper helper(mFileRequest, mFileHandle, file);
DispatchFileHandleSuccessEvent(&helper);
}
void BackgroundFileRequestChild::HandleResponse(const nsCString& aResponse) {
AssertIsOnOwningThread();
@ -4031,10 +3992,6 @@ mozilla::ipc::IPCResult BackgroundFileRequestChild::Recv__delete__(
HandleResponse(aResponse.get_nsresult());
break;
case FileRequestResponse::TFileRequestGetFileResponse:
HandleResponse(aResponse.get_FileRequestGetFileResponse());
break;
case FileRequestResponse::TFileRequestReadResponse:
HandleResponse(aResponse.get_FileRequestReadResponse().data());
break;

Просмотреть файл

@ -822,8 +822,6 @@ class BackgroundFileRequestChild final : public PBackgroundFileRequestChild {
void HandleResponse(nsresult aResponse);
void HandleResponse(const FileRequestGetFileResponse& aResponse);
void HandleResponse(const nsCString& aResponse);
void HandleResponse(const FileRequestMetadata& aResponse);

Просмотреть файл

@ -1,407 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FileSnapshot.h"
#include "IDBDatabase.h"
#include "IDBFileHandle.h"
#include "IDBMutableFile.h"
#include "mozilla/Assertions.h"
#include "mozilla/Mutex.h"
#include "nsIAsyncInputStream.h"
#include "nsICloneableInputStream.h"
#include "nsIIPCSerializableInputStream.h"
namespace mozilla {
namespace dom {
namespace indexedDB {
using namespace mozilla::ipc;
namespace {
class StreamWrapper final : public nsIAsyncInputStream,
public nsIInputStreamCallback,
public nsICloneableInputStream,
public nsIIPCSerializableInputStream {
class CloseRunnable;
nsCOMPtr<nsIEventTarget> mOwningThread;
nsCOMPtr<nsIInputStream> mInputStream;
RefPtr<IDBFileHandle> mFileHandle;
bool mFinished;
// This is needed to call OnInputStreamReady() with the correct inputStream.
// It is protected by mutex.
nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback;
Mutex mMutex;
public:
StreamWrapper(nsIInputStream* aInputStream, IDBFileHandle* aFileHandle)
: mOwningThread(aFileHandle->GetMutableFile()->Database()->EventTarget()),
mInputStream(aInputStream),
mFileHandle(aFileHandle),
mFinished(false),
mMutex("StreamWrapper::mMutex") {
AssertIsOnOwningThread();
MOZ_ASSERT(aInputStream);
MOZ_ASSERT(aFileHandle);
aFileHandle->AssertIsOnOwningThread();
mFileHandle->OnNewRequest();
}
private:
virtual ~StreamWrapper();
template <typename M>
void SerializeInternal(InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed, M* aManager);
bool IsOnOwningThread() const {
MOZ_ASSERT(mOwningThread);
bool current;
return NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)) && current;
}
void AssertIsOnOwningThread() const { MOZ_ASSERT(IsOnOwningThread()); }
void Finish() {
AssertIsOnOwningThread();
if (mFinished) {
return;
}
mFinished = true;
mFileHandle->OnRequestFinished(/* aActorDestroyedNormally */ true);
}
void Destroy() {
if (IsOnOwningThread()) {
delete this;
return;
}
RefPtr<Runnable> destroyRunnable = NewNonOwningRunnableMethod(
"StreamWrapper::Destroy", this, &StreamWrapper::Destroy);
MOZ_ALWAYS_SUCCEEDS(
mOwningThread->Dispatch(destroyRunnable, NS_DISPATCH_NORMAL));
}
bool IsCloneableInputStream() const {
nsCOMPtr<nsICloneableInputStream> stream = do_QueryInterface(mInputStream);
return !!stream;
}
bool IsIPCSerializableInputStream() const {
nsCOMPtr<nsIIPCSerializableInputStream> stream =
do_QueryInterface(mInputStream);
return !!stream;
}
bool IsAsyncInputStream() const {
nsCOMPtr<nsIAsyncInputStream> stream = do_QueryInterface(mInputStream);
return !!stream;
}
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIASYNCINPUTSTREAM
NS_DECL_NSIINPUTSTREAMCALLBACK
NS_DECL_NSICLONEABLEINPUTSTREAM
NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
};
class StreamWrapper::CloseRunnable final : public Runnable {
friend class StreamWrapper;
RefPtr<StreamWrapper> mStreamWrapper;
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(CloseRunnable, Runnable)
private:
explicit CloseRunnable(StreamWrapper* aStreamWrapper)
: Runnable("StreamWrapper::CloseRunnable"),
mStreamWrapper(aStreamWrapper) {}
~CloseRunnable() = default;
NS_IMETHOD
Run() override;
};
} // anonymous namespace
BlobImplSnapshot::BlobImplSnapshot(BlobImpl* aFileImpl,
IDBFileHandle* aFileHandle)
: mBlobImpl(aFileImpl) {
MOZ_ASSERT(aFileImpl);
MOZ_ASSERT(aFileHandle);
mFileHandle =
do_GetWeakReference(NS_ISUPPORTS_CAST(EventTarget*, aFileHandle));
}
BlobImplSnapshot::BlobImplSnapshot(BlobImpl* aFileImpl,
nsIWeakReference* aFileHandle)
: mBlobImpl(aFileImpl), mFileHandle(aFileHandle) {
MOZ_ASSERT(aFileImpl);
MOZ_ASSERT(aFileHandle);
}
NS_IMPL_ISUPPORTS_INHERITED(BlobImplSnapshot, BlobImpl, PIBlobImplSnapshot)
already_AddRefed<BlobImpl> BlobImplSnapshot::CreateSlice(
uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
ErrorResult& aRv) {
RefPtr<BlobImpl> blobImpl =
mBlobImpl->CreateSlice(aStart, aLength, aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
blobImpl = new BlobImplSnapshot(blobImpl, mFileHandle);
return blobImpl.forget();
}
void BlobImplSnapshot::CreateInputStream(nsIInputStream** aStream,
ErrorResult& aRv) {
nsCOMPtr<EventTarget> et = do_QueryReferent(mFileHandle);
RefPtr<IDBFileHandle> fileHandle = static_cast<IDBFileHandle*>(et.get());
if (!fileHandle || !fileHandle->IsOpen()) {
aRv.Throw(NS_ERROR_DOM_FILEHANDLE_INACTIVE_ERR);
return;
}
nsCOMPtr<nsIInputStream> stream;
mBlobImpl->CreateInputStream(getter_AddRefs(stream), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
RefPtr<StreamWrapper> wrapper = new StreamWrapper(stream, fileHandle);
wrapper.forget(aStream);
}
BlobImpl* BlobImplSnapshot::GetBlobImpl() const {
nsCOMPtr<EventTarget> et = do_QueryReferent(mFileHandle);
RefPtr<IDBFileHandle> fileHandle = static_cast<IDBFileHandle*>(et.get());
if (!fileHandle || !fileHandle->IsOpen()) {
return nullptr;
}
return mBlobImpl;
}
void BlobImplSnapshot::GetBlobImplType(nsAString& aBlobImplType) const {
aBlobImplType.AssignLiteral("BlobImplSnapshot[");
nsAutoString blobImplType;
mBlobImpl->GetBlobImplType(blobImplType);
aBlobImplType.Append(blobImplType);
aBlobImplType.AppendLiteral("]");
}
StreamWrapper::~StreamWrapper() {
AssertIsOnOwningThread();
Finish();
}
NS_IMPL_ADDREF(StreamWrapper)
NS_IMPL_RELEASE_WITH_DESTROY(StreamWrapper, Destroy())
NS_INTERFACE_MAP_BEGIN(StreamWrapper)
NS_INTERFACE_MAP_ENTRY(nsIInputStream)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIAsyncInputStream, IsAsyncInputStream())
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIInputStreamCallback,
IsAsyncInputStream())
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICloneableInputStream,
IsCloneableInputStream())
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIPCSerializableInputStream,
IsIPCSerializableInputStream())
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInputStream)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
StreamWrapper::Close() {
RefPtr<CloseRunnable> closeRunnable = new CloseRunnable(this);
MOZ_ALWAYS_SUCCEEDS(
mOwningThread->Dispatch(closeRunnable, NS_DISPATCH_NORMAL));
return NS_OK;
}
NS_IMETHODIMP
StreamWrapper::Available(uint64_t* _retval) {
return mInputStream->Available(_retval);
}
NS_IMETHODIMP
StreamWrapper::Read(char* aBuf, uint32_t aCount, uint32_t* _retval) {
return mInputStream->Read(aBuf, aCount, _retval);
}
NS_IMETHODIMP
StreamWrapper::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
uint32_t aCount, uint32_t* _retval) {
return mInputStream->ReadSegments(aWriter, aClosure, aCount, _retval);
}
NS_IMETHODIMP
StreamWrapper::IsNonBlocking(bool* _retval) {
return mInputStream->IsNonBlocking(_retval);
}
void StreamWrapper::Serialize(InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed,
ParentToChildStreamActorManager* aManager) {
SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize,
aSizeUsed, aManager);
}
void StreamWrapper::Serialize(InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed,
ChildToParentStreamActorManager* aManager) {
SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize,
aSizeUsed, aManager);
}
template <typename M>
void StreamWrapper::SerializeInternal(InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed, M* aManager) {
MOZ_ASSERT(aSizeUsed);
*aSizeUsed = 0;
nsCOMPtr<nsIIPCSerializableInputStream> stream =
do_QueryInterface(mInputStream);
if (stream) {
stream->Serialize(aParams, aFileDescriptors, aDelayedStart, aMaxSize,
aSizeUsed, aManager);
}
}
bool StreamWrapper::Deserialize(const InputStreamParams& aParams,
const FileDescriptorArray& aFileDescriptors) {
MOZ_CRASH("This method should never be called");
return false;
}
NS_IMETHODIMP
StreamWrapper::CloseWithStatus(nsresult aStatus) {
nsCOMPtr<nsIAsyncInputStream> stream = do_QueryInterface(mInputStream);
if (!stream) {
return NS_ERROR_NO_INTERFACE;
}
nsresult rv = stream->CloseWithStatus(aStatus);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return Close();
}
NS_IMETHODIMP
StreamWrapper::AsyncWait(nsIInputStreamCallback* aCallback, uint32_t aFlags,
uint32_t aRequestedCount,
nsIEventTarget* aEventTarget) {
nsCOMPtr<nsIAsyncInputStream> stream = do_QueryInterface(mInputStream);
if (!stream) {
return NS_ERROR_NO_INTERFACE;
}
nsCOMPtr<nsIInputStreamCallback> callback = aCallback ? this : nullptr;
{
MutexAutoLock lock(mMutex);
if (mAsyncWaitCallback && aCallback) {
return NS_ERROR_FAILURE;
}
mAsyncWaitCallback = aCallback;
}
return stream->AsyncWait(callback, aFlags, aRequestedCount, aEventTarget);
}
// nsIInputStreamCallback
NS_IMETHODIMP
StreamWrapper::OnInputStreamReady(nsIAsyncInputStream* aStream) {
nsCOMPtr<nsIAsyncInputStream> stream = do_QueryInterface(mInputStream);
if (!stream) {
return NS_ERROR_NO_INTERFACE;
}
nsCOMPtr<nsIInputStreamCallback> callback;
{
MutexAutoLock lock(mMutex);
// We have been canceled in the meanwhile.
if (!mAsyncWaitCallback) {
return NS_OK;
}
callback = std::move(mAsyncWaitCallback);
}
MOZ_ASSERT(callback);
return callback->OnInputStreamReady(this);
}
// nsICloneableInputStream
NS_IMETHODIMP
StreamWrapper::GetCloneable(bool* aCloneable) {
nsCOMPtr<nsICloneableInputStream> stream = do_QueryInterface(mInputStream);
if (!stream) {
*aCloneable = false;
return NS_ERROR_NO_INTERFACE;
}
return stream->GetCloneable(aCloneable);
}
NS_IMETHODIMP
StreamWrapper::Clone(nsIInputStream** aResult) {
nsCOMPtr<nsICloneableInputStream> stream = do_QueryInterface(mInputStream);
if (!stream) {
return NS_ERROR_NO_INTERFACE;
}
return stream->Clone(aResult);
}
NS_IMETHODIMP
StreamWrapper::CloseRunnable::Run() {
mStreamWrapper->Finish();
return NS_OK;
}
} // namespace indexedDB
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -1,156 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_indexeddb_filesnapshot_h__
#define mozilla_dom_indexeddb_filesnapshot_h__
#include "mozilla/Attributes.h"
#include "mozilla/dom/File.h"
#include "nsISupports.h"
#include "nsIWeakReferenceUtils.h"
#define FILEIMPLSNAPSHOT_IID \
{ \
0x0dfc11b1, 0x75d3, 0x473b, { \
0x8c, 0x67, 0xb7, 0x23, 0xf4, 0x67, 0xd6, 0x73 \
} \
}
class PIBlobImplSnapshot : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(FILEIMPLSNAPSHOT_IID)
virtual mozilla::dom::BlobImpl* GetBlobImpl() const = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(PIBlobImplSnapshot, FILEIMPLSNAPSHOT_IID)
namespace mozilla {
namespace dom {
class IDBFileHandle;
namespace indexedDB {
class BlobImplSnapshot final : public BlobImpl, public PIBlobImplSnapshot {
RefPtr<BlobImpl> mBlobImpl;
nsWeakPtr mFileHandle;
public:
BlobImplSnapshot(BlobImpl* aFileImpl, IDBFileHandle* aFileHandle);
NS_DECL_ISUPPORTS_INHERITED
private:
BlobImplSnapshot(BlobImpl* aFileImpl, nsIWeakReference* aFileHandle);
~BlobImplSnapshot() = default;
// BlobImpl
virtual void GetName(nsAString& aName) const override {
mBlobImpl->GetName(aName);
}
virtual void GetDOMPath(nsAString& aPath) const override {
mBlobImpl->GetDOMPath(aPath);
}
virtual void SetDOMPath(const nsAString& aPath) override {
mBlobImpl->SetDOMPath(aPath);
}
virtual int64_t GetLastModified(ErrorResult& aRv) override {
return mBlobImpl->GetLastModified(aRv);
}
virtual void SetLastModified(int64_t aLastModified) override {
mBlobImpl->SetLastModified(aLastModified);
}
virtual void GetMozFullPath(nsAString& aName,
SystemCallerGuarantee aGuarantee,
ErrorResult& aRv) override {
mBlobImpl->GetMozFullPath(aName, aGuarantee, aRv);
}
virtual void GetMozFullPathInternal(nsAString& aFileName,
ErrorResult& aRv) override {
mBlobImpl->GetMozFullPathInternal(aFileName, aRv);
}
virtual uint64_t GetSize(ErrorResult& aRv) override {
return mBlobImpl->GetSize(aRv);
}
virtual void GetType(nsAString& aType) override { mBlobImpl->GetType(aType); }
virtual void GetBlobImplType(nsAString& aBlobImplType) const override;
size_t GetAllocationSize() const override {
return mBlobImpl->GetAllocationSize();
}
size_t GetAllocationSize(
FallibleTArray<BlobImpl*>& aVisitedBlobs) const override {
return mBlobImpl->GetAllocationSize(aVisitedBlobs);
}
virtual uint64_t GetSerialNumber() const override {
return mBlobImpl->GetSerialNumber();
}
virtual already_AddRefed<BlobImpl> CreateSlice(uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv) override;
virtual const nsTArray<RefPtr<BlobImpl>>* GetSubBlobImpls() const override {
return mBlobImpl->GetSubBlobImpls();
}
virtual void CreateInputStream(nsIInputStream** aStream,
ErrorResult& aRv) override;
virtual int64_t GetFileId() override { return mBlobImpl->GetFileId(); }
virtual nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
nsACString& aContentType,
nsACString& aCharset) override {
return mBlobImpl->GetSendInfo(aBody, aContentLength, aContentType,
aCharset);
}
virtual void SetLazyData(const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
int64_t aLastModifiedDate) override {
MOZ_CRASH("This should never be called!");
}
virtual bool IsMemoryFile() const override {
return mBlobImpl->IsMemoryFile();
}
virtual bool IsSizeUnknown() const override {
return mBlobImpl->IsSizeUnknown();
}
virtual bool IsDateUnknown() const override {
return mBlobImpl->IsDateUnknown();
}
virtual bool IsFile() const override { return mBlobImpl->IsFile(); }
virtual bool MayBeClonedToOtherThreads() const override { return false; }
// PIBlobImplSnapshot
virtual BlobImpl* GetBlobImpl() const override;
};
} // namespace indexedDB
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_indexeddb_filesnapshot_h__

Просмотреть файл

@ -181,22 +181,6 @@ RefPtr<IDBFileHandle> IDBMutableFile::Open(FileMode aMode,
return fileHandle;
}
RefPtr<DOMRequest> IDBMutableFile::GetFile(ErrorResult& aError) {
RefPtr<IDBFileHandle> fileHandle = Open(FileMode::Readonly, aError);
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
FileRequestGetFileParams params;
auto request =
IDBFileRequest::Create(fileHandle, /* aWrapAsDOMRequest */ true);
fileHandle->StartRequest(request, params);
return request;
}
NS_IMPL_ADDREF_INHERITED(IDBMutableFile, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(IDBMutableFile, DOMEventTargetHelper)

Просмотреть файл

@ -111,8 +111,6 @@ class IDBMutableFile final : public DOMEventTargetHelper {
MOZ_MUST_USE RefPtr<IDBFileHandle> Open(FileMode aMode, ErrorResult& aError);
MOZ_MUST_USE RefPtr<DOMRequest> GetFile(ErrorResult& aError);
IMPL_EVENT_HANDLER(abort)
IMPL_EVENT_HANDLER(error)

Просмотреть файл

@ -45,7 +45,6 @@ EXPORTS.mozilla.dom += [
EXPORTS.mozilla.dom.indexedDB += [
'ActorsParent.h',
'FileSnapshot.h',
'IDBResult.h',
'Key.h',
'KeyPath.h',
@ -56,7 +55,6 @@ EXPORTS.mozilla.dom.indexedDB += [
UNIFIED_SOURCES += [
'ActorsChild.cpp',
'FileInfo.cpp',
'FileSnapshot.cpp',
'IDBCursor.cpp',
'IDBCursorType.cpp',
'IDBDatabase.cpp',

Просмотреть файл

@ -13,9 +13,6 @@ interface IDBMutableFile : EventTarget {
[Throws, UseCounter]
IDBFileHandle open(optional FileMode mode = "readonly");
[Throws, UseCounter]
DOMRequest getFile();
attribute EventHandler onabort;
attribute EventHandler onerror;
};

Просмотреть файл

@ -27,7 +27,6 @@
#include "mozilla/dom/FileSystemTaskBase.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/PMediaTransportChild.h"
#include "mozilla/dom/PendingIPCBlobChild.h"
#include "mozilla/dom/TemporaryIPCBlobChild.h"
#include "mozilla/dom/cache/ActorUtils.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
@ -312,17 +311,6 @@ bool BackgroundChildImpl::DeallocPBackgroundStorageChild(
return true;
}
dom::PPendingIPCBlobChild* BackgroundChildImpl::AllocPPendingIPCBlobChild(
const IPCBlob& aBlob) {
return new dom::PendingIPCBlobChild(aBlob);
}
bool BackgroundChildImpl::DeallocPPendingIPCBlobChild(
dom::PPendingIPCBlobChild* aActor) {
delete aActor;
return true;
}
dom::PRemoteWorkerChild* BackgroundChildImpl::AllocPRemoteWorkerChild(
const RemoteWorkerData& aData) {
RefPtr<dom::RemoteWorkerChild> agent = new dom::RemoteWorkerChild(aData);

Просмотреть файл

@ -117,12 +117,6 @@ class BackgroundChildImpl : public PBackgroundChild,
virtual bool DeallocPBackgroundStorageChild(
PBackgroundStorageChild* aActor) override;
virtual PPendingIPCBlobChild* AllocPPendingIPCBlobChild(
const IPCBlob& aBlob) override;
virtual bool DeallocPPendingIPCBlobChild(
PPendingIPCBlobChild* aActor) override;
virtual already_AddRefed<PIPCBlobInputStreamChild>
AllocPIPCBlobInputStreamChild(const nsID& aID,
const uint64_t& aSize) override;

Просмотреть файл

@ -26,7 +26,6 @@
#include "mozilla/dom/PGamepadTestChannelParent.h"
#include "mozilla/dom/MediaTransportParent.h"
#include "mozilla/dom/MessagePortParent.h"
#include "mozilla/dom/PendingIPCBlobParent.h"
#include "mozilla/dom/ServiceWorkerActors.h"
#include "mozilla/dom/ServiceWorkerManagerParent.h"
#include "mozilla/dom/ServiceWorkerRegistrar.h"
@ -477,21 +476,6 @@ BackgroundParentImpl::AllocPIdleSchedulerParent() {
return actor.forget();
}
mozilla::dom::PPendingIPCBlobParent*
BackgroundParentImpl::AllocPPendingIPCBlobParent(const IPCBlob& aBlob) {
MOZ_CRASH("PPendingIPCBlobParent actors should be manually constructed!");
}
bool BackgroundParentImpl::DeallocPPendingIPCBlobParent(
mozilla::dom::PPendingIPCBlobParent* aActor) {
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
delete aActor;
return true;
}
mozilla::dom::PRemoteWorkerParent*
BackgroundParentImpl::AllocPRemoteWorkerParent(const RemoteWorkerData& aData) {
RefPtr<dom::RemoteWorkerParent> agent = new dom::RemoteWorkerParent();

Просмотреть файл

@ -142,12 +142,6 @@ class BackgroundParentImpl : public PBackgroundParent,
virtual already_AddRefed<PIdleSchedulerParent> AllocPIdleSchedulerParent()
override;
virtual PPendingIPCBlobParent* AllocPPendingIPCBlobParent(
const IPCBlob& aBlob) override;
virtual bool DeallocPPendingIPCBlobParent(
PPendingIPCBlobParent* aActor) override;
virtual already_AddRefed<PIPCBlobInputStreamParent>
AllocPIPCBlobInputStreamParent(const nsID& aID,
const uint64_t& aSize) override;

Просмотреть файл

@ -26,7 +26,6 @@ include protocol PHttpBackgroundChannel;
include protocol PIdleScheduler;
include protocol PIPCBlobInputStream;
include protocol PMediaTransport;
include protocol PPendingIPCBlob;
include protocol PRemoteWorker;
include protocol PRemoteWorkerController;
include protocol PRemoteWorkerService;
@ -95,7 +94,6 @@ sync protocol PBackground
manages PIdleScheduler;
manages PIPCBlobInputStream;
manages PMediaTransport;
manages PPendingIPCBlob;
manages PRemoteWorker;
manages PRemoteWorkerController;
manages PRemoteWorkerService;
@ -243,8 +241,6 @@ child:
async PParentToChildStream();
async PPendingIPCBlob(IPCBlob blob);
async PRemoteWorker(RemoteWorkerData data);
both: