Bug 1264287: Convert Wifi to use |UniquePtr|, r=nfroyd
authorThomas Zimmermann <tdz@users.sourceforge.net>
Fri, 15 Apr 2016 09:29:42 +0200
changeset 293359 8ed65e8e9c754ea6dbef9f9df94cef89f670c628
parent 293358 e475e587c4488565896189f09739f37738cbfe24
child 293360 3f471f76af290c6dda6cb8dcfc69873307575b13
push id30180
push userkwierso@gmail.com
push dateFri, 15 Apr 2016 21:31:41 +0000
treeherdermozilla-central@ded7cf683d5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1264287
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 1264287: Convert Wifi to use |UniquePtr|, r=nfroyd
dom/wifi/WifiProxyService.cpp
dom/wifi/WifiUtils.cpp
dom/wifi/WifiUtils.h
--- a/dom/wifi/WifiProxyService.cpp
+++ b/dom/wifi/WifiProxyService.cpp
@@ -24,17 +24,17 @@ using namespace mozilla;
 using namespace mozilla::dom;
 
 namespace mozilla {
 
 // The singleton Wifi service, to be used on the main thread.
 static StaticRefPtr<WifiProxyService> gWifiProxyService;
 
 // The singleton supplicant class, that can be used on any thread.
-static nsAutoPtr<WpaSupplicant> gWpaSupplicant;
+static UniquePtr<WpaSupplicant> gWpaSupplicant;
 
 // Runnable used dispatch the WaitForEvent result on the main thread.
 class WifiEventDispatcher : public nsRunnable
 {
 public:
   WifiEventDispatcher(const nsAString& aEvent, const nsACString& aInterface)
     : mEvent(aEvent)
     , mInterface(aInterface)
@@ -155,17 +155,17 @@ WifiProxyService::FactoryCreate()
   }
 
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!gWifiProxyService) {
     gWifiProxyService = new WifiProxyService();
     ClearOnShutdown(&gWifiProxyService);
 
-    gWpaSupplicant = new WpaSupplicant();
+    gWpaSupplicant = MakeUnique<WpaSupplicant>();
     ClearOnShutdown(&gWpaSupplicant);
   }
 
   RefPtr<WifiProxyService> service = gWifiProxyService.get();
   return service.forget();
 }
 
 NS_IMETHODIMP
--- a/dom/wifi/WifiUtils.cpp
+++ b/dom/wifi/WifiUtils.cpp
@@ -382,23 +382,23 @@ public:
 // Concrete class to use to access the wpa supplicant.
 WpaSupplicant::WpaSupplicant()
 {
   char propVersion[PROPERTY_VALUE_MAX];
   property_get("ro.build.version.sdk", propVersion, "0");
   mSdkVersion = strtol(propVersion, nullptr, 10);
 
   if (mSdkVersion < 16) {
-    mImpl = new ICSWpaSupplicantImpl();
+    mImpl = MakeUnique<ICSWpaSupplicantImpl>();
   } else if (mSdkVersion < 19) {
-    mImpl = new JBWpaSupplicantImpl();
+    mImpl = MakeUnique<JBWpaSupplicantImpl>();
   } else {
-    mImpl = new KKWpaSupplicantImpl();
+    mImpl = MakeUnique<KKWpaSupplicantImpl>();
   }
-  mWifiHotspotUtils = new WifiHotspotUtils();
+  mWifiHotspotUtils = MakeUnique<WifiHotspotUtils>();
 };
 
 void WpaSupplicant::WaitForEvent(nsAString& aEvent, const nsCString& aInterface)
 {
   CHECK_HWLIB()
 
   char buffer[BUFFER_SIZE];
   int32_t ret = mImpl->do_wifi_wait_for_event(aInterface.get(), buffer, BUFFER_SIZE);
--- a/dom/wifi/WifiUtils.h
+++ b/dom/wifi/WifiUtils.h
@@ -8,18 +8,18 @@
  * Abstraction on top of the wifi support from libhardware_legacy that we
  * use to talk to the wpa_supplicant.
  */
 
 #ifndef WifiUtils_h
 #define WifiUtils_h
 
 #include "nsString.h"
-#include "nsAutoPtr.h"
 #include "mozilla/dom/WifiOptionsBinding.h"
+#include "mozilla/UniquePtr.h"
 #include "WifiHotspotUtils.h"
 
 // Needed to add a copy constructor to WifiCommandOptions.
 struct CommandOptions
 {
 public:
   CommandOptions(const mozilla::dom::WifiCommandOptions& aOther) {
 
@@ -46,17 +46,17 @@ public:
 };
 
 // Abstract class that exposes libhardware_legacy functions we need for
 // wifi management.
 // We use the ICS signatures here since they are likely more future-proof.
 class WpaSupplicantImpl
 {
 public:
-  // Suppress warning from nsAutoPtr
+  // Suppress warning from |UniquePtr|
   virtual ~WpaSupplicantImpl() {}
 
   virtual int32_t
   do_wifi_wait_for_event(const char *iface, char *buf, size_t len) = 0; // KK == ICS != JB
 
   virtual int32_t
   do_wifi_command(const char* iface, const char* cmd, char* buff, size_t* len) = 0; // KK == ICS != JB
 
@@ -89,18 +89,18 @@ public:
   // null-terminated so that we can pass it to c API without
   // conversion
   void WaitForEvent(nsAString& aEvent, const nsCString& aInterface);
   bool ExecuteCommand(CommandOptions aOptions,
                       mozilla::dom::WifiResultOptions& result,
                       const nsCString& aInterface);
 
 private:
-  nsAutoPtr<WpaSupplicantImpl> mImpl;
-  nsAutoPtr<WifiHotspotUtils> mWifiHotspotUtils;
+  UniquePtr<WpaSupplicantImpl> mImpl;
+  UniquePtr<WifiHotspotUtils> mWifiHotspotUtils;
 
   uint32_t mSdkVersion;
 
 protected:
   void CheckBuffer(char* buffer, int32_t length, nsAString& aEvent);
   uint32_t MakeMask(uint32_t len);
 };