diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 03:05:46 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 03:05:46 +0000 |
commit | 85c55dcd717445cd3763b5c94f9902b4cdd194b0 (patch) | |
tree | 2deea721cfac202e3eb8556f66a4cf317a331288 /chrome/browser/profile.cc | |
parent | f1a8b962f0a6f1deb6c8c05a3f86d541e2ba61dd (diff) | |
download | chromium_src-85c55dcd717445cd3763b5c94f9902b4cdd194b0.zip chromium_src-85c55dcd717445cd3763b5c94f9902b4cdd194b0.tar.gz chromium_src-85c55dcd717445cd3763b5c94f9902b4cdd194b0.tar.bz2 |
Move the spellchecker to the renderer.
The motivation is that this removes the sync IPC on every call to the spellchecker. Also, currently we spellcheck in the IO thread, which frequently needs to go to disk (in particular, the entire spellcheck dictionary starts paged out), so this will block just the single renderer when that happens, rather than the whole IO thread.
This breaks the SpellChecker class into two new classes.
1) On the browser side, we have SpellCheckHost. This class handles browser-wide tasks, such as keeping the custom words list in sync with the on-disk custom words dictionary, downloading missing dictionaries, etc. On Posix, it also opens the bdic file since the renderer isn't allowed to open files. SpellCheckHost is created and destroyed on the UI thread. It is initialized on the file thread.
2) On the renderer side, SpellChecker2. This class will one day be renamed SpellChecker. It handles actual checking of the words, memory maps the dictionary file, loads hunspell, etc. There is one SpellChecker2 per RenderThread (hence one per render process).
My intention is for this patch to move Linux to this new approach, and follow up with ports for Windows (which will involve passing a dictionary file name rather than a file descriptor through to the renderer) and Mac (which will involve adding sync ViewHost IPC callsfor when the platform spellchecker is enabled). Note that anyone using the platform spellchecker rather than Hunspell will get no benefit out of this refactor.
There should be no loss of functionality for Linux (or any other platform) in this patch. The following should all still work:
- dictionary is loaded lazily
- hunspell is initialized lazily, per renderer
- language changes work.
- Dynamic downloading of new dictionaries
- auto spell correct works (as well as toggling it).
- disabling spellcheck works.
- custom words work (including adding in one renderer and immediately having it take effect in other renderers, for certain values of "immediate")
TODO:
- move spellchecker unit tests to test SpellCheck2
- add sync IPC for platform spellchecker; port to Mac
- add dictionary location fallback; port to Windows
- remove SpellChecker classes from browser/
BUG=25677
Review URL: http://codereview.chromium.org/357003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31199 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profile.cc')
-rw-r--r-- | chrome/browser/profile.cc | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 0402b57..9c182bb 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -483,6 +483,16 @@ class OffTheRecordProfileImpl : public Profile, profile_->DeleteSpellChecker(); } +#if defined(SPELLCHECKER_IN_RENDERER) + virtual SpellCheckHost* GetSpellCheckHost() { + return profile_->GetSpellCheckHost(); + } + + virtual void ReinitializeSpellCheckHost(bool force) { + profile_->ReinitializeSpellCheckHost(force); + } +#endif + virtual WebKitContext* GetWebKitContext() { if (!webkit_context_.get()) webkit_context_ = new WebKitContext(GetPath(), true); @@ -574,6 +584,10 @@ ProfileImpl::ProfileImpl(const FilePath& path) created_theme_provider_(false), start_time_(Time::Now()), spellchecker_(NULL), +#if defined(OS_LINUX) + spellcheck_host_(NULL), + spellcheck_host_ready_(false), +#endif shutdown_session_service_(false) { DCHECK(!path.empty()) << "Using an empty path will attempt to write " << "profile files to the root directory!"; @@ -745,6 +759,10 @@ ProfileImpl::~ProfileImpl() { if (history_service_.get()) history_service_->Cleanup(); +#if defined(SPELLCHECKER_IN_RENDERER) + if (spellcheck_host_.get()) + spellcheck_host_->UnsetObserver(); +#endif DeleteSpellCheckerImpl(false); if (default_request_context_ == request_context_) { @@ -1272,6 +1290,47 @@ void ProfileImpl::ReinitializeSpellChecker() { } } +#if defined(SPELLCHECKER_IN_RENDERER) +SpellCheckHost* ProfileImpl::GetSpellCheckHost() { + return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL; +} + +void ProfileImpl::ReinitializeSpellCheckHost(bool force) { + // If we are already loading the spellchecker, and this is just a hint to + // load the spellchecker, do nothing. + if (!force && spellcheck_host_.get()) + return; + + bool notify = false; + if (spellcheck_host_.get()) { + spellcheck_host_->UnsetObserver(); + spellcheck_host_.release(); + spellcheck_host_ready_ = false; + notify = true; + } + + PrefService* prefs = GetPrefs(); + if (prefs->GetBoolean(prefs::kEnableSpellCheck)) { + // Retrieve the (perhaps updated recently) dictionary name from preferences. + spellcheck_host_ = new SpellCheckHost(this, + WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)), + GetRequestContext()); + spellcheck_host_->AddRef(); + } else if (notify) { + // The spellchecker has been disabled. + SpellCheckHostInitialized(); + } +} + +void ProfileImpl::SpellCheckHostInitialized() { + spellcheck_host_ready_ = + spellcheck_host_ && spellcheck_host_->bdict_fd().fd != -1; + NotificationService::current()->Notify( + NotificationType::SPELLCHECK_HOST_REINITIALIZED, + Source<Profile>(this), NotificationService::NoDetails()); +} +#endif + void ProfileImpl::NotifySpellCheckerChanged() { SpellcheckerReinitializedDetails scoped_spellchecker; scoped_spellchecker.spellchecker = spellchecker_; @@ -1340,9 +1399,14 @@ void ProfileImpl::Observe(NotificationType type, PrefService* prefs = Source<PrefService>(source).ptr(); DCHECK(pref_name_in && prefs); if (*pref_name_in == prefs::kSpellCheckDictionary || - *pref_name_in == prefs::kEnableSpellCheck || - *pref_name_in == prefs::kEnableAutoSpellCorrect) { +#if !defined(SPELLCHECKER_IN_RENDERER) + *pref_name_in == prefs::kEnableAutoSpellCorrect || +#endif + *pref_name_in == prefs::kEnableSpellCheck) { ReinitializeSpellChecker(); +#if defined(SPELLCHECKER_IN_RENDERER) + ReinitializeSpellCheckHost(true); +#endif } } else if (NotificationType::THEME_INSTALLED == type) { Extension* extension = Details<Extension>(details).ptr(); |