Commit 3184365a authored by Bruce Long's avatar Bruce Long Committed by Commit Bot

Windows Spellcheck: Add flag to delay spellcheck service initialization

As a step towards improving spellcheck initialization performance,
with the ultimate goal of not loading the Windows spellcheck platform
DLLs until needed (e.g. when actually performing a spellcheck), this
CL adds a new feature flag allowing the initialization of the
spellcheck service on browser startup to be prevented. This should
allow addressing the rest of the performance issue in stages.

Since Chromium already by default initializes the spellcheck service
on startup for custom dictionary synchronization, the command line
for launching the browser with Windows hybrid spellchecking enabled
but no initialization of the spellcheck service is:

chrome --enable-features=
WinUseBrowserSpellChecker,WinDelaySpellcheckServiceInit
--disable-sync-types="Dictionary"

Downstream Edge has Windows spellcheck enabled by default and does
not perform a custom dictionary sync, so the corresponding command
line for Edge is:

msEdge --enable-features=WinDelaySpellcheckServiceInit

Bug: 1064351
Change-Id: I91559193918cce6895133a9e9c440513b55fdd65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227450Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarGuillaume Jenkins <gujen@google.com>
Commit-Queue: Bruce Long <brlong@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#774710}
parent 1c6dea7e
...@@ -1357,7 +1357,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -1357,7 +1357,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// Windows platform spellcheck dictionary language tags used to populate the // Windows platform spellcheck dictionary language tags used to populate the
// context menu for editable content. // context menu for editable content.
if (spellcheck::UseWinHybridSpellChecker() && if (spellcheck::UseWinHybridSpellChecker() &&
profile_->GetPrefs()->GetBoolean(spellcheck::prefs::kSpellCheckEnable)) { profile_->GetPrefs()->GetBoolean(spellcheck::prefs::kSpellCheckEnable) &&
!base::FeatureList::IsEnabled(
spellcheck::kWinDelaySpellcheckServiceInit)) {
SpellcheckServiceFactory::GetForContext(profile_); SpellcheckServiceFactory::GetForContext(profile_);
} }
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
......
...@@ -43,6 +43,8 @@ class SpellcheckServiceFactory : public BrowserContextKeyedServiceFactory { ...@@ -43,6 +43,8 @@ class SpellcheckServiceFactory : public BrowserContextKeyedServiceFactory {
#if defined(OS_WIN) #if defined(OS_WIN)
FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceWindowsHybridBrowserTest, FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceWindowsHybridBrowserTest,
WindowsHybridSpellcheck); WindowsHybridSpellcheck);
FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceWindowsHybridBrowserTestDelayInit,
WindowsHybridSpellcheckDelayInit);
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
DISALLOW_COPY_AND_ASSIGN(SpellcheckServiceFactory); DISALLOW_COPY_AND_ASSIGN(SpellcheckServiceFactory);
......
...@@ -666,4 +666,36 @@ IN_PROC_BROWSER_TEST_F(SpellcheckServiceWindowsHybridBrowserTest, ...@@ -666,4 +666,36 @@ IN_PROC_BROWSER_TEST_F(SpellcheckServiceWindowsHybridBrowserTest,
// include Windows spellcheck languages that lack Hunspell support. // include Windows spellcheck languages that lack Hunspell support.
ASSERT_FALSE(service->windows_spellcheck_dictionary_map_.empty()); ASSERT_FALSE(service->windows_spellcheck_dictionary_map_.empty());
} }
class SpellcheckServiceWindowsHybridBrowserTestDelayInit
: public SpellcheckServiceBrowserTest {
public:
SpellcheckServiceWindowsHybridBrowserTestDelayInit() = default;
void SetUp() override {
// Don't initialize the SpellcheckService on browser launch.
feature_list_.InitWithFeatures(
/*enabled_features=*/{spellcheck::kWinUseBrowserSpellChecker,
spellcheck::kWinDelaySpellcheckServiceInit},
/*disabled_features=*/{});
InProcessBrowserTest::SetUp();
}
};
IN_PROC_BROWSER_TEST_F(SpellcheckServiceWindowsHybridBrowserTestDelayInit,
WindowsHybridSpellcheckDelayInit) {
if (!spellcheck::WindowsVersionSupportsSpellchecker())
return;
ASSERT_TRUE(spellcheck::UseBrowserSpellChecker());
// Note that the base class forces dictionary sync to not be performed, and
// the kWinDelaySpellcheckServiceInit flag is set, which together should
// prevent creation of a SpellcheckService object on browser startup. So
// testing here that this is indeed the case.
SpellcheckService* service = static_cast<SpellcheckService*>(
SpellcheckServiceFactory::GetInstance()->GetServiceForBrowserContext(
GetContext(), /* create */ false));
ASSERT_EQ(nullptr, service);
}
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
...@@ -33,6 +33,9 @@ bool UseBrowserSpellChecker() { ...@@ -33,6 +33,9 @@ bool UseBrowserSpellChecker() {
const base::Feature kWinUseBrowserSpellChecker{ const base::Feature kWinUseBrowserSpellChecker{
"WinUseBrowserSpellChecker", base::FEATURE_DISABLED_BY_DEFAULT}; "WinUseBrowserSpellChecker", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kWinDelaySpellcheckServiceInit{
"WinDelaySpellcheckServiceInit", base::FEATURE_DISABLED_BY_DEFAULT};
bool WindowsVersionSupportsSpellchecker() { bool WindowsVersionSupportsSpellchecker() {
return base::win::GetVersion() > base::win::Version::WIN7 && return base::win::GetVersion() > base::win::Version::WIN7 &&
base::win::GetVersion() < base::win::Version::WIN_LAST; base::win::GetVersion() < base::win::Version::WIN_LAST;
......
...@@ -22,6 +22,16 @@ bool UseBrowserSpellChecker(); ...@@ -22,6 +22,16 @@ bool UseBrowserSpellChecker();
#if defined(OS_WIN) #if defined(OS_WIN)
extern const base::Feature kWinUseBrowserSpellChecker; extern const base::Feature kWinUseBrowserSpellChecker;
// If enabled, don't initialize the SpellcheckService on browser launch.
// Since Chromium already by default initializes the spellcheck service
// on startup for custom dictionary synchronization, the command line
// for launching the browser with Windows hybrid spellchecking enabled
// but no initialization of the spellcheck service is:
// chrome
// --enable-features=WinUseBrowserSpellChecker,WinDelaySpellcheckServiceInit
// --disable-sync-types="Dictionary"
extern const base::Feature kWinDelaySpellcheckServiceInit;
bool WindowsVersionSupportsSpellchecker(); bool WindowsVersionSupportsSpellchecker();
bool UseWinHybridSpellChecker(); bool UseWinHybridSpellChecker();
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
......
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