Skip to content

Commit

Permalink
Introduce migration code.
Browse files Browse the repository at this point in the history
We are now switching new input method engines which based on extension IME API.
This is migration code for the users who already uses Japanese input method to
be able to use new Japanese input method without any user action.

BUG=236747
TEST=Manually confirmed that old input method is unchecked and new input method
is checked in chrome://options/languages

Review URL: https://chromiumcodereview.appspot.com/14621007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197842 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nona@chromium.org committed May 2, 2013
1 parent 4c81f70 commit c418b6d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
25 changes: 25 additions & 0 deletions chrome/browser/chromeos/input_method/input_method_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ bool Contains(const std::vector<std::string>& container,
container.end();
}

const struct MigrationInputMethodList {
const char* old_input_method;
const char* new_input_method;
} kMigrationInputMethodList[] = {
{ "mozc", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us" },
{ "mozc-jp", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp" },
{ "mozc-dv", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us" },
};

} // namespace

InputMethodManagerImpl::InputMethodManagerImpl(
Expand Down Expand Up @@ -227,6 +236,22 @@ bool InputMethodManagerImpl::EnableInputMethods(
return true;
}

bool InputMethodManagerImpl::MigrateOldInputMethods(
std::vector<std::string>* input_method_ids) {
bool rewritten = false;
for (size_t i = 0; i < input_method_ids->size(); ++i) {
for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kMigrationInputMethodList); ++j) {
if (input_method_ids->at(i) ==
kMigrationInputMethodList[j].old_input_method) {
input_method_ids->at(i).assign(
kMigrationInputMethodList[j].new_input_method);
rewritten = true;
}
}
}
return rewritten;
}

bool InputMethodManagerImpl::SetInputMethodConfig(
const std::string& section,
const std::string& config_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class InputMethodManagerImpl : public InputMethodManager,
const std::string& initial_layout) OVERRIDE;
virtual bool EnableInputMethods(
const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
virtual bool MigrateOldInputMethods(
std::vector<std::string>* input_method_ids) OVERRIDE;
virtual bool SetInputMethodConfig(
const std::string& section,
const std::string& config_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,5 +1202,31 @@ TEST_F(InputMethodManagerImplTest,
EXPECT_EQ(ext_id2, controller_->change_input_method_id_);
}

TEST_F(InputMethodManagerImplTest,
MigrateOldInputMethodTest) {
std::vector<std::string> input_method_ids;
input_method_ids.push_back("mozc");
input_method_ids.push_back("mozc-jp");
input_method_ids.push_back("xkb:us::eng");
input_method_ids.push_back("mozc-hangul");

manager_->MigrateOldInputMethods(&input_method_ids);

ASSERT_EQ(4U, input_method_ids.size());
EXPECT_EQ(input_method_ids.end(),
std::find(input_method_ids.begin(), input_method_ids.end(),
"mozc"));
EXPECT_EQ(input_method_ids.end(),
std::find(input_method_ids.begin(), input_method_ids.end(),
"mozc-jp"));
EXPECT_NE(input_method_ids.end(),
std::find(input_method_ids.begin(), input_method_ids.end(),
"xkb:us::eng"));
EXPECT_NE(input_method_ids.end(),
std::find(input_method_ids.begin(), input_method_ids.end(),
"mozc-hangul"));

}

} // namespace input_method
} // namespace chromeos
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ bool MockInputMethodManager::EnableInputMethods(
return true;
}

bool MockInputMethodManager::MigrateOldInputMethods(
std::vector<std::string>* input_method_ids) {
return false;
}

bool MockInputMethodManager::SetInputMethodConfig(
const std::string& section,
const std::string& config_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class MockInputMethodManager : public InputMethodManager {
const std::string& initial_layout) OVERRIDE;
virtual bool EnableInputMethods(
const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
virtual bool MigrateOldInputMethods(
std::vector<std::string>* input_method_ids) OVERRIDE;
virtual bool SetInputMethodConfig(
const std::string& section,
const std::string& config_name,
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/chromeos/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ void Preferences::SetLanguageConfigStringListAsCSV(const char* section,

if (section == std::string(language_prefs::kGeneralSectionName) &&
name == std::string(language_prefs::kPreloadEnginesConfigName)) {
// TODO(nona): Remove this function after few milestones are passed.
// (http://crbug.com/236747)
if (input_method_manager_->MigrateOldInputMethods(&split_values))
preload_engines_.SetValue(JoinString(split_values, ','));
input_method_manager_->EnableInputMethods(split_values);
return;
}
Expand Down
7 changes: 7 additions & 0 deletions chromeos/ime/input_method_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class InputMethodManager {
virtual bool EnableInputMethods(
const std::vector<std::string>& new_active_input_method_ids) = 0;

// Remaps old input methods like "mozc" to new input methods. Return true if
// at least one IME is migrated.
// TODO(nona): Remove this function after few milestones are passed.
// (http://crbug.com/236747)
virtual bool MigrateOldInputMethods(
std::vector<std::string>* input_method_ids) = 0;

// Updates a configuration of a system input method engine with |value|.
// Returns true if the configuration is correctly set.
virtual bool SetInputMethodConfig(const std::string& section,
Expand Down

0 comments on commit c418b6d

Please sign in to comment.