Bug 1000922 - Use nsMainThreadPtrHandle instead of already_AddRefed and forget for callbacks in NativeOSFileInternals.cpp r=jdm

--HG--
extra : commitid : C07ABGMwgs1
This commit is contained in:
Chris Manchester 2015-08-31 14:28:47 -07:00
parent 9885740a5f
commit baa38d5d62

View File

@ -407,8 +407,8 @@ public:
* alread_AddRefed to ensure that we do not manipulate main-thread
* only refcounters off the main thread.
*/
ErrorEvent(already_AddRefed<nsINativeOSFileSuccessCallback>&& aOnSuccess,
already_AddRefed<nsINativeOSFileErrorCallback>&& aOnError,
ErrorEvent(nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback>& aOnSuccess,
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback>& aOnError,
already_AddRefed<AbstractResult>& aDiscardedResult,
const nsACString& aOperation,
int32_t aOSError)
@ -433,13 +433,13 @@ public:
return NS_OK;
}
private:
// The callbacks. Maintained as nsRefPtr as they are generally
// The callbacks. Maintained as nsMainThreadPtrHandle as they are generally
// xpconnect values, which cannot be manipulated with nsCOMPtr off
// the main thread. We store both the success callback and the
// error callback to ensure that they are safely released on the
// main thread.
nsRefPtr<nsINativeOSFileSuccessCallback> mOnSuccess;
nsRefPtr<nsINativeOSFileErrorCallback> mOnError;
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback> mOnSuccess;
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback> mOnError;
nsRefPtr<AbstractResult> mDiscardedResult;
int32_t mOSError;
nsCString mOperation;
@ -461,8 +461,8 @@ public:
* we do not manipulate xpconnect refcounters off the main thread
* (which is illegal).
*/
SuccessEvent(already_AddRefed<nsINativeOSFileSuccessCallback>&& aOnSuccess,
already_AddRefed<nsINativeOSFileErrorCallback>&& aOnError,
SuccessEvent(nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback>& aOnSuccess,
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback>& aOnError,
already_AddRefed<nsINativeOSFileResult>& aResult)
: mOnSuccess(aOnSuccess)
, mOnError(aOnError)
@ -483,13 +483,13 @@ public:
return NS_OK;
}
private:
// The callbacks. Maintained as nsRefPtr as they are generally
// The callbacks. Maintained as nsMainThreadPtrHandle as they are generally
// xpconnect values, which cannot be manipulated with nsCOMPtr off
// the main thread. We store both the success callback and the
// error callback to ensure that they are safely released on the
// main thread.
nsRefPtr<nsINativeOSFileSuccessCallback> mOnSuccess;
nsRefPtr<nsINativeOSFileErrorCallback> mOnError;
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback> mOnSuccess;
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback> mOnError;
nsRefPtr<nsINativeOSFileResult> mResult;
};
@ -501,8 +501,8 @@ public:
*/
class AbstractDoEvent: public nsRunnable {
public:
AbstractDoEvent(already_AddRefed<nsINativeOSFileSuccessCallback>& aOnSuccess,
already_AddRefed<nsINativeOSFileErrorCallback>& aOnError)
AbstractDoEvent(nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback>& aOnSuccess,
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback>& aOnError)
: mOnSuccess(aOnSuccess)
, mOnError(aOnError)
#if defined(DEBUG)
@ -519,8 +519,8 @@ public:
already_AddRefed<AbstractResult>&& aDiscardedResult,
int32_t aOSError = 0) {
Resolve();
nsRefPtr<ErrorEvent> event = new ErrorEvent(mOnSuccess.forget(),
mOnError.forget(),
nsRefPtr<ErrorEvent> event = new ErrorEvent(mOnSuccess,
mOnError,
aDiscardedResult,
aOperation,
aOSError);
@ -539,8 +539,8 @@ public:
*/
void Succeed(already_AddRefed<nsINativeOSFileResult>&& aResult) {
Resolve();
nsRefPtr<SuccessEvent> event = new SuccessEvent(mOnSuccess.forget(),
mOnError.forget(),
nsRefPtr<SuccessEvent> event = new SuccessEvent(mOnSuccess,
mOnError,
aResult);
nsresult rv = NS_DispatchToMainThread(event);
if (NS_FAILED(rv)) {
@ -566,8 +566,8 @@ private:
}
private:
nsRefPtr<nsINativeOSFileSuccessCallback> mOnSuccess;
nsRefPtr<nsINativeOSFileErrorCallback> mOnError;
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback> mOnSuccess;
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback> mOnError;
#if defined(DEBUG)
// |true| once the action is complete
bool mResolved;
@ -587,8 +587,8 @@ public:
*/
AbstractReadEvent(const nsAString& aPath,
const uint64_t aBytes,
already_AddRefed<nsINativeOSFileSuccessCallback>& aOnSuccess,
already_AddRefed<nsINativeOSFileErrorCallback>& aOnError)
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback>& aOnSuccess,
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback>& aOnError)
: AbstractDoEvent(aOnSuccess, aOnError)
, mPath(aPath)
, mBytes(aBytes)
@ -736,8 +736,8 @@ class DoReadToTypedArrayEvent final : public AbstractReadEvent {
public:
DoReadToTypedArrayEvent(const nsAString& aPath,
const uint32_t aBytes,
already_AddRefed<nsINativeOSFileSuccessCallback>&& aOnSuccess,
already_AddRefed<nsINativeOSFileErrorCallback>&& aOnError)
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback>& aOnSuccess,
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback>& aOnError)
: AbstractReadEvent(aPath, aBytes,
aOnSuccess, aOnError)
, mResult(new TypedArrayResult(TimeStamp::Now()))
@ -774,8 +774,8 @@ public:
DoReadToStringEvent(const nsAString& aPath,
const nsACString& aEncoding,
const uint32_t aBytes,
already_AddRefed<nsINativeOSFileSuccessCallback>&& aOnSuccess,
already_AddRefed<nsINativeOSFileErrorCallback>&& aOnError)
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback>& aOnSuccess,
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback>& aOnError)
: AbstractReadEvent(aPath, aBytes, aOnSuccess, aOnError)
, mEncoding(aEncoding)
, mResult(new StringResult(TimeStamp::Now()))
@ -890,17 +890,21 @@ NativeOSFileInternalsService::Read(const nsAString& aPath,
// Prepare the off main thread event and dispatch it
nsCOMPtr<nsINativeOSFileSuccessCallback> onSuccess(aOnSuccess);
nsMainThreadPtrHandle<nsINativeOSFileSuccessCallback> onSuccessHandle(
new nsMainThreadPtrHolder<nsINativeOSFileSuccessCallback>(onSuccess));
nsCOMPtr<nsINativeOSFileErrorCallback> onError(aOnError);
nsMainThreadPtrHandle<nsINativeOSFileErrorCallback> onErrorHandle(
new nsMainThreadPtrHolder<nsINativeOSFileErrorCallback>(onError));
nsRefPtr<AbstractDoEvent> event;
if (encoding.IsEmpty()) {
event = new DoReadToTypedArrayEvent(aPath, bytes,
onSuccess.forget(),
onError.forget());
onSuccessHandle,
onErrorHandle);
} else {
event = new DoReadToStringEvent(aPath, encoding, bytes,
onSuccess.forget(),
onError.forget());
onSuccessHandle,
onErrorHandle);
}
nsresult rv;