Bug 910498 - Changes to device storage to support CreateFd. r=bent

* * *
Bug 910498 - Camera changes to use CreateFd. r=mikeh
* * *
Fixes for windows build
This commit is contained in:
Dave Hylands 2014-01-16 17:01:27 -08:00
parent 3b6056c3b8
commit 05d0d7f21d
12 changed files with 635 additions and 187 deletions

View File

@ -14,7 +14,7 @@
#include "nsDOMEventTargetHelper.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
#include "DOMRequest.h"
#include "mozilla/dom/DOMRequest.h"
#define DEVICESTORAGE_PICTURES "pictures"
#define DEVICESTORAGE_VIDEOS "videos"
@ -23,6 +23,7 @@
#define DEVICESTORAGE_SDCARD "sdcard"
#define DEVICESTORAGE_CRASHES "crashes"
class DeviceStorageFile;
class nsIInputStream;
namespace mozilla {
@ -31,6 +32,9 @@ class DeviceStorageEnumerationParameters;
class DOMCursor;
class DOMRequest;
} // namespace dom
namespace ipc {
class FileDescriptor;
}
} // namespace mozilla
class DeviceStorageFile MOZ_FINAL
@ -102,6 +106,7 @@ public:
nsresult CalculateSizeAndModifiedDate();
nsresult CalculateMimeType();
nsresult CreateFileDescriptor(mozilla::ipc::FileDescriptor& aFileDescriptor);
private:
void Init();

View File

@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=80: */
/* 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 DeviceStorageFileDescriptor_h
#define DeviceStorageFileDescriptor_h
#include "mozilla/ipc/FileDescriptor.h"
class DeviceStorageFileDescriptor MOZ_FINAL
: public mozilla::RefCounted<DeviceStorageFileDescriptor>
{
public:
nsRefPtr<DeviceStorageFile> mDSFile;
mozilla::ipc::FileDescriptor mFileDescriptor;
};
#endif

View File

@ -5,6 +5,7 @@
#include "DeviceStorageRequestChild.h"
#include "DeviceStorageFileDescriptor.h"
#include "nsDeviceStorage.h"
#include "nsDOMFile.h"
#include "mozilla/dom/ipc/Blob.h"
@ -20,11 +21,27 @@ DeviceStorageRequestChild::DeviceStorageRequestChild()
}
DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest,
DeviceStorageFile* aFile)
DeviceStorageFile* aDSFile)
: mRequest(aRequest)
, mFile(aFile)
, mDSFile(aDSFile)
, mCallback(nullptr)
{
MOZ_ASSERT(aRequest);
MOZ_ASSERT(aDSFile);
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
}
DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest,
DeviceStorageFile* aDSFile,
DeviceStorageFileDescriptor* aDSFileDescriptor)
: mRequest(aRequest)
, mDSFile(aDSFile)
, mDSFileDescriptor(aDSFileDescriptor)
, mCallback(nullptr)
{
MOZ_ASSERT(aRequest);
MOZ_ASSERT(aDSFile);
MOZ_ASSERT(aDSFileDescriptor);
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
}
@ -53,7 +70,7 @@ DeviceStorageRequestChild::
case DeviceStorageResponseValue::TSuccessResponse:
{
nsString fullPath;
mFile->GetFullPath(fullPath);
mDSFile->GetFullPath(fullPath);
AutoJSContext cx;
JS::Rooted<JS::Value> result(cx,
StringToJsval(mRequest->GetOwner(), fullPath));
@ -61,6 +78,22 @@ DeviceStorageRequestChild::
break;
}
case DeviceStorageResponseValue::TFileDescriptorResponse:
{
FileDescriptorResponse r = aValue;
nsString fullPath;
mDSFile->GetFullPath(fullPath);
AutoJSContext cx;
JS::Rooted<JS::Value> result(cx,
StringToJsval(mRequest->GetOwner(), fullPath));
mDSFileDescriptor->mDSFile = mDSFile;
mDSFileDescriptor->mFileDescriptor = r.fileDescriptor();
mRequest->FireSuccess(result);
break;
}
case DeviceStorageResponseValue::TBlobResponse:
{
BlobResponse r = aValue;

View File

@ -7,12 +7,15 @@
#define mozilla_dom_devicestorage_DeviceStorageRequestChild_h
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
#include "DOMRequest.h"
class DeviceStorageFile;
class DeviceStorageFileDescriptor;
namespace mozilla {
namespace dom {
class DOMRequest;
namespace devicestorage {
class DeviceStorageRequestChildCallback
@ -26,6 +29,8 @@ class DeviceStorageRequestChild : public PDeviceStorageRequestChild
public:
DeviceStorageRequestChild();
DeviceStorageRequestChild(DOMRequest* aRequest, DeviceStorageFile* aFile);
DeviceStorageRequestChild(DOMRequest* aRequest, DeviceStorageFile* aFile,
DeviceStorageFileDescriptor* aFileDescrptor);
~DeviceStorageRequestChild();
void SetCallback(class DeviceStorageRequestChildCallback *aCallback);
@ -34,7 +39,8 @@ public:
private:
nsRefPtr<DOMRequest> mRequest;
nsRefPtr<DeviceStorageFile> mFile;
nsRefPtr<DeviceStorageFile> mDSFile;
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
DeviceStorageRequestChildCallback* mCallback;
};

View File

@ -29,7 +29,7 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache
= DeviceStorageUsedSpaceCache::CreateOrGet();
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
MOZ_ASSERT(usedSpaceCache);
}
void
@ -53,7 +53,23 @@ DeviceStorageRequestParent::Dispatch()
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
MOZ_ASSERT(target);
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
case DeviceStorageParams::TDeviceStorageCreateFdParams:
{
DeviceStorageCreateFdParams p = mParams;
nsRefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
nsRefPtr<CancelableRunnable> r = new CreateFdEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
MOZ_ASSERT(target);
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
@ -68,7 +84,7 @@ DeviceStorageRequestParent::Dispatch()
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
MOZ_ASSERT(target);
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
@ -83,7 +99,7 @@ DeviceStorageRequestParent::Dispatch()
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
MOZ_ASSERT(target);
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
@ -98,7 +114,7 @@ DeviceStorageRequestParent::Dispatch()
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
MOZ_ASSERT(target);
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
@ -107,7 +123,7 @@ DeviceStorageRequestParent::Dispatch()
{
DeviceStorageUsedSpaceCache* usedSpaceCache
= DeviceStorageUsedSpaceCache::CreateOrGet();
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
MOZ_ASSERT(usedSpaceCache);
DeviceStorageUsedSpaceParams p = mParams;
@ -127,7 +143,8 @@ DeviceStorageRequestParent::Dispatch()
new DeviceStorageFile(p.type(), p.storageName());
nsRefPtr<PostAvailableResultEvent> r
= new PostAvailableResultEvent(this, dsf);
NS_DispatchToMainThread(r);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
MOZ_ASSERT(NS_SUCCEEDED(rv));
break;
}
@ -139,7 +156,8 @@ DeviceStorageRequestParent::Dispatch()
new DeviceStorageFile(p.type(), p.storageName());
nsRefPtr<PostFormatResultEvent> r
= new PostFormatResultEvent(this, dsf);
NS_DispatchToMainThread(r);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(r);
MOZ_ASSERT(NS_SUCCEEDED(rv));
break;
}
@ -154,7 +172,7 @@ DeviceStorageRequestParent::Dispatch()
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
MOZ_ASSERT(target);
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
@ -187,6 +205,14 @@ DeviceStorageRequestParent::EnsureRequiredPermissions(
break;
}
case DeviceStorageParams::TDeviceStorageCreateFdParams:
{
DeviceStorageCreateFdParams p = mParams;
type = p.type();
requestType = DEVICE_STORAGE_REQUEST_CREATEFD;
break;
}
case DeviceStorageParams::TDeviceStorageGetParams:
{
DeviceStorageGetParams p = mParams;
@ -312,7 +338,7 @@ DeviceStorageRequestParent::PostFreeSpaceResultEvent::
nsresult
DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
FreeSpaceStorageResponse response(mFreeSpace);
unused << mParent->Send__delete__(mParent, response);
@ -334,7 +360,7 @@ DeviceStorageRequestParent::PostUsedSpaceResultEvent::
nsresult
DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
UsedSpaceStorageResponse response(mUsedSpace);
unused << mParent->Send__delete__(mParent, response);
@ -352,7 +378,7 @@ DeviceStorageRequestParent::PostErrorEvent::~PostErrorEvent() {}
nsresult
DeviceStorageRequestParent::PostErrorEvent::CancelableRun() {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
ErrorResponse response(mError);
unused << mParent->Send__delete__(mParent, response);
@ -369,7 +395,7 @@ DeviceStorageRequestParent::PostSuccessEvent::~PostSuccessEvent() {}
nsresult
DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
SuccessResponse response;
unused << mParent->Send__delete__(mParent, response);
@ -394,7 +420,7 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::~PostBlobSuccessEvent() {}
nsresult
DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
nsString mime;
CopyASCIItoUTF16(mMimeType, mime);
@ -437,13 +463,54 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::
nsresult
DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
EnumerationResponse response(mStorageType, mRelPath, mPaths);
unused << mParent->Send__delete__(mParent, response);
return NS_OK;
}
DeviceStorageRequestParent::CreateFdEvent::
CreateFdEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
{
}
DeviceStorageRequestParent::CreateFdEvent::~CreateFdEvent()
{
}
nsresult
DeviceStorageRequestParent::CreateFdEvent::CancelableRun()
{
MOZ_ASSERT(!NS_IsMainThread());
nsRefPtr<nsRunnable> r;
bool check = false;
mFile->mFile->Exists(&check);
if (check) {
nsCOMPtr<PostErrorEvent> event
= new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
return NS_DispatchToMainThread(event);
}
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);
}
DeviceStorageRequestParent::WriteFileEvent::
WriteFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile,
@ -461,14 +528,13 @@ DeviceStorageRequestParent::WriteFileEvent::~WriteFileEvent()
nsresult
DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(!NS_IsMainThread());
nsRefPtr<nsRunnable> r;
if (!mInputStream) {
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
bool check = false;
@ -476,8 +542,7 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
if (check) {
nsCOMPtr<PostErrorEvent> event
= new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
NS_DispatchToMainThread(event);
return NS_OK;
return NS_DispatchToMainThread(event);
}
nsresult rv = mFile->Write(mInputStream);
@ -489,11 +554,9 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
r = new PostPathResultEvent(mParent, mFile->mPath);
}
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
DeviceStorageRequestParent::DeleteFileEvent::
DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
@ -508,7 +571,7 @@ DeviceStorageRequestParent::DeleteFileEvent::~DeleteFileEvent()
nsresult
DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(!NS_IsMainThread());
mFile->Remove();
@ -523,8 +586,7 @@ DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
r = new PostPathResultEvent(mParent, mFile->mPath);
}
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
DeviceStorageRequestParent::FreeSpaceFileEvent::
@ -542,7 +604,7 @@ DeviceStorageRequestParent::FreeSpaceFileEvent::~FreeSpaceFileEvent()
nsresult
DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun()
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(!NS_IsMainThread());
int64_t freeSpace = 0;
if (mFile) {
@ -551,8 +613,7 @@ DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun()
nsCOMPtr<nsIRunnable> r;
r = new PostFreeSpaceResultEvent(mParent, static_cast<uint64_t>(freeSpace));
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
DeviceStorageRequestParent::UsedSpaceFileEvent::
@ -570,7 +631,7 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::~UsedSpaceFileEvent()
nsresult
DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(!NS_IsMainThread());
uint64_t picturesUsage = 0, videosUsage = 0, musicUsage = 0, totalUsage = 0;
mFile->AccumDiskUsage(&picturesUsage, &videosUsage,
@ -588,8 +649,7 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
} else {
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, totalUsage);
}
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
DeviceStorageRequestParent::ReadFileEvent::
@ -614,7 +674,7 @@ DeviceStorageRequestParent::ReadFileEvent::~ReadFileEvent()
nsresult
DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(!NS_IsMainThread());
nsCOMPtr<nsIRunnable> r;
bool check = false;
@ -622,30 +682,26 @@ DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
if (!check) {
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
int64_t fileSize;
nsresult rv = mFile->mFile->GetFileSize(&fileSize);
if (NS_FAILED(rv)) {
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
PRTime modDate;
rv = mFile->mFile->GetLastModifiedTime(&modDate);
if (NS_FAILED(rv)) {
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
r = new PostBlobSuccessEvent(mParent, mFile, static_cast<uint64_t>(fileSize),
mMimeType, modDate);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
DeviceStorageRequestParent::EnumerateFileEvent::
@ -665,7 +721,7 @@ DeviceStorageRequestParent::EnumerateFileEvent::~EnumerateFileEvent()
nsresult
DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(!NS_IsMainThread());
nsCOMPtr<nsIRunnable> r;
if (mFile->mFile) {
@ -673,8 +729,7 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
mFile->mFile->Exists(&check);
if (!check) {
r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
}
@ -691,8 +746,7 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType,
mFile->mRootDir, values);
NS_DispatchToMainThread(r);
return NS_OK;
return NS_DispatchToMainThread(r);
}
@ -711,13 +765,36 @@ DeviceStorageRequestParent::PostPathResultEvent::~PostPathResultEvent()
nsresult
DeviceStorageRequestParent::PostPathResultEvent::CancelableRun()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
SuccessResponse response;
unused << mParent->Send__delete__(mParent, response);
return NS_OK;
}
DeviceStorageRequestParent::PostFileDescriptorResultEvent::
PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent,
const FileDescriptor& aFileDescriptor)
: CancelableRunnable(aParent)
, mFileDescriptor(aFileDescriptor)
{
}
DeviceStorageRequestParent::PostFileDescriptorResultEvent::
~PostFileDescriptorResultEvent()
{
}
nsresult
DeviceStorageRequestParent::PostFileDescriptorResultEvent::CancelableRun()
{
MOZ_ASSERT(NS_IsMainThread());
FileDescriptorResponse response(mFileDescriptor);
unused << mParent->Send__delete__(mParent, response);
return NS_OK;
}
DeviceStorageRequestParent::PostAvailableResultEvent::
PostAvailableResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
@ -734,7 +811,7 @@ DeviceStorageRequestParent::PostAvailableResultEvent::
nsresult
DeviceStorageRequestParent::PostAvailableResultEvent::CancelableRun()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
nsString state = NS_LITERAL_STRING("unavailable");
if (mFile) {
@ -762,7 +839,7 @@ DeviceStorageRequestParent::PostFormatResultEvent::
nsresult
DeviceStorageRequestParent::PostFormatResultEvent::CancelableRun()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(NS_IsMainThread());
nsString state = NS_LITERAL_STRING("unavailable");
if (mFile) {

View File

@ -119,6 +119,16 @@ private:
InfallibleTArray<DeviceStorageFileValue> mPaths;
};
class CreateFdEvent : public CancelableRunnable
{
public:
CreateFdEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile);
virtual ~CreateFdEvent();
virtual nsresult CancelableRun();
private:
nsRefPtr<DeviceStorageFile> mFile;
};
class WriteFileEvent : public CancelableRunnable
{
public:
@ -193,6 +203,18 @@ private:
nsString mPath;
};
class PostFileDescriptorResultEvent : public CancelableRunnable
{
public:
PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent,
const FileDescriptor& aFileDescriptor);
virtual ~PostFileDescriptorResultEvent();
virtual nsresult CancelableRun();
private:
nsRefPtr<DeviceStorageFile> mFile;
FileDescriptor mFileDescriptor;
};
class PostFreeSpaceResultEvent : public CancelableRunnable
{
public:

View File

@ -20,6 +20,11 @@ struct SuccessResponse
{
};
struct FileDescriptorResponse
{
FileDescriptor fileDescriptor;
};
struct BlobResponse
{
PBlob blob;
@ -62,6 +67,7 @@ union DeviceStorageResponseValue
{
ErrorResponse;
SuccessResponse;
FileDescriptorResponse;
BlobResponse;
EnumerationResponse;
FreeSpaceStorageResponse;

View File

@ -8,6 +8,7 @@ TEST_DIRS += ['test', 'ipc']
EXPORTS += [
'DeviceStorage.h',
'DeviceStorageFileDescriptor.h',
'nsDeviceStorage.h',
]

File diff suppressed because it is too large Load Diff

View File

@ -52,7 +52,8 @@ enum DeviceStorageRequestType {
DEVICE_STORAGE_REQUEST_FREE_SPACE,
DEVICE_STORAGE_REQUEST_USED_SPACE,
DEVICE_STORAGE_REQUEST_AVAILABLE,
DEVICE_STORAGE_REQUEST_FORMAT
DEVICE_STORAGE_REQUEST_FORMAT,
DEVICE_STORAGE_REQUEST_CREATEFD
};
class DeviceStorageUsedSpaceCache MOZ_FINAL
@ -90,8 +91,8 @@ public:
void Invalidate(const nsAString& aStorageName)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(mIOThread, "Null mIOThread!");
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIOThread);
nsRefPtr<InvalidateRunnable> r = new InvalidateRunnable(this, aStorageName);
mIOThread->Dispatch(r, NS_DISPATCH_NORMAL);
@ -99,8 +100,8 @@ public:
void Dispatch(nsIRunnable* aRunnable)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(mIOThread, "Null mIOThread!");
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIOThread);
mIOThread->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
}

View File

@ -11,7 +11,12 @@ interface nsIDOMDeviceStorageChangeEvent;
interface nsIDOMEventListener;
interface nsIFile;
[scriptable, uuid(7c1b2305-0f14-4c07-8a8a-359eeb850068), builtinclass]
%{C++
class DeviceStorageFileDescriptor;
%}
[ptr] native DeviceStorageFdPtr(DeviceStorageFileDescriptor);
[scriptable, uuid(8b724547-3c78-4244-969a-f00a1f4ae0c3), builtinclass]
interface nsIDOMDeviceStorage : nsIDOMEventTarget
{
[implicit_jscontext] attribute jsval onchange;
@ -34,5 +39,8 @@ interface nsIDOMDeviceStorage : nsIDOMEventTarget
// for storing new files.
readonly attribute bool default;
[noscript] nsIFile getRootDirectoryForFile(in DOMString aName);
// Note: aFileDescriptor is reference counted, which is why we're using
// a pointer rather than a reference.
[noscript] nsIDOMDOMRequest createFileDescriptor(in DOMString aName,
in DeviceStorageFdPtr aFileDescriptor);
};

View File

@ -94,6 +94,13 @@ struct DeviceStorageAddParams
PBlob blob;
};
struct DeviceStorageCreateFdParams
{
nsString type;
nsString storageName;
nsString relpath;
};
struct DeviceStorageGetParams
{
nsString type;
@ -120,6 +127,7 @@ struct DeviceStorageEnumerationParams
union DeviceStorageParams
{
DeviceStorageAddParams;
DeviceStorageCreateFdParams;
DeviceStorageGetParams;
DeviceStorageDeleteParams;
DeviceStorageEnumerationParams;