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
|
|
|
|
|
|
|
|
#include "mozilla/dom/devicestorage/PDeviceStorageRequestParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
virtual void ActorDestroy(ActorDestroyReason);
|
|
|
|
|
|
|
|
protected:
|
2012-06-19 23:14:39 +00:00
|
|
|
~DeviceStorageRequestParent();
|
|
|
|
|
|
|
|
private:
|
2012-08-09 22:41:18 +00: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();
|
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-08-22 15:56:38 +00:00
|
|
|
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, uint32_t aLength, nsACString& aMimeType);
|
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-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:
|
|
|
|
PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, 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:
|
|
|
|
InfallibleTArray<DeviceStorageFileValue> mPaths;
|
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
class WriteFileEvent : public CancelableRunnable
|
2012-06-19 23:14:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-09 22:41:18 +00:00
|
|
|
WriteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile, nsIInputStream* aInputStream);
|
|
|
|
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;
|
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;
|
|
|
|
};
|
|
|
|
|
2012-07-31 19:28:23 +00:00
|
|
|
class StatFileEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StatFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
|
|
|
|
virtual ~StatFileEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2012-07-31 19:28:23 +00:00
|
|
|
class PostStatResultEvent : public CancelableRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostStatResultEvent(DeviceStorageRequestParent* aParent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t aFreeBytes,
|
|
|
|
int64_t aTotalBytes);
|
2012-07-31 19:28:23 +00:00
|
|
|
virtual ~PostStatResultEvent();
|
|
|
|
virtual nsresult CancelableRun();
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t mFreeBytes, mTotalBytes;
|
2012-07-31 19:28:23 +00:00
|
|
|
};
|
|
|
|
|
2012-08-09 22:41:18 +00:00
|
|
|
protected:
|
|
|
|
void AddRunnable(CancelableRunnable* aRunnable) {
|
|
|
|
mRunnables.AppendElement(aRunnable);
|
|
|
|
}
|
|
|
|
void RemoveRunnable(CancelableRunnable* aRunnable) {
|
|
|
|
mRunnables.RemoveElement(aRunnable);
|
|
|
|
}
|
|
|
|
nsTArray<nsRefPtr<CancelableRunnable> > mRunnables;
|
2012-06-19 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace devicestorage
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|