summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/input_method/input_method_configuration.cc
blob: dc20c4102c807435bad83a6c03a6cbd16245120b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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.

#include "chrome/browser/chromeos/input_method/input_method_configuration.h"

#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
#include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h"
#include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
#include "ui/base/ime/chromeos/ibus_bridge.h"

namespace chromeos {
namespace input_method {

namespace {
InputMethodPersistence* g_input_method_persistence = NULL;
BrowserStateMonitor* g_browser_state_monitor = NULL;
}  // namespace

void OnSessionStateChange(InputMethodManagerImpl* input_method_manager_impl,
                          InputMethodPersistence* input_method_persistence,
                          InputMethodManager::State new_state) {
  input_method_persistence->OnSessionStateChange(new_state);
  input_method_manager_impl->SetState(new_state);
}

void Initialize(
    const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
    const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) {
  IBusBridge::Initialize();

  InputMethodManagerImpl* impl = new InputMethodManagerImpl(
      scoped_ptr<InputMethodDelegate>(new InputMethodDelegateImpl));
  impl->Init(ui_task_runner.get());
  InputMethodManager::Initialize(impl);
  g_input_method_persistence = new InputMethodPersistence(impl);
  g_browser_state_monitor = new BrowserStateMonitor(
      base::Bind(&OnSessionStateChange, impl, g_input_method_persistence));

  DVLOG(1) << "InputMethodManager initialized";
}

void InitializeForTesting(InputMethodManager* mock_manager) {
  InputMethodManager::Initialize(mock_manager);
  DVLOG(1) << "InputMethodManager for testing initialized";
}

void Shutdown() {
  delete g_browser_state_monitor;
  g_browser_state_monitor = NULL;

  delete g_input_method_persistence;
  g_input_method_persistence = NULL;

  InputMethodManager::Shutdown();

  IBusBridge::Shutdown();

  DVLOG(1) << "InputMethodManager shutdown";
}

InputMethodManager* GetInputMethodManager() {
  return InputMethodManager::Get();
}

}  // namespace input_method
}  // namespace chromeos