Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 "chrome/browser/chromeos/input_method/ibus_engine_controller.h" | 5 #include "chrome/browser/chromeos/input_method/ibus_engine_controller.h" |
| 6 | 6 |
| 7 #if defined(HAVE_IBUS) | 7 #if defined(HAVE_IBUS) |
| 8 #include <ibus.h> | 8 #include <ibus.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 reinterpret_cast<gpointer>(G_CALLBACK(IBusBusDisconnectedCallback)), | 613 reinterpret_cast<gpointer>(G_CALLBACK(IBusBusDisconnectedCallback)), |
| 614 this); | 614 this); |
| 615 } | 615 } |
| 616 | 616 |
| 617 // Handles "connected" signal from ibus-daemon. | 617 // Handles "connected" signal from ibus-daemon. |
| 618 static void IBusBusConnectedCallback(IBusBus* bus, gpointer user_data) { | 618 static void IBusBusConnectedCallback(IBusBus* bus, gpointer user_data) { |
| 619 LOG(WARNING) << "IBus connection is recovered."; | 619 LOG(WARNING) << "IBus connection is recovered."; |
| 620 g_return_if_fail(user_data); | 620 g_return_if_fail(user_data); |
| 621 IBusEngineControllerImpl* self | 621 IBusEngineControllerImpl* self |
| 622 = static_cast<IBusEngineControllerImpl*>(user_data); | 622 = static_cast<IBusEngineControllerImpl*>(user_data); |
| 623 if (!g_factory_) { | |
| 624 g_factory_ = ibus_factory_new(ibus_bus_get_connection(bus)); | |
|
Peng
2011/10/26 17:53:21
I only find you create g_factory in connected sign
Zachary Kuznia
2011/10/27 07:25:11
Done.
| |
| 625 } | |
| 626 | |
| 623 if (!self->MaybeCreateComponent()) { | 627 if (!self->MaybeCreateComponent()) { |
| 624 LOG(ERROR) << "MaybeCreateComponent() failed"; | 628 LOG(ERROR) << "MaybeCreateComponent() failed"; |
| 625 return; | 629 return; |
| 626 } | 630 } |
| 627 } | 631 } |
| 628 | 632 |
| 629 // Handles "disconnected" signal from ibus-daemon. | 633 // Handles "disconnected" signal from ibus-daemon. |
| 630 static void IBusBusDisconnectedCallback(IBusBus* bus, gpointer user_data) { | 634 static void IBusBusDisconnectedCallback(IBusBus* bus, gpointer user_data) { |
| 631 LOG(WARNING) << "IBus connection is terminated."; | 635 LOG(WARNING) << "IBus connection is terminated."; |
| 636 g_factory_ = NULL; | |
| 632 } | 637 } |
| 633 | 638 |
| 634 bool MaybeCreateComponent() { | 639 bool MaybeCreateComponent() { |
| 635 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { | 640 if (!ibus_ || !ibus_bus_is_connected(ibus_) || !g_factory_) { |
| 636 return false; | 641 return false; |
| 637 } | 642 } |
| 638 | 643 |
| 639 VLOG(1) << "MaybeCreateComponent"; | 644 VLOG(1) << "MaybeCreateComponent"; |
| 640 IBusComponent* component = ibus_component_new(bus_name_.c_str(), | 645 IBusComponent* component = ibus_component_new(bus_name_.c_str(), |
| 641 description_.c_str(), | 646 description_.c_str(), |
| 642 "", | 647 "", |
| 643 "", | 648 "", |
| 644 engine_name_.c_str(), | 649 engine_name_.c_str(), |
| 645 "", | 650 "", |
| 646 "", | 651 "", |
| 647 ""); | 652 ""); |
| 648 ibus_component_add_engine(component, | 653 ibus_component_add_engine(component, |
| 649 ibus_engine_desc_new(engine_id_.c_str(), | 654 ibus_engine_desc_new(engine_id_.c_str(), |
| 650 description_.c_str(), | 655 description_.c_str(), |
| 651 description_.c_str(), | 656 description_.c_str(), |
| 652 language_.c_str(), | 657 language_.c_str(), |
| 653 "", | 658 "", |
| 654 engine_name_.c_str(), | 659 engine_name_.c_str(), |
| 655 "", | 660 "", |
| 656 layout_.c_str())); | 661 layout_.c_str())); |
| 657 | 662 |
| 658 IBusFactory* factory = ibus_factory_new(ibus_bus_get_connection(ibus_)); | 663 ibus_factory_add_engine(g_factory_, engine_id_.c_str(), |
| 659 ibus_factory_add_engine(factory, engine_id_.c_str(), | |
| 660 IBUS_TYPE_CHROMEOS_ENGINE); | 664 IBUS_TYPE_CHROMEOS_ENGINE); |
| 661 ibus_bus_register_component(ibus_, component); | 665 ibus_bus_register_component(ibus_, component); |
| 662 g_object_unref(component); | 666 g_object_unref(component); |
| 663 | 667 |
| 664 return true; | 668 return true; |
| 665 } | 669 } |
| 666 | 670 |
| 667 static void OnServiceMethodCall(IBusService* service, | 671 static void OnServiceMethodCall(IBusService* service, |
| 668 GDBusConnection* connection, | 672 GDBusConnection* connection, |
| 669 const gchar* sender, | 673 const gchar* sender, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 unsigned int page_size_; | 868 unsigned int page_size_; |
| 865 unsigned int cursor_position_; | 869 unsigned int cursor_position_; |
| 866 std::string aux_text_; | 870 std::string aux_text_; |
| 867 bool aux_text_visible_; | 871 bool aux_text_visible_; |
| 868 std::vector<EngineProperty*> properties_; | 872 std::vector<EngineProperty*> properties_; |
| 869 std::map<std::string, EngineProperty*> property_map_; | 873 std::map<std::string, EngineProperty*> property_map_; |
| 870 | 874 |
| 871 std::set<IBusChromeOSEngine*> engine_instances_; | 875 std::set<IBusChromeOSEngine*> engine_instances_; |
| 872 | 876 |
| 873 static ConnectionMap* g_connections_; | 877 static ConnectionMap* g_connections_; |
| 878 static IBusFactory* g_factory_; | |
| 874 }; | 879 }; |
| 875 | 880 |
| 876 IBusEngineControllerImpl::ConnectionMap* | 881 IBusEngineControllerImpl::ConnectionMap* |
| 877 IBusEngineControllerImpl::g_connections_ = NULL; | 882 IBusEngineControllerImpl::g_connections_ = NULL; |
| 878 | 883 |
| 884 IBusFactory* IBusEngineControllerImpl::g_factory_ = NULL; | |
| 885 | |
| 879 void ibus_chromeos_engine_class_init(IBusChromeOSEngineClass *klass) { | 886 void ibus_chromeos_engine_class_init(IBusChromeOSEngineClass *klass) { |
| 880 IBusEngineControllerImpl::InitEngineClass(klass); | 887 IBusEngineControllerImpl::InitEngineClass(klass); |
| 881 } | 888 } |
| 882 | 889 |
| 883 void ibus_chromeos_engine_init(IBusChromeOSEngine* engine) { | 890 void ibus_chromeos_engine_init(IBusChromeOSEngine* engine) { |
| 884 IBusEngineControllerImpl::InitEngine(engine); | 891 IBusEngineControllerImpl::InitEngine(engine); |
| 885 } | 892 } |
| 886 | 893 |
| 887 #endif // HAVE_IBUS | 894 #endif // HAVE_IBUS |
| 888 | 895 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 906 #else | 913 #else |
| 907 return NULL; | 914 return NULL; |
| 908 #endif | 915 #endif |
| 909 } | 916 } |
| 910 | 917 |
| 911 IBusEngineController::~IBusEngineController() { | 918 IBusEngineController::~IBusEngineController() { |
| 912 } | 919 } |
| 913 | 920 |
| 914 } // namespace input_method | 921 } // namespace input_method |
| 915 } // namespace chromeos | 922 } // namespace chromeos |
| OLD | NEW |