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