Bug 1186750 part 3 - Abstract CancelableFileEvent in DeviceStorageReqeustParent and use already_AddRefed&& for passing DeviceStorageFile parameter. r=dhylands

This commit is contained in:
Xidorn Quan 2015-11-19 16:10:42 +11:00
parent 1db6db9163
commit f9fc7276e6
2 changed files with 63 additions and 77 deletions

View File

@ -52,8 +52,8 @@ DeviceStorageRequestParent::Dispatch()
blobImpl->GetInternalStream(getter_AddRefs(stream), rv);
MOZ_ASSERT(!rv.Failed());
RefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream,
DEVICE_STORAGE_REQUEST_CREATE);
RefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf.forget(), stream,
DEVICE_STORAGE_REQUEST_CREATE);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -77,8 +77,8 @@ DeviceStorageRequestParent::Dispatch()
blobImpl->GetInternalStream(getter_AddRefs(stream), rv);
MOZ_ASSERT(!rv.Failed());
RefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream,
DEVICE_STORAGE_REQUEST_APPEND);
RefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf.forget(), stream,
DEVICE_STORAGE_REQUEST_APPEND);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -94,7 +94,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
RefPtr<CancelableRunnable> r = new CreateFdEvent(this, dsf);
RefPtr<CancelableRunnable> r = new CreateFdEvent(this, dsf.forget());
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -109,7 +109,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName(),
p.rootDir(), p.relpath());
RefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf);
RefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf.forget());
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -124,7 +124,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
RefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf);
RefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf.forget());
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -139,7 +139,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName());
RefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf);
RefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf.forget());
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -158,7 +158,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName());
RefPtr<UsedSpaceFileEvent> r = new UsedSpaceFileEvent(this, dsf);
RefPtr<UsedSpaceFileEvent> r = new UsedSpaceFileEvent(this, dsf.forget());
usedSpaceCache->Dispatch(r);
break;
@ -171,7 +171,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName());
RefPtr<PostFormatResultEvent> r
= new PostFormatResultEvent(this, dsf);
= new PostFormatResultEvent(this, dsf.forget());
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
MOZ_ASSERT(NS_SUCCEEDED(rv));
break;
@ -184,7 +184,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName());
RefPtr<PostMountResultEvent> r
= new PostMountResultEvent(this, dsf);
= new PostMountResultEvent(this, dsf.forget());
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
MOZ_ASSERT(NS_SUCCEEDED(rv));
break;
@ -197,7 +197,7 @@ DeviceStorageRequestParent::Dispatch()
RefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName());
RefPtr<PostUnmountResultEvent> r
= new PostUnmountResultEvent(this, dsf);
= new PostUnmountResultEvent(this, dsf.forget());
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
MOZ_ASSERT(NS_SUCCEEDED(rv));
break;
@ -210,7 +210,7 @@ DeviceStorageRequestParent::Dispatch()
= new DeviceStorageFile(p.type(), p.storageName(),
p.rootdir(), NS_LITERAL_STRING(""));
RefPtr<CancelableRunnable> r
= new EnumerateFileEvent(this, dsf, p.since());
= new EnumerateFileEvent(this, dsf.forget(), p.since());
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
@ -630,9 +630,9 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
}
DeviceStorageRequestParent::ReadFileEvent::
ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
ReadFileEvent(DeviceStorageRequestParent* aParent,
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile))
{
nsCOMPtr<nsIMIMEService> mimeService
= do_GetService(NS_MIMESERVICE_CONTRACTID);
@ -677,7 +677,8 @@ DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
return NS_DispatchToMainThread(r);
}
r = new PostBlobSuccessEvent(mParent, mFile, static_cast<uint64_t>(fileSize),
r = new PostBlobSuccessEvent(mParent, mFile.forget(),
static_cast<uint64_t>(fileSize),
mMimeType, modDate);
return NS_DispatchToMainThread(r);
}

View File

