blob: dc3b2c5dcf584ff0aae230dfd71d8896c11fa04c (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// 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/chromeos/chromeos_version.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 "chromeos/ime/ibus_bridge.h"
namespace chromeos {
namespace input_method {
namespace {
InputMethodManager* g_input_method_manager = NULL;
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() {
DCHECK(!g_input_method_manager);
if (!base::chromeos::IsRunningOnChromeOS()) {
// IBusBridge is for ChromeOS on desktop Linux not for ChromeOS Devices or
// production at this moment.
// TODO(nona): Remove this condition when ibus-daemon is gone.
// (crbug.com/170671)
IBusBridge::Initialize();
}
InputMethodManagerImpl* impl = new InputMethodManagerImpl(
scoped_ptr<InputMethodDelegate>(new InputMethodDelegateImpl));
impl->Init();
g_input_method_manager = impl;
g_input_method_persistence =
new InputMethodPersistence(g_input_method_manager);
g_browser_state_monitor = new BrowserStateMonitor(
base::Bind(&OnSessionStateChange, impl, g_input_method_persistence));
DVLOG(1) << "InputMethodManager initialized";
}
void InitializeForTesting(InputMethodManager* mock_manager) {
DCHECK(!g_input_method_manager);
g_input_method_manager = 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;
delete g_input_method_manager;
g_input_method_manager = NULL;
if (IBusBridge::Get()) {
// TODO(nona): Remove this condition when ibus-daemon is gone.
IBusBridge::Shutdown();
}
DVLOG(1) << "InputMethodManager shutdown";
}
InputMethodManager* GetInputMethodManager() {
DCHECK(g_input_method_manager);
return g_input_method_manager;
}
} // namespace input_method
} // namespace chromeos
|