Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_manager.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 public: | 68 public: |
| 69 InputMethodManagerImpl() | 69 InputMethodManagerImpl() |
| 70 : ibus_controller_(NULL), | 70 : ibus_controller_(NULL), |
| 71 should_launch_ime_(false), | 71 should_launch_ime_(false), |
| 72 ime_connected_(false), | 72 ime_connected_(false), |
| 73 defer_ime_startup_(false), | 73 defer_ime_startup_(false), |
| 74 enable_auto_ime_shutdown_(true), | 74 enable_auto_ime_shutdown_(true), |
| 75 #if !defined(TOUCH_UI) | 75 #if !defined(TOUCH_UI) |
| 76 candidate_window_controller_(NULL), | 76 candidate_window_controller_(NULL), |
| 77 #endif | 77 #endif |
| 78 shutting_down_(false), | |
| 78 ibus_daemon_process_handle_(base::kNullProcessHandle) { | 79 ibus_daemon_process_handle_(base::kNullProcessHandle) { |
| 79 // Observe APP_TERMINATING to stop input method daemon gracefully. | 80 // Observe APP_TERMINATING to stop input method daemon gracefully. |
| 80 // We should not use APP_EXITING here since logout might be canceled by | 81 // We should not use APP_EXITING here since logout might be canceled by |
| 81 // JavaScript after APP_EXITING is sent (crosbug.com/11055). | 82 // JavaScript after APP_EXITING is sent (crosbug.com/11055). |
| 82 // Note that even if we fail to stop input method daemon from | 83 // Note that even if we fail to stop input method daemon from |
| 83 // Chrome in case of a sudden crash, we have a way to do it from an | 84 // Chrome in case of a sudden crash, we have a way to do it from an |
| 84 // upstart script. See crosbug.com/6515 and crosbug.com/6995 for | 85 // upstart script. See crosbug.com/6515 and crosbug.com/6995 for |
| 85 // details. | 86 // details. |
| 86 notification_registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 87 notification_registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 87 NotificationService::AllSources()); | 88 NotificationService::AllSources()); |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 // Launches input method daemon if these are not yet running. Returns true if | 826 // Launches input method daemon if these are not yet running. Returns true if |
| 826 // the daemon is started. Otherwise, e.g. the daemon is already started, | 827 // the daemon is started. Otherwise, e.g. the daemon is already started, |
| 827 // returns false. | 828 // returns false. |
| 828 bool MaybeLaunchInputMethodDaemon() { | 829 bool MaybeLaunchInputMethodDaemon() { |
| 829 // CandidateWindowController requires libcros to be loaded. Besides, | 830 // CandidateWindowController requires libcros to be loaded. Besides, |
| 830 // launching ibus-daemon without libcros loaded doesn't make sense. | 831 // launching ibus-daemon without libcros loaded doesn't make sense. |
| 831 if (!should_launch_ime_) { | 832 if (!should_launch_ime_) { |
| 832 return false; | 833 return false; |
| 833 } | 834 } |
| 834 | 835 |
| 836 if (shutting_down_) { | |
| 837 LOG(ERROR) << "Trying to launch input method while shutting down"; | |
|
Daniel Erat
2011/08/25 14:08:19
nit: change this to a NOTREACHED() so we'll crash
| |
| 838 return false; | |
| 839 } | |
| 840 | |
| 835 #if !defined(TOUCH_UI) | 841 #if !defined(TOUCH_UI) |
| 836 if (!candidate_window_controller_.get()) { | 842 if (!candidate_window_controller_.get()) { |
| 837 candidate_window_controller_.reset( | 843 candidate_window_controller_.reset( |
| 838 new input_method::CandidateWindowController); | 844 new input_method::CandidateWindowController); |
| 839 if (!candidate_window_controller_->Init()) { | 845 if (!candidate_window_controller_->Init()) { |
| 840 LOG(WARNING) << "Failed to initialize the candidate window controller"; | 846 LOG(WARNING) << "Failed to initialize the candidate window controller"; |
| 841 } | 847 } |
| 842 } | 848 } |
| 843 #endif | 849 #endif |
| 844 | 850 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 void SetEnableAutoImeShutdown(bool enable) { | 903 void SetEnableAutoImeShutdown(bool enable) { |
| 898 enable_auto_ime_shutdown_ = enable; | 904 enable_auto_ime_shutdown_ = enable; |
| 899 } | 905 } |
| 900 | 906 |
| 901 // NotificationObserver implementation: | 907 // NotificationObserver implementation: |
| 902 void Observe(int type, | 908 void Observe(int type, |
| 903 const NotificationSource& source, | 909 const NotificationSource& source, |
| 904 const NotificationDetails& details) { | 910 const NotificationDetails& details) { |
| 905 // Stop the input method daemon on browser shutdown. | 911 // Stop the input method daemon on browser shutdown. |
| 906 if (type == content::NOTIFICATION_APP_TERMINATING) { | 912 if (type == content::NOTIFICATION_APP_TERMINATING) { |
| 913 shutting_down_ = true; | |
| 907 notification_registrar_.RemoveAll(); | 914 notification_registrar_.RemoveAll(); |
| 908 StopInputMethodDaemon(); | 915 StopInputMethodDaemon(); |
| 909 #if !defined(TOUCH_UI) | 916 #if !defined(TOUCH_UI) |
| 910 candidate_window_controller_.reset(NULL); | 917 candidate_window_controller_.reset(NULL); |
| 911 #endif | 918 #endif |
| 912 } | 919 } |
| 913 } | 920 } |
| 914 | 921 |
| 915 // A reference to the language api, to allow callbacks when the input method | 922 // A reference to the language api, to allow callbacks when the input method |
| 916 // status changes. | 923 // status changes. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 // TODO(yusukes): clear this variable when a user logs in. | 966 // TODO(yusukes): clear this variable when a user logs in. |
| 960 std::string tentative_current_input_method_id_; | 967 std::string tentative_current_input_method_id_; |
| 961 | 968 |
| 962 // The candidate window. This will be deleted when the APP_TERMINATING | 969 // The candidate window. This will be deleted when the APP_TERMINATING |
| 963 // message is sent. | 970 // message is sent. |
| 964 #if !defined(TOUCH_UI) | 971 #if !defined(TOUCH_UI) |
| 965 scoped_ptr<input_method::CandidateWindowController> | 972 scoped_ptr<input_method::CandidateWindowController> |
| 966 candidate_window_controller_; | 973 candidate_window_controller_; |
| 967 #endif | 974 #endif |
| 968 | 975 |
| 976 // True if we've received the APP_TERMINATING notification. | |
| 977 bool shutting_down_; | |
| 978 | |
| 969 // The process handle of the IBus daemon. kNullProcessHandle if it's not | 979 // The process handle of the IBus daemon. kNullProcessHandle if it's not |
| 970 // running. | 980 // running. |
| 971 base::ProcessHandle ibus_daemon_process_handle_; | 981 base::ProcessHandle ibus_daemon_process_handle_; |
| 972 | 982 |
| 973 // An object which keeps a list of available virtual keyboards. | 983 // An object which keeps a list of available virtual keyboards. |
| 974 input_method::VirtualKeyboardSelector virtual_keyboard_selector_; | 984 input_method::VirtualKeyboardSelector virtual_keyboard_selector_; |
| 975 | 985 |
| 976 // The active input method ids cache. | 986 // The active input method ids cache. |
| 977 std::vector<std::string> active_input_method_ids_; | 987 std::vector<std::string> active_input_method_ids_; |
| 978 | 988 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 989 return InputMethodManagerImpl::GetInstance(); | 999 return InputMethodManagerImpl::GetInstance(); |
| 990 } | 1000 } |
| 991 | 1001 |
| 992 } // namespace input_method | 1002 } // namespace input_method |
| 993 } // namespace chromeos | 1003 } // namespace chromeos |
| 994 | 1004 |
| 995 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 1005 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 996 // won't be deleted until it's last InvokeLater is run. | 1006 // won't be deleted until it's last InvokeLater is run. |
| 997 DISABLE_RUNNABLE_METHOD_REFCOUNT( | 1007 DISABLE_RUNNABLE_METHOD_REFCOUNT( |
| 998 chromeos::input_method::InputMethodManagerImpl); | 1008 chromeos::input_method::InputMethodManagerImpl); |
| OLD | NEW |