From 6866ddaadbd5db8f7e56a746a68c93b5490caa0a Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Thu, 16 Aug 2012 16:03:06 -0700 Subject: [PATCH] Bug 783398 - DeviceStorage makes calls to nsVolumeService from the IOThread. r=dhylands --HG-- extra : rebase_source : 8f3fef5b349f5810e256f8f5f4b6217854a03518 --- .../DeviceStorageRequestParent.cpp | 29 +++++++++---------- .../DeviceStorageRequestParent.h | 4 +-- dom/devicestorage/nsDeviceStorage.cpp | 29 ++++++++++--------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/dom/devicestorage/DeviceStorageRequestParent.cpp b/dom/devicestorage/DeviceStorageRequestParent.cpp index 5942c8e87ebe..5ab23080f8da 100644 --- a/dom/devicestorage/DeviceStorageRequestParent.cpp +++ b/dom/devicestorage/DeviceStorageRequestParent.cpp @@ -316,18 +316,8 @@ DeviceStorageRequestParent::StatFileEvent::CancelableRun() NS_DispatchToMainThread(r); return NS_OK; } - nsString state; - state.Assign(NS_LITERAL_STRING("available")); - -#ifdef MOZ_WIDGET_GONK - rv = GetSDCardStatus(state); - if (NS_FAILED(rv)) { - r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); - NS_DispatchToMainThread(r); - return NS_OK; - } -#endif - r = new PostStatResultEvent(mParent, diskUsage, freeSpace, state); + + r = new PostStatResultEvent(mParent, diskUsage, freeSpace); NS_DispatchToMainThread(r); return NS_OK; } @@ -447,12 +437,10 @@ DeviceStorageRequestParent::PostPathResultEvent::CancelableRun() DeviceStorageRequestParent::PostStatResultEvent::PostStatResultEvent(DeviceStorageRequestParent* aParent, PRInt64 aFreeBytes, - PRInt64 aTotalBytes, - nsAString& aState) + PRInt64 aTotalBytes) : CancelableRunnable(aParent) , mFreeBytes(aFreeBytes) , mTotalBytes(aTotalBytes) - , mState(aState) { } @@ -465,7 +453,16 @@ DeviceStorageRequestParent::PostStatResultEvent::CancelableRun() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - StatStorageResponse response(mFreeBytes, mTotalBytes, mState); + 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); unused << mParent->Send__delete__(mParent, response); return NS_OK; } diff --git a/dom/devicestorage/DeviceStorageRequestParent.h b/dom/devicestorage/DeviceStorageRequestParent.h index c1a118a57c13..794cb89c10a8 100644 --- a/dom/devicestorage/DeviceStorageRequestParent.h +++ b/dom/devicestorage/DeviceStorageRequestParent.h @@ -175,13 +175,11 @@ private: public: PostStatResultEvent(DeviceStorageRequestParent* aParent, PRInt64 aFreeBytes, - PRInt64 aTotalBytes, - nsAString& aState); + PRInt64 aTotalBytes); virtual ~PostStatResultEvent(); virtual nsresult CancelableRun(); private: PRInt64 mFreeBytes, mTotalBytes; - nsString mState; }; protected: diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index 20383c878ff2..8d47f588ce5c 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -856,10 +856,9 @@ nsDOMDeviceStorageCursor::IPDLRelease() class PostStatResultEvent : public nsRunnable { public: - PostStatResultEvent(nsRefPtr& aRequest, PRInt64 aFreeBytes, PRInt64 aTotalBytes, nsAString& aState) + PostStatResultEvent(nsRefPtr& aRequest, PRInt64 aFreeBytes, PRInt64 aTotalBytes) : mFreeBytes(aFreeBytes) , mTotalBytes(aTotalBytes) - , mState(aState) { mRequest.swap(aRequest); } @@ -870,7 +869,18 @@ public: { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsRefPtr domstat = new nsDOMDeviceStorageStat(mFreeBytes, mTotalBytes, mState); + nsString state; + state.Assign(NS_LITERAL_STRING("available")); +#ifdef MOZ_WIDGET_GONK + nsresult rv = GetSDCardStatus(state); + if (NS_FAILED(rv)) { + mRequest->FireError(NS_ERROR_FAILURE); + mRequest = nullptr; + return NS_OK; + } +#endif + + nsRefPtr domstat = new nsDOMDeviceStorageStat(mFreeBytes, mTotalBytes, state); jsval result = InterfaceToJsval(mRequest->GetOwner(), domstat, @@ -1069,17 +1079,8 @@ public: NS_DispatchToMainThread(r); return NS_OK; } - nsString state; - state.Assign(NS_LITERAL_STRING("available")); -#ifdef MOZ_WIDGET_GONK - rv = GetSDCardStatus(state); - if (NS_FAILED(rv)) { - r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_UNKNOWN, mFile); - NS_DispatchToMainThread(r); - return NS_OK; - } -#endif - r = new PostStatResultEvent(mRequest, diskUsage, freeSpace, state); + + r = new PostStatResultEvent(mRequest, diskUsage, freeSpace); NS_DispatchToMainThread(r); return NS_OK; }