Bug 1261307: Convert RIL sockets to |UniquePtr|, r=nfroyd

This commit is contained in:
Thomas Zimmermann 2016-04-05 13:40:11 +02:00
parent a1ade1d06b
commit bd8f7f577e
5 changed files with 24 additions and 24 deletions

View File

@ -38,7 +38,7 @@ class RilConsumer;
static const char RIL_SOCKET_NAME[] = "/dev/socket/rilproxy";
static nsTArray<nsAutoPtr<RilConsumer>> sRilConsumers;
static nsTArray<UniquePtr<RilConsumer>> sRilConsumers;
//
// RilConsumer
@ -60,7 +60,7 @@ public:
void ReceiveSocketData(JSContext* aCx,
int aIndex,
nsAutoPtr<UnixSocketBuffer>& aBuffer) override;
UniquePtr<UnixSocketBuffer>& aBuffer) override;
void OnConnectSuccess(int aIndex) override;
void OnConnectError(int aIndex) override;
void OnDisconnect(int aIndex) override;
@ -182,7 +182,7 @@ RilConsumer::Send(JSContext* aCx, const CallArgs& aArgs)
return NS_OK;
}
nsAutoPtr<UnixSocketRawData> raw;
UniquePtr<UnixSocketRawData> raw;
Value v = aArgs[1];
@ -193,7 +193,7 @@ RilConsumer::Send(JSContext* aCx, const CallArgs& aArgs)
return NS_ERROR_FAILURE;
}
raw = new UnixSocketRawData(abs.ptr(), abs.length());
raw = MakeUnique<UnixSocketRawData>(abs.ptr(), abs.length());
} else if (!v.isPrimitive()) {
JSObject* obj = v.toObjectOrNull();
if (!JS_IsTypedArrayObject(obj)) {
@ -221,7 +221,7 @@ RilConsumer::Send(JSContext* aCx, const CallArgs& aArgs)
aCx, "Incorrect argument. Shared memory not supported");
return NS_ERROR_FAILURE;
}
raw = new UnixSocketRawData(data, size);
raw = MakeUnique<UnixSocketRawData>(data, size);
} else {
JS_ReportError(
aCx, "Incorrect argument. Expecting a string or a typed array");
@ -233,7 +233,7 @@ RilConsumer::Send(JSContext* aCx, const CallArgs& aArgs)
return NS_ERROR_FAILURE;
}
mSocket->SendSocketData(raw.forget());
mSocket->SendSocketData(raw.release());
return NS_OK;
}
@ -289,9 +289,9 @@ RilConsumer::Close()
void
RilConsumer::ReceiveSocketData(JSContext* aCx,
int aIndex,
nsAutoPtr<UnixSocketBuffer>& aBuffer)
UniquePtr<UnixSocketBuffer>& aBuffer)
{
Receive(aCx, (uint32_t)aIndex, aBuffer);
Receive(aCx, (uint32_t)aIndex, aBuffer.get());
}
void
@ -323,7 +323,7 @@ RilConsumer::OnDisconnect(int aIndex)
// RilWorker
//
nsTArray<nsAutoPtr<RilWorker>> RilWorker::sRilWorkers;
nsTArray<UniquePtr<RilWorker>> RilWorker::sRilWorkers;
nsresult
RilWorker::Register(unsigned int aClientId,
@ -339,7 +339,7 @@ RilWorker::Register(unsigned int aClientId,
}
// Now that we're set up, connect ourselves to the RIL thread.
sRilWorkers[aClientId] = new RilWorker(aDispatcher);
sRilWorkers[aClientId] = MakeUnique<RilWorker>(aDispatcher);
nsresult rv = sRilWorkers[aClientId]->RegisterConsumer(aClientId);
if (NS_FAILED(rv)) {
@ -386,7 +386,7 @@ public:
MOZ_ASSERT(!sRilConsumers[mClientId]);
nsAutoPtr<RilConsumer> rilConsumer(new RilConsumer());
auto rilConsumer = MakeUnique<RilConsumer>();
nsresult rv = rilConsumer->ConnectWorkerToRIL(aCx);
if (NS_FAILED(rv)) {
@ -397,7 +397,7 @@ public:
if (NS_FAILED(rv)) {
return false;
}
sRilConsumers[mClientId] = rilConsumer;
sRilConsumers[mClientId] = Move(rilConsumer);
return true;
}

View File

@ -7,7 +7,6 @@
#ifndef mozilla_ipc_Ril_h
#define mozilla_ipc_Ril_h 1
#include "nsAutoPtr.h"
#include "nsError.h"
#include "nsTArray.h"
@ -34,16 +33,17 @@ public:
static void Shutdown();
// Public for |MakeUnique| Call |Register| instead.
RilWorker(mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
private:
class RegisterConsumerTask;
class UnregisterConsumerTask;
RilWorker(mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
nsresult RegisterConsumer(unsigned int aClientId);
void UnregisterConsumer(unsigned int aClientId);
static nsTArray<nsAutoPtr<RilWorker>> sRilWorkers;
static nsTArray<UniquePtr<RilWorker>> sRilWorkers;
RefPtr<mozilla::dom::workers::WorkerCrossThreadDispatcher> mDispatcher;
};

View File

@ -93,7 +93,7 @@ private:
/**
* I/O buffer for received data
*/
nsAutoPtr<UnixSocketRawData> mBuffer;
UniquePtr<UnixSocketRawData> mBuffer;
};
RilSocketIO::RilSocketIO(WorkerCrossThreadDispatcher* aDispatcher,
@ -170,7 +170,7 @@ RilSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
MOZ_ASSERT(aBuffer);
if (!mBuffer) {
mBuffer = new UnixSocketRawData(MAX_READ_SIZE);
mBuffer = MakeUnique<UnixSocketRawData>(MAX_READ_SIZE);
}
*aBuffer = mBuffer.get();
@ -212,13 +212,13 @@ public:
private:
RilSocketIO* mIO;
nsAutoPtr<UnixSocketBuffer> mBuffer;
UniquePtr<UnixSocketBuffer> mBuffer;
};
void
RilSocketIO::ConsumeBuffer()
{
RefPtr<ReceiveTask> task = new ReceiveTask(this, mBuffer.forget());
RefPtr<ReceiveTask> task = new ReceiveTask(this, mBuffer.release());
NS_WARN_IF(!mDispatcher->PostTask(task));
}
@ -342,7 +342,7 @@ RilSocket::~RilSocket()
void
RilSocket::ReceiveSocketData(JSContext* aCx,
nsAutoPtr<UnixSocketBuffer>& aBuffer)
UniquePtr<UnixSocketBuffer>& aBuffer)
{
mConsumer->ReceiveSocketData(aCx, mIndex, aBuffer);
}

View File

@ -48,7 +48,7 @@ public:
* @param aCx The RIL worker's JS context.
* @param aBuffer Data received from the socket.
*/
void ReceiveSocketData(JSContext* aCx, nsAutoPtr<UnixSocketBuffer>& aBuffer);
void ReceiveSocketData(JSContext* aCx, UniquePtr<UnixSocketBuffer>& aBuffer);
/**
* Starts a task on the socket that will try to connect to a socket in a

View File

@ -7,7 +7,7 @@
#ifndef mozilla_ipc_RilSocketConsumer_h
#define mozilla_ipc_RilSocketConsumer_h
#include "nsAutoPtr.h"
#include "mozilla/UniquePtr.h"
class JSContext;
@ -31,7 +31,7 @@ public:
*/
virtual void ReceiveSocketData(JSContext* aCx,
int aIndex,
nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
UniquePtr<UnixSocketBuffer>& aBuffer) = 0;
/**
* Callback for socket success. Consumer-thread only.