@ -74,6 +74,17 @@ private:
bool mCanceled;
};
class CancelableFileEvent : public CancelableRunnable
{
protected:
CancelableFileEvent(DeviceStorageRequestParent* aParent,
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableRunnable(aParent)
, mFile(Move(aFile)) {}
RefPtr<DeviceStorageFile> mFile;
};
class PostErrorEvent : public CancelableRunnable
{
public:
@ -93,24 +104,22 @@ private:
virtual nsresult CancelableRun();
};
class PostBlobSuccessEvent : public CancelableRunnable
class PostBlobSuccessEvent : public CancelableFileEvent
{
public:
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile,
already_AddRefed<DeviceStorageFile>&& aFile,
uint32_t aLength, nsACString& aMimeType,
uint64_t aLastModifiedDate)
: CancelableRunnable(aParent)
: CancelableFileEvent(aParent, Move(aFile))
, mLength(aLength)
, mLastModificationDate(aLastModifiedDate)
, mFile(aFile)
, mMimeType(aMimeType) {}
virtual ~PostBlobSuccessEvent() {}
virtual nsresult CancelableRun();
private:
uint32_t mLength;
uint64_t mLastModificationDate;
RefPtr<DeviceStorageFile> mFile;
nsCString mMimeType;
};
@ -133,99 +142,84 @@ private:
InfallibleTArray<DeviceStorageFileValue> mPaths;
};
class CreateFdEvent : public CancelableRunnable
class CreateFdEvent : public CancelableFileEvent
{
public:
CreateFdEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
CreateFdEvent(DeviceStorageRequestParent* aParent,
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~CreateFdEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
class WriteFileEvent : public CancelableRunnable
class WriteFileEvent : public CancelableFileEvent
{
public:
WriteFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile,
already_AddRefed<DeviceStorageFile>&& aFile,
nsIInputStream* aInputStream, int32_t aRequestType)
: CancelableRunnable(aParent)
, mFile(aFile)
: CancelableFileEvent(aParent, Move(aFile))
, mInputStream(aInputStream)
, mRequestType(aRequestType) {}
virtual ~WriteFileEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
nsCOMPtr<nsIInputStream> mInputStream;
int32_t mRequestType;
};
class DeleteFileEvent : public CancelableRunnable
class DeleteFileEvent : public CancelableFileEvent
{
public:
DeleteFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~DeleteFileEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
class FreeSpaceFileEvent : public CancelableRunnable
class FreeSpaceFileEvent : public CancelableFileEvent
{
public:
FreeSpaceFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~FreeSpaceFileEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
class UsedSpaceFileEvent : public CancelableRunnable
class UsedSpaceFileEvent : public CancelableFileEvent
{
public:
UsedSpaceFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~UsedSpaceFileEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
class ReadFileEvent : public CancelableRunnable
class ReadFileEvent : public CancelableFileEvent
{
public:
ReadFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile);
already_AddRefed<DeviceStorageFile>&& aFile);
virtual ~ReadFileEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
nsCString mMimeType;
};
class EnumerateFileEvent : public CancelableRunnable
class EnumerateFileEvent : public CancelableFileEvent
{
public:
EnumerateFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile, uint64_t aSince)
: CancelableRunnable(aParent)
, mFile(aFile)
already_AddRefed<DeviceStorageFile>&& aFile,
uint64_t aSince)
: CancelableFileEvent(aParent, Move(aFile))
, mSince(aSince) {}
virtual ~EnumerateFileEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
uint64_t mSince;
};
@ -282,43 +276,34 @@ private:
uint64_t mUsedSpace;
};
class PostFormatResultEvent : public CancelableRunnable
class PostFormatResultEvent : public CancelableFileEvent
{
public:
PostFormatResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~PostFormatResultEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
class PostMountResultEvent : public CancelableRunnable
class PostMountResultEvent : public CancelableFileEvent
{
public:
PostMountResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~PostMountResultEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
class PostUnmountResultEvent : public CancelableRunnable
class PostUnmountResultEvent : public CancelableFileEvent
{
public:
PostUnmountResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile) {}
already_AddRefed<DeviceStorageFile>&& aFile)
: CancelableFileEvent(aParent, Move(aFile)) {}
virtual ~PostUnmountResultEvent() {}
virtual nsresult CancelableRun();
private:
RefPtr<DeviceStorageFile> mFile;
};
protected: