Skip to content

Commit

Permalink
Get the data version from mozc server
Browse files Browse the repository at this point in the history
Now MOZC_DICTIONARY_VERSION is explicitly logged via MozcMetricsType.

As far as I observed,
onKeyboardActivated() is called before onStartInputView(), where we used to log the MOZC_DICTIONARY_VERSION event.

PiperOrigin-RevId: 608481758
  • Loading branch information
Toshiyuki Hanaoka authored and hiroyuki-komatsu committed Feb 20, 2024
1 parent 1772fc3 commit f87369e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/protocol/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/session/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <memory>
#include <string>

#include "absl/time/time.h"
#include "composer/composer.h"
#include "composer/table.h"
#include "engine/engine_interface.h"
Expand All @@ -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"

Expand Down
14 changes: 13 additions & 1 deletion src/session/session_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/session/session_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/session/session_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,5 +859,17 @@ TEST_F(SessionHandlerTest, EngineReloadSessionExistsTest) {
EXPECT_EQ(new_engine_ptr, &handler.engine());
}

TEST_F(SessionHandlerTest, GetServerVersionTest) {
auto engine = std::make_unique<MockEngine>();
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

0 comments on commit f87369e

Please sign in to comment.