summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/profile.cc')
-rw-r--r--chrome/browser/profile.cc80
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();
}