[go: up one dir, main page]

Swap D-Bus and IBus initialization order to avoid race conditions.

Initialize D-Bus connection first so that the destructor of the InputMethodStatusConnection class does not terminate the IBus connection between im-ibus.so and ibus-daemon.
This change is not for a specific bug, but might be worth not to trigger subtle bugs in im-ibus, libibus, and libdbus.

BUG=3683
TEST=manually

Review URL: http://codereview.chromium.org/2627009

Conflicts:

	chromeos_input_method.cc
diff --git a/chromeos_input_method.cc b/chromeos_input_method.cc
index 0ea385b..bc1bc4a 100644
--- a/chromeos_input_method.cc
+++ b/chromeos_input_method.cc
@@ -507,21 +507,7 @@
 
   // Initializes IBus and DBus connections.
   bool Init() {
-    // Establish IBus connection between ibus-daemon to retrieve the list of
-    // available input method engines, change the current input method engine,
-    // and so on.
     ibus_init();
-    ibus_ = ibus_bus_new();
-
-    // Check the IBus connection status.
-    if (!ibus_) {
-      LOG(ERROR) << "ibus_bus_new() failed";
-      return false;
-    }
-    if (!ibus_bus_is_connected(ibus_)) {
-      DLOG(INFO) << "ibus_bus_is_connected() failed";
-      return false;
-    }
 
     // Establish a DBus connection between the candidate_window process for
     // Chromium OS to handle signals (e.g. "FocusIn") from the process.
@@ -556,6 +542,21 @@
                      G_CALLBACK(DBusProxyDestroyCallback),
                      this);
 
+    // Establish IBus connection between ibus-daemon to retrieve the list of
+    // available input method engines, change the current input method engine,
+    // and so on.
+    ibus_ = ibus_bus_new();
+
+    // Check the IBus connection status.
+    if (!ibus_) {
+      LOG(ERROR) << "ibus_bus_new() failed";
+      return false;
+    }
+    if (!ibus_bus_is_connected(ibus_)) {
+      DLOG(INFO) << "ibus_bus_is_connected() failed";
+      return false;
+    }
+
     // Register the callback function for "global-engine-changed".
     g_signal_connect(ibus_,
                      "global-engine-changed",