2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-06-20 03:14:39 +04:00
|
|
|
/* 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 "nsIMIMEService.h"
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "mozilla/unused.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/ipc/BlobParent.h"
|
2012-08-10 02:41:18 +04:00
|
|
|
#include "ContentParent.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2012-12-22 15:53:38 +04:00
|
|
|
#include "AppProcessChecker.h"
|
2012-11-30 09:41:40 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-24 01:30:40 +04:00
|
|
|
#include "nsNetCID.h"
|
2012-06-20 03:14:39 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace devicestorage {
|
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestParent::DeviceStorageRequestParent(
|
|
|
|
const DeviceStorageParams& aParams)
|
2012-11-30 09:41:40 +04:00
|
|
|
: mParams(aParams)
|
|
|
|
, mMutex("DeviceStorageRequestParent::mMutex")
|
2015-03-31 04:43:17 +03:00
|
|
|
, mActorDestroyed(false)
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
|
2013-05-03 03:26:31 +04:00
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache
|
|
|
|
= DeviceStorageUsedSpaceCache::CreateOrGet();
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(usedSpaceCache);
|
2012-11-30 09:41:40 +04:00
|
|
|
}
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2012-11-30 09:41:40 +04:00
|
|
|
void
|
|
|
|
DeviceStorageRequestParent::Dispatch()
|
|
|
|
{
|
|
|
|
switch (mParams.type()) {
|
2012-06-20 03:14:39 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageAddParams:
|
|
|
|
{
|
2012-11-30 09:41:40 +04:00
|
|
|
DeviceStorageAddParams p = mParams;
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2013-05-11 13:10:18 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
|
|
|
BlobParent* bp = static_cast<BlobParent*>(p.blobParent());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BlobImpl> blobImpl = bp->GetBlobImpl();
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2015-05-19 17:36:37 +03:00
|
|
|
ErrorResult rv;
|
2012-08-10 02:41:18 +04:00
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
2015-05-19 17:36:37 +03:00
|
|
|
blobImpl->GetInternalStream(getter_AddRefs(stream), rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf.forget(), stream,
|
|
|
|
DEVICE_STORAGE_REQUEST_CREATE);
|
2014-06-10 12:51:28 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
MOZ_ASSERT(target);
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageAppendParams:
|
|
|
|
{
|
|
|
|
DeviceStorageAppendParams p = mParams;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2014-06-10 12:51:28 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
|
|
|
|
|
|
|
BlobParent* bp = static_cast<BlobParent*>(p.blobParent());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BlobImpl> blobImpl = bp->GetBlobImpl();
|
2014-06-10 12:51:28 +04:00
|
|
|
|
2015-05-19 17:36:37 +03:00
|
|
|
ErrorResult rv;
|
2014-06-10 12:51:28 +04:00
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
2015-05-19 17:36:37 +03:00
|
|
|
blobImpl->GetInternalStream(getter_AddRefs(stream), rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2014-06-10 12:51:28 +04:00
|
|
|
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf.forget(), stream,
|
|
|
|
DEVICE_STORAGE_REQUEST_APPEND);
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(target);
|
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageCreateFdParams:
|
|
|
|
{
|
|
|
|
DeviceStorageCreateFdParams p = mParams;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2014-01-17 05:01:27 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
|
|
|
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<CancelableRunnable> r = new CreateFdEvent(this, dsf.forget());
|
2014-01-17 05:01:27 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
MOZ_ASSERT(target);
|
2012-06-20 03:14:39 +04:00
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageGetParams:
|
|
|
|
{
|
2012-11-30 09:41:40 +04:00
|
|
|
DeviceStorageGetParams p = mParams;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2013-08-03 03:35:16 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName(),
|
|
|
|
p.rootDir(), p.relpath());
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf.forget());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(target);
|
2012-06-20 03:14:39 +04:00
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageDeleteParams:
|
|
|
|
{
|
2012-11-30 09:41:40 +04:00
|
|
|
DeviceStorageDeleteParams p = mParams;
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2013-05-11 13:10:18 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf.forget());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(target);
|
2012-06-20 03:14:39 +04:00
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-25 23:05:24 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageFreeSpaceParams:
|
2012-07-31 23:28:23 +04:00
|
|
|
{
|
2013-01-25 23:05:24 +04:00
|
|
|
DeviceStorageFreeSpaceParams p = mParams;
|
2012-07-31 23:28:23 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2013-05-11 13:10:18 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName());
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf.forget());
|
2012-07-31 23:28:23 +04:00
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(target);
|
2012-07-31 23:28:23 +04:00
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-25 23:05:24 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageUsedSpaceParams:
|
|
|
|
{
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageUsedSpaceCache* usedSpaceCache
|
|
|
|
= DeviceStorageUsedSpaceCache::CreateOrGet();
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(usedSpaceCache);
|
2013-05-03 03:26:31 +04:00
|
|
|
|
2013-01-25 23:05:24 +04:00
|
|
|
DeviceStorageUsedSpaceParams p = mParams;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2013-05-11 13:10:18 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName());
|
2015-11-19 08:10:42 +03:00
|
|
|
RefPtr<UsedSpaceFileEvent> r = new UsedSpaceFileEvent(this, dsf.forget());
|
2013-01-25 23:05:24 +04:00
|
|
|
|
2013-05-03 03:26:31 +04:00
|
|
|
usedSpaceCache->Dispatch(r);
|
2013-01-25 23:05:24 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageFormatParams:
|
|
|
|
{
|
|
|
|
DeviceStorageFormatParams p = mParams;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2013-09-06 10:11:58 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PostFormatResultEvent> r
|
2015-11-19 08:10:42 +03:00
|
|
|
= new PostFormatResultEvent(this, dsf.forget());
|
2014-01-17 05:01:27 +04:00
|
|
|
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2013-09-06 10:11:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-04 15:24:19 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageMountParams:
|
|
|
|
{
|
|
|
|
DeviceStorageMountParams p = mParams;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2014-03-04 15:24:19 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PostMountResultEvent> r
|
2015-11-19 08:10:42 +03:00
|
|
|
= new PostMountResultEvent(this, dsf.forget());
|
2014-03-04 15:24:19 +04:00
|
|
|
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageUnmountParams:
|
|
|
|
{
|
|
|
|
DeviceStorageUnmountParams p = mParams;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf =
|
2014-03-04 15:24:19 +04:00
|
|
|
new DeviceStorageFile(p.type(), p.storageName());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PostUnmountResultEvent> r
|
2015-11-19 08:10:42 +03:00
|
|
|
= new PostUnmountResultEvent(this, dsf.forget());
|
2014-03-04 15:24:19 +04:00
|
|
|
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageEnumerationParams:
|
|
|
|
{
|
2012-11-30 09:41:40 +04:00
|
|
|
DeviceStorageEnumerationParams p = mParams;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf
|
2013-08-03 03:35:16 +04:00
|
|
|
= new DeviceStorageFile(p.type(), p.storageName(),
|
|
|
|
p.rootdir(), NS_LITERAL_STRING(""));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CancelableRunnable> r
|
2015-11-19 08:10:42 +03:00
|
|
|
= new EnumerateFileEvent(this, dsf.forget(), p.since());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> target
|
|
|
|
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(target);
|
2012-06-20 03:14:39 +04:00
|
|
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-30 09:41:40 +04:00
|
|
|
bool
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestParent::EnsureRequiredPermissions(
|
|
|
|
mozilla::dom::ContentParent* aParent)
|
2012-11-30 09:41:40 +04:00
|
|
|
{
|
|
|
|
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString type;
|
|
|
|
DeviceStorageRequestType requestType;
|
|
|
|
|
|
|
|
switch (mParams.type())
|
|
|
|
{
|
|
|
|
case DeviceStorageParams::TDeviceStorageAddParams:
|
|
|
|
{
|
|
|
|
DeviceStorageAddParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_CREATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-10 12:51:28 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageAppendParams:
|
|
|
|
{
|
|
|
|
DeviceStorageAppendParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_APPEND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-17 05:01:27 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageCreateFdParams:
|
|
|
|
{
|
|
|
|
DeviceStorageCreateFdParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_CREATEFD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-30 09:41:40 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageGetParams:
|
|
|
|
{
|
|
|
|
DeviceStorageGetParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_READ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageDeleteParams:
|
|
|
|
{
|
|
|
|
DeviceStorageDeleteParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_DELETE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-25 23:05:24 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageFreeSpaceParams:
|
|
|
|
{
|
|
|
|
DeviceStorageFreeSpaceParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_FREE_SPACE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageUsedSpaceParams:
|
|
|
|
{
|
|
|
|
DeviceStorageUsedSpaceParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_FREE_SPACE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageAvailableParams:
|
2012-11-30 09:41:40 +04:00
|
|
|
{
|
2013-01-25 23:05:24 +04:00
|
|
|
DeviceStorageAvailableParams p = mParams;
|
2012-11-30 09:41:40 +04:00
|
|
|
type = p.type();
|
2013-01-25 23:05:24 +04:00
|
|
|
requestType = DEVICE_STORAGE_REQUEST_AVAILABLE;
|
2012-11-30 09:41:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-19 06:48:05 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageStatusParams:
|
|
|
|
{
|
|
|
|
DeviceStorageStatusParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_STATUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageFormatParams:
|
|
|
|
{
|
|
|
|
DeviceStorageFormatParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_FORMAT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-04 15:24:19 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageMountParams:
|
|
|
|
{
|
|
|
|
DeviceStorageMountParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_MOUNT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageParams::TDeviceStorageUnmountParams:
|
|
|
|
{
|
|
|
|
DeviceStorageUnmountParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_UNMOUNT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-30 09:41:40 +04:00
|
|
|
case DeviceStorageParams::TDeviceStorageEnumerationParams:
|
|
|
|
{
|
|
|
|
DeviceStorageEnumerationParams p = mParams;
|
|
|
|
type = p.type();
|
|
|
|
requestType = DEVICE_STORAGE_REQUEST_READ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The 'apps' type is special. We only want this exposed
|
|
|
|
// if the caller has the "webapps-manage" permission.
|
|
|
|
if (type.EqualsLiteral("apps")) {
|
|
|
|
if (!AssertAppProcessPermission(aParent, "webapps-manage")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString permissionName;
|
2013-08-03 03:35:16 +04:00
|
|
|
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type,
|
|
|
|
permissionName);
|
2012-11-30 09:41:40 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString access;
|
|
|
|
rv = DeviceStorageTypeChecker::GetAccessForRequest(requestType, access);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-22 07:48:51 +04:00
|
|
|
permissionName.Append('-');
|
2012-11-30 09:41:40 +04:00
|
|
|
permissionName.Append(access);
|
|
|
|
|
|
|
|
if (!AssertAppProcessPermission(aParent, permissionName.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
DeviceStorageRequestParent::~DeviceStorageRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(DeviceStorageRequestParent);
|
|
|
|
}
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
NS_IMPL_ADDREF(DeviceStorageRequestParent)
|
|
|
|
NS_IMPL_RELEASE(DeviceStorageRequestParent)
|
2012-08-10 02:41:18 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason)
|
|
|
|
{
|
2012-08-28 19:39:22 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
2015-03-31 04:43:17 +03:00
|
|
|
mActorDestroyed = true;
|
2015-11-19 08:10:42 +03:00
|
|
|
for (auto& runnable : mRunnables) {
|
|
|
|
runnable->Cancel();
|
2012-08-10 02:41:18 +04:00
|
|
|
}
|
2015-11-19 08:10:42 +03:00
|
|
|
// Ensure we clear all references to the runnables so that there won't
|
|
|
|
// be leak due to cyclic reference. Note that it is safe to release
|
|
|
|
// the references here, since if a runnable is not cancelled yet, the
|
|
|
|
// corresponding thread should still hold a reference to it, and thus
|
|
|
|
// the runnable will end up being released in that thread, not here.
|
|
|
|
mRunnables.Clear();
|
2012-08-10 02:41:18 +04:00
|
|
|
}
|
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(
|
|
|
|
DeviceStorageRequestParent* aParent,
|
|
|
|
uint64_t aFreeSpace)
|
2013-01-25 23:05:24 +04:00
|
|
|
: CancelableRunnable(aParent)
|
|
|
|
, mFreeSpace(aFreeSpace)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestParent::PostFreeSpaceResultEvent::
|
|
|
|
~PostFreeSpaceResultEvent() {}
|
2013-01-25 23:05:24 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-25 23:05:24 +04:00
|
|
|
|
|
|
|
FreeSpaceStorageResponse response(mFreeSpace);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2013-01-25 23:05:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-25 23:05:24 +04:00
|
|
|
|
|
|
|
UsedSpaceStorageResponse response(mUsedSpace);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2013-01-25 23:05:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestParent::PostErrorEvent::
|
|
|
|
PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError)
|
2012-08-10 02:41:18 +04:00
|
|
|
: CancelableRunnable(aParent)
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2012-08-10 02:41:18 +04:00
|
|
|
CopyASCIItoUTF16(aError, mError);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostErrorEvent::CancelableRun() {
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
ErrorResponse response(mError);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2012-06-20 03:14:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() {
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
|
|
|
SuccessResponse response;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2012-06-20 03:14:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsString mime;
|
|
|
|
CopyASCIItoUTF16(mMimeType, mime);
|
|
|
|
|
2013-08-03 03:34:59 +04:00
|
|
|
nsString fullPath;
|
|
|
|
mFile->GetFullPath(fullPath);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BlobImpl> blob =
|
2015-05-12 15:11:03 +03:00
|
|
|
new BlobImplFile(fullPath, mime, mLength, mFile->mFile,
|
2015-05-12 15:09:51 +03:00
|
|
|
mLastModificationDate);
|
2012-08-10 02:41:18 +04:00
|
|
|
|
|
|
|
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
|
2015-05-12 15:11:03 +03:00
|
|
|
BlobParent* actor = cp->GetOrCreateActorForBlobImpl(blob);
|
2013-01-18 00:33:42 +04:00
|
|
|
if (!actor) {
|
|
|
|
ErrorResponse response(NS_LITERAL_STRING(POST_ERROR_EVENT_UNKNOWN));
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2013-01-18 00:33:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-10 02:41:18 +04:00
|
|
|
|
|
|
|
BlobResponse response;
|
|
|
|
response.blobParent() = actor;
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2012-06-20 03:14:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2013-04-18 18:13:23 +04:00
|
|
|
EnumerationResponse response(mStorageType, mRelPath, mPaths);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2012-06-20 03:14:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-17 05:01:27 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::CreateFdEvent::CancelableRun()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
2014-04-04 02:06:26 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2014-01-17 05:01:27 +04:00
|
|
|
|
2014-09-04 22:13:55 +04:00
|
|
|
if (!mFile->mFile) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
return NS_DispatchToMainThread(r);
|
|
|
|
}
|
2014-01-17 05:01:27 +04:00
|
|
|
bool check = false;
|
|
|
|
mFile->mFile->Exists(&check);
|
|
|
|
if (check) {
|
2014-04-04 02:06:26 +04:00
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
|
|
|
|
return NS_DispatchToMainThread(r);
|
2014-01-17 05:01:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FileDescriptor fileDescriptor;
|
|
|
|
nsresult rv = mFile->CreateFileDescriptor(fileDescriptor);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("CreateFileDescriptor failed");
|
|
|
|
mFile->Dump("CreateFileDescriptor failed");
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = new PostFileDescriptorResultEvent(mParent, fileDescriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_DispatchToMainThread(r);
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2014-04-04 02:06:26 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2014-09-04 22:13:55 +04:00
|
|
|
if (!mInputStream || !mFile->mFile) {
|
2012-08-10 02:41:18 +04:00
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-08-10 02:41:18 +04:00
|
|
|
}
|
|
|
|
|
2012-10-13 19:20:14 +04:00
|
|
|
bool check = false;
|
2014-06-10 12:51:28 +04:00
|
|
|
nsresult rv;
|
2012-10-13 19:20:14 +04:00
|
|
|
mFile->mFile->Exists(&check);
|
2014-06-10 12:51:28 +04:00
|
|
|
|
|
|
|
if (mRequestType == DEVICE_STORAGE_REQUEST_CREATE) {
|
|
|
|
if (check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
|
|
|
|
return NS_DispatchToMainThread(r);
|
|
|
|
}
|
|
|
|
rv = mFile->Write(mInputStream);
|
|
|
|
} else if (mRequestType == DEVICE_STORAGE_REQUEST_APPEND) {
|
|
|
|
if (!check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
|
|
|
return NS_DispatchToMainThread(r);
|
|
|
|
}
|
|
|
|
rv = mFile->Append(mInputStream);
|
|
|
|
} else {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
2014-04-04 02:06:26 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-10-13 19:20:14 +04:00
|
|
|
}
|
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = new PostPathResultEvent(mParent, mFile->mPath);
|
|
|
|
}
|
|
|
|
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2012-08-18 06:43:00 +04:00
|
|
|
mFile->Remove();
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2014-04-04 02:06:26 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2012-06-20 03:14:39 +04:00
|
|
|
|
2014-09-04 22:13:55 +04:00
|
|
|
if (!mFile->mFile) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
return NS_DispatchToMainThread(r);
|
|
|
|
}
|
2012-06-20 03:14:39 +04:00
|
|
|
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-10 02:41:18 +04:00
|
|
|
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 23:28:23 +04:00
|
|
|
nsresult
|
2013-01-25 23:05:24 +04:00
|
|
|
DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun()
|
2012-07-31 23:28:23 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2012-07-31 23:28:23 +04:00
|
|
|
|
2012-08-31 07:15:32 +04:00
|
|
|
int64_t freeSpace = 0;
|
2013-05-11 13:10:18 +04:00
|
|
|
if (mFile) {
|
2015-06-17 05:30:56 +03:00
|
|
|
mFile->GetStorageFreeSpace(&freeSpace);
|
2012-07-31 23:28:23 +04:00
|
|
|
}
|
2012-09-14 09:37:00 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2013-05-03 03:26:31 +04:00
|
|
|
r = new PostFreeSpaceResultEvent(mParent, static_cast<uint64_t>(freeSpace));
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2013-01-25 23:05:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
|
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2013-01-25 23:05:24 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
uint64_t picturesUsage = 0, videosUsage = 0, musicUsage = 0, totalUsage = 0;
|
|
|
|
mFile->AccumDiskUsage(&picturesUsage, &videosUsage,
|
|
|
|
&musicUsage, &totalUsage);
|
2013-01-25 23:05:24 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2013-05-11 13:10:18 +04:00
|
|
|
if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
|
2013-08-03 03:35:16 +04:00
|
|
|
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType,
|
|
|
|
picturesUsage);
|
2013-05-11 13:10:18 +04:00
|
|
|
}
|
2013-05-11 13:10:18 +04:00
|
|
|
else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
|
|
|
|
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, videosUsage);
|
|
|
|
}
|
|
|
|
else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_MUSIC)) {
|
|
|
|
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, musicUsage);
|
2013-05-11 17:47:37 +04:00
|
|
|
} else {
|
2013-05-11 13:10:18 +04:00
|
|
|
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, totalUsage);
|
2013-05-03 03:26:31 +04:00
|
|
|
}
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-07-31 23:28:23 +04:00
|
|
|
}
|
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestParent::ReadFileEvent::
|
2015-11-19 08:10:42 +03:00
|
|
|
ReadFileEvent(DeviceStorageRequestParent* aParent,
|
|
|
|
already_AddRefed<DeviceStorageFile>&& aFile)
|
|
|
|
: CancelableFileEvent(aParent, Move(aFile))
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2013-08-03 03:35:16 +04:00
|
|
|
nsCOMPtr<nsIMIMEService> mimeService
|
|
|
|
= do_GetService(NS_MIMESERVICE_CONTRACTID);
|
2012-06-20 03:14:39 +04:00
|
|
|
if (mimeService) {
|
|
|
|
nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mMimeType.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2014-09-04 22:13:55 +04:00
|
|
|
|
|
|
|
if (!mFile->mFile) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
|
|
|
return NS_DispatchToMainThread(r);
|
|
|
|
}
|
2012-06-20 03:14:39 +04:00
|
|
|
bool check = false;
|
|
|
|
mFile->mFile->Exists(&check);
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
if (!check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t fileSize;
|
2012-06-20 03:14:39 +04:00
|
|
|
nsresult rv = mFile->mFile->GetFileSize(&fileSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-18 22:29:32 +04:00
|
|
|
PRTime modDate;
|
|
|
|
rv = mFile->mFile->GetLastModifiedTime(&modDate);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-10-18 22:29:32 +04:00
|
|
|
}
|
|
|
|
|
2015-11-19 08:10:42 +03:00
|
|
|
r = new PostBlobSuccessEvent(mParent, mFile.forget(),
|
|
|
|
static_cast<uint64_t>(fileSize),
|
2013-08-03 03:35:16 +04:00
|
|
|
mMimeType, modDate);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
nsCOMPtr<nsIRunnable> r;
|
2013-05-11 13:10:18 +04:00
|
|
|
if (mFile->mFile) {
|
|
|
|
bool check = false;
|
|
|
|
mFile->mFile->Exists(&check);
|
|
|
|
if (!check) {
|
|
|
|
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2013-05-11 13:10:18 +04:00
|
|
|
}
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DeviceStorageFile> > files;
|
2012-06-20 03:14:39 +04:00
|
|
|
mFile->CollectFiles(files, mSince);
|
|
|
|
|
|
|
|
InfallibleTArray<DeviceStorageFileValue> values;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = files.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2013-05-11 13:10:18 +04:00
|
|
|
DeviceStorageFileValue dsvf(files[i]->mStorageName, files[i]->mPath);
|
2012-06-20 03:14:39 +04:00
|
|
|
values.AppendElement(dsvf);
|
|
|
|
}
|
|
|
|
|
2013-08-03 03:35:16 +04:00
|
|
|
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType,
|
|
|
|
mFile->mRootDir, values);
|
2014-01-17 05:01:27 +04:00
|
|
|
return NS_DispatchToMainThread(r);
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 02:41:18 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostPathResultEvent::CancelableRun()
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-20 03:14:39 +04:00
|
|
|
|
|
|
|
SuccessResponse response;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2012-06-20 03:14:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-17 05:01:27 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostFileDescriptorResultEvent::CancelableRun()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
FileDescriptorResponse response(mFileDescriptor);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2014-02-19 06:48:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostFormatResultEvent::CancelableRun()
|
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-09-06 10:11:58 +04:00
|
|
|
|
|
|
|
nsString state = NS_LITERAL_STRING("unavailable");
|
|
|
|
if (mFile) {
|
|
|
|
mFile->DoFormat(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
FormatStorageResponse response(state);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2013-09-06 10:11:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-04 15:24:19 +04:00
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostMountResultEvent::CancelableRun()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsString state = NS_LITERAL_STRING("unavailable");
|
|
|
|
if (mFile) {
|
|
|
|
mFile->DoMount(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
MountStorageResponse response(state);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2014-03-04 15:24:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DeviceStorageRequestParent::PostUnmountResultEvent::CancelableRun()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsString state = NS_LITERAL_STRING("unavailable");
|
|
|
|
if (mFile) {
|
|
|
|
mFile->DoUnmount(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnmountStorageResponse response(state);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mParent->Send__delete__(mParent, response);
|
2014-03-04 15:24:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
} // namespace devicestorage
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|