2012-06-19 23:14:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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_devicestorage_DeviceStorageRequestParent_h
|
|
|
|
#define mozilla_dom_devicestorage_DeviceStorageRequestParent_h
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
#include "mozilla/dom/devicestorage/PDeviceStorageRequestParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2012-11-30 05:41:40 +00:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsDeviceStorage.h"
|
2012-08-09 22:41:18 +00:00
|
|
|
#include "nsTArray.h"
|
2012-06-19 23:14:39 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace devicestorage {
|
|
|
|
|
|
|
|
class DeviceStorageRequestParent : public PDeviceStorageRequestParent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeviceStorageRequestParent(const DeviceStorageParams& aParams);
|
2012-08-09 22:41:18 +00:00
|
|
|
|
2014-03-27 20:38:33 +00:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef();
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release();
|
2012-11-30 05:41:40 +00:00
|
|
|
|
|
|
|
bool EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent);
|
|
|
|
void Dispatch();
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason);
|
|
|
|
|
|
|
|
protected:
|
2012-06-19 23:14:39 +00:00
|
|
|
~DeviceStorageRequestParent();
|
|
|
|
|
|
|
|
private:
|
2013-07-19 02:21:20 +00:00
|
|
|
ThreadSafeAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
2012-11-30 05:41:40 +00:00
|
|
|
DeviceStorageParams mParams;
|
2012-08-09 22:41:18 +00:00
|
|
|
|
|
|
|
class CancelableRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CancelableRunnable(DeviceStorageRequestParent* aParent)
|
|
|
|
: mParent(aParent)
|
|
|
|
{
|
2012-08-28 15:39:22 +00:00
|
|
|
mCanceled = !(mParent->AddRunnable(this));
|
2012-08-09 22:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CancelableRunnable() {
|
|
|
|
}
|
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE {
|
2012-08-09 22:41:18 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mCanceled) {
|
|
|
|
rv = CancelableRun();
|
2012-08-28 15:38:31 +00:00
|
|
|
mParent->RemoveRunnable(this);
|
2012-08-09 22:41:18 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() {
|
|
|
|
mCanceled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult CancelableRun() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<DeviceStorageRequestParent> mParent;
|
|
|
|
private:
|
|
|
|
bool mCanceled;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PostErrorEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~PostErrorEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
nsString mError;
|
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class PostSuccessEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostSuccessEvent(DeviceStorageRequestParent* aParent);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~PostSuccessEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class PostBlobSuccessEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-10-18 18:29:32 +00:00
|
|
|
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, uint32_t aLength, nsACString& aMimeType, uint64_t aLastModifiedDate);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~PostBlobSuccessEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLength;
|
2012-10-18 18:29:32 +00:00
|
|
|
uint64_t mLastModificationDate;
|
2012-08-09 22:41:18 +00:00
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2012-06-19 23:14:39 +00:00
|
|
|
nsCString mMimeType;
|
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class PostEnumerationSuccessEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-04-18 14:13:23 +00:00
|
|
|
PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
const nsAString& aStorageType,
|
|
|
|
const nsAString& aRelPath,
|
|
|
|
InfallibleTArray<DeviceStorageFileValue>& aPaths);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~PostEnumerationSuccessEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
2013-04-18 14:13:23 +00:00
|
|
|
const nsString mStorageType;
|
|
|
|
const nsString mRelPath;
|
2012-06-19 23:14:39 +00:00
|
|
|
InfallibleTArray<DeviceStorageFileValue> mPaths;
|
|
|
|
};
|
|
|
|
|
2014-01-17 01:01:27 +00:00
|
|
|
class CreateFdEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CreateFdEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~CreateFdEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class WriteFileEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-06-10 08:51:28 +00:00
|
|
|
WriteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile,
|
|
|
|
nsIInputStream* aInputStream, int32_t aRequestType);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~WriteFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2012-08-09 22:41:18 +00:00
|
|
|
nsCOMPtr<nsIInputStream> mInputStream;
|
2014-06-10 08:51:28 +00:00
|
|
|
int32_t mRequestType;
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class DeleteFileEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~DeleteFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
2013-01-25 19:05:24 +00:00
|
|
|
class FreeSpaceFileEvent : public CancelableRunnable
|
2012-07-31 19:28:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-01-25 19:05:24 +00:00
|
|
|
FreeSpaceFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~FreeSpaceFileEvent();
|
2012-07-31 19:28:23 +00:00
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2013-01-25 19:05:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class UsedSpaceFileEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UsedSpaceFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~UsedSpaceFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
2012-07-31 19:28:23 +00:00
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class ReadFileEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~ReadFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
nsCString mMimeType;
|
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class EnumerateFileEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
EnumerateFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, uint64_t aSince);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~EnumerateFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t mSince;
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class PostPathResultEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostPathResultEvent(DeviceStorageRequestParent* aParent, const nsAString& aPath);
|
2012-08-09 22:41:18 +00:00
|
|
|
virtual ~PostPathResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 23:14:39 +00:00
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
nsString mPath;
|
|
|
|
};
|
|
|
|
|
2014-01-17 01:01:27 +00:00
|
|
|
class PostFileDescriptorResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
const FileDescriptor& aFileDescriptor);
|
|
|
|
virtual ~PostFileDescriptorResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
FileDescriptor mFileDescriptor;
|
|
|
|
};
|
|
|
|
|
2013-01-25 19:05:24 +00:00
|
|
|
class PostFreeSpaceResultEvent : public CancelableRunnable
|
2012-07-31 19:28:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-01-25 19:05:24 +00:00
|
|
|
PostFreeSpaceResultEvent(DeviceStorageRequestParent* aParent,
|
2013-05-02 23:26:31 +00:00
|
|
|
uint64_t aFreeSpace);
|
2013-01-25 19:05:24 +00:00
|
|
|
virtual ~PostFreeSpaceResultEvent();
|
2012-07-31 19:28:23 +00:00
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
2013-05-02 23:26:31 +00:00
|
|
|
uint64_t mFreeSpace;
|
2013-01-25 19:05:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PostUsedSpaceResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent,
|
2013-05-02 23:26:31 +00:00
|
|
|
const nsAString& aType,
|
|
|
|
uint64_t aUsedSpace);
|
2013-01-25 19:05:24 +00:00
|
|
|
virtual ~PostUsedSpaceResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
2013-05-02 23:26:31 +00:00
|
|
|
nsString mType;
|
|
|
|
uint64_t mUsedSpace;
|
2013-01-25 19:05:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PostAvailableResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-04-18 14:13:23 +00:00
|
|
|
PostAvailableResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
2013-01-25 19:05:24 +00:00
|
|
|
virtual ~PostAvailableResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2013-04-02 19:52:21 +00:00
|
|
|
private:
|
2013-04-18 14:13:23 +00:00
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
2013-01-25 19:05:24 +00:00
|
|
|
};
|
2012-07-31 19:28:23 +00:00
|
|
|
|
2014-02-19 02:48:05 +00:00
|
|
|
class PostStatusResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostStatusResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~PostStatusResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
2013-09-06 06:11:58 +00:00
|
|
|
class PostFormatResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostFormatResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~PostFormatResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
2014-03-04 11:24:19 +00:00
|
|
|
class PostMountResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostMountResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~PostMountResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PostUnmountResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostUnmountResultEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~PostUnmountResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
protected:
|
2012-08-28 15:39:22 +00:00
|
|
|
bool AddRunnable(CancelableRunnable* aRunnable) {
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
if (mActorDestoryed)
|
|
|
|
return false;
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
mRunnables.AppendElement(aRunnable);
|
2012-08-28 15:39:22 +00:00
|
|
|
return true;
|
2012-08-09 22:41:18 +00:00
|
|
|
}
|
2012-08-28 15:39:22 +00:00
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
void RemoveRunnable(CancelableRunnable* aRunnable) {
|
2012-08-28 15:39:22 +00:00
|
|
|
MutexAutoLock lock(mMutex);
|
2012-08-09 22:41:18 +00:00
|
|
|
mRunnables.RemoveElement(aRunnable);
|
|
|
|
}
|
2012-08-28 15:39:22 +00:00
|
|
|
|
|
|
|
Mutex mMutex;
|
|
|
|
bool mActorDestoryed;
|
2012-08-09 22:41:18 +00:00
|
|
|
nsTArray<nsRefPtr<CancelableRunnable> > mRunnables;
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace devicestorage
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|