Bug 1187904: Remove |BluetoothDaemonConnector| and random-address creator, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 03 Aug 2015 13:17:02 +0200
changeset 287493 30d6aae8ad3a0ac9c6d191e45939f2c4db2a36ab
parent 287492 911af3f44bbcfb519acd7c2fdcdb8313bbf661a5
child 287494 3579abb90b81d87f35b2e38526a70ba7cff042f6
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1187904
milestone42.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 1187904: Remove |BluetoothDaemonConnector| and random-address creator, r=shuang
dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
dom/bluetooth/bluedroid/BluetoothDaemonConnector.h
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
dom/bluetooth/moz.build
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* 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/. */
-
-#include "BluetoothDaemonConnector.h"
-#include <fcntl.h>
-#include <sys/un.h>
-#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
-#include "nsThreadUtils.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-BluetoothDaemonConnector::BluetoothDaemonConnector(
-  const nsACString& aSocketName)
-  : mSocketName(aSocketName)
-{
-  MOZ_COUNT_CTOR_INHERITED(BluetoothDaemonConnector, UnixSocketConnector);
-}
-
-BluetoothDaemonConnector::~BluetoothDaemonConnector()
-{
-  MOZ_COUNT_CTOR_INHERITED(BluetoothDaemonConnector, UnixSocketConnector);
-}
-
-nsresult
-BluetoothDaemonConnector::CreateSocket(int& aFd) const
-{
-  aFd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
-  if (aFd < 0) {
-    BT_WARNING("Could not open Bluetooth daemon socket!");
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonConnector::SetSocketFlags(int aFd) const
-{
-  static const int sReuseAddress = 1;
-
-  // Set close-on-exec bit.
-  int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD));
-  if (flags < 0) {
-    return NS_ERROR_FAILURE;
-  }
-  flags |= FD_CLOEXEC;
-  int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags));
-  if (res < 0) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Set non-blocking status flag.
-  flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
-  if (flags < 0) {
-    return NS_ERROR_FAILURE;
-  }
-  flags |= O_NONBLOCK;
-  res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags));
-  if (res < 0) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Set socket addr to be reused even if kernel is still waiting to close.
-  res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress,
-                   sizeof(sReuseAddress));
-  if (res < 0) {
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonConnector::CreateAddress(struct sockaddr& aAddress,
-                                        socklen_t& aAddressLength) const
-{
-  static const size_t sNameOffset = 1;
-
-  struct sockaddr_un* address =
-    reinterpret_cast<struct sockaddr_un*>(&aAddress);
-
-  size_t namesiz = mSocketName.Length() + 1; // include trailing '\0'
-
-  if (NS_WARN_IF((sNameOffset + namesiz) > sizeof(address->sun_path))) {
-    return NS_ERROR_FAILURE;
-  }
-
-  address->sun_family = AF_UNIX;
-  memset(address->sun_path, '\0', sNameOffset); // abstract socket
-  memcpy(address->sun_path + sNameOffset, mSocketName.get(), namesiz);
-
-  aAddressLength =
-    offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz;
-
-  return NS_OK;
-}
-
-// |UnixSocketConnector|
-
-nsresult
-BluetoothDaemonConnector::ConvertAddressToString(
-  const struct sockaddr& aAddress, socklen_t aAddressLength,
-  nsACString& aAddressString)
-{
-  MOZ_ASSERT(aAddress.sa_family == AF_UNIX);
-
-  const struct sockaddr_un* un =
-    reinterpret_cast<const struct sockaddr_un*>(&aAddress);
-
-  size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path);
-
-  aAddressString.Assign(un->sun_path, len);
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonConnector::CreateListenSocket(struct sockaddr* aAddress,
-                                             socklen_t* aAddressLength,
-                                             int& aListenFd)
-{
-  ScopedClose fd;
-
-  nsresult rv = CreateSocket(fd.rwget());
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  rv = SetSocketFlags(fd);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  if (aAddress && aAddressLength) {
-    rv = CreateAddress(*aAddress, *aAddressLength);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-
-  aListenFd = fd.forget();
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonConnector::AcceptStreamSocket(int aListenFd,
-                                             struct sockaddr* aAddress,
-                                             socklen_t* aAddressLength,
-                                             int& aStreamFd)
-{
-  ScopedClose fd(
-    TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength)));
-  if (fd < 0) {
-    NS_WARNING("Cannot accept file descriptor!");
-    return NS_ERROR_FAILURE;
-  }
-  nsresult rv = SetSocketFlags(fd);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  aStreamFd = fd.forget();
-
-  return NS_OK;
-}
-
-nsresult
-BluetoothDaemonConnector::CreateStreamSocket(struct sockaddr* aAddress,
-                                             socklen_t* aAddressLength,
-                                             int& aStreamFd)
-{
-  MOZ_CRASH("|BluetoothDaemonConnector| does not support "
-            "creating stream sockets.");
-  return NS_ERROR_ABORT;
-}
-
-nsresult
-BluetoothDaemonConnector::Duplicate(UnixSocketConnector*& aConnector)
-{
-  aConnector = new BluetoothDaemonConnector(*this);
-
-  return NS_OK;
-}
-
-END_BLUETOOTH_NAMESPACE
deleted file mode 100644
--- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* 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_dom_bluetooth_bluedroid_bluetoothdaemonconnector_h
-#define mozilla_dom_bluetooth_bluedroid_bluetoothdaemonconnector_h
-
-#include "mozilla/dom/bluetooth/BluetoothCommon.h"
-#include "mozilla/ipc/UnixSocketConnector.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothDaemonConnector final
-  : public mozilla::ipc::UnixSocketConnector
-{
-public:
-  BluetoothDaemonConnector(const nsACString& aSocketName);
-  ~BluetoothDaemonConnector();
-
-  // Methods for |UnixSocketConnector|
-  //
-
-  nsresult ConvertAddressToString(const struct sockaddr& aAddress,
-                                  socklen_t aAddressLength,
-                                  nsACString& aAddressString) override;
-
-  nsresult CreateListenSocket(struct sockaddr* aAddress,
-                              socklen_t* aAddressLength,
-                              int& aListenFd) override;
-
-  nsresult AcceptStreamSocket(int aListenFd,
-                              struct sockaddr* aAddress,
-                              socklen_t* aAddressLen,
-                              int& aStreamFd) override;
-
-  nsresult CreateStreamSocket(struct sockaddr* aAddress,
-                              socklen_t* aAddressLength,
-                              int& aStreamFd) override;
-
-  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
-
-private:
-  nsresult CreateSocket(int& aFd) const;
-  nsresult SetSocketFlags(int aFd) const;
-  nsresult CreateAddress(struct sockaddr& aAddress,
-                         socklen_t& aAddressLength) const;
-
-  nsCString mSocketName;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
@@ -15,17 +15,16 @@
 #include "BluetoothDaemonHelpers.h"
 #include "BluetoothDaemonSetupInterface.h"
 #include "BluetoothDaemonSocketInterface.h"
 #include "mozilla/ipc/DaemonRunnables.h"
 #include "mozilla/ipc/DaemonSocket.h"
 #include "mozilla/ipc/DaemonSocketConnector.h"
 #include "mozilla/ipc/ListenSocket.h"
 #include "mozilla/unused.h"
-#include "prrng.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 using namespace mozilla::ipc;
 
 static const int sRetryInterval = 100; // ms
 
 //
@@ -1758,56 +1757,16 @@ public:
   }
 
 private:
   BluetoothDaemonInterface* mInterface;
   nsRefPtr<BluetoothResultHandler> mRes;
   bool mRegisteredSocketModule;
 };
 
