| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h" |
| 9 #include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h" | 11 #include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h" |
| 10 #include "chrome/browser/chromeos/input_method/input_method_manager_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" |
| 11 | 14 |
| 12 namespace chromeos { | 15 namespace chromeos { |
| 13 namespace input_method { | 16 namespace input_method { |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 InputMethodManager* g_input_method_manager = NULL; | 19 InputMethodManager* g_input_method_manager = NULL; |
| 20 InputMethodPersistence* g_input_method_persistence = NULL; |
| 21 BrowserStateMonitor* g_browser_state_monitor = NULL; |
| 17 } // namespace | 22 } // namespace |
| 18 | 23 |
| 24 void 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 } |
| 19 | 30 |
| 20 void Initialize() { | 31 void Initialize() { |
| 21 DCHECK(!g_input_method_manager); | 32 DCHECK(!g_input_method_manager); |
| 22 | 33 |
| 23 InputMethodManagerImpl* impl = new InputMethodManagerImpl( | 34 InputMethodManagerImpl* impl = new InputMethodManagerImpl( |
| 24 scoped_ptr<InputMethodDelegate>(new InputMethodDelegateImpl)); | 35 scoped_ptr<InputMethodDelegate>(new InputMethodDelegateImpl)); |
| 25 impl->Init(); | 36 impl->Init(); |
| 26 g_input_method_manager = impl; | 37 g_input_method_manager = impl; |
| 38 g_input_method_persistence = |
| 39 new InputMethodPersistence(g_input_method_manager); |
| 40 g_browser_state_monitor = new BrowserStateMonitor( |
| 41 base::Bind(&OnSessionStateChange, impl, g_input_method_persistence)); |
| 27 | 42 |
| 28 DVLOG(1) << "InputMethodManager initialized"; | 43 DVLOG(1) << "InputMethodManager initialized"; |
| 29 } | 44 } |
| 30 | 45 |
| 31 void InitializeForTesting(InputMethodManager* mock_manager) { | 46 void InitializeForTesting(InputMethodManager* mock_manager) { |
| 32 DCHECK(!g_input_method_manager); | 47 DCHECK(!g_input_method_manager); |
| 33 g_input_method_manager = mock_manager; | 48 g_input_method_manager = mock_manager; |
| 34 DVLOG(1) << "InputMethodManager for testing initialized"; | 49 DVLOG(1) << "InputMethodManager for testing initialized"; |
| 35 } | 50 } |
| 36 | 51 |
| 37 void Shutdown() { | 52 void Shutdown() { |
| 53 delete g_browser_state_monitor; |
| 54 g_browser_state_monitor = NULL; |
| 55 |
| 56 delete g_input_method_persistence; |
| 57 g_input_method_persistence = NULL; |
| 58 |
| 38 delete g_input_method_manager; | 59 delete g_input_method_manager; |
| 39 g_input_method_manager = NULL; | 60 g_input_method_manager = NULL; |
| 61 |
| 40 DVLOG(1) << "InputMethodManager shutdown"; | 62 DVLOG(1) << "InputMethodManager shutdown"; |
| 41 } | 63 } |
| 42 | 64 |
| 43 InputMethodManager* GetInputMethodManager() { | 65 InputMethodManager* GetInputMethodManager() { |
| 44 DCHECK(g_input_method_manager); | 66 DCHECK(g_input_method_manager); |
| 45 return g_input_method_manager; | 67 return g_input_method_manager; |
| 46 } | 68 } |
| 47 | 69 |
| 48 } // namespace input_method | 70 } // namespace input_method |
| 49 } // namespace chromeos | 71 } // namespace chromeos |
| OLD | NEW |