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

Unified 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, remove |should_hide_properties_| 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/input_method/ibus_controller_impl.h
diff --git a/chrome/browser/chromeos/input_method/ibus_controller_impl.h b/chrome/browser/chromeos/input_method/ibus_controller_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..210e11de5832255b1e87ba34b3c71cd9d6c2b90e
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/ibus_controller_impl.h
@@ -0,0 +1,165 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_
+#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_
+#pragma once
+
+#include <gio/gio.h> // GAsyncResult and related types.
+#include <glib-object.h>
+
+#include <string>
+#include <vector>
+
+#include "base/process_util.h"
+#include "chrome/browser/chromeos/input_method/ibus_controller_base.h"
+#include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
+#include "ui/base/glib/glib_signal.h"
+
+// Do not #include ibus.h here. That makes it impossible to compile unit tests
+// for the class.
+struct _IBusBus;
+struct _IBusConfig;
+struct _IBusPanelService;
+struct _IBusPropList;
+struct _IBusProperty;
+typedef struct _IBusBus IBusBus;
+typedef struct _IBusConfig IBusConfig;
+typedef struct _IBusPanelService IBusPanelService;
+typedef struct _IBusPropList IBusPropList;
+typedef struct _IBusProperty IBusProperty;
+
+namespace chromeos {
+namespace input_method {
+
+struct InputMethodConfigValue;
+struct InputMethodProperty;
+typedef std::vector<InputMethodProperty> InputMethodPropertyList;
+
+// The IBusController implementation.
+class IBusControllerImpl : public IBusControllerBase {
+ public:
+ IBusControllerImpl();
+ virtual ~IBusControllerImpl();
+
+ // IBusController overrides:
+ virtual bool Start() OVERRIDE;
+ virtual bool Stop() OVERRIDE;
+ virtual bool ChangeInputMethod(const std::string& id) OVERRIDE;
+ virtual bool ActivateInputMethodProperty(const std::string& key) OVERRIDE;
+#if defined(USE_VIRTUAL_KEYBOARD)
+ virtual void SendHandwritingStroke(const HandwritingStroke& stroke) OVERRIDE;
+ virtual void CancelHandwriting(int n_strokes) OVERRIDE;
+#endif
+
+ // Calls <anonymous_namespace>::FindAndUpdateProperty. This method is just for
+ // unit testing.
+ static bool FindAndUpdatePropertyForTesting(
+ const InputMethodProperty& new_prop,
+ InputMethodPropertyList* prop_list);
+
+ private:
+ // Functions that end with Thunk are used to deal with glib callbacks.
+ CHROMEG_CALLBACK_0(IBusControllerImpl, void, BusConnected, IBusBus*);
+ CHROMEG_CALLBACK_0(IBusControllerImpl, void, BusDisconnected, IBusBus*);
+ CHROMEG_CALLBACK_3(IBusControllerImpl, void, BusNameOwnerChanged,
+ IBusBus*, const gchar*, const gchar*, const gchar*);
+ CHROMEG_CALLBACK_1(IBusControllerImpl, void, FocusIn,
+ IBusPanelService*, const gchar*);
+ CHROMEG_CALLBACK_1(IBusControllerImpl, void, RegisterProperties,
+ IBusPanelService*, IBusPropList*);
+ CHROMEG_CALLBACK_1(IBusControllerImpl, void, UpdateProperty,
+ IBusPanelService*, IBusProperty*);
+
+ // IBusControllerBase overrides:
+ virtual bool SetInputMethodConfigInternal(
+ const ConfigKeyType& key,
+ const InputMethodConfigValue& value) OVERRIDE;
+
+ // Checks if |ibus_| and |ibus_config_| connections are alive.
+ bool IBusConnectionsAreAlive();
+
+ // Restores connections to ibus-daemon and ibus-memconf if they are not ready.
+ void MaybeRestoreConnections();
+
+ // Initializes IBusBus object if it's not yet done.
+ void MaybeInitializeIBusBus();
+
+ // Creates IBusConfig object if it's not created yet AND |ibus_| connection
+ // is ready.
+ void MaybeRestoreIBusConfig();
+
+ // Destroys IBusConfig object if |ibus_| connection is not ready. This
+ // function does nothing if |ibus_config_| is NULL or |ibus_| connection is
+ // still alive. Note that the IBusConfig object can't be used when |ibus_|
+ // connection is not ready.
+ void MaybeDestroyIBusConfig();
+
+ // Just calls ibus_bus_set_global_engine_async() with the |id|.
+ void SendChangeInputMethodRequest(const std::string& id);
+
+ // Calls SetInputMethodConfigInternal() for each |current_config_values_|.
+ void SendAllInputMethodConfigs();
+
+ // Starts listening to the "connected", "disconnected", and
+ // "name-owner-changed" D-Bus signals from ibus-daemon.
+ void ConnectBusSignals();
+
+ // Starts listening to the "focus-in", "register-properties", and
+ // "update-property" D-Bus signals from ibus-daemon.
+ void ConnectPanelServiceSignals();
+
+ // Starts ibus-daemon if it's not yet started and |should_launch_daemon_| is
+ // true.
+ bool MaybeLaunchIBusDaemon();
+
+ // Launches an input method procsess specified by the given command
+ // line. On success, returns true and stores the process handle in
+ // |process_handle|. Otherwise, returns false, and the contents of
+ // |process_handle| is untouched. |watch_func| will be called when the
+ // process terminates.
+ bool LaunchProcess(const std::string& command_line,
+ base::ProcessHandle* process_handle,
+ GChildWatchFunc watch_func);
+
+ // A callback function that will be called when ibus_config_set_value_async()
+ // request is finished.
+ static void SetInputMethodConfigCallback(GObject* source_object,
+ GAsyncResult* res,
+ gpointer user_data);
+
+ // Called when the input method process is shut down.
+ static void OnIBusDaemonExit(GPid pid,
+ gint status,
+ IBusControllerImpl* controller);
+
+ // Connection to the ibus-daemon via IBus API. These objects are used to
+ // call ibus-daemon's API (e.g. activate input methods, set config, ...)
+ IBusBus* ibus_;
+ IBusConfig* ibus_config_;
+
+ // true when ibus-daemon should be running.
+ bool should_launch_daemon_;
+
+ // The process handle of the IBus daemon. kNullProcessHandle if it's not
+ // running.
+ base::ProcessHandle process_handle_;
+
+ // Current input context path.
+ std::string current_input_context_path_;
+
+ // The input method ID which is currently selected. The ID is sent to the
+ // daemon when |ibus_| and |ibus_config_| connections are both established.
+ std::string current_input_method_id_;
+
+ // An object which knows all valid input methods and layout IDs.
+ InputMethodWhitelist whitelist_;
+
+ DISALLOW_COPY_AND_ASSIGN(IBusControllerImpl);
+};
+
+} // namespace input_method
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698