input_method_configuration.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
6
7#include "base/bind.h"
8#include "base/logging.h"
9#include "base/memory/scoped_ptr.h"
10#include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
11#include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h"
12#include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
13#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
14#include "chromeos/ime/ibus_bridge.h"
15
16namespace chromeos {
17namespace input_method {
18
19namespace {
20InputMethodPersistence* g_input_method_persistence = NULL;
21BrowserStateMonitor* g_browser_state_monitor = NULL;
22}  // namespace
23
24void OnSessionStateChange(InputMethodManagerImpl* input_method_manager_impl,
25                          InputMethodPersistence* input_method_persistence,
26                          InputMethodManager::State new_state) {
27  input_method_persistence->OnSessionStateChange(new_state);
28  input_method_manager_impl->SetState(new_state);
29}
30
31void Initialize(
32    const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
33    const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) {
34  IBusDaemonController::Initialize(ui_task_runner, file_task_runner);
35  IBusBridge::Initialize();
36  IBusDaemonController::GetInstance()->Start();
37
38  InputMethodManagerImpl* impl = new InputMethodManagerImpl(
39      scoped_ptr<InputMethodDelegate>(new InputMethodDelegateImpl));
40  impl->Init(ui_task_runner.get());
41  InputMethodManager::Initialize(impl);
42  g_input_method_persistence = new InputMethodPersistence(impl);
43  g_browser_state_monitor = new BrowserStateMonitor(
44      base::Bind(&OnSessionStateChange, impl, g_input_method_persistence));
45
46  DVLOG(1) << "InputMethodManager initialized";
47}
48
49void InitializeForTesting(InputMethodManager* mock_manager) {
50  InputMethodManager::Initialize(mock_manager);
51  DVLOG(1) << "InputMethodManager for testing initialized";
52}
53
54void Shutdown() {
55  delete g_browser_state_monitor;
56  g_browser_state_monitor = NULL;
57
58  delete g_input_method_persistence;
59  g_input_method_persistence = NULL;
60
61  InputMethodManager::Shutdown();
62
63  IBusBridge::Shutdown();
64  IBusDaemonController::Shutdown();
65
66  DVLOG(1) << "InputMethodManager shutdown";
67}
68
69InputMethodManager* GetInputMethodManager() {
70  return InputMethodManager::Get();
71}
72
73}  // namespace input_method
74}  // namespace chromeos
75