diff --git a/src/protocol/commands.proto b/src/protocol/commands.proto index 46f75a9ee..d9c100abe 100644 --- a/src/protocol/commands.proto +++ b/src/protocol/commands.proto @@ -1109,13 +1109,11 @@ message Input { // Sends reload spellchecker. RELOAD_SPELL_CHECKER = 29; + GET_SERVER_VERSION = 19; + // Number of commands. // When new command is added, the command should use below number // and NUM_OF_COMMANDS should be incremented. - // - // Note: This enum lack the value for 19 and it may cause a crash. - // Please reuse these value if you can. - // 19 was used to clear synced data on dev channel. NUM_OF_COMMANDS = 30; } required CommandType type = 1; @@ -1328,7 +1326,7 @@ message DeletionRange { optional int32 length = 2; } -// Next ID: 26 +// Next ID: 27 message Output { optional uint64 id = 1 [jstype = JS_STRING]; @@ -1420,6 +1418,12 @@ message Output { // Candidate words stored in 1D array. The field should be filled without // using any personal data. optional CandidateList incognito_candidate_words = 25; + + message VersionInfo { + optional string mozc_version = 1; + optional string data_version = 2; + } + optional VersionInfo server_version = 26; } message Command { diff --git a/src/session/session.h b/src/session/session.h index fa5c2b9e8..1ed775cb0 100644 --- a/src/session/session.h +++ b/src/session/session.h @@ -37,6 +37,7 @@ #include #include +#include "absl/time/time.h" #include "composer/composer.h" #include "composer/table.h" #include "engine/engine_interface.h" @@ -45,7 +46,6 @@ #include "session/internal/ime_context.h" #include "session/internal/keymap.h" #include "session/session_interface.h" -#include "absl/time/time.h" #include "testing/friend_test.h" #include "transliteration/transliteration.h" diff --git a/src/session/session_handler.cc b/src/session/session_handler.cc index 7cc0963a9..6bce5a46c 100644 --- a/src/session/session_handler.cc +++ b/src/session/session_handler.cc @@ -47,6 +47,7 @@ #include "base/logging.h" #include "base/protobuf/message.h" #include "base/stopwatch.h" +#include "base/version.h" #include "base/vlog.h" #include "composer/table.h" #include "config/character_form_manager.h" @@ -389,6 +390,9 @@ bool SessionHandler::EvalCommand(commands::Command *command) { case commands::Input::RELOAD_SPELL_CHECKER: eval_succeeded = ReloadSpellChecker(command); break; + case commands::Input::GET_SERVER_VERSION: + eval_succeeded = GetServerVersion(command); + break; default: eval_succeeded = false; } @@ -407,7 +411,7 @@ bool SessionHandler::EvalCommand(commands::Command *command) { } if (eval_succeeded) { - // TODO(komatsu): Make sre if checking eval_succeeded is necessary or not. + // TODO(komatsu): Make sure if checking eval_succeeded is necessary or not. observer_handler_->EvalCommandHandler(*command); } @@ -538,6 +542,14 @@ void SessionHandler::MaybeReloadEngine(commands::Command *command) { table_manager_->ClearCaches(); } +bool SessionHandler::GetServerVersion(mozc::commands::Command *command) const { + commands::Output::VersionInfo *version_info = + command->mutable_output()->mutable_server_version(); + version_info->set_mozc_version(Version::GetMozcVersion()); + version_info->set_data_version(engine_->GetDataVersion()); + return true; +} + bool SessionHandler::CreateSession(commands::Command *command) { // prevent DOS attack // don't allow CreateSession in very short period. diff --git a/src/session/session_handler.h b/src/session/session_handler.h index 535f3f895..dc4efa1c6 100644 --- a/src/session/session_handler.h +++ b/src/session/session_handler.h @@ -135,6 +135,7 @@ class SessionHandler : public SessionHandlerInterface { bool NoOperation(commands::Command *command); bool CheckSpelling(commands::Command *command); bool ReloadSpellChecker(commands::Command *command); + bool GetServerVersion(commands::Command *command) const; // Replaces engine_ with a new instance if it is ready. void MaybeReloadEngine(commands::Command *command); diff --git a/src/session/session_handler_test.cc b/src/session/session_handler_test.cc index 5d06de3b4..1550e7b94 100644 --- a/src/session/session_handler_test.cc +++ b/src/session/session_handler_test.cc @@ -859,5 +859,17 @@ TEST_F(SessionHandlerTest, EngineReloadSessionExistsTest) { EXPECT_EQ(new_engine_ptr, &handler.engine()); } +TEST_F(SessionHandlerTest, GetServerVersionTest) { + auto engine = std::make_unique(); + EXPECT_CALL(*engine, GetDataVersion()) + .WillRepeatedly(Return("24.20240101.01")); + + SessionHandler handler(std::move(engine)); + commands::Command command; + command.mutable_input()->set_type(commands::Input::GET_SERVER_VERSION); + handler.EvalCommand(&command); + EXPECT_EQ(command.output().server_version().data_version(), "24.20240101.01"); +} + } // namespace mozc