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

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

Issue 9999018: chrome/browser/chromeos/input_method/ refactoring [part 6 of 6] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_
7 #pragma once
8
9 #include <gio/gio.h> // GAsyncResult and related types.
10 #include <glib-object.h>
11
12 #include <string>
13 #include <vector>
14
15 #include "base/process_util.h"
16 #include "chrome/browser/chromeos/input_method/ibus_controller_base.h"
17 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
18 #include "ui/base/glib/glib_signal.h"
19
20 // Do not #include ibus.h here. That makes it impossible to compile unit tests
21 // for the class.
22 struct _IBusBus;
23 struct _IBusConfig;
24 struct _IBusPanelService;
25 struct _IBusPropList;
26 struct _IBusProperty;
27 typedef struct _IBusBus IBusBus;
28 typedef struct _IBusConfig IBusConfig;
29 typedef struct _IBusPanelService IBusPanelService;
30 typedef struct _IBusPropList IBusPropList;
31 typedef struct _IBusProperty IBusProperty;
32
33 namespace chromeos {
34 namespace input_method {
35
36 struct InputMethodConfigValue;
37 struct InputMethodProperty;
38 typedef std::vector<InputMethodProperty> InputMethodPropertyList;
39
40 // The IBusController implementation.
41 class IBusControllerImpl : public IBusControllerBase {
42 public:
43 IBusControllerImpl();
44 virtual ~IBusControllerImpl();
45
46 // IBusController overrides:
47 virtual bool Start(const std::vector<std::string>& ids) OVERRIDE;
48 virtual bool Stop() OVERRIDE;
49 virtual bool ChangeInputMethod(const std::string& id) OVERRIDE;
50 virtual bool ActivateInputMethodProperty(const std::string& key) OVERRIDE;
51 #if defined(USE_VIRTUAL_KEYBOARD)
52 virtual void SendHandwritingStroke(const HandwritingStroke& stroke) OVERRIDE;
53 virtual void CancelHandwriting(int n_strokes) OVERRIDE;
54 #endif
55
56 // Calls <anonymous_namespace>::FindAndUpdateProperty. This method is just for
57 // unit testing.
58 static bool FindAndUpdatePropertyForTesting(
59 const InputMethodProperty& new_prop,
60 InputMethodPropertyList* prop_list);
61
62 private:
63 // Functions that end with Thunk are used to deal with glib callbacks.
64 CHROMEG_CALLBACK_0(IBusControllerImpl, void, BusConnected, IBusBus*);
65 CHROMEG_CALLBACK_0(IBusControllerImpl, void, BusDisconnected, IBusBus*);
66 CHROMEG_CALLBACK_3(IBusControllerImpl, void, BusNameOwnerChanged,
67 IBusBus*, const gchar*, const gchar*, const gchar*);
68 CHROMEG_CALLBACK_1(IBusControllerImpl, void, FocusIn,
69 IBusPanelService*, const gchar*);
70 CHROMEG_CALLBACK_1(IBusControllerImpl, void, RegisterProperties,
71 IBusPanelService*, IBusPropList*);
72 CHROMEG_CALLBACK_1(IBusControllerImpl, void, UpdateProperty,
73 IBusPanelService*, IBusProperty*);
74
75 // IBusControllerBase overrides:
76 virtual bool SetInputMethodConfigInternal(
77 const ConfigKeyType& key,
78 const InputMethodConfigValue& value) OVERRIDE;
79
80 // Checks if |ibus_| and |ibus_config_| connections are alive.
81 bool IBusConnectionsAreAlive();
82
83 // Restores connections to ibus-daemon and ibus-memconf if they are not ready.
84 void MaybeRestoreConnections();
85
86 // Initializes IBusBus object if it's not yet done.
87 void MaybeInitializeIBusBus();
88
89 // Creates IBusConfig object if it's not created yet AND |ibus_| connection
90 // is ready.
91 void MaybeRestoreIBusConfig();
92
93 // Destroys IBusConfig object if |ibus_| connection is not ready. This
94 // function does nothing if |ibus_config_| is NULL or |ibus_| connection is
95 // still alive. Note that the IBusConfig object can't be used when |ibus_|
96 // connection is not ready.
97 void MaybeDestroyIBusConfig();
98
99 // Just calls ibus_bus_set_global_engine_async() with the |id|.
100 void SendChangeInputMethodRequest(const std::string& id);
101
102 // Calls SetInputMethodConfigInternal() for each |current_config_values_|.
103 void SendAllInputMethodConfigs();
104
105 // Starts listening to the "connected", "disconnected", and
106 // "name-owner-changed" D-Bus signals from ibus-daemon.
107 void ConnectBusSignals();
108
109 // Starts listening to the "focus-in", "register-properties", and
110 // "update-property" D-Bus signals from ibus-daemon.
111 void ConnectPanelServiceSignals();
112
113 // Starts ibus-daemon if it's not yet started and |should_launch_daemon_| is
114 // true.
115 bool MaybeLaunchIBusDaemon();
116
117 // Launches an input method procsess specified by the given command
118 // line. On success, returns true and stores the process handle in
119 // |process_handle|. Otherwise, returns false, and the contents of
120 // |process_handle| is untouched. |watch_func| will be called when the
121 // process terminates.
122 bool LaunchProcess(const std::string& command_line,
123 base::ProcessHandle* process_handle,
124 GChildWatchFunc watch_func);
125
126 // A callback function that will be called when ibus_config_set_value_async()
127 // request is finished.
128 static void SetInputMethodConfigCallback(GObject* source_object,
129 GAsyncResult* res,
130 gpointer user_data);
131
132 // Called when the input method process is shut down.
133 static void OnIBusDaemonExit(GPid pid,
134 gint status,
135 IBusControllerImpl* controller);
136
137 // Connection to the ibus-daemon via IBus API. These objects are used to
138 // call ibus-daemon's API (e.g. activate input methods, set config, ...)
139 IBusBus* ibus_;
140 IBusConfig* ibus_config_;
141
142 // true when ibus-daemon should be running.
143 bool should_launch_daemon_;
144
145 // The process handle of the IBus daemon. kNullProcessHandle if it's not
146 // running.
147 base::ProcessHandle process_handle_;
148
149 // Current input context path.
150 std::string current_input_context_path_;
151
152 // The input method ID which is currently selected. The ID is sent to the
153 // daemon when |ibus_| and |ibus_config_| connections are both established.
154 std::string current_input_method_id_;
155
156 // An object which knows all valid input method and layout IDs.
157 InputMethodWhitelist whitelist_;
158
159 DISALLOW_COPY_AND_ASSIGN(IBusControllerImpl);
160 };
161
162 } // namespace input_method
163 } // namespace chromeos
164
165 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698