Commit b420e016 authored by Bruce Long's avatar Bruce Long Committed by Commit Bot

Fix DCHECK fail in SpellcheckPlatformWinTest.SpellCheckAsyncMethods

ResolveLocaleName should only fail if buffer size insufficient, but
it can succeed yet return an empty string for certain language tags
such as ht.

Fix is to not DCHECK when ResolveLocaleName fails to return a
valid locale name, and instead fallback to the unresolved name.

Also adds DVLOG logging when a language with no platform dictionary
support is encountered (like zh-CN).

Bug: 1031556
Change-Id: I2602f247742b9ccf96c885339f6390639f6cf981
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955801Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Bruce Long <brlong@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#722966}
parent 7cc2904b
...@@ -545,18 +545,32 @@ void WindowsSpellChecker:: ...@@ -545,18 +545,32 @@ void WindowsSpellChecker::
// (zh-Hans-CN e.g.) need to be converted to locale names via // (zh-Hans-CN e.g.) need to be converted to locale names via
// ResolveLocaleName before being passed to spell checker API. // ResolveLocaleName before being passed to spell checker API.
wchar_t locale_name[LOCALE_NAME_MAX_LENGTH]; wchar_t locale_name[LOCALE_NAME_MAX_LENGTH];
// ResolveLocaleName can only fail if buffer size insufficient. const wchar_t* preferred_language =
::ResolveLocaleName( base::as_wcstr(base::AsStringPiece16(language_scoped.Get()));
base::as_wcstr(base::AsStringPiece16(language_scoped.Get())), // ResolveLocaleName should only fail if buffer size insufficient, but
locale_name, LOCALE_NAME_MAX_LENGTH); // it can succeed yet return an empty string for certain language tags
// such as ht.
if (!::ResolveLocaleName(preferred_language, locale_name,
LOCALE_NAME_MAX_LENGTH) ||
!*locale_name) {
DVLOG(1) << "ResolveLocaleName failed or returned empty string for "
"preferred language "
<< preferred_language
<< ", will try unresolved language name.";
base::wcslcpy(locale_name, preferred_language, LOCALE_NAME_MAX_LENGTH);
}
// See if the language has a dictionary available. Some preferred // See if the language has a dictionary available. Some preferred
// languages have no spellchecking support (zh-CN e.g.). // languages have no spellchecking support (zh-CN e.g.).
BOOL is_language_supported = FALSE; BOOL is_language_supported = FALSE;
hr = spell_checker_factory_->IsSupported(locale_name, hr = spell_checker_factory_->IsSupported(locale_name,
&is_language_supported); &is_language_supported);
DCHECK(SUCCEEDED(hr)); DCHECK(SUCCEEDED(hr));
if (is_language_supported) if (is_language_supported) {
supported_languages.push_back(base::WideToUTF8(locale_name)); supported_languages.push_back(base::WideToUTF8(locale_name));
} else {
DVLOG(2) << "No platform spellchecking support for locale name "
<< locale_name;
}
} }
} }
......
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