diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 07:04:07 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 07:04:07 +0000 |
commit | 2e7b6282c22188eb4406e9c08ca9a56bac01f047 (patch) | |
tree | 70f862c67c0b2b2850659f050929544e0ca33757 /chrome/common/notification_registrar.cc | |
parent | c984666719a722d4a3666068528cf35f2042d081 (diff) | |
download | chromium_src-2e7b6282c22188eb4406e9c08ca9a56bac01f047.zip chromium_src-2e7b6282c22188eb4406e9c08ca9a56bac01f047.tar.gz chromium_src-2e7b6282c22188eb4406e9c08ca9a56bac01f047.tar.bz2 |
Adding instrument to NotificationRegistrar to check
Add() and Remove() are called from same thread.
Note I already checked in a fix for the bug. The CL
is trying to check whether the issue exists in other
code path.
TEST=none
BUG=27834
Review URL: http://codereview.chromium.org/449044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33802 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/notification_registrar.cc')
-rw-r--r-- | chrome/common/notification_registrar.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/chrome/common/notification_registrar.cc b/chrome/common/notification_registrar.cc index 4da68ee..a124f0d 100644 --- a/chrome/common/notification_registrar.cc +++ b/chrome/common/notification_registrar.cc @@ -24,6 +24,11 @@ bool NotificationRegistrar::Record::operator==(const Record& other) const { } NotificationRegistrar::NotificationRegistrar() { + if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id_)) { + // If we are not created in well known thread, GetCurrentThreadIdentifier + // fails. Assign thread_id_ to an ID not used. + thread_id_ = ChromeThread::ID_COUNT; + } } NotificationRegistrar::~NotificationRegistrar() { @@ -38,6 +43,16 @@ void NotificationRegistrar::Add(NotificationObserver* observer, registered_.end()) << "Duplicate registration."; registered_.push_back(record); + if (ChromeThread::IsWellKnownThread(thread_id_)) { + if (!ChromeThread::CurrentlyOn(thread_id_)) { + // We are created on a well known thread, but this function is called + // on a different thread. This could be a bug, or maybe the object is + // passed around. + // To be safe, reset thread_id_ so we don't call CHECK during remove. + thread_id_ = ChromeThread::ID_COUNT; + } + } + NotificationService::current()->AddObserver(observer, type, source); } @@ -54,6 +69,8 @@ void NotificationRegistrar::Remove(NotificationObserver* observer, } registered_.erase(found); + CheckCalledOnValidWellKnownThread(); + // This can be NULL if our owner outlives the NotificationService, e.g. if our // owner is a Singleton. NotificationService* service = NotificationService::current(); @@ -71,6 +88,8 @@ void NotificationRegistrar::RemoveAll() { if (registered_.empty()) return; + CheckCalledOnValidWellKnownThread(); + // This can be NULL if our owner outlives the NotificationService, e.g. if our // owner is a Singleton. NotificationService* service = NotificationService::current(); @@ -87,3 +106,9 @@ void NotificationRegistrar::RemoveAll() { bool NotificationRegistrar::IsEmpty() const { return registered_.empty(); } + +void NotificationRegistrar::CheckCalledOnValidWellKnownThread() { + if (ChromeThread::IsWellKnownThread(thread_id_)) { + CHECK(ChromeThread::CurrentlyOn(thread_id_)); + } +} |