ime_service.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_SERVICES_IME_IME_SERVICE_H_
  5. #define ASH_SERVICES_IME_IME_SERVICE_H_
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "ash/services/ime/connection_factory.h"
  11. #include "ash/services/ime/decoder/decoder_engine.h"
  12. #include "ash/services/ime/decoder/system_engine.h"
  13. #include "ash/services/ime/public/cpp/shared_lib/interfaces.h"
  14. #include "ash/services/ime/public/mojom/ime_service.mojom.h"
  15. #include "ash/services/ime/rule_based_engine.h"
  16. #include "base/feature_list.h"
  17. #include "base/files/file_path.h"
  18. #include "base/metrics/field_trial_params.h"
  19. #include "mojo/public/cpp/bindings/pending_receiver.h"
  20. #include "mojo/public/cpp/bindings/pending_remote.h"
  21. #include "mojo/public/cpp/bindings/receiver.h"
  22. #include "mojo/public/cpp/bindings/receiver_set.h"
  23. namespace ash {
  24. namespace ime {
  25. class FieldTrialParamsRetriever {
  26. public:
  27. virtual ~FieldTrialParamsRetriever() = default;
  28. virtual std::string GetFieldTrialParamValueByFeature(
  29. const base::Feature& feature,
  30. const std::string& param_name) = 0;
  31. };
  32. class FieldTrialParamsRetrieverImpl : public FieldTrialParamsRetriever {
  33. public:
  34. explicit FieldTrialParamsRetrieverImpl() = default;
  35. ~FieldTrialParamsRetrieverImpl() override = default;
  36. FieldTrialParamsRetrieverImpl(const FieldTrialParamsRetrieverImpl&) = delete;
  37. FieldTrialParamsRetrieverImpl& operator=(
  38. const FieldTrialParamsRetrieverImpl&) = delete;
  39. std::string GetFieldTrialParamValueByFeature(
  40. const base::Feature& feature,
  41. const std::string& param_name) override;
  42. };
  43. class ImeService : public mojom::ImeService,
  44. public mojom::InputEngineManager,
  45. public ImeCrosPlatform {
  46. public:
  47. explicit ImeService(
  48. mojo::PendingReceiver<mojom::ImeService> receiver,
  49. ImeDecoder* ime_decoder,
  50. std::unique_ptr<FieldTrialParamsRetriever> field_trial_params_retriever);
  51. ImeService(const ImeService&) = delete;
  52. ImeService& operator=(const ImeService&) = delete;
  53. ~ImeService() override;
  54. // ImeCrosPlatform overrides:
  55. const char* GetFieldTrialParamValueByFeature(const char* feature_name,
  56. const char* param_name) override;
  57. private:
  58. // mojom::ImeService overrides:
  59. void SetPlatformAccessProvider(
  60. mojo::PendingRemote<mojom::PlatformAccessProvider> provider) override;
  61. void BindInputEngineManager(
  62. mojo::PendingReceiver<mojom::InputEngineManager> receiver) override;
  63. // mojom::InputEngineManager overrides:
  64. void ConnectToImeEngine(
  65. const std::string& ime_spec,
  66. mojo::PendingReceiver<mojom::InputChannel> to_engine_request,
  67. mojo::PendingRemote<mojom::InputChannel> from_engine,
  68. const std::vector<uint8_t>& extra,
  69. ConnectToImeEngineCallback callback) override;
  70. void ConnectToInputMethod(
  71. const std::string& ime_spec,
  72. mojo::PendingReceiver<mojom::InputMethod> input_method,
  73. mojo::PendingRemote<mojom::InputMethodHost> input_method_host,
  74. ConnectToInputMethodCallback callback) override;
  75. void InitializeConnectionFactory(
  76. mojo::PendingReceiver<mojom::ConnectionFactory> connection_factory,
  77. mojom::ConnectionTarget connection_target,
  78. InitializeConnectionFactoryCallback callback) override;
  79. // ImeCrosPlatform overrides:
  80. const char* GetImeBundleDir() override;
  81. const char* GetImeUserHomeDir() override;
  82. void Unused3() override;
  83. void Unused2() override;
  84. int SimpleDownloadToFileV2(const char* url,
  85. const char* file_path,
  86. SimpleDownloadCallbackV2 callback) override;
  87. void Unused1() override;
  88. void RunInMainSequence(ImeSequencedTask task, int task_id) override;
  89. bool IsFeatureEnabled(const char* feature_name) override;
  90. // Callback used when a file download finishes by the |SimpleURLLoader|.
  91. // The |url| is the original download url and bound when downloading request
  92. // starts. On failure, |file| will be empty.
  93. void SimpleDownloadFinishedV2(SimpleDownloadCallbackV2 callback,
  94. const std::string& url_str,
  95. const base::FilePath& file);
  96. const MojoSystemThunks* GetMojoSystemThunks() override;
  97. // To be called before attempting to initialise a new backend connection, to
  98. // ensure there is one and only one such connection at any point in time.
  99. void ResetAllBackendConnections();
  100. mojo::Receiver<mojom::ImeService> receiver_;
  101. scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
  102. // For the duration of this ImeService's lifetime, there should be one and
  103. // only one of these backend connections (represented as "engine" or "factory"
  104. // instances) at any point in time.
  105. // TODO(b/214153032): Rename to better reflect what these represent:
  106. // decoder_engine_ --> proto_mode_shared_lib_engine_
  107. // system_engine_ --> mojo_mode_shared_lib_engine_
  108. // connection_factory_ --> rule_based_engine_mojo_connection_factory_
  109. std::unique_ptr<DecoderEngine> decoder_engine_;
  110. std::unique_ptr<SystemEngine> system_engine_;
  111. std::unique_ptr<ConnectionFactory> connection_factory_;
  112. // Platform delegate for access to privilege resources.
  113. mojo::Remote<mojom::PlatformAccessProvider> platform_access_;
  114. mojo::ReceiverSet<mojom::InputEngineManager> manager_receivers_;
  115. // TODO(b/214153032): Rename to better reflect what this represents:
  116. // ime_decoder_ --> ime_shared_lib_
  117. ImeDecoder* ime_decoder_ = nullptr;
  118. std::unique_ptr<FieldTrialParamsRetriever> field_trial_params_retriever_;
  119. };
  120. } // namespace ime
  121. } // namespace ash
  122. #endif // ASH_SERVICES_IME_IME_SERVICE_H_