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
|
|
|
|
|
|
|
|
#include "mozilla/dom/devicestorage/PDeviceStorageRequestParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
|
|
|
|
#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:
|
|
|
|
DeviceStorageRequestParent(const DeviceStorageParams& aParams);
|
2012-08-09 15:41:18 -07:00
|
|
|
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
virtual void ActorDestroy(ActorDestroyReason);
|
|
|
|
|
|
|
|
protected:
|
2012-06-19 16:14:39 -07:00
|
|
|
~DeviceStorageRequestParent();
|
|
|
|
|
|
|
|
private:
|
2012-08-09 15:41:18 -07:00
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
|
|
|
|
class CancelableRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CancelableRunnable(DeviceStorageRequestParent* aParent)
|
|
|
|
: mParent(aParent)
|
|
|
|
, mCanceled(false)
|
|
|
|
{
|
|
|
|
mParent->AddRunnable(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CancelableRunnable() {
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mCanceled) {
|
|
|
|
rv = CancelableRun();
|
|
|
|
mParent->RemoveRunnable(this);
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
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-08-09 15:41:18 -07:00
|
|
|
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, PRUint32 aLength, nsACString& aMimeType);
|
|
|
|
virtual ~PostBlobSuccessEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
2012-06-19 16:14:39 -07:00
|
|
|
private:
|
2012-08-09 15:41:18 -07:00
|
|
|
PRUint32 mLength;
|
|
|
|
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:
|
|
|
|
PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, 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:
|
|
|
|
InfallibleTArray<DeviceStorageFileValue> mPaths;
|
|
|
|
};
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
class WriteFileEvent : public CancelableRunnable
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-08-09 15:41:18 -07:00
|
|
|
WriteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, nsIInputStream* aInputStream);
|
|
|
|
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;
|
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;
|
|
|
|
};
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
class StatFileEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StatFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~StatFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
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-16 16:14:37 -07:00
|
|
|
EnumerateFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, PRUint64 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-16 16:14:37 -07:00
|
|
|
PRUint64 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;
|
|
|
|
};
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
class PostStatResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostStatResultEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
PRInt64 aFreeBytes,
|
2012-08-16 16:03:06 -07:00
|
|
|
PRInt64 aTotalBytes);
|
2012-07-31 12:28:23 -07:00
|
|
|
virtual ~PostStatResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
PRInt64 mFreeBytes, mTotalBytes;
|
|
|
|
};
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
protected:
|
|
|
|
void AddRunnable(CancelableRunnable* aRunnable) {
|
|
|
|
mRunnables.AppendElement(aRunnable);
|
|
|
|
}
|
|
|
|
void RemoveRunnable(CancelableRunnable* aRunnable) {
|
|
|
|
mRunnables.RemoveElement(aRunnable);
|
|
|
|
}
|
|
|
|
nsTArray<nsRefPtr<CancelableRunnable> > mRunnables;
|
2012-06-19 16:14:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace devicestorage
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|