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 "DeviceStorageRequestChild.h"
|
2014-01-17 05:01:27 +04:00
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
2012-06-20 03:14:39 +04:00
|
|
|
#include "nsDeviceStorage.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/BlobChild.h"
|
2012-06-20 03:14:39 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace devicestorage {
|
|
|
|
|
|
|
|
DeviceStorageRequestChild::DeviceStorageRequestChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
|
|
|
|
}
|
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
DeviceStorageRequestChild::DeviceStorageRequestChild(DeviceStorageRequest* aRequest)
|
2012-06-20 03:14:39 +04:00
|
|
|
: mRequest(aRequest)
|
|
|
|
{
|
2014-01-17 05:01:27 +04:00
|
|
|
MOZ_ASSERT(aRequest);
|
2012-06-20 03:14:39 +04:00
|
|
|
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceStorageRequestChild::~DeviceStorageRequestChild() {
|
|
|
|
MOZ_COUNT_DTOR(DeviceStorageRequestChild);
|
|
|
|
}
|
2012-08-10 02:41:18 +04:00
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
bool
|
2013-08-03 03:35:16 +04:00
|
|
|
DeviceStorageRequestChild::
|
|
|
|
Recv__delete__(const DeviceStorageResponseValue& aValue)
|
2012-06-20 03:14:39 +04:00
|
|
|
{
|
|
|
|
switch (aValue.type()) {
|
|
|
|
|
|
|
|
case DeviceStorageResponseValue::TErrorResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("error %u", mRequest->GetId());
|
2012-06-20 03:14:39 +04:00
|
|
|
ErrorResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Reject(r.error());
|
2012-06-20 03:14:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageResponseValue::TSuccessResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("success %u", mRequest->GetId());
|
2013-08-03 03:34:59 +04:00
|
|
|
nsString fullPath;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->GetFile()->GetFullPath(fullPath);
|
|
|
|
mRequest->Resolve(fullPath);
|
2014-01-17 05:01:27 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageResponseValue::TFileDescriptorResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("fd %u", mRequest->GetId());
|
2014-01-17 05:01:27 +04:00
|
|
|
FileDescriptorResponse r = aValue;
|
|
|
|
|
2015-08-26 03:13:34 +03:00
|
|
|
DeviceStorageFile* file = mRequest->GetFile();
|
|
|
|
DeviceStorageFileDescriptor* descriptor = mRequest->GetFileDescriptor();
|
2014-01-17 05:01:27 +04:00
|
|
|
nsString fullPath;
|
2015-08-26 03:13:34 +03:00
|
|
|
file->GetFullPath(fullPath);
|
|
|
|
descriptor->mDSFile = file;
|
|
|
|
descriptor->mFileDescriptor = r.fileDescriptor();
|
|
|
|
mRequest->Resolve(fullPath);
|
2012-06-20 03:14:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageResponseValue::TBlobResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("blob %u", mRequest->GetId());
|
2012-06-20 03:14:39 +04:00
|
|
|
BlobResponse r = aValue;
|
2012-08-10 02:41:18 +04:00
|
|
|
BlobChild* actor = static_cast<BlobChild*>(r.blobChild());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BlobImpl> blobImpl = actor->GetBlobImpl();
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Resolve(blobImpl.get());
|
2012-07-31 23:28:23 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-25 23:05:24 +04:00
|
|
|
case DeviceStorageResponseValue::TFreeSpaceStorageResponse:
|
2012-07-31 23:28:23 +04:00
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("free %u", mRequest->GetId());
|
2013-01-25 23:05:24 +04:00
|
|
|
FreeSpaceStorageResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Resolve(r.freeBytes());
|
2013-01-25 23:05:24 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-07-31 23:28:23 +04:00
|
|
|
|
2013-01-25 23:05:24 +04:00
|
|
|
case DeviceStorageResponseValue::TUsedSpaceStorageResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("used %u", mRequest->GetId());
|
2013-01-25 23:05:24 +04:00
|
|
|
UsedSpaceStorageResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Resolve(r.usedBytes());
|
2013-01-25 23:05:24 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
case DeviceStorageResponseValue::TFormatStorageResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("format %u", mRequest->GetId());
|
2013-09-06 10:11:58 +04:00
|
|
|
FormatStorageResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Resolve(r.mountState());
|
2012-06-20 03:14:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-04 15:24:19 +04:00
|
|
|
case DeviceStorageResponseValue::TMountStorageResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("mount %u", mRequest->GetId());
|
2014-03-04 15:24:19 +04:00
|
|
|
MountStorageResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Resolve(r.storageStatus());
|
2014-03-04 15:24:19 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeviceStorageResponseValue::TUnmountStorageResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("unmount %u", mRequest->GetId());
|
2014-03-04 15:24:19 +04:00
|
|
|
UnmountStorageResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
mRequest->Resolve(r.storageStatus());
|
2014-03-04 15:24:19 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-20 03:14:39 +04:00
|
|
|
case DeviceStorageResponseValue::TEnumerationResponse:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_INFO("enumerate %u", mRequest->GetId());
|
2012-06-20 03:14:39 +04:00
|
|
|
EnumerationResponse r = aValue;
|
2015-08-26 03:13:34 +03:00
|
|
|
auto request = static_cast<DeviceStorageCursorRequest*>(mRequest.get());
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = r.paths().Length();
|
2015-08-26 03:13:34 +03:00
|
|
|
request->AddFiles(count);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DeviceStorageFile> dsf
|
2013-08-03 03:35:16 +04:00
|
|
|
= new DeviceStorageFile(r.type(), r.paths()[i].storageName(),
|
|
|
|
r.rootdir(), r.paths()[i].name());
|
2015-08-26 03:13:34 +03:00
|
|
|
request->AddFile(dsf.forget());
|
2012-06-20 03:14:39 +04:00
|
|
|
}
|
2015-08-26 03:13:34 +03:00
|
|
|
request->Continue();
|
2012-06-20 03:14:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2015-08-26 03:13:34 +03:00
|
|
|
DS_LOG_ERROR("unknown %u", mRequest->GetId());
|
2012-06-20 03:14:39 +04:00
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace devicestorage
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|