diff --git a/src/engine/BUILD.bazel b/src/engine/BUILD.bazel index 55525635a..845c88a8d 100644 --- a/src/engine/BUILD.bazel +++ b/src/engine/BUILD.bazel @@ -47,12 +47,10 @@ mozc_cc_library( "//base:thread", "//data_manager", "//protocol:engine_builder_cc_proto", - "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log", "@com_google_absl//absl/log:check", "@com_google_absl//absl/status", - "@com_google_absl//absl/synchronization", ], ) @@ -84,11 +82,8 @@ mozc_cc_library( name = "engine_interface", hdrs = ["engine_interface.h"], deps = [ - ":engine_builder", ":supplemental_model_interface", - ":user_data_manager_interface", "//converter:converter_interface", - "//data_manager:data_manager_interface", "//protocol:engine_builder_cc_proto", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", @@ -189,7 +184,6 @@ mozc_cc_library( ":minimal_engine", ":modules", ":supplemental_model_interface", - ":user_data_manager_interface", "//base:vlog", "//converter", "//converter:converter_interface", @@ -241,9 +235,7 @@ mozc_cc_library( deps = [ ":engine_interface", ":supplemental_model_interface", - ":user_data_manager_interface", "//converter:converter_interface", - "//data_manager:data_manager_interface", "//testing:gunit", "@com_google_absl//absl/status", "@com_google_absl//absl/strings:string_view", @@ -358,31 +350,6 @@ mozc_cc_library( ], ) -mozc_cc_library( - name = "user_data_manager_mock", - testonly = 1, - hdrs = ["user_data_manager_mock.h"], - visibility = [ - "//:__subpackages__", - ], - deps = [ - ":user_data_manager_interface", - "//testing:gunit", - ], -) - -mozc_cc_library( - name = "user_data_manager_interface", - hdrs = ["user_data_manager_interface.h"], - visibility = [ - # For //session:session_handler_scenario_test. - "//session:__pkg__", - ], - deps = [ - "@com_google_absl//absl/strings", - ], -) - mozc_cc_library( name = "minimal_engine", srcs = ["minimal_engine.cc"], @@ -393,7 +360,6 @@ mozc_cc_library( deps = [ ":engine_interface", ":modules", - ":user_data_manager_interface", "//base/strings:assign", "//composer", "//converter:converter_interface", diff --git a/src/engine/engine.cc b/src/engine/engine.cc index ab3c3f311..f3a7193ab 100644 --- a/src/engine/engine.cc +++ b/src/engine/engine.cc @@ -46,7 +46,6 @@ #include "engine/data_loader.h" #include "engine/modules.h" #include "engine/supplemental_model_interface.h" -#include "engine/user_data_manager_interface.h" #include "prediction/dictionary_predictor.h" #include "prediction/predictor.h" #include "prediction/predictor_interface.h" @@ -56,60 +55,6 @@ #include "rewriter/rewriter_interface.h" namespace mozc { -namespace { - -using ::mozc::prediction::PredictorInterface; - -class UserDataManager final : public UserDataManagerInterface { - public: - UserDataManager(PredictorInterface *predictor, RewriterInterface *rewriter) - : predictor_(predictor), rewriter_(rewriter) {} - - UserDataManager(const UserDataManager &) = delete; - UserDataManager &operator=(const UserDataManager &) = delete; - - bool Sync() override; - bool Reload() override; - bool ClearUserHistory() override; - bool ClearUserPrediction() override; - bool ClearUnusedUserPrediction() override; - bool Wait() override; - - private: - PredictorInterface *predictor_; - RewriterInterface *rewriter_; -}; - -bool UserDataManager::Sync() { - // TODO(noriyukit): In the current implementation, if rewriter_->Sync() fails, - // predictor_->Sync() is never called. Check if we should call - // predictor_->Sync() or not. - return rewriter_->Sync() && predictor_->Sync(); -} - -bool UserDataManager::Reload() { - // TODO(noriyukit): The same TODO as Sync(). - return rewriter_->Reload() && predictor_->Reload(); -} - -bool UserDataManager::ClearUserHistory() { - rewriter_->Clear(); - return true; -} - -bool UserDataManager::ClearUserPrediction() { - predictor_->ClearAllHistory(); - return true; -} - -bool UserDataManager::ClearUnusedUserPrediction() { - predictor_->ClearUnusedHistory(); - return true; -} - -bool UserDataManager::Wait() { return predictor_->Wait(); } - -} // namespace absl::StatusOr> Engine::CreateDesktopEngine( std::unique_ptr data_manager) { @@ -191,7 +136,7 @@ absl::Status Engine::Init(std::unique_ptr modules, converter_ = std::make_unique(*modules_, *immutable_converter_); RETURN_IF_NULL(converter_); - std::unique_ptr predictor; + std::unique_ptr predictor; { // Create a predictor with three sub-predictors, dictionary predictor, user // history predictor, and extra predictor. @@ -225,8 +170,6 @@ absl::Status Engine::Init(std::unique_ptr modules, converter_->Init(std::move(predictor), std::move(rewriter)); - user_data_manager_ = std::make_unique(predictor_, rewriter_); - initialized_ = true; return absl::Status(); @@ -234,36 +177,41 @@ absl::Status Engine::Init(std::unique_ptr modules, } bool Engine::Reload() { - if (!modules_->GetUserDictionary()) { - return true; + if (modules_ && modules_->GetUserDictionary()) { + modules_->GetUserDictionary()->Reload(); } - MOZC_VLOG(1) << "Reloading user dictionary"; - bool result_dictionary = modules_->GetUserDictionary()->Reload(); - MOZC_VLOG(1) << "Reloading UserDataManager"; - bool result_user_data = GetUserDataManager()->Reload(); - return result_dictionary && result_user_data; + return rewriter_ && rewriter_->Reload() && predictor_ && predictor_->Reload(); } bool Engine::Sync() { - GetUserDataManager()->Sync(); - if (!modules_->GetUserDictionary()) { - return true; + if (modules_ && modules_->GetUserDictionary()) { + modules_->GetUserDictionary()->Sync(); } - return modules_->GetUserDictionary()->Sync(); + return rewriter_ && rewriter_->Sync() && predictor_ && predictor_->Sync(); } bool Engine::Wait() { - if (modules_->GetUserDictionary()) { + if (modules_ && modules_->GetUserDictionary()) { modules_->GetUserDictionary()->WaitForReloader(); } - return GetUserDataManager()->Wait(); + return predictor_ && predictor_->Wait(); } -bool Engine::ReloadAndWait() { - if (!Reload()) { - return false; +bool Engine::ReloadAndWait() { return Reload() && Wait(); } + +bool Engine::ClearUserHistory() { + if (rewriter_) { + rewriter_->Clear(); } - return Wait(); + return true; +} + +bool Engine::ClearUserPrediction() { + return predictor_ && predictor_->ClearAllHistory(); +} + +bool Engine::ClearUnusedUserPrediction() { + return predictor_ && predictor_->ClearUnusedHistory(); } bool Engine::MaybeReloadEngine(EngineReloadResponse *response) { @@ -303,8 +251,8 @@ bool Engine::MaybeReloadEngine(EngineReloadResponse *response) { continue; } - if (user_data_manager_) { - user_data_manager_->Wait(); + if (predictor_) { + predictor_->Wait(); } // Reloads DataManager. diff --git a/src/engine/engine.h b/src/engine/engine.h index 2725eac62..4dfe0a071 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -47,7 +47,6 @@ #include "engine/minimal_engine.h" #include "engine/modules.h" #include "engine/supplemental_model_interface.h" -#include "engine/user_data_manager_interface.h" #include "prediction/predictor_interface.h" #include "rewriter/rewriter_interface.h" @@ -113,14 +112,13 @@ class Engine : public EngineInterface { bool Wait() override; bool ReloadAndWait() override; + bool ClearUserHistory() override; + bool ClearUserPrediction() override; + bool ClearUnusedUserPrediction() override; + absl::Status ReloadModules(std::unique_ptr modules, bool is_mobile); - UserDataManagerInterface *GetUserDataManager() override { - return initialized_ ? user_data_manager_.get() - : minimal_engine_.GetUserDataManager(); - } - absl::string_view GetDataVersion() const override { return GetDataManager()->GetDataVersion(); } @@ -150,10 +148,11 @@ class Engine : public EngineInterface { // Maybe reload a new data manager. Returns true if reloaded. bool MaybeReloadEngine(EngineReloadResponse *response) override; bool SendEngineReloadRequest(const EngineReloadRequest &request) override; - void SetDataLoaderForTesting(std::unique_ptr loader) override { + + void SetDataLoaderForTesting(std::unique_ptr loader) { loader_ = std::move(loader); } - void SetAlwaysWaitForLoaderResponseFutureForTesting(bool value) override { + void SetAlwaysWaitForLoaderResponseFutureForTesting(bool value) { loader_->SetAlwaysWaitForLoaderResponseFutureForTesting(value); } @@ -179,7 +178,6 @@ class Engine : public EngineInterface { RewriterInterface *rewriter_ = nullptr; std::unique_ptr converter_; - std::unique_ptr user_data_manager_; }; } // namespace mozc diff --git a/src/engine/engine_interface.h b/src/engine/engine_interface.h index 50aa8a741..c51c5fd70 100644 --- a/src/engine/engine_interface.h +++ b/src/engine/engine_interface.h @@ -37,9 +37,7 @@ #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "converter/converter_interface.h" -#include "engine/data_loader.h" #include "engine/supplemental_model_interface.h" -#include "engine/user_data_manager_interface.h" #include "protocol/engine_builder.pb.h" namespace mozc { @@ -62,32 +60,38 @@ class EngineInterface { // Returns the predictor name. virtual absl::string_view GetPredictorName() const = 0; + // Gets the version of underlying data set. + virtual absl::string_view GetDataVersion() const = 0; + // Reloads internal data, e.g., user dictionary, etc. // This function may read data from local files. // Returns true if successfully reloaded or did nothing. - virtual bool Reload() = 0; + virtual bool Reload() { return true; } // Synchronizes internal data, e.g., user dictionary, etc. // This function may write data into local files. // Returns true if successfully synced or did nothing. - virtual bool Sync() = 0; + virtual bool Sync() { return true; } // Waits for reloader. // Returns true if successfully waited or did nothing. - virtual bool Wait() = 0; + virtual bool Wait() { return true; } // Reloads internal data and wait for reloader. // Returns true if successfully reloaded and waited, or did nothing. - virtual bool ReloadAndWait() = 0; + virtual bool ReloadAndWait() { return true; } - // Gets a user data manager. - virtual UserDataManagerInterface *GetUserDataManager() = 0; + // Clears user history data. + virtual bool ClearUserHistory() { return true; } - // Gets the version of underlying data set. - virtual absl::string_view GetDataVersion() const = 0; + // Clears user prediction data. + virtual bool ClearUserPrediction() { return true; } + + // Clears unused user prediction data. + virtual bool ClearUnusedUserPrediction() { return true; } // Gets the user POS list. - virtual std::vector GetPosList() const = 0; + virtual std::vector GetPosList() const { return {}; } virtual void SetSupplementalModel( const engine::SupplementalModelInterface *supplemental_model) {} @@ -99,8 +103,6 @@ class EngineInterface { virtual bool SendEngineReloadRequest(const EngineReloadRequest &request) { return false; } - virtual void SetDataLoaderForTesting(std::unique_ptr loader) {} - virtual void SetAlwaysWaitForLoaderResponseFutureForTesting(bool value) {} protected: EngineInterface() = default; diff --git a/src/engine/engine_mock.h b/src/engine/engine_mock.h index d485c80cf..afe5d3834 100644 --- a/src/engine/engine_mock.h +++ b/src/engine/engine_mock.h @@ -39,7 +39,6 @@ #include "converter/converter_interface.h" #include "engine/engine_interface.h" #include "engine/supplemental_model_interface.h" -#include "engine/user_data_manager_interface.h" #include "testing/gmock.h" namespace mozc { @@ -48,12 +47,14 @@ class MockEngine : public EngineInterface { public: MOCK_METHOD(ConverterInterface *, GetConverter, (), (const, override)); MOCK_METHOD(absl::string_view, GetPredictorName, (), (const, override)); + MOCK_METHOD(absl::string_view, GetDataVersion, (), (const, override)); MOCK_METHOD(bool, Reload, (), (override)); MOCK_METHOD(bool, Sync, (), (override)); MOCK_METHOD(bool, Wait, (), (override)); + MOCK_METHOD(bool, ClearUserHistory, (), (override)); + MOCK_METHOD(bool, ClearUserPrediction, (), (override)); + MOCK_METHOD(bool, ClearUnusedUserPrediction, (), (override)); MOCK_METHOD(bool, ReloadAndWait, (), (override)); - MOCK_METHOD(UserDataManagerInterface *, GetUserDataManager, (), (override)); - MOCK_METHOD(absl::string_view, GetDataVersion, (), (const, override)); MOCK_METHOD(std::vector, GetPosList, (), (const, override)); MOCK_METHOD(void, SetSupplementalModel, (const engine::SupplementalModelInterface *), (override)); diff --git a/src/engine/minimal_engine.cc b/src/engine/minimal_engine.cc index 844d177db..07511d8c0 100644 --- a/src/engine/minimal_engine.cc +++ b/src/engine/minimal_engine.cc @@ -44,24 +44,11 @@ #include "converter/segments.h" #include "data_manager/data_manager.h" #include "data_manager/data_manager_interface.h" -#include "engine/user_data_manager_interface.h" #include "request/conversion_request.h" namespace mozc { namespace { -class UserDataManagerStub : public UserDataManagerInterface { - public: - UserDataManagerStub() = default; - - bool Sync() override { return true; } - bool Reload() override { return true; } - bool ClearUserHistory() override { return true; } - bool ClearUserPrediction() override { return true; } - bool ClearUnusedUserPrediction() override { return true; } - bool Wait() override { return true; } -}; - bool AddAsIsCandidate(const absl::string_view key, Segments *segments) { if (key.empty()) { return false; @@ -169,7 +156,6 @@ class MinimalConverter : public ConverterInterface { MinimalEngine::MinimalEngine() : converter_(std::make_unique()), - user_data_manager_(std::make_unique()), data_manager_(std::make_unique()) {} ConverterInterface *MinimalEngine::GetConverter() const { @@ -181,14 +167,8 @@ absl::string_view MinimalEngine::GetPredictorName() const { return kPredictorName; } -UserDataManagerInterface *MinimalEngine::GetUserDataManager() { - return user_data_manager_.get(); -} - const DataManagerInterface *MinimalEngine::GetDataManager() const { return data_manager_.get(); } -std::vector MinimalEngine::GetPosList() const { return {}; } - } // namespace mozc diff --git a/src/engine/minimal_engine.h b/src/engine/minimal_engine.h index 9be5ecdf9..6411cad3a 100644 --- a/src/engine/minimal_engine.h +++ b/src/engine/minimal_engine.h @@ -40,7 +40,6 @@ #include "data_manager/data_manager_interface.h" #include "engine/engine_interface.h" #include "engine/modules.h" -#include "engine/user_data_manager_interface.h" namespace mozc { @@ -54,23 +53,17 @@ class MinimalEngine : public EngineInterface { ConverterInterface *GetConverter() const override; absl::string_view GetPredictorName() const override; - bool Reload() override { return true; } - bool Sync() override { return true; } - bool Wait() override { return true; } - bool ReloadAndWait() override { return true; } - UserDataManagerInterface *GetUserDataManager() override; absl::string_view GetDataVersion() const override { return "0.0.0"; } - std::vector GetPosList() const override; absl::Status ReloadModules(std::unique_ptr modules, bool is_mobile) { return absl::OkStatus(); } + const DataManagerInterface *GetDataManager() const; private: std::unique_ptr converter_; - std::unique_ptr user_data_manager_; std::unique_ptr data_manager_; }; diff --git a/src/engine/user_data_manager_interface.h b/src/engine/user_data_manager_interface.h deleted file mode 100644 index 6bcb5763e..000000000 --- a/src/engine/user_data_manager_interface.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// UserDataManagerInterface is responsible for the management of the -// user data in the persistent storage, i.e. syncing, reloading, or -// clear-out. - -#ifndef MOZC_ENGINE_USER_DATA_MANAGER_INTERFACE_H_ -#define MOZC_ENGINE_USER_DATA_MANAGER_INTERFACE_H_ - -#include "absl/strings/string_view.h" - -namespace mozc { - -class UserDataManagerInterface { - public: - virtual ~UserDataManagerInterface() = default; - - // Syncs mutable user data to local file system. - virtual bool Sync() = 0; - - // Reloads mutable user data from local file system. - virtual bool Reload() = 0; - - // Clears user history data. - virtual bool ClearUserHistory() = 0; - - // Clears user prediction data. - virtual bool ClearUserPrediction() = 0; - - // Clears unused user prediction data. - virtual bool ClearUnusedUserPrediction() = 0; - - // Waits for syncer thread to complete. - virtual bool Wait() = 0; -}; - -} // namespace mozc - -#endif // MOZC_ENGINE_USER_DATA_MANAGER_INTERFACE_H_ diff --git a/src/engine/user_data_manager_mock.h b/src/engine/user_data_manager_mock.h deleted file mode 100644 index bf92aeb4d..000000000 --- a/src/engine/user_data_manager_mock.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef MOZC_ENGINE_USER_DATA_MANAGER_MOCK_H_ -#define MOZC_ENGINE_USER_DATA_MANAGER_MOCK_H_ - -#include "engine/user_data_manager_interface.h" -#include "testing/gmock.h" - -namespace mozc { - -class MockUserDataManager : public UserDataManagerInterface { - public: - MockUserDataManager() = default; - ~MockUserDataManager() override = default; - - MOCK_METHOD(bool, Sync, (), (override)); - MOCK_METHOD(bool, Reload, (), (override)); - MOCK_METHOD(bool, ClearUserHistory, (), (override)); - MOCK_METHOD(bool, ClearUserPrediction, (), (override)); - MOCK_METHOD(bool, ClearUnusedUserPrediction, (), (override)); - MOCK_METHOD(bool, Wait, (), (override)); -}; - -} // namespace mozc - -#endif // MOZC_ENGINE_USER_DATA_MANAGER_MOCK_H_ diff --git a/src/session/BUILD.bazel b/src/session/BUILD.bazel index 91d9a8543..721664292 100644 --- a/src/session/BUILD.bazel +++ b/src/session/BUILD.bazel @@ -234,7 +234,6 @@ mozc_cc_test( "//data_manager/testing:mock_data_manager", "//engine", "//engine:mock_data_engine_factory", - "//engine:user_data_manager_interface", "//protocol:candidate_window_cc_proto", "//protocol:commands_cc_proto", "//protocol:config_cc_proto", @@ -298,7 +297,6 @@ mozc_cc_library( "//engine", "//engine:engine_interface", "//engine:supplemental_model_interface", - "//engine:user_data_manager_interface", "//protocol:commands_cc_proto", "//protocol:config_cc_proto", "//protocol:engine_builder_cc_proto", @@ -373,7 +371,6 @@ mozc_cc_test( "//engine:mock_data_engine_factory", "//engine:modules", "//engine:supplemental_model_interface", - "//engine:user_data_manager_mock", "//protocol:commands_cc_proto", "//protocol:config_cc_proto", "//session/internal:keymap", @@ -689,7 +686,6 @@ mozc_cc_library( "//config:config_handler", "//engine:engine_factory", "//engine:engine_interface", - "//engine:user_data_manager_interface", "//prediction:user_history_predictor", "//protocol:candidate_window_cc_proto", "//protocol:commands_cc_proto", diff --git a/src/session/session_handler.cc b/src/session/session_handler.cc index a7b7ab0ef..56d22d396 100644 --- a/src/session/session_handler.cc +++ b/src/session/session_handler.cc @@ -54,7 +54,6 @@ #include "dictionary/user_dictionary_session_handler.h" #include "engine/engine_interface.h" #include "engine/supplemental_model_interface.h" -#include "engine/user_data_manager_interface.h" #include "protocol/commands.pb.h" #include "protocol/config.pb.h" #include "protocol/engine_builder.pb.h" @@ -253,21 +252,21 @@ bool SessionHandler::ReloadAndWait(commands::Command *command) { bool SessionHandler::ClearUserHistory(commands::Command *command) { MOZC_VLOG(1) << "Clearing user history"; - engine_->GetUserDataManager()->ClearUserHistory(); + engine_->ClearUserHistory(); UsageStats::IncrementCount("ClearUserHistory"); return true; } bool SessionHandler::ClearUserPrediction(commands::Command *command) { MOZC_VLOG(1) << "Clearing user prediction"; - engine_->GetUserDataManager()->ClearUserPrediction(); + engine_->ClearUserPrediction(); UsageStats::IncrementCount("ClearUserPrediction"); return true; } bool SessionHandler::ClearUnusedUserPrediction(commands::Command *command) { MOZC_VLOG(1) << "Clearing unused user prediction"; - engine_->GetUserDataManager()->ClearUnusedUserPrediction(); + engine_->ClearUnusedUserPrediction(); UsageStats::IncrementCount("ClearUnusedUserPrediction"); return true; } diff --git a/src/session/session_handler_test.cc b/src/session/session_handler_test.cc index bc75cb918..e928c66e5 100644 --- a/src/session/session_handler_test.cc +++ b/src/session/session_handler_test.cc @@ -59,7 +59,6 @@ #include "engine/mock_data_engine_factory.h" #include "engine/modules.h" #include "engine/supplemental_model_interface.h" -#include "engine/user_data_manager_mock.h" #include "protocol/commands.pb.h" #include "protocol/config.pb.h" #include "session/internal/keymap.h" @@ -618,7 +617,6 @@ TEST_F(SessionHandlerTest, VerifySyncIsCalledTest) { commands::Input::CLEANUP, }; for (size_t i = 0; i < std::size(command_types); ++i) { - MockUserDataManager mock_user_data_manager; auto engine = std::make_unique(); EXPECT_CALL(*engine, Sync()).WillOnce(Return(true)); @@ -633,7 +631,6 @@ TEST_F(SessionHandlerTest, VerifySyncIsCalledTest) { } TEST_F(SessionHandlerTest, SyncDataTest) { - MockUserDataManager mock_user_data_manager; auto engine = std::make_unique(); EXPECT_CALL(*engine, Sync()).WillOnce(Return(true)); EXPECT_CALL(*engine, Wait()).WillOnce(Return(true)); diff --git a/src/session/session_handler_tool.cc b/src/session/session_handler_tool.cc index a0eb518eb..e841b2a2a 100644 --- a/src/session/session_handler_tool.cc +++ b/src/session/session_handler_tool.cc @@ -59,7 +59,6 @@ #include "config/config_handler.h" #include "engine/engine_factory.h" #include "engine/engine_interface.h" -#include "engine/user_data_manager_interface.h" #include "prediction/user_history_predictor.h" #include "protocol/candidate_window.pb.h" #include "protocol/commands.pb.h" @@ -100,8 +99,8 @@ std::string ToTextFormat(const Message &proto) { SessionHandlerTool::SessionHandlerTool(std::unique_ptr engine) : id_(0), + engine_(engine.get()), usage_observer_(std::make_unique()), - data_manager_(engine->GetUserDataManager()), handler_(std::make_unique(std::move(engine))) { handler_->AddObserver(usage_observer_.get()); } @@ -260,7 +259,9 @@ bool SessionHandlerTool::SetConfig(const config::Config &config, } bool SessionHandlerTool::SyncData() { - return data_manager_->Sync() && data_manager_->Wait(); + engine_->Sync(); + engine_->Wait(); + return true; } void SessionHandlerTool::SetCallbackText(const absl::string_view text) { diff --git a/src/session/session_handler_tool.h b/src/session/session_handler_tool.h index b44e636f9..25b714a3f 100644 --- a/src/session/session_handler_tool.h +++ b/src/session/session_handler_tool.h @@ -40,7 +40,6 @@ #include "absl/strings/string_view.h" #include "absl/types/span.h" #include "engine/engine_interface.h" -#include "engine/user_data_manager_interface.h" #include "protocol/candidate_window.pb.h" #include "protocol/commands.pb.h" #include "protocol/config.pb.h" @@ -101,8 +100,8 @@ class SessionHandlerTool { bool allow_callback); uint64_t id_; // Session ID + EngineInterface *engine_ = nullptr; std::unique_ptr usage_observer_; - UserDataManagerInterface *data_manager_; std::unique_ptr handler_; std::string callback_text_; }; diff --git a/src/session/session_regression_test.cc b/src/session/session_regression_test.cc index 7099fffd0..7df503a44 100644 --- a/src/session/session_regression_test.cc +++ b/src/session/session_regression_test.cc @@ -45,7 +45,6 @@ #include "data_manager/testing/mock_data_manager.h" #include "engine/engine.h" #include "engine/mock_data_engine_factory.h" -#include "engine/user_data_manager_interface.h" #include "protocol/candidate_window.pb.h" #include "protocol/commands.pb.h" #include "protocol/config.pb.h" @@ -96,9 +95,9 @@ class SessionRegressionTest : public testing::TestWithTempUserProfile { // Clear previous data just in case. It should work without this clear, // however the reality is Windows environment has a flacky test issue. - engine->GetUserDataManager()->ClearUserHistory(); - engine->GetUserDataManager()->ClearUserPrediction(); - engine->GetUserDataManager()->Wait(); + engine->ClearUserHistory(); + engine->ClearUserPrediction(); + engine->Wait(); handler_ = std::make_unique(std::move(engine)); ResetSession();