Bug 1261307: Convert RIL sockets to |UniquePtr|, r=nfroyd
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 05 Apr 2016 13:40:11 +0200
changeset 291632 6d72a998142a67abdf81082e0b4803d2fa52a503
parent 291631 e7d1dab0ba6ff0e4be3aa1688a355ccbd16ecda3
child 291633 26d2542166766085c978adb3bf6130441cbe13c2
push id74645
push usertdz@users.sourceforge.net
push dateTue, 05 Apr 2016 11:42:01 +0000
treeherdermozilla-inbound@7e2855721acc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1261307
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1261307: Convert RIL sockets to |UniquePtr|, r=nfroyd
ipc/ril/Ril.cpp
ipc/ril/Ril.h
ipc/ril/RilSocket.cpp
ipc/ril/RilSocket.h
ipc/ril/RilSocketConsumer.h
--- a/ipc/ril/Ril.cpp
+++ b/ipc/ril/Ril.cpp
@@ -33,17 +33,17 @@ namespace ipc {
 
 USING_WORKERS_NAMESPACE;
 using namespace JS;
 
 class RilConsumer;
 
 static const char RIL_SOCKET_NAME[] = "/dev/socket/rilproxy";
 
-static nsTArray<nsAutoPtr<RilConsumer>> sRilConsumers;
+static nsTArray<UniquePtr<RilConsumer>> sRilConsumers;
 
 //
 // RilConsumer
 //
 
 class RilConsumer final : public RilSocketConsumer
 {
 public:
@@ -55,17 +55,17 @@ public:
                     WorkerCrossThreadDispatcher* aDispatcher);
   void Unregister();
 
   // Methods for |RilSocketConsumer|
   //
 
   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;
 
 protected:
   static bool PostRILMessage(JSContext* aCx, unsigned aArgc, Value* aVp);
 
   nsresult Send(JSContext* aCx, const CallArgs& aArgs);
@@ -177,28 +177,28 @@ nsresult
 RilConsumer::Send(JSContext* aCx, const CallArgs& aArgs)
 {
   if (NS_WARN_IF(!mSocket) ||
       NS_WARN_IF(mSocket->GetConnectionStatus() == SOCKET_DISCONNECTED)) {
     // Probably shutting down.
     return NS_OK;
   }
 
-  nsAutoPtr<UnixSocketRawData> raw;
+  UniquePtr<UnixSocketRawData> raw;
 
   Value v = aArgs[1];
 
   if (v.isString()) {
     JSAutoByteString abs;
     Rooted<JSString*> str(aCx, v.toString());
     if (!abs.encodeUtf8(aCx, str)) {
       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)) {
       JS_ReportError(aCx, "Object passed in wasn't a typed array");
       return NS_ERROR_FAILURE;
     }
 
     uint32_t type = JS_GetArrayBufferViewType(obj);
@@ -216,29 +216,29 @@ RilConsumer::Send(JSContext* aCx, const 
       AutoCheckCannotGC nogc;
       data = JS_GetArrayBufferViewData(obj, &isShared, nogc);
     }
     if (isShared) {
       JS_ReportError(
         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");
     return NS_ERROR_FAILURE;
   }
 
   if (!raw) {
     JS_ReportError(aCx, "Unable to post to RIL");
     return NS_ERROR_FAILURE;
   }
 
-  mSocket->SendSocketData(raw.forget());
+  mSocket->SendSocketData(raw.release());
 
   return NS_OK;
 }
 
 nsresult
 RilConsumer::Receive(JSContext* aCx,
                      uint32_t aClientId,
                      const UnixSocketBuffer* aBuffer)
@@ -284,19 +284,19 @@ RilConsumer::Close()
   }
 }
 
 // |RilSocketConnector|
 
 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
 RilConsumer::OnConnectSuccess(int aIndex)
 {
   // Nothing to do here.
   CHROMIUM_LOG("RIL[%d]: %s\n", aIndex, __FUNCTION__);
 }
@@ -318,33 +318,33 @@ RilConsumer::OnDisconnect(int aIndex)
   mSocket->Connect(new RilConnector(mAddress, aIndex),
                    mSocket->GetSuggestedConnectDelayMs());
 }
 
 //
 // RilWorker
 //
 
-nsTArray<nsAutoPtr<RilWorker>> RilWorker::sRilWorkers;
+nsTArray<UniquePtr<RilWorker>> RilWorker::sRilWorkers;
 
 nsresult
 RilWorker::Register(unsigned int aClientId,
                     WorkerCrossThreadDispatcher* aDispatcher)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   sRilWorkers.EnsureLengthAtLeast(aClientId + 1);
 
   if (sRilWorkers[aClientId]) {
     NS_WARNING("RilWorkers already registered");
     return NS_ERROR_FAILURE;
   }
 
   // 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)) {
     return rv;
   }
 
   return NS_OK;
 }
