Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2690)

Unified Diff: chrome/common/notification_registrar.cc

Issue 449044: Adding instrument to NotificationRegistrar to check... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/notification_registrar.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/notification_registrar.cc
===================================================================
--- chrome/common/notification_registrar.cc (revision 33330)
+++ chrome/common/notification_registrar.cc (working copy)
@@ -24,6 +24,11 @@
}
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 @@
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 @@
}
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 @@
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 @@
bool NotificationRegistrar::IsEmpty() const {
return registered_.empty();
}
+
+void NotificationRegistrar::CheckCalledOnValidWellKnownThread() {
+ if (ChromeThread::IsWellKnownThread(thread_id_)) {
+ CHECK(ChromeThread::CurrentlyOn(thread_id_));
+ }
+}
« no previous file with comments | « chrome/common/notification_registrar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698