summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-02 01:29:29 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-02 01:29:29 +0000
commite3448ea27e38817f78ea1a4678831fb507a6d1c9 (patch)
tree464ad655ff1f1cc52710cc971bb6a240789bd40e
parentd833fa2a5d20d413834b6db5a882142a6b7f965a (diff)
downloadchromium_src-e3448ea27e38817f78ea1a4678831fb507a6d1c9.zip
chromium_src-e3448ea27e38817f78ea1a4678831fb507a6d1c9.tar.gz
chromium_src-e3448ea27e38817f78ea1a4678831fb507a6d1c9.tar.bz2
Add Profile::DeleteSpellChecker(), which my MemoryPurger will use to purge the spellchecker objects from memory.
This reworks the SpellChecker management functions inside the ProfileImpl for simplicity. The only notable side effect is that GetSpellChecker() will now cause a notification if it inits |spellchecker_|, just like ReinitializeSpellChecker() already did. This was just to simplify the code; at the point this fires, no one will be listening yet, so it won't actually do anything. Also use a temporary at one spot in browser_render_process_host.cc instead of calling a heavyweight function twice in a row. BUG=23400 TEST=none Review URL: http://codereview.chromium.org/259009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27816 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_profile_impl.h5
-rw-r--r--chrome/browser/profile.cc81
-rw-r--r--chrome/browser/profile.h24
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc5
-rw-r--r--chrome/test/testing_profile.h1
5 files changed, 58 insertions, 58 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.h b/chrome/browser/automation/automation_profile_impl.h
index 22a41c8..797d94e 100644
--- a/chrome/browser/automation/automation_profile_impl.h
+++ b/chrome/browser/automation/automation_profile_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -187,6 +187,9 @@ class AutomationProfileImpl : public Profile {
virtual SpellChecker* GetSpellChecker() {
return original_profile_->GetSpellChecker();
}
+ virtual void DeleteSpellChecker() {
+ return original_profile_->DeleteSpellChecker();
+ }
virtual WebKitContext* GetWebKitContext() {
return original_profile_->GetWebKitContext();
}
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index f0dc61f..ebf96c7 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -477,6 +477,10 @@ class OffTheRecordProfileImpl : public Profile,
return profile_->GetSpellChecker();
}
+ virtual void DeleteSpellChecker() {
+ profile_->DeleteSpellChecker();
+ }
+
virtual WebKitContext* GetWebKitContext() {
if (!webkit_context_.get())
webkit_context_ = new WebKitContext(GetPath(), true);
@@ -754,17 +758,7 @@ ProfileImpl::~ProfileImpl() {
if (history_service_.get())
history_service_->Cleanup();
- // The I/O thread may be NULL during testing.
- base::Thread* io_thread = g_browser_process->io_thread();
-
- if (spellchecker_) {
- // The spellchecker must be deleted on the I/O thread. During testing, we
- // don't have an I/O thread.
- if (io_thread)
- io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
- else
- spellchecker_->Release();
- }
+ DeleteSpellCheckerImpl(false);
if (default_request_context_ == request_context_) {
#if defined(OS_LINUX)
@@ -1256,25 +1250,12 @@ class NotifySpellcheckerChangeTask : public Task {
SpellcheckerReinitializedDetails spellchecker_;
};
-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_) {
- // The spellchecker must be deleted on the I/O thread.
- // A dummy variable to aid in logical clarity.
- SpellChecker* last_spellchecker = spellchecker_;
-
- if (io_thread)
- io_thread->message_loop()->ReleaseSoon(FROM_HERE, last_spellchecker);
- else // during testing, we don't have an I/O thread
- last_spellchecker->Release();
- }
-
- // Retrieve the (perhaps updated recently) dictionary name from preferences.
+void ProfileImpl::ReinitializeSpellChecker() {
PrefService* prefs = GetPrefs();
- bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck);
+ if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
+ DeleteSpellCheckerImpl(false);
- if (enable_spellcheck) {
+ // Retrieve the (perhaps updated recently) dictionary name from preferences.
FilePath dict_dir;
PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
// Note that, as the object pointed to by previously by spellchecker_
@@ -1285,29 +1266,43 @@ void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
GetRequestContext(),
FilePath());
spellchecker_->AddRef(); // Manual refcounting.
- } else {
- spellchecker_ = NULL;
- }
- // Set auto spell correct status for spellchecker.
- if (spellchecker_) {
+ // Set auto spell correct status for spellchecker.
spellchecker_->EnableAutoSpellCorrect(
prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
+
+ NotifySpellCheckerChanged();
+ } else {
+ DeleteSpellCheckerImpl(true);
}
+}
- if (need_to_broadcast && io_thread) { // Notify resource message filters.
+void ProfileImpl::NotifySpellCheckerChanged() {
+ // The I/O thread may be NULL during testing.
+ base::Thread* io_thread = g_browser_process->io_thread();
+ if (io_thread) { // Notify resource message filters.
SpellcheckerReinitializedDetails scoped_spellchecker;
scoped_spellchecker.spellchecker = spellchecker_;
- if (io_thread) {
- io_thread->message_loop()->PostTask(
- FROM_HERE,
- new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
- }
+ io_thread->message_loop()->PostTask(FROM_HERE,
+ new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
}
}
-void ProfileImpl::ReinitializeSpellChecker() {
- InitializeSpellChecker(true);
+void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
+ if (spellchecker_) {
+ // The spellchecker must be deleted on the I/O thread.
+ // The I/O thread may be NULL during testing.
+ base::Thread* io_thread = g_browser_process->io_thread();
+ if (io_thread)
+ io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
+ else // during testing, we don't have an I/O thread
+ spellchecker_->Release();
+
+ spellchecker_ = NULL;
+
+ if (notify)
+ NotifySpellCheckerChanged();
+ }
}
SpellChecker* ProfileImpl::GetSpellChecker() {
@@ -1317,7 +1312,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(false);
+ ReinitializeSpellChecker();
}
return spellchecker_;
@@ -1351,7 +1346,7 @@ void ProfileImpl::Observe(NotificationType type,
if (*pref_name_in == prefs::kSpellCheckDictionary ||
*pref_name_in == prefs::kEnableSpellCheck ||
*pref_name_in == prefs::kEnableAutoSpellCorrect) {
- InitializeSpellChecker(true);
+ ReinitializeSpellChecker();
}
} else if (NotificationType::THEME_INSTALLED == type) {
Extension* extension = Details<Extension>(details).ptr();
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 675c6aa..a2f055f 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -313,7 +313,8 @@ class Profile {
virtual void ResetTabRestoreService() = 0;
// This reinitializes the spellchecker according to the current dictionary
- // language, and enable spell check option, in the prefs.
+ // language, and enable spell check option, in the prefs. Then a
+ // SPELLCHECKER_REINITIALIZED notification is sent on the IO thread.
virtual void ReinitializeSpellChecker() = 0;
// Returns the spell checker object for this profile. THIS OBJECT MUST ONLY
@@ -321,6 +322,10 @@ class Profile {
// sent to the I/O thread where it is actually used.
virtual SpellChecker* GetSpellChecker() = 0;
+ // Deletes the spellchecker. This is only really useful when we need to purge
+ // memory.
+ virtual void DeleteSpellChecker() = 0;
+
// Returns the WebKitContext assigned to this profile.
virtual WebKitContext* GetWebKitContext() = 0;
@@ -416,6 +421,7 @@ class ProfileImpl : public Profile,
virtual void ResetTabRestoreService();
virtual void ReinitializeSpellChecker();
virtual SpellChecker* GetSpellChecker();
+ virtual void DeleteSpellChecker() { DeleteSpellCheckerImpl(true); }
virtual WebKitContext* GetWebKitContext();
virtual void MarkAsCleanShutdown();
virtual void InitExtensions();
@@ -448,14 +454,8 @@ class ProfileImpl : public Profile,
GetSessionService();
}
- // Initializes the spellchecker. If the spellchecker already exsts, then
- // it is released, and initialized again. This model makes sure that
- // spellchecker language can be changed without restarting the browser.
- // NOTE: This is being currently called in the UI thread, which is OK as long
- // as the spellchecker object is USED in the IO thread.
- // The |need_to_broadcast| parameter tells it whether to broadcast the new
- // spellchecker to the resource message filters.
- void InitializeSpellChecker(bool need_to_broadcast);
+ void NotifySpellCheckerChanged();
+ void DeleteSpellCheckerImpl(bool notify);
NotificationRegistrar registrar_;
@@ -551,8 +551,8 @@ struct hash<Profile*> {
#endif
// This struct is used to pass the spellchecker object through the notification
-// NOTIFY_SPELLCHECKER_REINITIALIZED. This is used as the details for the
-// notification service.
+// SPELLCHECKER_REINITIALIZED. This is used as the details for the notification
+// service.
struct SpellcheckerReinitializedDetails {
scoped_refptr<SpellChecker> spellchecker;
};
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 2fbf4bf..068cda8 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -401,9 +401,10 @@ void BrowserRenderProcessHost::WidgetHidden() {
void BrowserRenderProcessHost::AddWord(const std::wstring& word) {
base::Thread* io_thread = g_browser_process->io_thread();
- if (profile()->GetSpellChecker()) {
+ SpellChecker* spellchecker = profile()->GetSpellChecker();
+ if (spellchecker) {
io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- profile()->GetSpellChecker(), &SpellChecker::AddWord, word));
+ spellchecker, &SpellChecker::AddWord, word));
}
}
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 0b80dec..14c31443 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -160,6 +160,7 @@ class TestingProfile : public Profile {
virtual void ResetTabRestoreService() {}
virtual void ReinitializeSpellChecker() {}
virtual SpellChecker* GetSpellChecker() { return NULL; }
+ virtual void DeleteSpellChecker() {}
virtual WebKitContext* GetWebKitContext() { return NULL; }
virtual WebKitContext* GetOffTheRecordWebKitContext() { return NULL; }
virtual void MarkAsCleanShutdown() {}