summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/options/language_config_model.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/options/language_config_model.cc')
-rw-r--r--chrome/browser/chromeos/options/language_config_model.cc41
1 files changed, 21 insertions, 20 deletions
diff --git a/chrome/browser/chromeos/options/language_config_model.cc b/chrome/browser/chromeos/options/language_config_model.cc
index 93818aec..fafa2f6 100644
--- a/chrome/browser/chromeos/options/language_config_model.cc
+++ b/chrome/browser/chromeos/options/language_config_model.cc
@@ -76,12 +76,14 @@ LanguageConfigModel::LanguageConfigModel(PrefService* pref_service)
// Initialize the maps and vectors.
InitInputMethodIdVectors();
- preload_engines_.Init(
+ preferred_languages_pref_.Init(
+ prefs::kLanguagePreferredLanguages, pref_service_, this);
+ preload_engines_pref_.Init(
prefs::kLanguagePreloadEngines, pref_service_, this);
// TODO(yusukes): It might be safer to call GetActiveLanguages() cros API
- // here and compare the result and preload_engines_.GetValue(). If there's
- // a discrepancy between IBus setting and Chrome prefs, we can resolve it
- // by calling preload_engines_SetValue() here.
+ // here and compare the result and preload_engines_pref_.GetValue().
+ // If there's a discrepancy between IBus setting and Chrome prefs, we
+ // can resolve it by calling preload_engines_pref_SetValue() here.
// Initialize the language codes currently activated.
NotifyPrefChanged();
@@ -122,11 +124,15 @@ size_t LanguageConfigModel::AddLanguageCode(
std::find(preferred_language_codes_.begin(),
preferred_language_codes_.end(),
language_code));
+ preferred_languages_pref_.SetValue(
+ JoinString(preferred_language_codes_, ','));
return added_at;
}
void LanguageConfigModel::RemoveLanguageAt(size_t row) {
preferred_language_codes_.erase(preferred_language_codes_.begin() + row);
+ preferred_languages_pref_.SetValue(
+ JoinString(preferred_language_codes_, ','));
}
void LanguageConfigModel::UpdateInputMethodPreferences(
@@ -136,7 +142,7 @@ void LanguageConfigModel::UpdateInputMethodPreferences(
// function below uses stable sort, the relateve order of input methods that
// belong to the same language (e.g. "mozc" and "xkb:jp::jpn") is maintained.
input_method::SortInputMethodIdsByNames(&new_input_method_ids);
- preload_engines_.SetValue(JoinString(new_input_method_ids, ','));
+ preload_engines_pref_.SetValue(JoinString(new_input_method_ids, ','));
}
void LanguageConfigModel::DeactivateInputMethodsFor(
@@ -186,12 +192,20 @@ bool LanguageConfigModel::InputMethodIsActivated(
void LanguageConfigModel::GetActiveInputMethodIds(
std::vector<std::string>* out_input_method_ids) {
- const std::string value = preload_engines_.GetValue();
+ const std::string value = preload_engines_pref_.GetValue();
out_input_method_ids->clear();
if (!value.empty())
SplitString(value, ',', out_input_method_ids);
}
+void LanguageConfigModel::GetPreferredLanguageCodes(
+ std::vector<std::string>* out_language_codes) {
+ const std::string value = preferred_languages_pref_.GetValue();
+ out_language_codes->clear();
+ if (!value.empty())
+ SplitString(value, ',', out_language_codes);
+}
+
void LanguageConfigModel::GetInputMethodIdsFromLanguageCode(
const std::string& language_code,
std::vector<std::string>* input_method_ids) const {
@@ -206,20 +220,7 @@ void LanguageConfigModel::GetInputMethodIdsFromLanguageCode(
}
void LanguageConfigModel::NotifyPrefChanged() {
- std::vector<std::string> input_method_ids;
- GetActiveInputMethodIds(&input_method_ids);
-
- std::set<std::string> language_code_set;
- for (size_t i = 0; i < input_method_ids.size(); ++i) {
- const std::string language_code =
- input_method::GetLanguageCodeFromInputMethodId(input_method_ids[i]);
- language_code_set.insert(language_code);
- }
-
- preferred_language_codes_.clear();
- preferred_language_codes_.assign(
- language_code_set.begin(), language_code_set.end());
- input_method::SortLanguageCodesByNames(&preferred_language_codes_);
+ GetPreferredLanguageCodes(&preferred_language_codes_);
}
void LanguageConfigModel::Observe(NotificationType type,