Rename input_method_linux_x11 as input_method_auralinux.
[chromium-blink-merge.git] / ui / base / ime / input_method_initializer.cc
blob6579b056f90fb3f592582c72121bacd9590ad6d0
1 // Copyright 2013 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.
5 #include "ui/base/ime/input_method_initializer.h"
7 #include "ui/base/ime/input_method_factory.h"
9 #if defined(OS_CHROMEOS)
10 #include "base/logging.h"
11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "ui/base/ime/chromeos/ibus_bridge.h"
13 #elif defined(USE_AURA) && defined(USE_X11)
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/base/ime/input_method_auralinux.h"
16 #include "ui/base/ime/linux/fake_input_method_context_factory.h"
17 #elif defined(OS_WIN)
18 #include "base/win/metro.h"
19 #include "ui/base/ime/win/tsf_bridge.h"
20 #endif
22 namespace {
24 #if defined(OS_CHROMEOS)
25 bool dbus_thread_manager_was_initialized = false;
26 #elif defined(USE_AURA) && defined(USE_X11)
27 const ui::LinuxInputMethodContextFactory* g_linux_input_method_context_factory;
28 #endif
30 } // namespace
32 namespace ui {
34 void InitializeInputMethod() {
35 #if defined(OS_CHROMEOS)
36 chromeos::IBusBridge::Initialize();
37 #elif defined(USE_AURA) && defined(USE_X11)
38 InputMethodAuraLinux::Initialize();
39 #elif defined(OS_WIN)
40 if (base::win::IsTSFAwareRequired())
41 TSFBridge::Initialize();
42 #endif
45 void ShutdownInputMethod() {
46 #if defined(OS_CHROMEOS)
47 chromeos::IBusBridge::Shutdown();
48 #elif defined(OS_WIN)
49 internal::DestroySharedInputMethod();
50 if (base::win::IsTSFAwareRequired())
51 TSFBridge::Shutdown();
52 #endif
55 void InitializeInputMethodForTesting() {
56 #if defined(OS_CHROMEOS)
57 chromeos::IBusBridge::Initialize();
58 // TODO(nona): Remove DBusThreadManager initialize.
59 if (!chromeos::DBusThreadManager::IsInitialized()) {
60 chromeos::DBusThreadManager::InitializeWithStub();
61 dbus_thread_manager_was_initialized = true;
63 #elif defined(USE_AURA) && defined(USE_X11)
64 if (!g_linux_input_method_context_factory)
65 g_linux_input_method_context_factory = new FakeInputMethodContextFactory();
66 const LinuxInputMethodContextFactory* factory =
67 LinuxInputMethodContextFactory::instance();
68 CHECK(!factory || factory == g_linux_input_method_context_factory)
69 << "LinuxInputMethodContextFactory was already initialized somewhere "
70 << "else.";
71 LinuxInputMethodContextFactory::SetInstance(
72 g_linux_input_method_context_factory);
73 #elif defined(OS_WIN)
74 if (base::win::IsTSFAwareRequired()) {
75 // Make sure COM is initialized because TSF depends on COM.
76 CoInitialize(NULL);
77 TSFBridge::Initialize();
79 #endif
82 void ShutdownInputMethodForTesting() {
83 #if defined(OS_CHROMEOS)
84 chromeos::IBusBridge::Shutdown();
85 // TODO(nona): Remove DBusThreadManager finalize.
86 if (dbus_thread_manager_was_initialized) {
87 chromeos::DBusThreadManager::Shutdown();
88 dbus_thread_manager_was_initialized = false;
90 ui::InputMethodFactory::SetInstance(NULL);
91 #elif defined(USE_AURA) && defined(USE_X11)
92 const LinuxInputMethodContextFactory* factory =
93 LinuxInputMethodContextFactory::instance();
94 CHECK(!factory || factory == g_linux_input_method_context_factory)
95 << "An unknown LinuxInputMethodContextFactory was set.";
96 LinuxInputMethodContextFactory::SetInstance(NULL);
97 delete g_linux_input_method_context_factory;
98 g_linux_input_method_context_factory = NULL;
99 #elif defined(OS_WIN)
100 internal::DestroySharedInputMethod();
101 if (base::win::IsTSFAwareRequired()) {
102 TSFBridge::Shutdown();
103 CoUninitialize();
105 #endif
108 } // namespace ui