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 #include "ui/base/ime/input_method_factory.h" 8 9 #if defined(OS_CHROMEOS) 10 #include "base/chromeos/chromeos_version.h" 11 #include "base/logging.h" 12 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/ime/ibus_daemon_controller.h" 14 #elif defined(OS_WIN) 15 #include "base/win/metro.h" 16 #include "ui/base/ime/win/tsf_bridge.h" 17 #endif 18 19 #if defined(OS_CHROMEOS) 20 namespace { 21 bool dbus_thread_manager_was_initialized = false; 22 } 23 #endif // OS_CHROMEOS 24 25 namespace ui { 26 27 void InitializeInputMethod() { 28 #if defined(OS_WIN) 29 if (base::win::IsTSFAwareRequired()) 30 ui::TSFBridge::Initialize(); 31 #endif 32 } 33 34 void ShutdownInputMethod() { 35 #if defined(OS_WIN) 36 ui::internal::DestroySharedInputMethod(); 37 if (base::win::IsTSFAwareRequired()) 38 ui::TSFBridge::Shutdown(); 39 #endif 40 } 41 42 void InitializeInputMethodForTesting() { 43 #if defined(OS_CHROMEOS) 44 if (!chromeos::DBusThreadManager::IsInitialized()) { 45 chromeos::DBusThreadManager::InitializeWithStub(); 46 dbus_thread_manager_was_initialized = true; 47 } 48 if (!chromeos::IBusDaemonController::GetInstance()) { 49 // Passing NULL is okay because IBusDaemonController will be initialized 50 // with stub implementation on non-ChromeOS device. 51 DCHECK(!base::chromeos::IsRunningOnChromeOS()); 52 chromeos::IBusDaemonController::Initialize(NULL, NULL); 53 } 54 #elif defined(OS_WIN) 55 if (base::win::IsTSFAwareRequired()) { 56 // Make sure COM is initialized because TSF depends on COM. 57 CoInitialize(NULL); 58 ui::TSFBridge::Initialize(); 59 } 60 #endif 61 } 62 63 void ShutdownInputMethodForTesting() { 64 #if defined(OS_CHROMEOS) 65 if (dbus_thread_manager_was_initialized) { 66 chromeos::DBusThreadManager::Shutdown(); 67 dbus_thread_manager_was_initialized = false; 68 } 69 if (chromeos::IBusDaemonController::GetInstance()) 70 chromeos::IBusDaemonController::Shutdown(); 71 #elif defined(OS_WIN) 72 ui::internal::DestroySharedInputMethod(); 73 if (base::win::IsTSFAwareRequired()) { 74 ui::TSFBridge::Shutdown(); 75 CoUninitialize(); 76 } 77 #endif 78 } 79 80 } // namespace ui 81