-nsresult
-BluetoothDaemonInterface::CreateRandomAddressString(
-  const nsACString& aPrefix, unsigned long aPostfixLength,
-  nsACString& aAddress)
-{
-  static const char sHexChar[16] = {
-    [0x0] = '0', [0x1] = '1', [0x2] = '2', [0x3] = '3',
-    [0x4] = '4', [0x5] = '5', [0x6] = '6', [0x7] = '7',
-    [0x8] = '8', [0x9] = '9', [0xa] = 'a', [0xb] = 'b',
-    [0xc] = 'c', [0xd] = 'd', [0xe] = 'e', [0xf] = 'f'
-  };
-
-  unsigned short seed[3];
-
-  if (NS_WARN_IF(!PR_GetRandomNoise(seed, sizeof(seed)))) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  aAddress = aPrefix;
-  aAddress.Append('-');
-
-  while (aPostfixLength) {
-
-    // Android doesn't provide rand_r, so we use nrand48 here,
-    // even though it's deprecated.
-    long value = nrand48(seed);
-
-    size_t bits = sizeof(value) * CHAR_BIT;
-
-    while ((bits > 4) && aPostfixLength) {
-      aAddress.Append(sHexChar[value&0xf]);
-      bits -= 4;
-      value >>= 4;
-      --aPostfixLength;
-    }
-  }
-
-  return NS_OK;
-}
-
 /*
  * The init procedure consists of several steps.
  *
  *  (1) Start listening for the command channel's socket connection: We
  *      do this before anything else, so that we don't miss connection
  *      requests from the Bluetooth daemon. This step will create a
  *      listen socket.
  *
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
@@ -134,20 +134,16 @@ protected:
     LISTEN_SOCKET,
     CMD_CHANNEL,
     NTF_CHANNEL
   };
 
   BluetoothDaemonInterface();
   ~BluetoothDaemonInterface();
 
-  nsresult CreateRandomAddressString(const nsACString& aPrefix,
-                                     unsigned long aPostfixLength,
-                                     nsACString& aAddress);
-
   // Methods for |DaemonSocketConsumer| and |ListenSocketConsumer|
   //
 
   void OnConnectSuccess(int aIndex) override;
   void OnConnectError(int aIndex) override;
   void OnDisconnect(int aIndex) override;
 
 private:
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -87,17 +87,16 @@ if CONFIG['MOZ_B2G_BT']:
                 'bluez',
             ]
             DEFINES['MOZ_B2G_BT_BLUEZ'] = True
         elif CONFIG['MOZ_B2G_BT_DAEMON']:
             SOURCES += [
                 'bluedroid/BluetoothA2dpManager.cpp',
                 'bluedroid/BluetoothDaemonA2dpInterface.cpp',
                 'bluedroid/BluetoothDaemonAvrcpInterface.cpp',
-                'bluedroid/BluetoothDaemonConnector.cpp',
                 'bluedroid/BluetoothDaemonGattInterface.cpp',
                 'bluedroid/BluetoothDaemonHandsfreeInterface.cpp',
                 'bluedroid/BluetoothDaemonHelpers.cpp',
                 'bluedroid/BluetoothDaemonInterface.cpp',
                 'bluedroid/BluetoothDaemonSetupInterface.cpp',
                 'bluedroid/BluetoothDaemonSocketInterface.cpp',
                 'bluedroid/BluetoothOppManager.cpp',
                 'bluedroid/BluetoothPbapManager.cpp',