Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/browser/chromeos/cros/input_method_library.cc

Issue 4162002: Reduce CPU usage for input method switching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/browser_thread.h" 16 #include "chrome/browser/browser_thread.h"
17 #include "chrome/browser/chromeos/cros/cros_library.h" 17 #include "chrome/browser/chromeos/cros/cros_library.h"
18 #include "chrome/browser/chromeos/cros/keyboard_library.h" 18 #include "chrome/browser/chromeos/cros/keyboard_library.h"
19 #include "chrome/browser/chromeos/input_method/input_method_util.h" 19 #include "chrome/browser/chromeos/input_method/input_method_util.h"
20 #include "chrome/browser/chromeos/language_preferences.h" 20 #include "chrome/browser/chromeos/language_preferences.h"
21 #include "chrome/common/notification_observer.h" 21 #include "chrome/common/notification_observer.h"
22 #include "chrome/common/notification_registrar.h" 22 #include "chrome/common/notification_registrar.h"
23 #include "chrome/common/notification_service.h" 23 #include "chrome/common/notification_service.h"
24 24
25 #define NOTIFY_FIRST_OBSERVER(ObserverType, observer_list, func) \
satorux1 2010/12/01 06:40:18 The macro seems to be only used once. Probably not
Yusuke Sato 2010/12/01 07:36:41 Done.
26 do { \
27 ObserverListBase<ObserverType>::Iterator it(observer_list); \
28 ObserverType* first_observer; \
29 if ((first_observer = it.GetNext()) != NULL) { \
30 first_observer->func; \
31 } \
32 } while (0)
33
25 namespace { 34 namespace {
35
26 const char kIBusDaemonPath[] = "/usr/bin/ibus-daemon"; 36 const char kIBusDaemonPath[] = "/usr/bin/ibus-daemon";
27 const char kCandidateWindowPath[] = "/opt/google/chrome/candidate_window"; 37 const char kCandidateWindowPath[] = "/opt/google/chrome/candidate_window";
28 38
29 // Finds a property which has |new_prop.key| from |prop_list|, and replaces the 39 // Finds a property which has |new_prop.key| from |prop_list|, and replaces the
30 // property with |new_prop|. Returns true if such a property is found. 40 // property with |new_prop|. Returns true if such a property is found.
31 bool FindAndUpdateProperty(const chromeos::ImeProperty& new_prop, 41 bool FindAndUpdateProperty(const chromeos::ImeProperty& new_prop,
32 chromeos::ImePropertyList* prop_list) { 42 chromeos::ImePropertyList* prop_list) {
33 for (size_t i = 0; i < prop_list->size(); ++i) { 43 for (size_t i = 0; i < prop_list->size(); ++i) {
34 chromeos::ImeProperty& prop = prop_list->at(i); 44 chromeos::ImeProperty& prop = prop_list->at(i);
35 if (prop.key == new_prop.key) { 45 if (prop.key == new_prop.key) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (pending_config_requests_.empty()) { 293 if (pending_config_requests_.empty()) {
284 timer_.Stop(); // no-op if it's not running. 294 timer_.Stop(); // no-op if it's not running.
285 } else if (!timer_.IsRunning()) { 295 } else if (!timer_.IsRunning()) {
286 // Flush is not completed. Start a timer if it's not yet running. 296 // Flush is not completed. Start a timer if it's not yet running.
287 static const int64 kTimerIntervalInMsec = 100; 297 static const int64 kTimerIntervalInMsec = 100;
288 timer_.Start(base::TimeDelta::FromMilliseconds(kTimerIntervalInMsec), 298 timer_.Start(base::TimeDelta::FromMilliseconds(kTimerIntervalInMsec),
289 this, &InputMethodLibraryImpl::FlushImeConfig); 299 this, &InputMethodLibraryImpl::FlushImeConfig);
290 } 300 }
291 301
292 if (active_input_methods_are_changed) { 302 if (active_input_methods_are_changed) {
293 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputMethodsChanged(this)); 303 const size_t num_active_input_methods = GetNumActiveInputMethods();
304 FOR_EACH_OBSERVER(Observer, observers_,
305 ActiveInputMethodsChanged(this,
306 current_input_method_,
307 num_active_input_methods));
294 } 308 }
295 } 309 }
296 310
297 static void InputMethodChangedHandler( 311 static void InputMethodChangedHandler(
298 void* object, 312 void* object,
299 const chromeos::InputMethodDescriptor& current_input_method) { 313 const chromeos::InputMethodDescriptor& current_input_method) {
300 // The handler is called when the input method method change is 314 // The handler is called when the input method method change is
301 // notified via a DBus connection. Since the DBus notificatiosn are 315 // notified via a DBus connection. Since the DBus notificatiosn are
302 // handled in the UI thread, we can assume that this functionalways 316 // handled in the UI thread, we can assume that this functionalways
303 // runs on the UI thread, but just in case. 317 // runs on the UI thread, but just in case.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 393
380 void ChangeCurrentInputMethod(const InputMethodDescriptor& new_input_method) { 394 void ChangeCurrentInputMethod(const InputMethodDescriptor& new_input_method) {
381 // Change the keyboard layout to a preferred layout for the input method. 395 // Change the keyboard layout to a preferred layout for the input method.
382 CrosLibrary::Get()->GetKeyboardLibrary()->SetCurrentKeyboardLayoutByName( 396 CrosLibrary::Get()->GetKeyboardLibrary()->SetCurrentKeyboardLayoutByName(
383 new_input_method.keyboard_layout); 397 new_input_method.keyboard_layout);
384 398
385 if (current_input_method_.id != new_input_method.id) { 399 if (current_input_method_.id != new_input_method.id) {
386 previous_input_method_ = current_input_method_; 400 previous_input_method_ = current_input_method_;
387 current_input_method_ = new_input_method; 401 current_input_method_ = new_input_method;
388 } 402 }
389 FOR_EACH_OBSERVER(Observer, observers_, InputMethodChanged(this)); 403 const size_t num_active_input_methods = GetNumActiveInputMethods();
404 FOR_EACH_OBSERVER(Observer, observers_,
405 InputMethodChanged(this,
406 previous_input_method_,
407 current_input_method_,
408 num_active_input_methods));
409 NOTIFY_FIRST_OBSERVER(Observer, observers_,
satorux1 2010/12/01 06:40:18 Please add a comment about why you notify this to
Yusuke Sato 2010/12/01 07:36:41 Done.
410 PreferenceUpdateNeeded(this,
411 previous_input_method_,
412 current_input_method_));
390 } 413 }
391 414
392 void RegisterProperties(const ImePropertyList& prop_list) { 415 void RegisterProperties(const ImePropertyList& prop_list) {
393 // |prop_list| might be empty. This means "clear all properties." 416 // |prop_list| might be empty. This means "clear all properties."
394 current_ime_properties_ = prop_list; 417 current_ime_properties_ = prop_list;
395 FOR_EACH_OBSERVER(Observer, observers_, ImePropertiesChanged(this));
396 } 418 }
397 419
398 void StartInputMethodProcesses() { 420 void StartInputMethodProcesses() {
399 should_launch_ime_ = true; 421 should_launch_ime_ = true;
400 MaybeLaunchInputMethodProcesses(); 422 MaybeLaunchInputMethodProcesses();
401 } 423 }
402 424
403 void UpdateProperty(const ImePropertyList& prop_list) { 425 void UpdateProperty(const ImePropertyList& prop_list) {
404 for (size_t i = 0; i < prop_list.size(); ++i) { 426 for (size_t i = 0; i < prop_list.size(); ++i) {
405 FindAndUpdateProperty(prop_list[i], &current_ime_properties_); 427 FindAndUpdateProperty(prop_list[i], &current_ime_properties_);
406 } 428 }
407 FOR_EACH_OBSERVER(Observer, observers_, ImePropertiesChanged(this));
408 } 429 }
409 430
410 // Launches an input method procsess specified by the given command 431 // Launches an input method procsess specified by the given command
411 // line. On success, returns true and stores the process ID in 432 // line. On success, returns true and stores the process ID in
412 // |process_id|. Otherwise, returns false, and the contents of 433 // |process_id|. Otherwise, returns false, and the contents of
413 // |process_id| is untouched. OnImeShutdown will be called when the 434 // |process_id| is untouched. OnImeShutdown will be called when the
414 // process terminates. 435 // process terminates.
415 bool LaunchInputMethodProcess(const std::string& command_line, 436 bool LaunchInputMethodProcess(const std::string& command_line,
416 int* process_id) { 437 int* process_id) {
417 GError *error = NULL; 438 GError *error = NULL;
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 return new InputMethodLibraryStubImpl(); 809 return new InputMethodLibraryStubImpl();
789 else 810 else
790 return new InputMethodLibraryImpl(); 811 return new InputMethodLibraryImpl();
791 } 812 }
792 813
793 } // namespace chromeos 814 } // namespace chromeos
794 815
795 // Allows InvokeLater without adding refcounting. This class is a Singleton and 816 // Allows InvokeLater without adding refcounting. This class is a Singleton and
796 // won't be deleted until it's last InvokeLater is run. 817 // won't be deleted until it's last InvokeLater is run.
797 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); 818 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698