Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cros/input_method_library.h" | 5 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 6 | 6 |
| 7 #include <glib.h> | 7 #include <glib.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 | 9 |
| 10 #include "unicode/uloc.h" | 10 #include "unicode/uloc.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 : input_method_status_connection_(NULL), | 56 : input_method_status_connection_(NULL), |
| 57 previous_input_method_("", "", "", ""), | 57 previous_input_method_("", "", "", ""), |
| 58 current_input_method_("", "", "", ""), | 58 current_input_method_("", "", "", ""), |
| 59 should_launch_ime_(false), | 59 should_launch_ime_(false), |
| 60 ime_connected_(false), | 60 ime_connected_(false), |
| 61 defer_ime_startup_(false), | 61 defer_ime_startup_(false), |
| 62 enable_auto_ime_shutdown_(true), | 62 enable_auto_ime_shutdown_(true), |
| 63 should_change_input_method_(false), | 63 should_change_input_method_(false), |
| 64 ibus_daemon_process_id_(0), | 64 ibus_daemon_process_id_(0), |
| 65 candidate_window_process_id_(0) { | 65 candidate_window_process_id_(0) { |
| 66 // TODO(yusukes): Using both CreateFallbackInputMethodDescriptors and | |
| 67 // chromeos::GetHardwareKeyboardLayoutName doesn't look clean. Probably | |
| 68 // we should unify these APIs. | |
| 66 scoped_ptr<InputMethodDescriptors> input_method_descriptors( | 69 scoped_ptr<InputMethodDescriptors> input_method_descriptors( |
| 67 CreateFallbackInputMethodDescriptors()); | 70 CreateFallbackInputMethodDescriptors()); |
| 68 current_input_method_ = input_method_descriptors->at(0); | 71 current_input_method_ = input_method_descriptors->at(0); |
| 69 if (CrosLibrary::Get()->EnsureLoaded()) { | 72 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 70 current_input_method_id_ = chromeos::GetHardwareKeyboardLayoutName(); | 73 current_input_method_id_ = chromeos::GetHardwareKeyboardLayoutName(); |
| 71 } | 74 } |
| 72 // Observe APP_EXITING to stop input method processes gracefully. | 75 // Observe APP_EXITING to stop input method processes gracefully. |
| 73 // Note that even if we fail to stop input method processes from | 76 // Note that even if we fail to stop input method processes from |
| 74 // Chrome in case of a sudden crash, we have a way to do it from an | 77 // Chrome in case of a sudden crash, we have a way to do it from an |
| 75 // upstart script. See crosbug.com/6515 and crosbug.com/6995 for | 78 // upstart script. See crosbug.com/6515 and crosbug.com/6995 for |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 bool success = false; | 156 bool success = false; |
| 154 if (EnsureLoadedAndStarted()) { | 157 if (EnsureLoadedAndStarted()) { |
| 155 success = chromeos::GetImeConfig(input_method_status_connection_, | 158 success = chromeos::GetImeConfig(input_method_status_connection_, |
| 156 section, config_name, out_value); | 159 section, config_name, out_value); |
| 157 } | 160 } |
| 158 return success; | 161 return success; |
| 159 } | 162 } |
| 160 | 163 |
| 161 bool SetImeConfig(const char* section, const char* config_name, | 164 bool SetImeConfig(const char* section, const char* config_name, |
| 162 const ImeConfigValue& value) { | 165 const ImeConfigValue& value) { |
| 163 MaybeStartOrStopInputMethodProcesses(section, config_name, value); | 166 // Start input method process if necessary. We don't stop the process here |
| 167 // since it can lead the successive FlushImeConfig() call to fail. | |
| 168 MaybeStartOrStopInputMethodProcesses( | |
| 169 section, config_name, value, false /* auto_ime_shutdown */); | |
|
satorux1
2011/01/05 06:52:31
This is a bit hard to read. I think it would be ea
Yusuke Sato
2011/01/05 10:05:55
Done.
| |
| 164 | 170 |
| 165 const ConfigKeyType key = std::make_pair(section, config_name); | 171 const ConfigKeyType key = std::make_pair(section, config_name); |
| 166 current_config_values_[key] = value; | 172 current_config_values_[key] = value; |
| 167 if (ime_connected_) { | 173 if (ime_connected_) { |
| 168 pending_config_requests_[key] = value; | 174 pending_config_requests_[key] = value; |
| 169 FlushImeConfig(); | 175 FlushImeConfig(); |
| 170 } | 176 } |
| 177 | |
| 178 // Stop input method process if necessary. | |
| 179 MaybeStartOrStopInputMethodProcesses( | |
| 180 section, config_name, value, enable_auto_ime_shutdown_); | |
| 171 return pending_config_requests_.empty(); | 181 return pending_config_requests_.empty(); |
| 172 } | 182 } |
| 173 | 183 |
| 174 virtual const InputMethodDescriptor& previous_input_method() const { | 184 virtual const InputMethodDescriptor& previous_input_method() const { |
| 175 return previous_input_method_; | 185 return previous_input_method_; |
| 176 } | 186 } |
| 177 virtual const InputMethodDescriptor& current_input_method() const { | 187 virtual const InputMethodDescriptor& current_input_method() const { |
| 178 return current_input_method_; | 188 return current_input_method_; |
| 179 } | 189 } |
| 180 | 190 |
| 181 virtual const ImePropertyList& current_ime_properties() const { | 191 virtual const ImePropertyList& current_ime_properties() const { |
| 182 return current_ime_properties_; | 192 return current_ime_properties_; |
| 183 } | 193 } |
| 184 | 194 |
| 185 private: | 195 private: |
| 186 // Starts or stops the input method processes based on the current state. | 196 // Starts or stops the input method processes based on the current state. |
|
satorux1
2011/01/05 06:52:31
Please add comments about parameters using this op
Yusuke Sato
2011/01/05 10:05:55
Done.
| |
| 187 void MaybeStartOrStopInputMethodProcesses( | 197 void MaybeStartOrStopInputMethodProcesses( |
| 188 const char* section, | 198 const char* section, |
| 189 const char* config_name, | 199 const char* config_name, |
| 190 const ImeConfigValue& value) { | 200 const ImeConfigValue& value, |
| 201 bool auto_ime_shutdown) { | |
| 191 if (!strcmp(language_prefs::kGeneralSectionName, section) && | 202 if (!strcmp(language_prefs::kGeneralSectionName, section) && |
|
satorux1
2011/01/05 06:52:31
You might want to change the parameters to const s
Yusuke Sato
2011/01/05 10:05:55
Done.
| |
| 192 !strcmp(language_prefs::kPreloadEnginesConfigName, config_name)) { | 203 !strcmp(language_prefs::kPreloadEnginesConfigName, config_name)) { |
| 193 if (EnsureLoadedAndStarted()) { | 204 if (EnsureLoadedAndStarted()) { |
| 194 // If there are no input methods other than one for the hardware | 205 // If there are no input methods other than one for the hardware |
| 195 // keyboard, we'll stop the input method processes. | 206 // keyboard, we'll stop the input method processes. |
| 196 if (value.type == ImeConfigValue::kValueTypeStringList && | 207 if (value.type == ImeConfigValue::kValueTypeStringList && |
| 197 value.string_list_value.size() == 1 && | 208 value.string_list_value.size() == 1 && |
| 198 value.string_list_value[0] == | 209 value.string_list_value[0] == |
| 199 chromeos::GetHardwareKeyboardLayoutName()) { | 210 chromeos::GetHardwareKeyboardLayoutName()) { |
| 200 if (enable_auto_ime_shutdown_) | 211 if (auto_ime_shutdown) |
| 201 StopInputMethodProcesses(); | 212 StopInputMethodProcesses(); |
| 202 } else if (!defer_ime_startup_) { | 213 } else if (!defer_ime_startup_) { |
| 203 StartInputMethodProcesses(); | 214 StartInputMethodProcesses(); |
| 204 } | 215 } |
| 205 chromeos::SetActiveInputMethods(input_method_status_connection_, value); | 216 chromeos::SetActiveInputMethods(input_method_status_connection_, value); |
| 206 } | 217 } |
| 207 } | 218 } |
| 208 } | 219 } |
| 209 | 220 |
| 210 // Changes the current input method to |input_method_id|. If the id is not in | 221 // Changes the current input method to |input_method_id|. If the id is not in |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 current_input_method_, | 308 current_input_method_, |
| 298 num_active_input_methods)); | 309 num_active_input_methods)); |
| 299 } | 310 } |
| 300 } | 311 } |
| 301 | 312 |
| 302 static void InputMethodChangedHandler( | 313 static void InputMethodChangedHandler( |
| 303 void* object, | 314 void* object, |
| 304 const chromeos::InputMethodDescriptor& current_input_method) { | 315 const chromeos::InputMethodDescriptor& current_input_method) { |
| 305 // The handler is called when the input method method change is | 316 // The handler is called when the input method method change is |
| 306 // notified via a DBus connection. Since the DBus notificatiosn are | 317 // notified via a DBus connection. Since the DBus notificatiosn are |
| 307 // handled in the UI thread, we can assume that this functionalways | 318 // handled in the UI thread, we can assume that this function always |
| 308 // runs on the UI thread, but just in case. | 319 // runs on the UI thread, but just in case. |
| 309 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 320 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 310 LOG(ERROR) << "Not on UI thread"; | 321 LOG(ERROR) << "Not on UI thread"; |
| 311 return; | 322 return; |
| 312 } | 323 } |
| 313 | 324 |
| 314 InputMethodLibraryImpl* input_method_library = | 325 InputMethodLibraryImpl* input_method_library = |
| 315 static_cast<InputMethodLibraryImpl*>(object); | 326 static_cast<InputMethodLibraryImpl*>(object); |
| 316 input_method_library->ChangeCurrentInputMethod(current_input_method); | 327 input_method_library->ChangeCurrentInputMethod(current_input_method); |
| 317 } | 328 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 // This is used to register this object to APP_EXITING notification. | 590 // This is used to register this object to APP_EXITING notification. |
| 580 NotificationRegistrar notification_registrar_; | 591 NotificationRegistrar notification_registrar_; |
| 581 | 592 |
| 582 // True if we should launch the input method processes. | 593 // True if we should launch the input method processes. |
| 583 bool should_launch_ime_; | 594 bool should_launch_ime_; |
| 584 // True if the connection to the IBus daemon is alive. | 595 // True if the connection to the IBus daemon is alive. |
| 585 bool ime_connected_; | 596 bool ime_connected_; |
| 586 // If true, we'll defer the startup until a non-default method is | 597 // If true, we'll defer the startup until a non-default method is |
| 587 // activated. | 598 // activated. |
| 588 bool defer_ime_startup_; | 599 bool defer_ime_startup_; |
| 589 bool enable_auto_ime_shutdown_; | 600 bool enable_auto_ime_shutdown_; |
|
satorux1
2011/01/05 06:52:31
Could you write a comment about this?
Yusuke Sato
2011/01/05 10:05:55
Done.
| |
| 590 // The ID of the current input method (ex. "mozc"). | 601 // The ID of the current input method (ex. "mozc"). |
| 591 std::string current_input_method_id_; | 602 std::string current_input_method_id_; |
| 592 // True if we should change the input method once the queue of the | 603 // True if we should change the input method once the queue of the |
| 593 // pending config requests becomes empty. | 604 // pending config requests becomes empty. |
| 594 bool should_change_input_method_; | 605 bool should_change_input_method_; |
| 595 | 606 |
| 596 // The process id of the IBus daemon. 0 if it's not running. The process | 607 // The process id of the IBus daemon. 0 if it's not running. The process |
| 597 // ID 0 is not used in Linux, hence it's safe to use 0 for this purpose. | 608 // ID 0 is not used in Linux, hence it's safe to use 0 for this purpose. |
| 598 int ibus_daemon_process_id_; | 609 int ibus_daemon_process_id_; |
| 599 // The process id of the candidate window. 0 if it's not running. | 610 // The process id of the candidate window. 0 if it's not running. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 return new InputMethodLibraryStubImpl(); | 819 return new InputMethodLibraryStubImpl(); |
| 809 else | 820 else |
| 810 return new InputMethodLibraryImpl(); | 821 return new InputMethodLibraryImpl(); |
| 811 } | 822 } |
| 812 | 823 |
| 813 } // namespace chromeos | 824 } // namespace chromeos |
| 814 | 825 |
| 815 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 826 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 816 // won't be deleted until it's last InvokeLater is run. | 827 // won't be deleted until it's last InvokeLater is run. |
| 817 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); | 828 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); |
| OLD | NEW |