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/. */
|
|
|
|
|
|
|
|
#include "DeviceStorageRequestParent.h"
|
|
|
|
#include "nsDOMFile.h"
|
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "mozilla/unused.h"
|
2012-08-09 15:41:18 -07:00
|
|
|
#include "mozilla/dom/ipc/Blob.h"
|
|
|
|
#include "ContentParent.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace devicestorage {
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
|
|
|
|
|
|
|
|
switch (aParams.type()) {
|
|
|
|
case DeviceStorageParams::TDeviceStorageAddParams:
|
|
|
|
{
|
|
|
|
DeviceStorageAddParams p = aParams;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
2012-08-09 15:41:18 -07:00
|
|
|
|
|
|
|
BlobParent* bp = static_cast<BlobParent*>(p.blobParent());
|
|
|
|
nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
|
|
blob->GetInternalStream(getter_AddRefs(stream));
|
|
|
|
|
|
|
|
nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(target, "Must have stream transport service");
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageGetParams:
|
|
|
|
{
|
|
|
|
DeviceStorageGetParams p = aParams;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
2012-08-09 15:41:18 -07:00
|
|
|
dsf->SetPath(p.name());
|
|
|
|
nsRefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(target, "Must have stream transport service");
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageDeleteParams:
|
|
|
|
{
|
|
|
|
DeviceStorageDeleteParams p = aParams;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
2012-08-09 15:41:18 -07:00
|
|
|
nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(target, "Must have stream transport service");
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
case DeviceStorageParams::TDeviceStorageStatParams:
|
|
|
|
{
|
|
|
|
DeviceStorageStatParams p = aParams;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
|
|
|
nsRefPtr<StatFileEvent> r = new StatFileEvent(this, dsf);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(target, "Must have stream transport service");
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
case DeviceStorageParams::TDeviceStorageEnumerationParams:
|
|
|
|
{
|
|
|
|
DeviceStorageEnumerationParams p = aParams;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
|
|
|
|
|
|
|
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
|
2012-08-09 15:41:18 -07:00
|
|
|
nsRefPtr<CancelableRunnable> r = new EnumerateFileEvent(this, dsf, p.since());
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(target, "Must have stream transport service");
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::~DeviceStorageRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(DeviceStorageRequestParent);
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(DeviceStorageRequestParent);
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(DeviceStorageRequestParent);
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mRunnables.Length();
|
|
|
|
for (int32_t index = 0; index < count; index++) {
|
2012-08-09 15:41:18 -07:00
|
|
|
mRunnables[index]->Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
DeviceStorageRequestParent::PostErrorEvent::PostErrorEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
const char* aError)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-08-09 15:41:18 -07:00
|
|
|
CopyASCIItoUTF16(aError, mError);
|
2012-06-19 16:14:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostErrorEvent::~PostErrorEvent() {}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostErrorEvent::CancelableRun() {
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
ErrorResponse response(mError);
|
|
|
|
unused << mParent->Send__delete__(mParent, response);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostSuccessEvent::PostSuccessEvent(DeviceStorageRequestParent* aParent)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostSuccessEvent::~PostSuccessEvent() {}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() {
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
SuccessResponse response;
|
|
|
|
unused << mParent->Send__delete__(mParent, response);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostBlobSuccessEvent::PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
|
2012-08-09 15:41:18 -07:00
|
|
|
DeviceStorageFile* aFile,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength,
|
2012-06-19 16:14:39 -07:00
|
|
|
nsACString& aMimeType)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
|
|
|
, mLength(aLength)
|
|
|
|
, mFile(aFile)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mMimeType(aMimeType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostBlobSuccessEvent::~PostBlobSuccessEvent() {}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsString mime;
|
|
|
|
CopyASCIItoUTF16(mMimeType, mime);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(mFile->mPath, mime, mLength, mFile->mFile);
|
|
|
|
|
|
|
|
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
|
|
|
|
BlobParent* actor = cp->GetOrCreateActorForBlob(blob);
|
|
|
|
|
|
|
|
BlobResponse response;
|
|
|
|
response.blobParent() = actor;
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
unused << mParent->Send__delete__(mParent, response);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
InfallibleTArray<DeviceStorageFileValue>& aPaths)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mPaths(aPaths)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::~PostEnumerationSuccessEvent() {}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
EnumerationResponse response(mPaths);
|
|
|
|
unused << mParent->Send__delete__(mParent, response);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::WriteFileEvent::WriteFileEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
DeviceStorageFile* aFile,
|
2012-08-09 15:41:18 -07:00
|
|
|
nsIInputStream* aInputStream)
|
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mFile(aFile)
|
2012-08-09 15:41:18 -07:00
|
|
|
, mInputStream(aInputStream)
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::WriteFileEvent::~WriteFileEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-08-09 15:41:18 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
nsRefPtr<nsRunnable> r;
|
2012-08-09 15:41:18 -07:00
|
|
|
|
|
|
|
if (!mInputStream) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mFile->Write(mInputStream);
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = new PostPathResultEvent(mParent, mFile->mPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::DeleteFileEvent::DeleteFileEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
DeviceStorageFile* aFile)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mFile(aFile)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::DeleteFileEvent::~DeleteFileEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-07-31 12:28:23 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-08-17 19:43:00 -07:00
|
|
|
mFile->Remove();
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsRunnable> r;
|
|
|
|
|
|
|
|
bool check = false;
|
|
|
|
mFile->mFile->Exists(&check);
|
|
|
|
if (check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = new PostPathResultEvent(mParent, mFile->mPath);
|
|
|
|
}
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
DeviceStorageRequestParent::StatFileEvent::StatFileEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
DeviceStorageFile* aFile)
|
|
|
|
: CancelableRunnable(aParent)
|
|
|
|
, mFile(aFile)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::StatFileEvent::~StatFileEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::StatFileEvent::CancelableRun()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t diskUsage = DeviceStorageFile::DirectoryDiskUsage(mFile->mFile);
|
2012-08-26 21:34:04 -07:00
|
|
|
int64_t freeSpace;
|
2012-07-31 12:28:23 -07:00
|
|
|
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-08-26 21:34:04 -07:00
|
|
|
freeSpace = 0;
|
2012-07-31 12:28:23 -07:00
|
|
|
}
|
2012-08-16 16:03:06 -07:00
|
|
|
|
|
|
|
r = new PostStatResultEvent(mParent, diskUsage, freeSpace);
|
2012-07-31 12:28:23 -07:00
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
DeviceStorageRequestParent::ReadFileEvent::ReadFileEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
DeviceStorageFile* aFile)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mFile(aFile)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
|
|
|
if (mimeService) {
|
|
|
|
nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mMimeType.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::ReadFileEvent::~ReadFileEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-07-31 12:28:23 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
|
|
|
bool check = false;
|
|
|
|
mFile->mFile->Exists(&check);
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
if (!check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t fileSize;
|
2012-06-19 16:14:39 -07:00
|
|
|
nsresult rv = mFile->mFile->GetFileSize(&fileSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
r = new PostBlobSuccessEvent(mParent, mFile, fileSize, mMimeType);
|
2012-06-19 16:14:39 -07:00
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::EnumerateFileEvent::EnumerateFileEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
DeviceStorageFile* aFile,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aSince)
|
2012-08-09 15:41:18 -07:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mFile(aFile)
|
|
|
|
, mSince(aSince)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::EnumerateFileEvent::~EnumerateFileEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-07-31 12:28:23 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
2012-08-09 15:41:18 -07:00
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
|
|
|
bool check = false;
|
|
|
|
mFile->mFile->Exists(&check);
|
|
|
|
if (!check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<DeviceStorageFile> > files;
|
|
|
|
mFile->CollectFiles(files, mSince);
|
|
|
|
|
|
|
|
InfallibleTArray<DeviceStorageFileValue> values;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = files.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2012-06-19 16:14:39 -07:00
|
|
|
nsString fullpath;
|
|
|
|
files[i]->mFile->GetPath(fullpath);
|
2012-08-09 15:41:18 -07:00
|
|
|
DeviceStorageFileValue dsvf(files[i]->mPath, fullpath);
|
2012-06-19 16:14:39 -07:00
|
|
|
values.AppendElement(dsvf);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = new PostEnumerationSuccessEvent(mParent, values);
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostPathResultEvent::PostPathResultEvent(DeviceStorageRequestParent* aParent,
|
2012-08-09 15:41:18 -07:00
|
|
|
const nsAString& aPath)
|
|
|
|
: CancelableRunnable(aParent)
|
2012-06-19 16:14:39 -07:00
|
|
|
, mPath(aPath)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostPathResultEvent::~PostPathResultEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-09 15:41:18 -07:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostPathResultEvent::CancelableRun()
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
SuccessResponse response;
|
|
|
|
unused << mParent->Send__delete__(mParent, response);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-31 12:28:23 -07:00
|
|
|
DeviceStorageRequestParent::PostStatResultEvent::PostStatResultEvent(DeviceStorageRequestParent* aParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aFreeBytes,
|
|
|
|
int64_t aTotalBytes)
|
2012-07-31 12:28:23 -07:00
|
|
|
: CancelableRunnable(aParent)
|
|
|
|
, mFreeBytes(aFreeBytes)
|
|
|
|
, mTotalBytes(aTotalBytes)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestParent::PostStatResultEvent::~PostStatResultEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostStatResultEvent::CancelableRun()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-08-16 16:03:06 -07:00
|
|
|
nsString state;
|
|
|
|
state.Assign(NS_LITERAL_STRING("available"));
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsresult rv = GetSDCardStatus(state);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
state.Assign(NS_LITERAL_STRING("unavailable"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
StatStorageResponse response(mFreeBytes, mTotalBytes, state);
|
2012-07-31 12:28:23 -07:00
|
|
|
unused << mParent->Send__delete__(mParent, response);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
|
|
|
|
} // namespace devicestorage
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|