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.
5 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/input_method/accessibility.h"
11 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
12 #include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h"
13 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
14 #include "chrome/browser/chromeos/input_method/input_method_persistence.h"
15 #include "ui/base/ime/chromeos/ibus_bridge.h"
18 namespace input_method
{
21 void OnSessionStateChange(InputMethodManagerImpl
* input_method_manager_impl
,
22 InputMethodPersistence
* input_method_persistence
,
23 InputMethodManager::State new_state
) {
24 input_method_persistence
->OnSessionStateChange(new_state
);
25 input_method_manager_impl
->SetState(new_state
);
28 class InputMethodConfiguration
{
30 InputMethodConfiguration() {}
31 virtual ~InputMethodConfiguration() {}
34 const scoped_refptr
<base::SequencedTaskRunner
>& ui_task_runner
) {
35 IBusBridge::Initialize();
37 InputMethodManagerImpl
* impl
= new InputMethodManagerImpl(
38 scoped_ptr
<InputMethodDelegate
>(new InputMethodDelegateImpl
));
39 impl
->Init(ui_task_runner
.get());
40 InputMethodManager::Initialize(impl
);
42 DCHECK(InputMethodManager::Get());
44 accessibility_
.reset(new Accessibility(impl
));
45 input_method_persistence_
.reset(new InputMethodPersistence(impl
));
46 browser_state_monitor_
.reset(new BrowserStateMonitor(
47 base::Bind(&OnSessionStateChange
,
49 input_method_persistence_
.get())));
51 DVLOG(1) << "InputMethodManager initialized";
54 void InitializeForTesting(InputMethodManager
* mock_manager
) {
55 InputMethodManager::Initialize(mock_manager
);
56 DVLOG(1) << "InputMethodManager for testing initialized";
60 accessibility_
.reset();
61 browser_state_monitor_
.reset();
62 input_method_persistence_
.reset();
64 InputMethodManager::Shutdown();
66 IBusBridge::Shutdown();
68 DVLOG(1) << "InputMethodManager shutdown";
72 scoped_ptr
<Accessibility
> accessibility_
;
73 scoped_ptr
<BrowserStateMonitor
> browser_state_monitor_
;
74 scoped_ptr
<InputMethodPersistence
> input_method_persistence_
;
77 InputMethodConfiguration
* g_input_method_configuration
= NULL
;
82 const scoped_refptr
<base::SequencedTaskRunner
>& ui_task_runner
,
83 const scoped_refptr
<base::SequencedTaskRunner
>& file_task_runner
) {
84 if (!g_input_method_configuration
)
85 g_input_method_configuration
= new InputMethodConfiguration();
86 g_input_method_configuration
->Initialize(ui_task_runner
);
89 void InitializeForTesting(InputMethodManager
* mock_manager
) {
90 if (!g_input_method_configuration
)
91 g_input_method_configuration
= new InputMethodConfiguration();
92 g_input_method_configuration
->InitializeForTesting(mock_manager
);
96 if (!g_input_method_configuration
)
99 g_input_method_configuration
->Shutdown();
100 delete g_input_method_configuration
;
101 g_input_method_configuration
= NULL
;
104 } // namespace input_method
105 } // namespace chromeos