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. 4 5#include "ui/base/ime/input_method_initializer.h" 6 7#if defined(OS_CHROMEOS) 8#include "ui/base/ime/chromeos/ime_bridge.h" 9#elif defined(USE_AURA) && defined(OS_LINUX) 10#include "base/logging.h" 11#include "ui/base/ime/linux/fake_input_method_context_factory.h" 12#endif 13 14namespace { 15 16#if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) 17const ui::LinuxInputMethodContextFactory* g_linux_input_method_context_factory; 18#endif 19 20} // namespace 21 22namespace ui { 23 24void InitializeInputMethod() { 25#if defined(OS_CHROMEOS) 26 chromeos::IMEBridge::Initialize(); 27#endif 28} 29 30void ShutdownInputMethod() { 31#if defined(OS_CHROMEOS) 32 chromeos::IMEBridge::Shutdown(); 33#endif 34} 35 36void InitializeInputMethodForTesting() { 37#if defined(OS_CHROMEOS) 38 chromeos::IMEBridge::Initialize(); 39#elif defined(USE_AURA) && defined(OS_LINUX) 40 if (!g_linux_input_method_context_factory) 41 g_linux_input_method_context_factory = new FakeInputMethodContextFactory(); 42 const LinuxInputMethodContextFactory* factory = 43 LinuxInputMethodContextFactory::instance(); 44 CHECK(!factory || factory == g_linux_input_method_context_factory) 45 << "LinuxInputMethodContextFactory was already initialized somewhere " 46 << "else."; 47 LinuxInputMethodContextFactory::SetInstance( 48 g_linux_input_method_context_factory); 49#endif 50} 51 52void ShutdownInputMethodForTesting() { 53#if defined(OS_CHROMEOS) 54 chromeos::IMEBridge::Shutdown(); 55#elif defined(USE_AURA) && defined(OS_LINUX) 56 const LinuxInputMethodContextFactory* factory = 57 LinuxInputMethodContextFactory::instance(); 58 CHECK(!factory || factory == g_linux_input_method_context_factory) 59 << "An unknown LinuxInputMethodContextFactory was set."; 60 LinuxInputMethodContextFactory::SetInstance(NULL); 61 delete g_linux_input_method_context_factory; 62 g_linux_input_method_context_factory = NULL; 63#endif 64} 65 66} // namespace ui 67