Skip to content

Commit

Permalink
Remove COM runtime dependency from ImeUtil::SetDefault
Browse files Browse the repository at this point in the history
This is a bonus cleanup thanks to effort on #837.

With my previous commit [1], 'ImeUtil::SetDefault' no longer needs to
depend on COM runtime.

There must be no user observable behavior change.

#codehealth

 [1]: 006084c

PiperOrigin-RevId: 582380940
  • Loading branch information
yukawa authored and hiroyuki-komatsu committed Nov 14, 2023
1 parent 4a6c2ac commit f2ff1fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/win32/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,10 @@ mozc_cc_library(
target_compatible_with = ["@platforms//os:windows"],
deps = [
":input_dll",
":msctf_dll",
":tsf_profile",
"//base:logging",
"//base:system_util",
"//base/win32:com",
"//base/win32:scoped_com",
"//base/win32:wide_char",
"@com_microsoft_wil//:wil",
],
Expand Down
23 changes: 14 additions & 9 deletions src/win32/base/imm_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@

#include "base/logging.h"
#include "base/system_util.h"
#include "base/win32/com.h"
#include "base/win32/scoped_com.h"
#include "base/win32/wide_char.h"
#include "win32/base/input_dll.h"
#include "win32/base/tsf_profile.h"
Expand Down Expand Up @@ -89,13 +87,20 @@ bool ImeUtil::SetDefault() {
return false;
}

// Activate the TSF Mozc.
ScopedCOMInitializer com_initializer;
auto profile_mgr = ComCreateInstance<ITfInputProcessorProfileMgr>(
CLSID_TF_InputProcessorProfiles);
if (!profile_mgr) {
DLOG(ERROR) << "CoCreateInstance CLSID_TF_InputProcessorProfiles failed";
return false;
wil::com_ptr_nothrow<ITfInputProcessorProfileMgr> profile_mgr;
{
wil::com_ptr_nothrow<ITfInputProcessorProfiles> profiles;
HRESULT result = TF_CreateInputProcessorProfiles(profiles.put());
if (!profiles) {
DLOG(ERROR) << "TF_CreateInputProcessorProfiles failed:" << result;
return false;
}
result = profiles.query_to(profile_mgr.put());
if (!profile_mgr) {
DLOG(ERROR) << "QueryInterface to ITfInputProcessorProfileMgr failed:"
<< result;
return false;
}
}
const LANGID kLANGJaJP = MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN);
if (FAILED(profile_mgr->ActivateProfile(
Expand Down
1 change: 1 addition & 0 deletions src/win32/base/win32_base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
'dependencies': [
'<(mozc_src_dir)/base/base.gyp:base',
'input_dll_import_lib',
'msctf_dll_import_lib',
],
},
{
Expand Down

0 comments on commit f2ff1fd

Please sign in to comment.