Commit 0c6b25ab authored by Bao-Duy Tran's avatar Bao-Duy Tran Committed by Commit Bot

InputMethodAllowList: Remove unused code then de-OO-ify stateless class.

Besides being general cleanup, this also reduces usage of kInputMethods,
global const autogen'd from deprecated input_methods.txt config file.

Bug: 1134526,1134465
Change-Id: If6b9cf19944bb622bb58d56580b229c0bed530d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444673Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarMy Nguyen <myy@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Bao-Duy Tran <tranbaoduy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814445}
parent bb2e7e34
...@@ -63,8 +63,7 @@ class TestListener : public content::NotificationObserver { ...@@ -63,8 +63,7 @@ class TestListener : public content::NotificationObserver {
// background. // background.
InputMethodManager* manager = InputMethodManager::Get(); InputMethodManager* manager = InputMethodManager::Get();
manager->GetInputMethodUtil()->InitXkbInputMethodsForTesting( manager->GetInputMethodUtil()->InitXkbInputMethodsForTesting(
*chromeos::input_method::InputMethodAllowlist() *chromeos::input_method::allowlist::GetSupportedInputMethods());
.GetSupportedInputMethods());
std::vector<std::string> keyboard_layouts; std::vector<std::string> keyboard_layouts;
keyboard_layouts.push_back( keyboard_layouts.push_back(
......
...@@ -128,7 +128,7 @@ class MyMockInputMethodManager : public MockInputMethodManagerImpl { ...@@ -128,7 +128,7 @@ class MyMockInputMethodManager : public MockInputMethodManagerImpl {
std::unique_ptr<InputMethodDescriptors> GetSupportedInputMethods() std::unique_ptr<InputMethodDescriptors> GetSupportedInputMethods()
const override { const override {
return allowlist_.GetSupportedInputMethods(); return allowlist::GetSupportedInputMethods();
} }
std::string last_input_method_id_; std::string last_input_method_id_;
...@@ -136,7 +136,6 @@ class MyMockInputMethodManager : public MockInputMethodManagerImpl { ...@@ -136,7 +136,6 @@ class MyMockInputMethodManager : public MockInputMethodManagerImpl {
private: private:
StringPrefMember* previous_; StringPrefMember* previous_;
StringPrefMember* current_; StringPrefMember* current_;
InputMethodAllowlist allowlist_;
}; };
} // anonymous namespace } // anonymous namespace
......
...@@ -17,24 +17,11 @@ ...@@ -17,24 +17,11 @@
namespace chromeos { namespace chromeos {
namespace input_method { namespace input_method {
namespace allowlist {
const char kLanguageDelimiter[] = ","; const char kLanguageDelimiter[] = ",";
InputMethodAllowlist::InputMethodAllowlist() { std::unique_ptr<InputMethodDescriptors> GetSupportedInputMethods() {
for (const auto& input_method : kInputMethods) {
supported_input_methods_.insert(input_method.input_method_id);
}
}
InputMethodAllowlist::~InputMethodAllowlist() = default;
bool InputMethodAllowlist::InputMethodIdIsAllowlisted(
const std::string& input_method_id) const {
return supported_input_methods_.count(input_method_id) > 0;
}
std::unique_ptr<InputMethodDescriptors>
InputMethodAllowlist::GetSupportedInputMethods() const {
std::unique_ptr<InputMethodDescriptors> input_methods( std::unique_ptr<InputMethodDescriptors> input_methods(
new InputMethodDescriptors); new InputMethodDescriptors);
input_methods->reserve(base::size(kInputMethods)); input_methods->reserve(base::size(kInputMethods));
...@@ -59,5 +46,6 @@ InputMethodAllowlist::GetSupportedInputMethods() const { ...@@ -59,5 +46,6 @@ InputMethodAllowlist::GetSupportedInputMethods() const {
return input_methods; return input_methods;
} }
} // namespace allowlist
} // namespace input_method } // namespace input_method
} // namespace chromeos } // namespace chromeos
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#ifndef UI_BASE_IME_CHROMEOS_INPUT_METHOD_ALLOWLIST_H_ #ifndef UI_BASE_IME_CHROMEOS_INPUT_METHOD_ALLOWLIST_H_
#define UI_BASE_IME_CHROMEOS_INPUT_METHOD_ALLOWLIST_H_ #define UI_BASE_IME_CHROMEOS_INPUT_METHOD_ALLOWLIST_H_
#include <memory>
#include <set>
#include <string>
#include <vector> #include <vector>
#include "base/component_export.h" #include "base/component_export.h"
...@@ -19,27 +16,16 @@ namespace input_method { ...@@ -19,27 +16,16 @@ namespace input_method {
class InputMethodDescriptor; class InputMethodDescriptor;
typedef std::vector<InputMethodDescriptor> InputMethodDescriptors; typedef std::vector<InputMethodDescriptor> InputMethodDescriptors;
// A class which has allow listed input method list. The list is generated by namespace allowlist {
// gen_input_methods.py from input_methods.txt.
class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodAllowlist {
public:
InputMethodAllowlist();
~InputMethodAllowlist();
// Returns true if |input_method_id| is allowlisted. // Returns all input methods that are supported, including ones not active.
bool InputMethodIdIsAllowlisted(const std::string& input_method_id) const; // Based on the list generated by gen_input_methods.py from input_methods.txt.
// This function never returns nullptr. Note that input method extensions are
// Returns all input methods that are supported, including ones not active. // not included in the result.
// This function never returns NULL. Note that input method extensions are not std::unique_ptr<InputMethodDescriptors> COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS)
// included in the result. GetSupportedInputMethods();
std::unique_ptr<InputMethodDescriptors> GetSupportedInputMethods() const;
private:
std::set<std::string> supported_input_methods_;
DISALLOW_COPY_AND_ASSIGN(InputMethodAllowlist);
};
} // namespace allowlist
} // namespace input_method } // namespace input_method
} // namespace chromeos } // namespace chromeos
......
...@@ -48,7 +48,7 @@ class TestableInputMethodUtil : public InputMethodUtil { ...@@ -48,7 +48,7 @@ class TestableInputMethodUtil : public InputMethodUtil {
class InputMethodUtilTest : public testing::Test { class InputMethodUtilTest : public testing::Test {
public: public:
InputMethodUtilTest() InputMethodUtilTest()
: util_(&delegate_, allowlist_.GetSupportedInputMethods()) { : util_(&delegate_, allowlist::GetSupportedInputMethods()) {
delegate_.set_get_localized_string_callback( delegate_.set_get_localized_string_callback(
base::BindRepeating(&l10n_util::GetStringUTF16)); base::BindRepeating(&l10n_util::GetStringUTF16));
delegate_.set_get_display_language_name_callback( delegate_.set_get_display_language_name_callback(
...@@ -85,7 +85,7 @@ class InputMethodUtilTest : public testing::Test { ...@@ -85,7 +85,7 @@ class InputMethodUtilTest : public testing::Test {
GURL("")); GURL(""));
input_methods.push_back(zhuyin_ime); input_methods.push_back(zhuyin_ime);
util_.InitXkbInputMethodsForTesting(*allowlist_.GetSupportedInputMethods()); util_.InitXkbInputMethodsForTesting(*allowlist::GetSupportedInputMethods());
util_.AppendInputMethods(input_methods); util_.AppendInputMethods(input_methods);
} }
...@@ -117,7 +117,6 @@ class InputMethodUtilTest : public testing::Test { ...@@ -117,7 +117,6 @@ class InputMethodUtilTest : public testing::Test {
} }
FakeInputMethodDelegate delegate_; FakeInputMethodDelegate delegate_;
InputMethodAllowlist allowlist_;
TestableInputMethodUtil util_; TestableInputMethodUtil util_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment