Bug 931038: Remove blocking DBus interface, r=qdot
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 29 Oct 2013 11:08:16 +0100
changeset 152700 bb6c50eef491d17bea67ca30bc0ad6e5dbd5f40a
parent 152699 6bc7584a54823057cd317f783b5b4680ff7c464e
child 152701 1175c20975bb162098cc51426a8f31044ea54d7a
push id3269
push userryanvm@gmail.com
push dateThu, 31 Oct 2013 02:43:41 +0000
treeherderfx-team@f0d363d72753 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs931038
milestone27.0a1
Bug 931038: Remove blocking DBus interface, r=qdot All blocking calls to DBus have been replaced by non-blocking code. This patch removes the corresponding DBus interfaces.
ipc/dbus/RawDBusConnection.cpp
ipc/dbus/RawDBusConnection.h
--- a/ipc/dbus/RawDBusConnection.cpp
+++ b/ipc/dbus/RawDBusConnection.cpp
@@ -48,77 +48,33 @@ protected:
 
   virtual ~DBusConnectionSendRunnableBase()
   { }
 
   DBusConnection*   mConnection;
   DBusMessageRefPtr mMessage;
 };
 
-class DBusConnectionSendSyncRunnable : public DBusConnectionSendRunnableBase
-{
-public:
-  bool WaitForCompletion()
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    MonitorAutoLock autoLock(mCompletedMonitor);
-    while (!mCompleted) {
-      mCompletedMonitor.Wait();
-    }
-    return mSuccess;
-  }
-
-protected:
-  DBusConnectionSendSyncRunnable(DBusConnection* aConnection,
-                                 DBusMessage* aMessage)
-  : DBusConnectionSendRunnableBase(aConnection, aMessage),
-    mCompletedMonitor("DBusConnectionSendSyncRunnable.mCompleted"),
-    mCompleted(false),
-    mSuccess(false)
-  { }
-
-  virtual ~DBusConnectionSendSyncRunnable()
-  { }
-
-  // Call this function at the end of Run() to notify waiting
-  // threads.
-  void Completed(bool aSuccess)
-  {
-    MonitorAutoLock autoLock(mCompletedMonitor);
-    MOZ_ASSERT(!mCompleted);
-    mSuccess = aSuccess;
-    mCompleted = true;
-    mCompletedMonitor.Notify();
-  }
-
-private:
-  Monitor mCompletedMonitor;
-  bool    mCompleted;
-  bool    mSuccess;
-};
-
 //
 // Sends a message and returns the message's serial number to the
 // disaptching thread. Only run it in DBus thread.
 //
-class DBusConnectionSendRunnable : public DBusConnectionSendSyncRunnable
+class DBusConnectionSendRunnable : public DBusConnectionSendRunnableBase
 {
 public:
   DBusConnectionSendRunnable(DBusConnection* aConnection,
                              DBusMessage* aMessage)
-  : DBusConnectionSendSyncRunnable(aConnection, aMessage)
+  : DBusConnectionSendRunnableBase(aConnection, aMessage)
   { }
 
   NS_IMETHOD Run()
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
     dbus_bool_t success = dbus_connection_send(mConnection, mMessage, nullptr);
-    Completed(success == TRUE);
 
     NS_ENSURE_TRUE(success == TRUE, NS_ERROR_FAILURE);
 
     return NS_OK;
   }
 
 protected:
   ~DBusConnectionSendRunnable()
@@ -215,105 +171,16 @@ protected:
   { }
 
 private:
   DBusReplyCallback mCallback;
   void*             mData;
   int               mTimeout;
 };
 
