Bug 794619 - Remote the blobs returned from enumerate. r=bent

This commit is contained in:
Doug Turner 2012-10-04 13:40:45 -07:00
parent 6ee7b9f2c3
commit c9ecc05799
5 changed files with 101 additions and 16 deletions

View File

@ -14,6 +14,7 @@ namespace dom {
namespace devicestorage {
DeviceStorageRequestChild::DeviceStorageRequestChild()
: mCallback(nullptr)
{
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
}
@ -22,6 +23,7 @@ DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest,
DeviceStorageFile* aFile)
: mRequest(aRequest)
, mFile(aFile)
, mCallback(nullptr)
{
MOZ_COUNT_CTOR(DeviceStorageRequestChild);
}
@ -33,6 +35,11 @@ DeviceStorageRequestChild::~DeviceStorageRequestChild() {
bool
DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aValue)
{
if (mCallback) {
mCallback->RequestComplete();
mCallback = nullptr;
}
switch (aValue.type()) {
case DeviceStorageResponseValue::TErrorResponse:
@ -90,7 +97,7 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
}
nsCOMPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor);
NS_DispatchToMainThread(event);
event->Continue();
break;
}
@ -103,6 +110,11 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
return true;
}
void
DeviceStorageRequestChild::SetCallback(DeviceStorageRequestChildCallback *aCallback)
{
mCallback = aCallback;
}
} // namespace devicestorage
} // namespace dom

View File

@ -8,11 +8,19 @@
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
#include "DOMRequest.h"
#include "nsDeviceStorage.h"
class DeviceStorageFile;
namespace mozilla {
namespace dom {
namespace devicestorage {
class DeviceStorageRequestChildCallback
{
public:
virtual void RequestComplete() = 0;
};
class DeviceStorageRequestChild : public PDeviceStorageRequestChild
{
public:
@ -20,11 +28,15 @@ public:
DeviceStorageRequestChild(DOMRequest* aRequest, DeviceStorageFile* aFile);
~DeviceStorageRequestChild();
void SetCallback(class DeviceStorageRequestChildCallback *aCallback);
virtual bool Recv__delete__(const DeviceStorageResponseValue& value);
private:
nsRefPtr<DOMRequest> mRequest;
nsRefPtr<DeviceStorageFile> mFile;
DeviceStorageRequestChildCallback* mCallback;
};
} // namespace devicestorage

View File

@ -751,12 +751,12 @@ jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile)
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aWindow, "Null Window");
if (aFile->mEditable) {
// TODO - needs janv's file handle support.
if (!aFile) {
return JSVAL_NULL;
}
if (aFile == nullptr) {
if (aFile->mEditable) {
// TODO - needs janv's file handle support.
return JSVAL_NULL;
}
@ -912,21 +912,18 @@ ContinueCursorEvent::ContinueCursorEvent(DOMRequest* aRequest)
{
}
ContinueCursorEvent::~ContinueCursorEvent() {}
NS_IMETHODIMP
ContinueCursorEvent::Run() {
already_AddRefed<DeviceStorageFile>
ContinueCursorEvent::GetNextFile()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
jsval val = JSVAL_NULL;
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
nsString cursorStorageType;
cursor->GetStorageType(cursorStorageType);
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
if (!typeChecker) {
return NS_ERROR_FAILURE;
return nullptr;
}
while (cursor->mFiles.Length() > 0) {
@ -935,11 +932,58 @@ ContinueCursorEvent::Run() {
if (!typeChecker->Check(cursorStorageType, file->mFile)) {
continue;
}
val = nsIFileToJsval(cursor->GetOwner(), file);
cursor->mOkToCallContinue = true;
break;
return file.forget();
}
return nullptr;
}
ContinueCursorEvent::~ContinueCursorEvent() {}
void
ContinueCursorEvent::Continue()
{
if (XRE_GetProcessType() == GeckoProcessType_Default) {
NS_DispatchToMainThread(this);
return;
}
nsRefPtr<DeviceStorageFile> file = GetNextFile();
if (!file) {
// done with enumeration.
NS_DispatchToMainThread(this);
return;
}
nsString fullpath;
nsresult rv = file->mFile->GetPath(fullpath);
if (NS_FAILED(rv)) {
NS_ASSERTION(false, "GetPath failed to return a valid path");
return;
}
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
nsString cursorStorageType;
cursor->GetStorageType(cursorStorageType);
DeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, file);
child->SetCallback(cursor);
DeviceStorageGetParams params(cursorStorageType, file->mPath, fullpath);
ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params);
mRequest = nullptr;
}
NS_IMETHODIMP
ContinueCursorEvent::Run()
{
nsRefPtr<DeviceStorageFile> file = GetNextFile();
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
jsval val = nsIFileToJsval(cursor->GetOwner(), file);
cursor->mOkToCallContinue = true;
mRequest->FireSuccess(val);
mRequest = nullptr;
return NS_OK;
@ -1132,6 +1176,13 @@ nsDOMDeviceStorageCursor::IPDLRelease()
Release();
}
void
nsDOMDeviceStorageCursor::RequestComplete()
{
NS_ASSERTION(!mOkToCallContinue, "mOkToCallContinue must be false");
mOkToCallContinue = true;
}
class PostStatResultEvent : public nsRunnable
{
public:

View File

@ -30,6 +30,7 @@ class nsPIDOMWindow;
#include "prtime.h"
#include "DeviceStorage.h"
#include "DeviceStorageRequestChild.h"
#define POST_ERROR_EVENT_FILE_DOES_NOT_EXIST "File location doesn't exists"
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "File location is not enumerable"
@ -40,7 +41,9 @@ class nsPIDOMWindow;
#define POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED "Non-string type unsupported"
#define POST_ERROR_EVENT_NOT_IMPLEMENTED "Not implemented"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::devicestorage;
class DeviceStorageTypeChecker MOZ_FINAL
{
@ -97,14 +100,17 @@ private:
void AppendRelativePath();
};
class ContinueCursorEvent MOZ_FINAL: public nsRunnable
class ContinueCursorEvent MOZ_FINAL : public nsRunnable
{
public:
ContinueCursorEvent(nsRefPtr<DOMRequest>& aRequest);
ContinueCursorEvent(DOMRequest* aRequest);
~ContinueCursorEvent();
void Continue();
NS_IMETHOD Run();
private:
already_AddRefed<DeviceStorageFile> GetNextFile();
nsRefPtr<DOMRequest> mRequest;
};
@ -113,6 +119,7 @@ class nsDOMDeviceStorageCursor MOZ_FINAL
, public DOMRequest
, public nsIContentPermissionRequest
, public PCOMContentPermissionRequestChild
, public DeviceStorageRequestChildCallback
{
public:
NS_DECL_ISUPPORTS_INHERITED
@ -134,6 +141,8 @@ public:
void GetStorageType(nsAString & aType);
void RequestComplete();
private:
~nsDOMDeviceStorageCursor();

View File

@ -102,6 +102,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsContentUtils.h"
#include "nsIPrincipal.h"
#include "nsDeviceStorage.h"
using namespace base;
using namespace mozilla::docshell;