@@ -381,28 +381,28 @@ public:
   }
 
   bool RunTask(JSContext* aCx) override
   {
     sRilConsumers.EnsureLengthAtLeast(mClientId + 1);
 
     MOZ_ASSERT(!sRilConsumers[mClientId]);
 
-    nsAutoPtr<RilConsumer> rilConsumer(new RilConsumer());
+    auto rilConsumer = MakeUnique<RilConsumer>();
 
     nsresult rv = rilConsumer->ConnectWorkerToRIL(aCx);
     if (NS_FAILED(rv)) {
       return false;
     }
 
     rv = rilConsumer->Register(mClientId, mDispatcher);
     if (NS_FAILED(rv)) {
       return false;
     }
-    sRilConsumers[mClientId] = rilConsumer;
+    sRilConsumers[mClientId] = Move(rilConsumer);
 
     return true;
   }
 
 private:
   unsigned int mClientId;
   RefPtr<WorkerCrossThreadDispatcher> mDispatcher;
 };
--- a/ipc/ril/Ril.h
+++ b/ipc/ril/Ril.h
@@ -2,17 +2,16 @@
 /* vim: set ts=2 et sw=2 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 mozilla_ipc_Ril_h
 #define mozilla_ipc_Ril_h 1
 
-#include "nsAutoPtr.h"
 #include "nsError.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 
 namespace dom {
 namespace workers {
 
@@ -29,26 +28,27 @@ class RilWorker final
 {
 public:
   static nsresult Register(
     unsigned int aClientId,
     mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
 
   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;
 };
 
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_Ril_h
--- a/ipc/ril/RilSocket.cpp
+++ b/ipc/ril/RilSocket.cpp
@@ -88,17 +88,17 @@ private:
    * Task member for delayed connect task. Should only be access on consumer
    * thread.
    */
   CancelableTask* mDelayedConnectTask;
 
   /**
    * I/O buffer for received data
    */
-  nsAutoPtr<UnixSocketRawData> mBuffer;
+  UniquePtr<UnixSocketRawData> mBuffer;
 };
 
 RilSocketIO::RilSocketIO(WorkerCrossThreadDispatcher* aDispatcher,
                          MessageLoop* aConsumerLoop,
                          MessageLoop* aIOLoop,
                          RilSocket* aRilSocket,
                          UnixSocketConnector* aConnector)
   : ConnectionOrientedSocketIO(aConsumerLoop, aIOLoop, aConnector)
@@ -165,17 +165,17 @@ RilSocketIO::CancelDelayedConnectTask()
 // |DataSocketIO|
 
 nsresult
 RilSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
 {
   MOZ_ASSERT(aBuffer);
 
   if (!mBuffer) {
-    mBuffer = new UnixSocketRawData(MAX_READ_SIZE);
+    mBuffer = MakeUnique<UnixSocketRawData>(MAX_READ_SIZE);
   }
   *aBuffer = mBuffer.get();
 
   return NS_OK;
 }
 
 /**
  * |ReceiveTask| transfers data received on the I/O thread
@@ -207,23 +207,23 @@ public:
 
     rilSocket->ReceiveSocketData(aCx, mBuffer);
 
     return true;
   }
 
 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));
 }
 
 void
 RilSocketIO::DiscardBuffer()
 {
   // Nothing to do.
 }
@@ -337,17 +337,17 @@ RilSocket::~RilSocket()
 {
   MOZ_ASSERT(!mIO);
 
   MOZ_COUNT_DTOR_INHERITED(RilSocket, ConnectionOrientedSocket);
 }
 
 void
 RilSocket::ReceiveSocketData(JSContext* aCx,
-                             nsAutoPtr<UnixSocketBuffer>& aBuffer)
+                             UniquePtr<UnixSocketBuffer>& aBuffer)
 {
   mConsumer->ReceiveSocketData(aCx, mIndex, aBuffer);
 }
 
 nsresult
 RilSocket::Connect(UnixSocketConnector* aConnector, int aDelayMs,
                    MessageLoop* aConsumerLoop, MessageLoop* aIOLoop)
 {
--- a/ipc/ril/RilSocket.h
+++ b/ipc/ril/RilSocket.h
@@ -43,17 +43,17 @@ public:
             RilSocketConsumer* aConsumer, int aIndex);
 
   /**
    * Method to be called whenever data is received. RIL-worker only.
    *
    * @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
    * non-blocking manner.
    *
    * @param aConnector Connector object for socket type specific functions
    * @param aDelayMs Time delay in milliseconds.
    * @param aConsumerLoop The socket's consumer thread.
--- a/ipc/ril/RilSocketConsumer.h
+++ b/ipc/ril/RilSocketConsumer.h
@@ -2,17 +2,17 @@
 /* vim: set ts=2 et sw=2 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 mozilla_ipc_RilSocketConsumer_h
 #define mozilla_ipc_RilSocketConsumer_h
 
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
 
 class JSContext;
 
 namespace mozilla {
 namespace ipc {
 
 class UnixSocketBuffer;
 
@@ -26,17 +26,17 @@ public:
    * Method to be called whenever data is received. RIL-worker only.
    *
    * @param aCx The RIL worker's JS context.
    * @param aIndex The index that has been given to the stream socket.
    * @param aBuffer Data received from the socket.
    */
   virtual void ReceiveSocketData(JSContext* aCx,
                                  int aIndex,
-                                 nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
+                                 UniquePtr<UnixSocketBuffer>& aBuffer) = 0;
 
   /**
    * Callback for socket success. Consumer-thread only.
    *
    * @param aIndex The index that has been given to the stream socket.
    */
   virtual void OnConnectSuccess(int aIndex) = 0;