summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/cros/language_library.cc40
-rw-r--r--chrome/browser/chromeos/cros/language_library.h25
2 files changed, 59 insertions, 6 deletions
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc
index 09f3cbe..76a293f 100644
--- a/chrome/browser/chromeos/cros/language_library.cc
+++ b/chrome/browser/chromeos/cros/language_library.cc
@@ -244,12 +244,44 @@ bool LanguageLibraryImpl::GetImeConfig(
bool LanguageLibraryImpl::SetImeConfig(
const char* section, const char* config_name, const ImeConfigValue& value) {
- bool success = false;
+ const ConfigKeyType key = std::make_pair(section, config_name);
+ pending_config_requests_.erase(key);
+ pending_config_requests_.insert(std::make_pair(key, value));
+ FlushImeConfig();
+ return pending_config_requests_.empty();
+}
+
+void LanguageLibraryImpl::FlushImeConfig() {
if (EnsureLoadedAndStarted()) {
- success = chromeos::SetImeConfig(
- input_method_status_connection_, section, config_name, value);
+ LOG(INFO) << "Sending " << pending_config_requests_.size()
+ << " set config command(s)";
+ InputMethodConfigRequests::iterator iter = pending_config_requests_.begin();
+ while (iter != pending_config_requests_.end()) {
+ const std::string& section = iter->first.first;
+ const std::string& config_name = iter->first.second;
+ const ImeConfigValue& value = iter->second;
+ if (chromeos::SetImeConfig(input_method_status_connection_,
+ section.c_str(), config_name.c_str(), value)) {
+ // Successfully sent. Remove the command and proceed to the next one.
+ pending_config_requests_.erase(iter++);
+ } else {
+ LOG(ERROR) << "chromeos::SetImeConfig failed. Will retry later: "
+ << section << "/" << config_name;
+ ++iter; // Do not remove the command.
+ }
+ }
+ if (pending_config_requests_.empty()) {
+ timer_.Stop(); // no-op if it's not running.
+ }
+ } else {
+ LOG(INFO) << "No connection to IBus. # of pending set config commands: "
+ << pending_config_requests_.size();
+ if (!timer_.IsRunning()) {
+ static const int64 kTimerIntervalInSec = 1;
+ timer_.Start(base::TimeDelta::FromSeconds(kTimerIntervalInSec), this,
+ &LanguageLibraryImpl::FlushImeConfig);
+ }
}
- return success;
}
// static
diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h
index 0e902fd..89660d5 100644
--- a/chrome/browser/chromeos/cros/language_library.h
+++ b/chrome/browser/chromeos/cros/language_library.h
@@ -5,10 +5,13 @@
#ifndef CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_
+#include <map>
#include <string>
+#include <utility>
#include "base/observer_list.h"
#include "base/time.h"
+#include "base/timer.h"
#include "third_party/cros/chromeos_language.h"
namespace chromeos {
@@ -65,7 +68,9 @@ class LanguageLibrary {
ImeConfigValue* out_value) = 0;
// Updates a configuration of ibus-daemon or IBus engines with |value|.
- // Returns true if the configuration is successfully updated.
+ // Returns true if the configuration (and all pending configurations, if any)
+ // are processed. If ibus-daemon is not running, this function just queues
+ // the request and returns false.
// You can specify |section| and |config_name| arguments in the same way
// as GetImeConfig() above.
virtual bool SetImeConfig(const char* section,
@@ -185,6 +190,10 @@ class LanguageLibraryImpl : public LanguageLibrary {
// Called by the handler to notify focus changes.
void FocusChanged(bool is_focused);
+ // Tries to send all pending SetImeConfig requests to the input method config
+ // daemon.
+ void FlushImeConfig();
+
// A reference to the language api, to allow callbacks when the input method
// status changes.
InputMethodStatusConnection* input_method_status_connection_;
@@ -200,10 +209,22 @@ class LanguageLibraryImpl : public LanguageLibrary {
// true if a text input area in Chrome is focused.
bool is_focused_;
+ typedef std::pair<std::string, std::string> ConfigKeyType;
+ typedef std::map<ConfigKeyType, ImeConfigValue> InputMethodConfigRequests;
+ // SetImeConfig requests that are not yet completed.
+ // Use a map to queue config requests, so we only send the last request for
+ // the same config key (i.e. we'll discard ealier requests for the same
+ // config key). As we discard old requests for the same config key, the order
+ // of requests doesn't matter, so it's safe to use a map.
+ InputMethodConfigRequests pending_config_requests_;
+
+ // A timer for retrying to send |pendning_config_commands_| to the input
+ // method config daemon.
+ base::OneShotTimer<LanguageLibraryImpl> timer_;
+
DISALLOW_COPY_AND_ASSIGN(LanguageLibraryImpl);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_
-