Commit 765b0996 authored by Alex Keng's avatar Alex Keng Committed by Commit Bot

TSF: propagate HRESULT from TSF initialization

This CL changes the return value of TSFBridge::Initialize from void to
HRESULT and refactors the logics in TSFTextStore::TSFTextStore out to
TSFTextStore::Initialize. The HRESULTs of various COM calls during TSF
initialization are propagated so the caller can handle errors, if any,
accordingly.

Note at the moment upstream doesn't have any use case for the HRESULT,
but downstream will use the value for WebView2 initialization, ex.
handling errors due to creating CLSID_TF_CategoryMgr instance in a
thread initialized with COM_MTA (while all TSF functions expect STA)

Change-Id: I227000a594f203eecc37838ff877d3dcd077df2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340543
Commit-Queue: Alex Keng <shihken@microsoft.com>
Reviewed-by: default avatarYohei Yukawa <yukawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797396}
parent d24ca9ba
This diff is collapsed.
...@@ -36,7 +36,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFBridge { ...@@ -36,7 +36,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFBridge {
// Sets the thread local instance. Must be called before any calls to // Sets the thread local instance. Must be called before any calls to
// GetInstance(). // GetInstance().
static void Initialize(); static HRESULT Initialize();
// Injects an alternative TSFBridge such as MockTSFBridge for testing. The // Injects an alternative TSFBridge such as MockTSFBridge for testing. The
// injected object should be released by the caller. This function returns // injected object should be released by the caller. This function returns
......
...@@ -187,6 +187,7 @@ class TSFInputPanelTest : public testing::Test { ...@@ -187,6 +187,7 @@ class TSFInputPanelTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
text_store_ = new TSFTextStore(); text_store_ = new TSFTextStore();
EXPECT_EQ(S_OK, text_store_->Initialize());
sink_ = new MockStoreACPSink(); sink_ = new MockStoreACPSink();
EXPECT_EQ(S_OK, text_store_->AdviseSink(IID_ITextStoreACPSink, sink_.get(), EXPECT_EQ(S_OK, text_store_->AdviseSink(IID_ITextStoreACPSink, sink_.get(),
TS_AS_ALL_SINKS)); TS_AS_ALL_SINKS));
...@@ -216,7 +217,9 @@ class TSFMultipleInputPanelTest : public testing::Test { ...@@ -216,7 +217,9 @@ class TSFMultipleInputPanelTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
text_store1_ = new TSFTextStore(); text_store1_ = new TSFTextStore();
EXPECT_EQ(S_OK, text_store1_->Initialize());
text_store2_ = new TSFTextStore(); text_store2_ = new TSFTextStore();
EXPECT_EQ(S_OK, text_store2_->Initialize());
sink1_ = new MockStoreACPSink(); sink1_ = new MockStoreACPSink();
sink2_ = new MockStoreACPSink(); sink2_ = new MockStoreACPSink();
EXPECT_EQ(S_OK, text_store1_->AdviseSink(IID_ITextStoreACPSink, EXPECT_EQ(S_OK, text_store1_->AdviseSink(IID_ITextStoreACPSink,
......
...@@ -47,21 +47,27 @@ bool GetWindowClientRect(HWND window_handle, ...@@ -47,21 +47,27 @@ bool GetWindowClientRect(HWND window_handle,
} // namespace } // namespace
TSFTextStore::TSFTextStore() { TSFTextStore::TSFTextStore() {}
if (FAILED(::CoCreateInstance(CLSID_TF_CategoryMgr, nullptr, CLSCTX_ALL,
IID_PPV_ARGS(&category_manager_)))) { TSFTextStore::~TSFTextStore() {}
LOG(FATAL) << "Failed to initialize CategoryMgr.";
return; HRESULT TSFTextStore::Initialize() {
HRESULT hr = ::CoCreateInstance(CLSID_TF_CategoryMgr, nullptr, CLSCTX_ALL,
IID_PPV_ARGS(&category_manager_));
if (FAILED(hr)) {
DVLOG(1) << "Failed to initialize CategoryMgr.";
return hr;
} }
if (FAILED(::CoCreateInstance(CLSID_TF_DisplayAttributeMgr, nullptr,
CLSCTX_ALL, hr = ::CoCreateInstance(CLSID_TF_DisplayAttributeMgr, nullptr, CLSCTX_ALL,
IID_PPV_ARGS(&display_attribute_manager_)))) { IID_PPV_ARGS(&display_attribute_manager_));
LOG(FATAL) << "Failed to initialize DisplayAttributeMgr."; if (FAILED(hr)) {
return; DVLOG(1) << "Failed to initialize DisplayAttributeMgr.";
return hr;
} }
}
TSFTextStore::~TSFTextStore() {} return S_OK;
}
ULONG STDMETHODCALLTYPE TSFTextStore::AddRef() { ULONG STDMETHODCALLTYPE TSFTextStore::AddRef() {
return InterlockedIncrement(&ref_count_); return InterlockedIncrement(&ref_count_);
......
...@@ -108,6 +108,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFTextStore ...@@ -108,6 +108,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFTextStore
public: public:
TSFTextStore(); TSFTextStore();
virtual ~TSFTextStore(); virtual ~TSFTextStore();
HRESULT Initialize();
// ITextStoreACP: // ITextStoreACP:
IFACEMETHODIMP_(ULONG) AddRef() override; IFACEMETHODIMP_(ULONG) AddRef() override;
......
...@@ -140,6 +140,7 @@ class TSFTextStoreTest : public testing::Test { ...@@ -140,6 +140,7 @@ class TSFTextStoreTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
text_store_ = new TSFTextStore(); text_store_ = new TSFTextStore();
EXPECT_EQ(S_OK, text_store_->Initialize());
sink_ = new MockStoreACPSink(); sink_ = new MockStoreACPSink();
EXPECT_EQ(S_OK, text_store_->AdviseSink(IID_ITextStoreACPSink, sink_.get(), EXPECT_EQ(S_OK, text_store_->AdviseSink(IID_ITextStoreACPSink, sink_.get(),
TS_AS_ALL_SINKS)); TS_AS_ALL_SINKS));
......
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