-//
-// Legacy interface, don't use in new code
-//
-// Sends a message and waits for the reply. Only run it in DBus thread.
-//
-class DBusConnectionSendAndBlockRunnable : public DBusConnectionSendSyncRunnable
-{
-private:
-  static void Notify(DBusPendingCall* aCall, void* aData)
-  {
-    DBusConnectionSendAndBlockRunnable* runnable(
-        static_cast<DBusConnectionSendAndBlockRunnable*>(aData));
-
-    runnable->mReply = dbus_pending_call_steal_reply(aCall);
-
-    bool success = !!runnable->mReply;
-
-    if (runnable->mError) {
-      success = success && !dbus_error_is_set(runnable->mError);
-
-      if (!dbus_set_error_from_message(runnable->mError, runnable->mReply)) {
-        dbus_error_init(runnable->mError);
-      }
-    }
-
-    dbus_pending_call_cancel(aCall);
-    dbus_pending_call_unref(aCall);
-
-    runnable->Completed(success);
-  }
-
-public:
-  DBusConnectionSendAndBlockRunnable(DBusConnection* aConnection,
-                                     DBusMessage* aMessage,
-                                     int aTimeout,
-                                     DBusError* aError)
-  : DBusConnectionSendSyncRunnable(aConnection, aMessage),
-    mError(aError),
-    mReply(nullptr),
-    mTimeout(aTimeout)
-  { }
-
-  NS_IMETHOD Run()
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    DBusPendingCall* call = nullptr;
-
-    dbus_bool_t success = dbus_connection_send_with_reply(mConnection,
-                                                          mMessage,
-                                                          &call,
-                                                          mTimeout);
-    if (success == TRUE) {
-      success = dbus_pending_call_set_notify(call, Notify, this, nullptr);
-    } else {
-      if (mError) {
-        if (!call) {
-          dbus_set_error(mError, DBUS_ERROR_DISCONNECTED, "Connection is closed");
-        } else {
-          dbus_error_init(mError);
-        }
-      }
-    }
-
-    dbus_message_unref(mMessage);
-
-    if (!success) {
-      Completed(false);
-      NS_ENSURE_TRUE(success == TRUE, NS_ERROR_FAILURE);
-    }
-
-    return NS_OK;
-  }
-
-  DBusMessage* GetReply()
-  {
-    return mReply;
-  }
-
-protected:
-  ~DBusConnectionSendAndBlockRunnable()
-  { }
-
-private:
-  DBusError*   mError;
-  DBusMessage* mReply;
-  int          mTimeout;
-};
-
 }
 }
 
 //
 // RawDBusConnection
 //
 
 bool RawDBusConnection::sDBusIsInit(false);
@@ -409,68 +276,16 @@ bool RawDBusConnection::SendWithReply(DB
 
   if (!msg) {
     return false;
   }
 
   return SendWithReply(aCallback, aData, aTimeout, msg);
 }
 
-bool RawDBusConnection::SendWithError(DBusMessage** aReply,
-                                      DBusError* aError,
-                                      int aTimeout,
-                                      DBusMessage* aMessage)
-{
-  nsRefPtr<DBusConnectionSendAndBlockRunnable> t(
-    new DBusConnectionSendAndBlockRunnable(mConnection, aMessage,
-                                           aTimeout, aError));
-  MOZ_ASSERT(t);
-
-  nsresult rv = DispatchToDBusThread(t);
-
-  if (NS_FAILED(rv)) {
-    if (aMessage) {
-      dbus_message_unref(aMessage);
-    }
-    return false;
-  }
-
-  if (!t->WaitForCompletion()) {
-    return false;
-  }
-
-  if (aReply) {
-    *aReply = t->GetReply();
-  }
-
-  return true;
-}
-
-bool RawDBusConnection::SendWithError(DBusMessage** aReply,
-                                      DBusError* aError,
-                                      int aTimeout,
-                                      const char* aPath,
-                                      const char* aIntf,
-                                      const char* aFunc,
-                                      int aFirstArgType, ...)
-{
-  va_list args;
-
-  va_start(args, aFirstArgType);
-  DBusMessage* msg = BuildDBusMessage(aPath, aIntf, aFunc,
-                                      aFirstArgType, args);
-  va_end(args);
-
-  if (!msg) {
-    return false;
-  }
-
-  return SendWithError(aReply, aError, aTimeout, msg);
-}
-
 DBusMessage* RawDBusConnection::BuildDBusMessage(const char* aPath,
                                                  const char* aIntf,
                                                  const char* aFunc,
                                                  int aFirstArgType,
                                                  va_list aArgs)
 {
   DBusMessage* msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC,
                                                   aPath, aIntf, aFunc);
--- a/ipc/dbus/RawDBusConnection.h
+++ b/ipc/dbus/RawDBusConnection.h
@@ -48,25 +48,16 @@ public:
 
   bool SendWithReply(DBusReplyCallback aCallback, void* aData,
                      int aTimeout, DBusMessage* aMessage);
 
   bool SendWithReply(DBusReplyCallback aCallback, void* aData,
                      int aTimeout, const char* aPath, const char* aIntf,
                      const char *aFunc, int aFirstArgType, ...);
 
-  /* Legacy interface, don't use in new code */
-  bool SendWithError(DBusMessage** aReply, DBusError* aError, int aTimeout,
-                     DBusMessage* aMessage);
-
-  /* Legacy interface, don't use in new code */
-  bool SendWithError(DBusMessage** aReply, DBusError* aError, int aTimeout,
-                     const char* aPath, const char* aIntf, const char* aFunc,
-                     int aFirstArgType, ...);
-
 protected:
   DBusMessage* BuildDBusMessage(const char* aPath, const char* aIntf,
                                 const char* aFunc, int aFirstArgType,
                                 va_list args);
 
   Scoped<ScopedDBusConnectionPtrTraits> mConnection;
 
 private: