diff options
author | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-29 18:13:26 +0000 |
---|---|---|
committer | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-29 18:13:26 +0000 |
commit | e7244d88820ab2a18760c14f12c4bdb060d72114 (patch) | |
tree | f4ce1cd6be60c8a41a52f0607aa4721238db0f91 /chrome/browser/profile.cc | |
parent | 83b7bd304b48a7ec5f3532602c810bff6070e3d2 (diff) | |
download | chromium_src-e7244d88820ab2a18760c14f12c4bdb060d72114.zip chromium_src-e7244d88820ab2a18760c14f12c4bdb060d72114.tar.gz chromium_src-e7244d88820ab2a18760c14f12c4bdb060d72114.tar.bz2 |
Add option to disable/enable Spell Check. In addition, remove additional code in resource message filter, which was initilaizing spellchecker in the filter if it was NULL. This part of the code is not required since the resource message filter should not initialize spellchecker; it is up to the profile to give the spellchecker to the resource message filter.
Issue = 120
Review URL: http://codereview.chromium.org/7935
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4140 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profile.cc')
-rw-r--r-- | chrome/browser/profile.cc | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index a81cdd8..1890b1e 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -12,6 +12,7 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/values.h" +#include "chrome/app/locales/locale_settings.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" @@ -57,6 +58,9 @@ void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); + prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, + IDS_SPELLCHECK_DICTIONARY); + prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true); } //static @@ -489,11 +493,11 @@ class OffTheRecordProfileImpl : public Profile, return NULL; } - virtual void InitializeSpellChecker() { - profile_->InitializeSpellChecker(); + virtual void ResetTabRestoreService() { } - virtual void ResetTabRestoreService() { + virtual void ReinitializeSpellChecker() { + profile_->ReinitializeSpellChecker(); } virtual SpellChecker* GetSpellChecker() { @@ -558,6 +562,9 @@ ProfileImpl::ProfileImpl(const std::wstring& path) create_session_service_timer_.Start( TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, &ProfileImpl::EnsureSessionServiceCreated); + PrefService* prefs = GetPrefs(); + prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); + prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); } ProfileImpl::~ProfileImpl() { @@ -573,6 +580,11 @@ ProfileImpl::~ProfileImpl() { // before the history is shutdown so it can properly cancel all requests. download_manager_ = NULL; + // Remove pref observers. + PrefService* prefs = GetPrefs(); + prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this); + prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this); + #ifdef CHROME_PERSONALIZATION personalization_.reset(); #endif @@ -869,7 +881,8 @@ void ProfileImpl::ResetTabRestoreService() { class NotifySpellcheckerChangeTask : public Task { public: NotifySpellcheckerChangeTask( - Profile* profile, const SpellcheckerReinitializedDetails& spellchecker) + Profile* profile, + const SpellcheckerReinitializedDetails& spellchecker) : profile_(profile), spellchecker_(spellchecker) { } @@ -886,9 +899,7 @@ class NotifySpellcheckerChangeTask : public Task { SpellcheckerReinitializedDetails spellchecker_; }; -void ProfileImpl::InitializeSpellChecker() { - bool need_to_broadcast = false; - +void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) { // The I/O thread may be NULL during testing. base::Thread* io_thread = g_browser_process->io_thread(); if (spellchecker_) { @@ -900,33 +911,42 @@ void ProfileImpl::InitializeSpellChecker() { io_thread->message_loop()->ReleaseSoon(FROM_HERE, last_spellchecker); else // during testing, we don't have an I/O thread last_spellchecker->Release(); - - need_to_broadcast = true; } - std::wstring dict_dir; - PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); - // Retrieve the (perhaps updated recently) dictionary name from preferences. PrefService* prefs = GetPrefs(); - std::wstring language = prefs->GetString(prefs::kSpellCheckDictionary); + bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck); - // Note that, as the object pointed to by previously by spellchecker_ - // is being deleted in the io thread, the spellchecker_ can be made to point - // to a new object (RE-initialized) in parallel in this UI thread. - spellchecker_ = new SpellChecker(dict_dir, language, GetRequestContext(), - L""); - spellchecker_->AddRef(); // Manual refcounting. + if (enable_spellcheck) { + std::wstring dict_dir; + PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); + std::wstring language = prefs->GetString(prefs::kSpellCheckDictionary); + + // Note that, as the object pointed to by previously by spellchecker_ + // is being deleted in the io thread, the spellchecker_ can be made to point + // to a new object (RE-initialized) in parallel in this UI thread. + spellchecker_ = new SpellChecker(dict_dir, language, GetRequestContext(), + L""); + spellchecker_->AddRef(); // Manual refcounting. + } else { + spellchecker_ = NULL; + } if (need_to_broadcast && io_thread) { // Notify resource message filters. SpellcheckerReinitializedDetails scoped_spellchecker; scoped_spellchecker.spellchecker = spellchecker_; - io_thread->message_loop()->PostTask( - FROM_HERE, - new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); + if (io_thread) { + io_thread->message_loop()->PostTask( + FROM_HERE, + new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); + } } } +void ProfileImpl::ReinitializeSpellChecker() { + InitializeSpellChecker(true); +} + SpellChecker* ProfileImpl::GetSpellChecker() { if (!spellchecker_) { // This is where spellchecker gets initialized. Note that this is being @@ -934,7 +954,7 @@ SpellChecker* ProfileImpl::GetSpellChecker() { // it is *used* in the io thread. // TODO (sidchat) One day, change everything so that spellchecker gets // initialized in the IO thread itself. - InitializeSpellChecker(); + InitializeSpellChecker(false); } return spellchecker_; @@ -951,6 +971,20 @@ void ProfileImpl::MarkAsCleanShutdown() { } } +void ProfileImpl::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (NOTIFY_PREF_CHANGED == type) { + std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); + PrefService* prefs = Source<PrefService>(source).ptr(); + DCHECK(pref_name_in && prefs); + if (*pref_name_in == prefs::kSpellCheckDictionary || + *pref_name_in == prefs::kEnableSpellCheck) { + InitializeSpellChecker(true); + } + } +} + void ProfileImpl::StopCreateSessionServiceTimer() { create_session_service_timer_.Stop(); } |