summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 06:59:33 +0000
committerhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 06:59:33 +0000
commit303e8f00bec846e87a34e9a3e00f0947ae33a584 (patch)
tree58638382ffed902f6f4fe1d7728516ee830b6793 /chrome/browser
parent61e9572d1eeadfd4eb8326515fa73e3826de3111 (diff)
downloadchromium_src-303e8f00bec846e87a34e9a3e00f0947ae33a584.zip
chromium_src-303e8f00bec846e87a34e9a3e00f0947ae33a584.tar.gz
chromium_src-303e8f00bec846e87a34e9a3e00f0947ae33a584.tar.bz2
Fixing 27834 by always deleting ExtensionMessageService on
UI thread. BUG=27834 TEST=none Review URL: http://codereview.chromium.org/440012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_message_service.cc14
-rw-r--r--chrome/browser/extensions/extension_message_service.h10
2 files changed, 18 insertions, 6 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index 9058aee..ae43bd6 100644
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -115,6 +115,11 @@ ExtensionMessageService::ExtensionMessageService(Profile* profile)
: profile_(profile),
extension_devtools_manager_(NULL),
next_port_id_(0) {
+ if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id_)) {
+ // If we get created in unit test, GetCurrentThreadIdentifier fails.
+ // Assign thread_id_ to an ID not used.
+ thread_id_ = ChromeThread::ID_COUNT;
+ }
registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED,
NotificationService::AllSources());
registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED,
@@ -132,10 +137,11 @@ ExtensionMessageService::~ExtensionMessageService() {
void ExtensionMessageService::ProfileDestroyed() {
profile_ = NULL;
-
- // We remove notifications here because our destructor might be called on
- // a non-UI thread.
- registrar_.RemoveAll();
+ if (!registrar_.IsEmpty()) {
+ if (thread_id_ != ChromeThread::ID_COUNT)
+ CHECK(ChromeThread::CurrentlyOn(thread_id_));
+ registrar_.RemoveAll();
+ }
}
void ExtensionMessageService::AddEventListener(const std::string& event_name,
diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h
index bdd1187..a4c6037 100644
--- a/chrome/browser/extensions/extension_message_service.h
+++ b/chrome/browser/extensions/extension_message_service.h
@@ -12,6 +12,7 @@
#include "base/lock.h"
#include "base/ref_counted.h"
#include "chrome/common/notification_registrar.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension_devtools_manager.h"
#include "ipc/ipc_message.h"
@@ -44,7 +45,8 @@ class URLRequestContext;
// case that the port is a tab). The Sender is usually either a
// RenderProcessHost or a RenderViewHost.
class ExtensionMessageService
- : public base::RefCountedThreadSafe<ExtensionMessageService>,
+ : public base::RefCountedThreadSafe<
+ ExtensionMessageService, ChromeThread::DeleteOnUIThread>,
public NotificationObserver {
public:
// Javascript function name constants.
@@ -127,7 +129,8 @@ class ExtensionMessageService
ResourceMessageFilter* source);
private:
- friend class base::RefCountedThreadSafe<ExtensionMessageService>;
+ friend class ChromeThread;
+ friend class DeleteTask<ExtensionMessageService>;
// A map of channel ID to its channel object.
typedef std::map<int, MessageChannel*> MessageChannelMap;
@@ -195,6 +198,9 @@ class ExtensionMessageService
// used on the IO thread or the UI thread.
Lock next_port_id_lock_;
+ // The thread creating this object. Should be UI thread.
+ ChromeThread::ID thread_id_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService);
};