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

Side by Side Diff: chrome/browser/chromeos/input_method/ibus_controller_impl.cc

Issue 11428049: Remove ibus dependency from IBusBus related stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore previous input method at the beggining of connection Created 8 years 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 | Annotate | Revision Log
« 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_controller_impl.h" 5 #include "chrome/browser/chromeos/input_method/ibus_controller_impl.h"
6 6
7 #include <algorithm> // for std::reverse. 7 #include <algorithm> // for std::reverse.
8 #include <cstdio> 8 #include <cstdio>
9 #include <cstring> // for std::strcmp. 9 #include <cstring> // for std::strcmp.
10 #include <set> 10 #include <set>
11 #include <sstream> 11 #include <sstream>
12 #include <stack> 12 #include <stack>
13 #include <utility> 13 #include <utility>
14 14
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/environment.h" 17 #include "base/environment.h"
18 #include "base/files/file_path_watcher.h" 18 #include "base/files/file_path_watcher.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/message_loop.h" 20 #include "base/message_loop.h"
21 #include "base/rand_util.h" 21 #include "base/rand_util.h"
22 #include "base/string_split.h" 22 #include "base/string_split.h"
23 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
24 #include "chrome/browser/chromeos/input_method/input_method_config.h" 24 #include "chrome/browser/chromeos/input_method/input_method_config.h"
25 #include "chrome/browser/chromeos/input_method/input_method_property.h" 25 #include "chrome/browser/chromeos/input_method/input_method_property.h"
26 #include "chrome/browser/chromeos/input_method/input_method_util.h" 26 #include "chrome/browser/chromeos/input_method/input_method_util.h"
27 #include "chromeos/dbus/dbus_thread_manager.h" 27 #include "chromeos/dbus/dbus_thread_manager.h"
28 #include "chromeos/dbus/ibus/ibus_client.h"
28 #include "chromeos/dbus/ibus/ibus_config_client.h" 29 #include "chromeos/dbus/ibus/ibus_config_client.h"
29 #include "chromeos/dbus/ibus/ibus_constants.h" 30 #include "chromeos/dbus/ibus/ibus_constants.h"
30 #include "chromeos/dbus/ibus/ibus_input_context_client.h" 31 #include "chromeos/dbus/ibus/ibus_input_context_client.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "ui/aura/client/aura_constants.h" 33 #include "ui/aura/client/aura_constants.h"
33 #include "ui/aura/root_window.h" 34 #include "ui/aura/root_window.h"
34 #include "ui/base/ime/input_method_ibus.h" 35 #include "ui/base/ime/input_method_ibus.h"
35 36
36 // TODO(nona): Remove libibus dependency from this file. Then, write unit tests 37 // TODO(nona): Remove libibus dependency from this file. Then, write unit tests
37 // for all functions in this file. crbug.com/26334 38 // for all functions in this file. crbug.com/26334
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 bool IBusControllerImpl::Stop() { 516 bool IBusControllerImpl::Stop() {
516 if (ibus_daemon_status_ == IBUS_DAEMON_SHUTTING_DOWN || 517 if (ibus_daemon_status_ == IBUS_DAEMON_SHUTTING_DOWN ||
517 ibus_daemon_status_ == IBUS_DAEMON_STOP) { 518 ibus_daemon_status_ == IBUS_DAEMON_STOP) {
518 return true; 519 return true;
519 } 520 }
520 521
521 ibus_daemon_status_ = IBUS_DAEMON_SHUTTING_DOWN; 522 ibus_daemon_status_ = IBUS_DAEMON_SHUTTING_DOWN;
522 // TODO(nona): Shutdown ibus-bus connection. 523 // TODO(nona): Shutdown ibus-bus connection.
523 if (IBusConnectionsAreAlive()) { 524 if (IBusConnectionsAreAlive()) {
524 // Ask IBus to exit *asynchronously*. 525 // Ask IBus to exit *asynchronously*.
525 ibus_bus_exit_async(ibus_, 526 IBusClient* client = DBusThreadManager::Get()->GetIBusClient();
526 FALSE /* do not restart */, 527 if (client)
527 -1 /* timeout */, 528 client->Exit(IBusClient::SHUT_DOWN_IBUS_DAEMON,
528 NULL /* cancellable */, 529 base::Bind(&base::DoNothing));
529 NULL /* callback */,
530 NULL /* user_data */);
531 } else { 530 } else {
532 base::KillProcess(process_handle_, -1, false /* wait */); 531 base::KillProcess(process_handle_, -1, false /* wait */);
533 DVLOG(1) << "Killing ibus-daemon. PID=" 532 DVLOG(1) << "Killing ibus-daemon. PID="
534 << base::GetProcId(process_handle_); 533 << base::GetProcId(process_handle_);
535 } 534 }
536 process_handle_ = base::kNullProcessHandle; 535 process_handle_ = base::kNullProcessHandle;
537 return true; 536 return true;
538 } 537 }
539 538
540 bool IBusControllerImpl::ChangeInputMethod(const std::string& id) { 539 bool IBusControllerImpl::ChangeInputMethod(const std::string& id) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 633
635 ibus_init(); 634 ibus_init();
636 // Establish IBus connection between ibus-daemon to change the current input 635 // Establish IBus connection between ibus-daemon to change the current input
637 // method engine, properties, and so on. 636 // method engine, properties, and so on.
638 ibus_ = ibus_bus_new(); 637 ibus_ = ibus_bus_new();
639 DCHECK(ibus_); 638 DCHECK(ibus_);
640 639
641 // Register callback functions for IBusBus signals. 640 // Register callback functions for IBusBus signals.
642 ConnectBusSignals(); 641 ConnectBusSignals();
643 642
644 // Ask libibus to watch the NameOwnerChanged signal *asynchronously*.
645 ibus_bus_set_watch_dbus_signal(ibus_, TRUE);
646
647 if (ibus_bus_is_connected(ibus_)) { 643 if (ibus_bus_is_connected(ibus_)) {
648 DVLOG(1) << "IBus connection is ready: ibus-daemon is already running?"; 644 DVLOG(1) << "IBus connection is ready: ibus-daemon is already running?";
649 BusConnected(ibus_); 645 BusConnected(ibus_);
650 } 646 }
651 } 647 }
652 648
653 void IBusControllerImpl::SendChangeInputMethodRequest(const std::string& id) { 649 void IBusControllerImpl::SendChangeInputMethodRequest(const std::string& id) {
654 // Change the global engine *asynchronously*. 650 // Change the global engine *asynchronously*.
655 ibus_bus_set_global_engine_async(ibus_, 651 IBusClient* client = DBusThreadManager::Get()->GetIBusClient();
656 id.c_str(), 652 if (client)
657 -1, // use the default ibus timeout 653 client->SetGlobalEngine(id.c_str(), base::Bind(&base::DoNothing));
658 NULL, // cancellable
659 NULL, // callback
660 NULL); // user_data
661 } 654 }
662 655
663 bool IBusControllerImpl::SetInputMethodConfigInternal( 656 bool IBusControllerImpl::SetInputMethodConfigInternal(
664 const ConfigKeyType& key, 657 const ConfigKeyType& key,
665 const InputMethodConfigValue& value) { 658 const InputMethodConfigValue& value) {
666 IBusConfigClient* client = DBusThreadManager::Get()->GetIBusConfigClient(); 659 IBusConfigClient* client = DBusThreadManager::Get()->GetIBusConfigClient();
667 if (!client) 660 if (!client)
668 return false; 661 return false;
669 662
670 switch (value.type) { 663 switch (value.type) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 // Stop() or OnIBusDaemonExit() has already been called. 874 // Stop() or OnIBusDaemonExit() has already been called.
882 return; 875 return;
883 } 876 }
884 chromeos::DBusThreadManager::Get()->InitIBusBus(ibus_address); 877 chromeos::DBusThreadManager::Get()->InitIBusBus(ibus_address);
885 controller->ibus_daemon_status_ = IBUS_DAEMON_RUNNING; 878 controller->ibus_daemon_status_ = IBUS_DAEMON_RUNNING;
886 879
887 ui::InputMethodIBus* input_method_ibus = controller->GetInputMethod(); 880 ui::InputMethodIBus* input_method_ibus = controller->GetInputMethod();
888 DCHECK(input_method_ibus); 881 DCHECK(input_method_ibus);
889 input_method_ibus->OnConnected(); 882 input_method_ibus->OnConnected();
890 883
884 // Restores previous input method at the beggining of connection.
885 if (!controller->current_input_method_id_.empty()) {
886 controller->SendChangeInputMethodRequest(
887 controller->current_input_method_id_);
888 }
889
891 DBusThreadManager::Get()->GetIBusConfigClient()->InitializeAsync( 890 DBusThreadManager::Get()->GetIBusConfigClient()->InitializeAsync(
892 base::Bind(&IBusControllerImpl::OnIBusConfigClientInitialized, 891 base::Bind(&IBusControllerImpl::OnIBusConfigClientInitialized,
893 controller->weak_ptr_factory_.GetWeakPtr())); 892 controller->weak_ptr_factory_.GetWeakPtr()));
894 893
895 FOR_EACH_OBSERVER(Observer, controller->observers_, OnConnected()); 894 FOR_EACH_OBSERVER(Observer, controller->observers_, OnConnected());
896 895
897 VLOG(1) << "The ibus-daemon initialization is done."; 896 VLOG(1) << "The ibus-daemon initialization is done.";
898 } 897 }
899 898
900 // static 899 // static
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 936
938 // static 937 // static
939 bool IBusControllerImpl::FindAndUpdatePropertyForTesting( 938 bool IBusControllerImpl::FindAndUpdatePropertyForTesting(
940 const chromeos::input_method::InputMethodProperty& new_prop, 939 const chromeos::input_method::InputMethodProperty& new_prop,
941 chromeos::input_method::InputMethodPropertyList* prop_list) { 940 chromeos::input_method::InputMethodPropertyList* prop_list) {
942 return FindAndUpdateProperty(new_prop, prop_list); 941 return FindAndUpdateProperty(new_prop, prop_list);
943 } 942 }
944 943
945 } // namespace input_method 944 } // namespace input_method
946 } // namespace chromeos 945 } // 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