Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chromeos_input_method.cc

Issue 2627009: Swap D-Bus and IBus initialization order to avoid race conditions. (Closed) Base URL: ssh://git@gitrw.chromium.org//cros.git
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos_input_method.h" 5 #include "chromeos_input_method.h"
6 6
7 #include <dbus/dbus-glib-lowlevel.h> // for dbus_g_connection_get_connection. 7 #include <dbus/dbus-glib-lowlevel.h> // for dbus_g_connection_get_connection.
8 #include <ibus.h> 8 #include <ibus.h>
9 9
10 #include <algorithm> // for std::reverse. 10 #include <algorithm> // for std::reverse.
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 this); 528 this);
529 // Since the connection which ibus_ has is a "shared connection". We 529 // Since the connection which ibus_ has is a "shared connection". We
530 // should not close the connection. Just call g_object_unref. 530 // should not close the connection. Just call g_object_unref.
531 g_object_unref(ibus_); 531 g_object_unref(ibus_);
532 } 532 }
533 // |dbus_connection_| and |dbus_proxy_| will be destructed by ~scoped_ptr(). 533 // |dbus_connection_| and |dbus_proxy_| will be destructed by ~scoped_ptr().
534 } 534 }
535 535
536 // Initializes IBus and DBus connections. 536 // Initializes IBus and DBus connections.
537 bool Init() { 537 bool Init() {
538 // Establish IBus connection between ibus-daemon to retrieve the list of
539 // available input method engines, change the current input method engine,
540 // and so on.
541 ibus_init(); 538 ibus_init();
542 ibus_ = ibus_bus_new();
543
544 // Check the IBus connection status.
545 if (!ibus_) {
546 LOG(ERROR) << "ibus_bus_new() failed";
547 return false;
548 }
549 if (!ibus_bus_is_connected(ibus_)) {
550 DLOG(INFO) << "ibus_bus_is_connected() failed";
551 return false;
552 }
553 539
554 // Establish a DBus connection between the candidate_window process for 540 // Establish a DBus connection between the candidate_window process for
555 // Chromium OS to handle signals (e.g. "FocusIn") from the process. 541 // Chromium OS to handle signals (e.g. "FocusIn") from the process.
556 const char* address = ibus_get_address(); 542 const char* address = ibus_get_address();
557 if (!address) { 543 if (!address) {
558 LOG(ERROR) << "ibus_get_address returned NULL"; 544 LOG(ERROR) << "ibus_get_address returned NULL";
559 return false; 545 return false;
560 } 546 }
561 dbus_connection_.reset( 547 dbus_connection_.reset(
562 new dbus::BusConnection(dbus::GetPrivateBusConnection(address))); 548 new dbus::BusConnection(dbus::GetPrivateBusConnection(address)));
(...skipping 14 matching lines...) Expand all
577 return false; 563 return false;
578 } 564 }
579 565
580 // Register the callback function for "destroy". 566 // Register the callback function for "destroy".
581 dbus_proxy_is_alive_ = true; 567 dbus_proxy_is_alive_ = true;
582 g_signal_connect(dbus_proxy_->gproxy(), 568 g_signal_connect(dbus_proxy_->gproxy(),
583 "destroy", 569 "destroy",
584 G_CALLBACK(DBusProxyDestroyCallback), 570 G_CALLBACK(DBusProxyDestroyCallback),
585 this); 571 this);
586 572
573 // Establish IBus connection between ibus-daemon to retrieve the list of
574 // available input method engines, change the current input method engine,
575 // and so on.
576 ibus_ = ibus_bus_new();
577
578 // Check the IBus connection status.
579 if (!ibus_) {
580 LOG(ERROR) << "ibus_bus_new() failed";
581 return false;
582 }
583 if (!ibus_bus_is_connected(ibus_)) {
584 DLOG(INFO) << "ibus_bus_is_connected() failed";
585 return false;
586 }
587
587 // Register the callback function for IBusBus signals. 588 // Register the callback function for IBusBus signals.
588 g_signal_connect(ibus_, 589 g_signal_connect(ibus_,
589 "disconnected", 590 "disconnected",
590 G_CALLBACK(IBusBusDisconnectedCallback), 591 G_CALLBACK(IBusBusDisconnectedCallback),
591 this); 592 this);
592 g_signal_connect(ibus_, 593 g_signal_connect(ibus_,
593 "global-engine-changed", 594 "global-engine-changed",
594 G_CALLBACK(IBusBusGlobalEngineChangedCallback), 595 G_CALLBACK(IBusBusGlobalEngineChangedCallback),
595 this); 596 this);
596 597
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 InputMethodStatusConnection* connection) { 1197 InputMethodStatusConnection* connection) {
1197 g_return_val_if_fail(connection, false); 1198 g_return_val_if_fail(connection, false);
1198 const bool is_connected = connection->ConnectionIsAlive(); 1199 const bool is_connected = connection->ConnectionIsAlive();
1199 if (!is_connected) { 1200 if (!is_connected) {
1200 LOG(WARNING) << "ChromeOSInputMethodStatusConnectionIsAlive: NOT alive"; 1201 LOG(WARNING) << "ChromeOSInputMethodStatusConnectionIsAlive: NOT alive";
1201 } 1202 }
1202 return is_connected; 1203 return is_connected;
1203 } 1204 }
1204 1205
1205 } // namespace chromeos 1206 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698