Commit 7920d719 authored by Leo Zhang's avatar Leo Zhang Committed by Commit Bot

Set logger for loaded shared lib.

This will help IME service show logs better from loaded ime decoder.

TEST=Betty with new built DSO.
BUG=b/162375823

Change-Id: I9a3fa61078dfeae5a029b912c339cd80bc724a8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2497352
Commit-Queue: Leo Zhang <googleo@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821034}
parent f05b4316
......@@ -28,6 +28,23 @@ base::FilePath GetImeDecoderLibPath() {
return lib_path;
}
// Simple bridge between logging in the loaded shared library and logging in
// Chrome.
void ImeLoggerBridge(int severity, const char* message) {
switch (severity) {
case logging::LOG_INFO:
// TODO(b/162375823): VLOG_IF(INFO, is_debug_version).
break;
case logging::LOG_WARNING:
LOG(WARNING) << message;
break;
case logging::LOG_ERROR:
LOG(ERROR) << message;
break;
default:
break;
}
}
} // namespace
ImeDecoder::ImeDecoder() : status_(Status::kUninitialized) {
......@@ -55,6 +72,16 @@ ImeDecoder::ImeDecoder() : status_(Status::kUninitialized) {
return;
}
ImeEngineLoggerSetterFn loggerSetter =
reinterpret_cast<ImeEngineLoggerSetterFn>(
library.GetFunctionPointer("SetImeEngineLogger"));
if (loggerSetter) {
loggerSetter(ImeLoggerBridge);
} else {
// Not a blocking issue yet.
LOG(ERROR) << "Failed to load SetImeEngineLogger function.";
}
library_ = std::move(library);
status_ = Status::kSuccess;
}
......
......@@ -71,6 +71,9 @@ typedef void (*SimpleDownloadCallback)(int status_code, const char* file_path);
// A function pointer of a sequenced task.
typedef void (*ImeSequencedTask)(int task_id);
// A logger function pointer from chrome.
typedef void (*ChromeLoggerFunc)(int severity, const char* message);
// Based on RequestPriority defined at
// https://cs.chromium.org/chromium/src/net/base/request_priority.h?rcl=f9c935b73381772d508eebba1e216c437139d475
enum DownloadPriority {
......@@ -246,6 +249,9 @@ class ImeEngineMainEntry {
// Returns an instance of ImeEngineMainEntry from the IME shared library.
typedef ImeEngineMainEntry* (*ImeMainEntryCreateFn)(ImeCrosPlatform*);
// For use when bridging logs logged in IME shared library to Chrome logging.
typedef void (*ImeEngineLoggerSetterFn)(ChromeLoggerFunc);
// Defined name of ImeMainEntryCreateFn exported from shared library.
#define IME_MAIN_ENTRY_CREATE_FN_NAME "CreateImeMainEntry"
......
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