| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <gio/gio.h> // GAsyncResult and related types. | 8 #include <gio/gio.h> // GAsyncResult and related types. |
| 9 #include <glib-object.h> | |
| 10 | 9 |
| 11 #include <string> | 10 #include <string> |
| 12 #include <vector> | 11 #include <vector> |
| 13 | 12 |
| 14 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 15 #include "chrome/browser/chromeos/input_method/ibus_controller_base.h" | 14 #include "chrome/browser/chromeos/input_method/ibus_controller_base.h" |
| 16 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" | 15 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" |
| 17 #include "ui/base/glib/glib_signal.h" | 16 #include "chromeos/dbus/ibus/ibus_panel_service.h" |
| 18 | |
| 19 // Do not #include ibus.h here. That makes it impossible to compile unit tests | |
| 20 // for the class. | |
| 21 struct _IBusBus; | |
| 22 struct _IBusConfig; | |
| 23 struct _IBusPanelService; | |
| 24 struct _IBusPropList; | |
| 25 struct _IBusProperty; | |
| 26 typedef struct _IBusBus IBusBus; | |
| 27 typedef struct _IBusConfig IBusConfig; | |
| 28 typedef struct _IBusPanelService IBusPanelService; | |
| 29 typedef struct _IBusPropList IBusPropList; | |
| 30 typedef struct _IBusProperty IBusProperty; | |
| 31 | 17 |
| 32 namespace ui { | 18 namespace ui { |
| 33 class InputMethodIBus; | 19 class InputMethodIBus; |
| 34 } // namespace ui | 20 } // namespace ui |
| 35 | 21 |
| 36 namespace chromeos { | 22 namespace chromeos { |
| 37 namespace input_method { | 23 namespace input_method { |
| 38 | 24 |
| 39 struct InputMethodConfigValue; | 25 struct InputMethodConfigValue; |
| 40 struct InputMethodProperty; | 26 struct InputMethodProperty; |
| 41 typedef std::vector<InputMethodProperty> InputMethodPropertyList; | 27 typedef std::vector<InputMethodProperty> InputMethodPropertyList; |
| 42 | 28 |
| 43 // The IBusController implementation. | 29 // The IBusController implementation. |
| 44 class IBusControllerImpl : public IBusControllerBase { | 30 class IBusControllerImpl : public IBusControllerBase, |
| 31 public ibus::IBusPanelPropertyHandlerInterface { |
| 45 public: | 32 public: |
| 46 IBusControllerImpl(); | 33 IBusControllerImpl(); |
| 47 virtual ~IBusControllerImpl(); | 34 virtual ~IBusControllerImpl(); |
| 48 | 35 |
| 49 // IBusController overrides: | 36 // IBusController overrides: |
| 50 virtual bool Start() OVERRIDE; | 37 virtual bool Start() OVERRIDE; |
| 51 virtual void Reset() OVERRIDE; | 38 virtual void Reset() OVERRIDE; |
| 52 virtual bool Stop() OVERRIDE; | 39 virtual bool Stop() OVERRIDE; |
| 53 virtual bool ChangeInputMethod(const std::string& id) OVERRIDE; | 40 virtual bool ChangeInputMethod(const std::string& id) OVERRIDE; |
| 54 virtual bool ActivateInputMethodProperty(const std::string& key) OVERRIDE; | 41 virtual bool ActivateInputMethodProperty(const std::string& key) OVERRIDE; |
| 55 | 42 |
| 56 // Calls <anonymous_namespace>::FindAndUpdateProperty. This method is just for | 43 // Calls <anonymous_namespace>::FindAndUpdateProperty. This method is just for |
| 57 // unit testing. | 44 // unit testing. |
| 58 static bool FindAndUpdatePropertyForTesting( | 45 static bool FindAndUpdatePropertyForTesting( |
| 59 const InputMethodProperty& new_prop, | 46 const InputMethodProperty& new_prop, |
| 60 InputMethodPropertyList* prop_list); | 47 InputMethodPropertyList* prop_list); |
| 61 | 48 |
| 62 static void IBusDaemonInitializationDone(IBusControllerImpl* controller, | 49 static void IBusDaemonInitializationDone(IBusControllerImpl* controller, |
| 63 const std::string& ibus_address); | 50 const std::string& ibus_address); |
| 64 | 51 |
| 65 private: | 52 private: |
| 66 enum IBusDaemonStatus{ | 53 enum IBusDaemonStatus{ |
| 67 IBUS_DAEMON_INITIALIZING, | 54 IBUS_DAEMON_INITIALIZING, |
| 68 IBUS_DAEMON_RUNNING, | 55 IBUS_DAEMON_RUNNING, |
| 69 IBUS_DAEMON_SHUTTING_DOWN, | 56 IBUS_DAEMON_SHUTTING_DOWN, |
| 70 IBUS_DAEMON_STOP, | 57 IBUS_DAEMON_STOP, |
| 71 }; | 58 }; |
| 72 | 59 |
| 73 // Functions that end with Thunk are used to deal with glib callbacks. | |
| 74 CHROMEG_CALLBACK_0(IBusControllerImpl, void, BusConnected, IBusBus*); | |
| 75 CHROMEG_CALLBACK_1(IBusControllerImpl, void, RegisterProperties, | |
| 76 IBusPanelService*, IBusPropList*); | |
| 77 CHROMEG_CALLBACK_1(IBusControllerImpl, void, UpdateProperty, | |
| 78 IBusPanelService*, IBusProperty*); | |
| 79 | |
| 80 // IBusControllerBase overrides: | 60 // IBusControllerBase overrides: |
| 81 virtual bool SetInputMethodConfigInternal( | 61 virtual bool SetInputMethodConfigInternal( |
| 82 const ConfigKeyType& key, | 62 const ConfigKeyType& key, |
| 83 const InputMethodConfigValue& value) OVERRIDE; | 63 const InputMethodConfigValue& value) OVERRIDE; |
| 84 | 64 |
| 65 // ibus::IBusPanelPropertyHandlerInterface overrides: |
| 66 virtual void RegisterProperties( |
| 67 const ibus::IBusPropertyList& properties) OVERRIDE; |
| 68 virtual void UpdateProperty(const ibus::IBusProperty& property) OVERRIDE; |
| 69 |
| 85 // Checks if |ibus_| and |ibus_config_| connections are alive. | 70 // Checks if |ibus_| and |ibus_config_| connections are alive. |
| 86 bool IBusConnectionsAreAlive(); | 71 bool IBusConnectionsAreAlive(); |
| 87 | 72 |
| 88 // Restores connections to ibus-daemon and ibus-memconf if they are not ready. | |
| 89 void MaybeRestoreConnections(); | |
| 90 | |
| 91 // Initializes IBusBus object if it's not yet done. | |
| 92 void MaybeInitializeIBusBus(); | |
| 93 | |
| 94 // Creates IBusConfig object if it's not created yet AND |ibus_| connection | |
| 95 // is ready. | |
| 96 void MaybeRestoreIBusConfig(); | |
| 97 | |
| 98 // Destroys IBusConfig object if |ibus_| connection is not ready. This | |
| 99 // function does nothing if |ibus_config_| is NULL or |ibus_| connection is | |
| 100 // still alive. Note that the IBusConfig object can't be used when |ibus_| | |
| 101 // connection is not ready. | |
| 102 void MaybeDestroyIBusConfig(); | |
| 103 | |
| 104 // Just calls ibus_bus_set_global_engine_async() with the |id|. | 73 // Just calls ibus_bus_set_global_engine_async() with the |id|. |
| 105 void SendChangeInputMethodRequest(const std::string& id); | 74 void SendChangeInputMethodRequest(const std::string& id); |
| 106 | 75 |
| 107 // Starts listening to the "connected", "disconnected", and | |
| 108 // "name-owner-changed" D-Bus signals from ibus-daemon. | |
| 109 void ConnectBusSignals(); | |
| 110 | |
| 111 // Starts listening to the "focus-in", "register-properties", and | |
| 112 // "update-property" D-Bus signals from ibus-daemon. | |
| 113 void ConnectPanelServiceSignals(); | |
| 114 | |
| 115 // Adds address file watcher in FILE thread and then calls LaunchIBusDaemon. | 76 // Adds address file watcher in FILE thread and then calls LaunchIBusDaemon. |
| 116 bool StartIBusDaemon(); | 77 bool StartIBusDaemon(); |
| 117 | 78 |
| 118 // Starts ibus-daemon. | 79 // Starts ibus-daemon. |
| 119 void LaunchIBusDaemon(const std::string& ibus_address); | 80 void LaunchIBusDaemon(const std::string& ibus_address); |
| 120 | 81 |
| 121 // Launches an input method procsess specified by the given command | 82 // Launches an input method procsess specified by the given command |
| 122 // line. On success, returns true and stores the process handle in | 83 // line. On success, returns true and stores the process handle in |
| 123 // |process_handle|. Otherwise, returns false, and the contents of | 84 // |process_handle|. Otherwise, returns false, and the contents of |
| 124 // |process_handle| is untouched. |watch_func| will be called when the | 85 // |process_handle| is untouched. |watch_func| will be called when the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 135 void set_input_method_for_testing(ui::InputMethodIBus* input_method); | 96 void set_input_method_for_testing(ui::InputMethodIBus* input_method); |
| 136 | 97 |
| 137 // Called when the IBusConfigClient is initialized. | 98 // Called when the IBusConfigClient is initialized. |
| 138 void OnIBusConfigClientInitialized(); | 99 void OnIBusConfigClientInitialized(); |
| 139 | 100 |
| 140 // Called when the input method process is shut down. | 101 // Called when the input method process is shut down. |
| 141 static void OnIBusDaemonExit(GPid pid, | 102 static void OnIBusDaemonExit(GPid pid, |
| 142 gint status, | 103 gint status, |
| 143 IBusControllerImpl* controller); | 104 IBusControllerImpl* controller); |
| 144 | 105 |
| 145 // Connection to the ibus-daemon via IBus API. These objects are used to | |
| 146 // call ibus-daemon's API (e.g. activate input methods, set config, ...) | |
| 147 IBusBus* ibus_; | |
| 148 IBusConfig* ibus_config_; | |
| 149 | |
| 150 // The current ibus_daemon address. This value is assigned at the launching | 106 // The current ibus_daemon address. This value is assigned at the launching |
| 151 // ibus-daemon and used in bus connection initialization. | 107 // ibus-daemon and used in bus connection initialization. |
| 152 std::string ibus_daemon_address_; | 108 std::string ibus_daemon_address_; |
| 153 | 109 |
| 154 // The process handle of the IBus daemon. kNullProcessHandle if it's not | 110 // The process handle of the IBus daemon. kNullProcessHandle if it's not |
| 155 // running. | 111 // running. |
| 156 base::ProcessHandle process_handle_; | 112 base::ProcessHandle process_handle_; |
| 157 | 113 |
| 158 // Current input context path. | 114 // Current input context path. |
| 159 std::string current_input_context_path_; | 115 std::string current_input_context_path_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 174 // Used for making callbacks for PostTask. | 130 // Used for making callbacks for PostTask. |
| 175 base::WeakPtrFactory<IBusControllerImpl> weak_ptr_factory_; | 131 base::WeakPtrFactory<IBusControllerImpl> weak_ptr_factory_; |
| 176 | 132 |
| 177 DISALLOW_COPY_AND_ASSIGN(IBusControllerImpl); | 133 DISALLOW_COPY_AND_ASSIGN(IBusControllerImpl); |
| 178 }; | 134 }; |
| 179 | 135 |
| 180 } // namespace input_method | 136 } // namespace input_method |
| 181 } // namespace chromeos | 137 } // namespace chromeos |
| 182 | 138 |
| 183 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_ | 139 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_ |
| OLD | NEW |