summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 23:12:52 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 23:12:52 +0000
commit5658a60a850150c146906932f302bbf0cf8b9684 (patch)
tree184d74b274283eaf81550639c4fe9f4d0361d8b2
parent79084c2d01586797f762cbb308cb2c204dd9a164 (diff)
downloadchromium_src-5658a60a850150c146906932f302bbf0cf8b9684.zip
chromium_src-5658a60a850150c146906932f302bbf0cf8b9684.tar.gz
chromium_src-5658a60a850150c146906932f302bbf0cf8b9684.tar.bz2
Use ChromeThread::DeleteOnIOThread in a few places where an object must be deleted on a certain thread.
BUG=25354 Review URL: http://codereview.chromium.org/342090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30882 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/audio_renderer_host.cc17
-rw-r--r--chrome/browser/renderer_host/audio_renderer_host.h11
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.cc36
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.h4
-rw-r--r--chrome/browser/renderer_host/resource_handler.h5
-rw-r--r--chrome/browser/spellchecker.cc18
-rw-r--r--chrome/browser/spellchecker.h8
7 files changed, 36 insertions, 63 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.cc b/chrome/browser/renderer_host/audio_renderer_host.cc
index 0fb3fe8..7ea64e7 100644
--- a/chrome/browser/renderer_host/audio_renderer_host.cc
+++ b/chrome/browser/renderer_host/audio_renderer_host.cc
@@ -25,7 +25,6 @@
#include "base/process.h"
#include "base/shared_memory.h"
#include "base/waitable_event.h"
-#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/renderer_host/audio_renderer_host.h"
#include "chrome/common/render_messages.h"
#include "ipc/ipc_logging.h"
@@ -335,14 +334,13 @@ AudioRendererHost::AudioRendererHost()
: process_id_(0),
process_handle_(0),
ipc_sender_(NULL) {
- // Make sure we perform actual initialization operations in the thread where
- // this object should live.
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this, &AudioRendererHost::OnInitialized));
+ // Increase the ref count of this object so it is active until we do
+ // Release().
+ AddRef();
}
AudioRendererHost::~AudioRendererHost() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(sources_.empty());
}
@@ -498,13 +496,6 @@ void AudioRendererHost::OnNotifyPacketReady(const IPC::Message& msg,
}
}
-void AudioRendererHost::OnInitialized() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- // Increase the ref count of this object so it is active until we do
- // Release().
- AddRef();
-}
-
void AudioRendererHost::OnDestroyed() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
ipc_sender_ = NULL;
diff --git a/chrome/browser/renderer_host/audio_renderer_host.h b/chrome/browser/renderer_host/audio_renderer_host.h
index 1a3b6e5..a1549dd 100644
--- a/chrome/browser/renderer_host/audio_renderer_host.h
+++ b/chrome/browser/renderer_host/audio_renderer_host.h
@@ -74,6 +74,7 @@
#include "base/ref_counted.h"
#include "base/shared_memory.h"
#include "base/waitable_event.h"
+#include "chrome/browser/chrome_thread.h"
#include "ipc/ipc_message.h"
#include "media/audio/audio_output.h"
#include "media/audio/simple_sources.h"
@@ -82,15 +83,16 @@
class AudioManager;
struct ViewHostMsg_Audio_CreateStream;
-class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> {
+class AudioRendererHost
+ : public base::RefCountedThreadSafe<
+ AudioRendererHost, ChromeThread::DeleteOnIOThread> {
private:
class IPCAudioSource;
public:
// Called from UI thread from the owner of this object.
AudioRendererHost();
- // Destruction can happen on either UI thread or IO thread, but at destruction
- // all associated sources are destroyed and streams are closed.
+ // Destruction always happens on the IO thread (see DeleteOnIOThread above).
virtual ~AudioRendererHost();
// Called from UI thread from the owner of this object to kick start
@@ -315,9 +317,6 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> {
void OnNotifyPacketReady(const IPC::Message& msg, int stream_id,
size_t packet_size);
- // Called on IO thread when this object is created and initialized.
- void OnInitialized();
-
// Called on IO thread when this object needs to be destroyed and after
// Destroy() is called from owner of this class in UI thread.
void OnDestroyed();
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc
index 33e6489..6022e1f 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.cc
+++ b/chrome/browser/renderer_host/buffered_resource_handler.cc
@@ -9,7 +9,6 @@
#include "base/histogram.h"
#include "base/logging.h"
#include "base/string_util.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/renderer_host/download_throttling_resource_handler.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
@@ -396,15 +395,9 @@ bool BufferedResourceHandler::ShouldWaitForPlugins() {
host_->PauseRequest(info->child_id(), info->request_id(), true);
// Schedule plugin loading on the file thread.
- // Note: it's possible that the only reference to this object is the task. If
- // If the task executes on the file thread, and before it returns, the task it
- // posts to the IO thread runs, then this object will get destructed on the
- // file thread. This breaks assumptions in other message handlers (i.e. when
- // unregistering with NotificationService in the destructor).
- AddRef();
ChromeThread::PostTask(
ChromeThread::FILE, FROM_HERE,
- NewRunnableFunction(&BufferedResourceHandler::LoadPlugins, this));
+ NewRunnableMethod(this, &BufferedResourceHandler::LoadPlugins));
return true;
}
@@ -468,26 +461,23 @@ bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) {
GURL(), type, allow_wildcard, &info, NULL);
}
-void BufferedResourceHandler::LoadPlugins(BufferedResourceHandler* handler) {
+void BufferedResourceHandler::LoadPlugins() {
std::vector<WebPluginInfo> plugins;
NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE,
- NewRunnableFunction(&BufferedResourceHandler::OnPluginsLoaded,
- handler));
+ NewRunnableMethod(this, &BufferedResourceHandler::OnPluginsLoaded));
}
-void BufferedResourceHandler::OnPluginsLoaded(
- BufferedResourceHandler* handler) {
- handler->wait_for_plugins_ = false;
- if (handler->request_) {
- ResourceDispatcherHostRequestInfo* info =
- ResourceDispatcherHost::InfoForRequest(handler->request_);
- handler->host_->PauseRequest(info->child_id(), info->request_id(), false);
- if (!handler->CompleteResponseStarted(info->request_id(), false))
- handler->host_->CancelRequest(
- info->child_id(), info->request_id(), false);
- }
- handler->Release();
+void BufferedResourceHandler::OnPluginsLoaded() {
+ wait_for_plugins_ = false;
+ if (!request_)
+ return;
+
+ ResourceDispatcherHostRequestInfo* info =
+ ResourceDispatcherHost::InfoForRequest(request_);
+ host_->PauseRequest(info->child_id(), info->request_id(), false);
+ if (!CompleteResponseStarted(info->request_id(), false))
+ host_->CancelRequest(info->child_id(), info->request_id(), false);
}
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.h b/chrome/browser/renderer_host/buffered_resource_handler.h
index fa0e249..52608cc 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.h
+++ b/chrome/browser/renderer_host/buffered_resource_handler.h
@@ -62,10 +62,10 @@ class BufferedResourceHandler : public ResourceHandler {
bool ShouldDownload(bool* need_plugin_list);
// Called on the file thread to load the list of plugins.
- static void LoadPlugins(BufferedResourceHandler* handler);
+ void LoadPlugins();
// Called on the IO thread once the list of plugins has been loaded.
- static void OnPluginsLoaded(BufferedResourceHandler* handler);
+ void OnPluginsLoaded();
scoped_refptr<ResourceHandler> real_handler_;
scoped_refptr<ResourceResponse> response_;
diff --git a/chrome/browser/renderer_host/resource_handler.h b/chrome/browser/renderer_host/resource_handler.h
index 39a85fa..f4fe726 100644
--- a/chrome/browser/renderer_host/resource_handler.h
+++ b/chrome/browser/renderer_host/resource_handler.h
@@ -14,6 +14,7 @@
#include <string>
+#include "chrome/browser/chrome_thread.h"
#include "chrome/common/filter_policy.h"
#include "net/url_request/url_request_status.h"
#include "webkit/glue/resource_loader_bridge.h"
@@ -52,7 +53,9 @@ struct ResourceResponse : public base::RefCounted<ResourceResponse> {
// The resource dispatcher host uses this interface to push load events to the
// renderer, allowing for differences in the types of IPC messages generated.
// See the implementations of this interface defined below.
-class ResourceHandler : public base::RefCountedThreadSafe<ResourceHandler> {
+class ResourceHandler
+ : public base::RefCountedThreadSafe<
+ ResourceHandler, ChromeThread::DeleteOnIOThread> {
public:
virtual ~ResourceHandler() {}
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 11142d0..856deac 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -13,7 +13,6 @@
#include "base/path_service.h"
#include "base/stats_counters.h"
#include "base/string_util.h"
-#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_fetcher.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/spellchecker_common.h"
@@ -221,15 +220,12 @@ class ReadDictionaryTask : public Task {
ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE,
NewRunnableMethod(
- spellchecker_, &SpellChecker::HunspellInited, hunspell_,
+ spellchecker_.get(), &SpellChecker::HunspellInited, hunspell_,
bdict_file_, file_existed));
}
- // The SpellChecker we are working for. We are guaranteed to be outlived
- // by this object because it AddRefs() itself before calling us.
- // Accessing it is not necessarily thread safe, but are careful to only access
- // it in ways that are.
- SpellChecker* spellchecker_;
+ // The SpellChecker we are working for.
+ scoped_refptr<SpellChecker> spellchecker_;
Hunspell* hunspell_;
file_util::MemoryMappedFile* bdict_file_;
@@ -537,8 +533,6 @@ bool SpellChecker::Initialize() {
FilePath dictionary_file_name_usr = GetVersionedFileName(language_,
dict_dir_userdata);
- // Balances Release() in HunspellInited().
- AddRef();
ChromeThread::PostTask(
ChromeThread::FILE, FROM_HERE,
new ReadDictionaryTask(
@@ -560,9 +554,6 @@ void SpellChecker::HunspellInited(Hunspell* hunspell,
// File didn't exist. We need to download a dictionary.
DoDictionaryDownload();
}
-
- // Balances AddRef() in Initialize().
- Release();
return;
}
@@ -574,9 +565,6 @@ void SpellChecker::HunspellInited(Hunspell* hunspell,
hunspell_->add(custom_words_.front().c_str());
custom_words_.pop();
}
-
- // Balances AddRef() in Initialize().
- Release();
}
void SpellChecker::DoDictionaryDownload() {
diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h
index 26315d8..303956c 100644
--- a/chrome/browser/spellchecker.h
+++ b/chrome/browser/spellchecker.h
@@ -13,7 +13,7 @@
#include "base/string16.h"
#include "base/task.h"
#include "base/time.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_fetcher.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/spellcheck_worditerator.h"
@@ -42,8 +42,10 @@ class MemoryMappedFile;
// This object should also be deleted on the I/O thread only. It owns a
// reference to URLRequestContext which in turn owns the cache, etc. and must be
// deleted on the I/O thread itself.
-class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>,
- public URLFetcher::Delegate {
+class SpellChecker
+ : public base::RefCountedThreadSafe<
+ SpellChecker, ChromeThread::DeleteOnIOThread>,
+ public URLFetcher::Delegate {
public:
// Creates the spellchecker by reading dictionaries from the given directory,
// and defaulting to the given language. Both strings must be provided.