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

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

Issue 10159004: Extends DBusThreadManager to connect ibus-bus. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase on http://codereview.chromium.org/10195001/ and separate initialization. Created 8 years, 8 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
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 "base/environment.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/rand_util.h"
16 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
17 #include "base/string_split.h" 19 #include "base/string_split.h"
18 #include "chrome/browser/chromeos/input_method/input_method_config.h" 20 #include "chrome/browser/chromeos/input_method/input_method_config.h"
19 #include "chrome/browser/chromeos/input_method/input_method_property.h" 21 #include "chrome/browser/chromeos/input_method/input_method_property.h"
20 #include "chrome/browser/chromeos/input_method/input_method_util.h" 22 #include "chrome/browser/chromeos/input_method/input_method_util.h"
21 23
22 // TODO(nona): Remove libibus dependency from this file. Then, write unit tests 24 // TODO(nona): Remove libibus dependency from this file. Then, write unit tests
23 // for all functions in this file. crbug.com/26334 25 // for all functions in this file. crbug.com/26334
24 #if defined(HAVE_IBUS) 26 #if defined(HAVE_IBUS)
25 #include <ibus.h> 27 #include <ibus.h>
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 if (!prop_list.empty()) { 889 if (!prop_list.empty()) {
888 for (size_t i = 0; i < prop_list.size(); ++i) { 890 for (size_t i = 0; i < prop_list.size(); ++i) {
889 FindAndUpdateProperty(prop_list[i], &current_property_list_); 891 FindAndUpdateProperty(prop_list[i], &current_property_list_);
890 } 892 }
891 FOR_EACH_OBSERVER(Observer, observers_, PropertyChanged()); 893 FOR_EACH_OBSERVER(Observer, observers_, PropertyChanged());
892 } 894 }
893 } 895 }
894 896
895 bool IBusControllerImpl::MaybeLaunchIBusDaemon() { 897 bool IBusControllerImpl::MaybeLaunchIBusDaemon() {
896 static const char kIBusDaemonPath[] = "/usr/bin/ibus-daemon"; 898 static const char kIBusDaemonPath[] = "/usr/bin/ibus-daemon";
899 const std::string ibus_address = base::StringPrintf(
Yusuke Sato 2012/04/24 04:58:37 nit: move this down to line 908.
Seigo Nonaka 2012/04/26 00:14:32 Done.
900 "unix:abstract=/tmp/ibus-%0lX", base::RandUint64());
897 901
898 if (process_handle_ != base::kNullProcessHandle) { 902 if (process_handle_ != base::kNullProcessHandle) {
899 DVLOG(1) << "MaybeLaunchIBusDaemon: ibus-daemon is already running."; 903 DVLOG(1) << "MaybeLaunchIBusDaemon: ibus-daemon is already running.";
900 return false; 904 return false;
901 } 905 }
902 if (!should_launch_daemon_) 906 if (!should_launch_daemon_)
903 return false; 907 return false;
904 908
905 // TODO(zork): Send output to /var/log/ibus.log 909 // TODO(zork): Send output to /var/log/ibus.log
906 const std::string ibus_daemon_command_line = 910 const std::string ibus_daemon_command_line =
907 base::StringPrintf("%s --panel=disable --cache=none --restart --replace", 911 base::StringPrintf("%s --panel=disable --cache=none --restart --replace"
908 kIBusDaemonPath); 912 " --address=%s",
913 kIBusDaemonPath,
914 ibus_address.c_str());
909 if (!LaunchProcess(ibus_daemon_command_line, 915 if (!LaunchProcess(ibus_daemon_command_line,
910 &process_handle_, 916 &process_handle_,
911 reinterpret_cast<GChildWatchFunc>(OnIBusDaemonExit))) { 917 reinterpret_cast<GChildWatchFunc>(OnIBusDaemonExit))) {
912 DVLOG(1) << "Failed to launch " << ibus_daemon_command_line; 918 DVLOG(1) << "Failed to launch " << ibus_daemon_command_line;
913 return false; 919 return false;
914 } 920 }
921
922 // To avoid reading address file in UI thread, sets environment variable. The
Yusuke Sato 2012/04/24 04:58:37 You can remove 922-927. See http://codereview.chro
Seigo Nonaka 2012/04/26 00:14:32 Done.
923 // libibus uses IBUS_ADDRESS environment variable at first if available.
924 // https://github.com/ibus/ibus/blob/master/src/ibusshare.c#L188
925 // TODO(nona): Remove environment variable after fixing crosbug.com/26334.
926 scoped_ptr<base::Environment> env(base::Environment::Create());
927 env->SetVar("IBUS_ADDRESS", ibus_address.c_str());
928
929 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get();
930 dbus_thread_manager->InitializeIBusBus(ibus_address);
Yusuke Sato 2012/04/24 04:58:37 It seems that you code does not support dynamic ib
Seigo Nonaka 2012/04/26 00:14:32 I think latest patch support suggested case, howev
Yusuke Sato 2012/04/26 00:46:28 Ah ok, the dynamic shutdown feature is temporarily
Yusuke Sato 2012/04/26 00:48:48 s/crosbug 26443/crosbug 27051/
931
915 return true; 932 return true;
916 } 933 }
917 934
918 bool IBusControllerImpl::LaunchProcess(const std::string& command_line, 935 bool IBusControllerImpl::LaunchProcess(const std::string& command_line,
919 base::ProcessHandle* process_handle, 936 base::ProcessHandle* process_handle,
920 GChildWatchFunc watch_func) { 937 GChildWatchFunc watch_func) {
921 std::vector<std::string> argv; 938 std::vector<std::string> argv;
922 base::ProcessHandle handle = base::kNullProcessHandle; 939 base::ProcessHandle handle = base::kNullProcessHandle;
923 940
924 base::SplitString(command_line, ' ', &argv); 941 base::SplitString(command_line, ' ', &argv);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 995
979 // static 996 // static
980 bool IBusControllerImpl::FindAndUpdatePropertyForTesting( 997 bool IBusControllerImpl::FindAndUpdatePropertyForTesting(
981 const chromeos::input_method::InputMethodProperty& new_prop, 998 const chromeos::input_method::InputMethodProperty& new_prop,
982 chromeos::input_method::InputMethodPropertyList* prop_list) { 999 chromeos::input_method::InputMethodPropertyList* prop_list) {
983 return FindAndUpdateProperty(new_prop, prop_list); 1000 return FindAndUpdateProperty(new_prop, prop_list);
984 } 1001 }
985 1002
986 } // namespace input_method 1003 } // namespace input_method
987 } // namespace chromeos 1004 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/dbus/dbus_thread_manager.h » ('j') | chromeos/dbus/dbus_thread_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698