OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/notification_service.h" | 5 #include "chrome/common/notification_service.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/thread_local.h" | 8 #include "base/thread_local.h" |
9 | 9 |
10 static base::LazyInstance<base::ThreadLocalPointer<NotificationService> > | 10 static base::LazyInstance<base::ThreadLocalPointer<NotificationService> > |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 observer_list->AddObserver(observer); | 53 observer_list->AddObserver(observer); |
54 #ifndef NDEBUG | 54 #ifndef NDEBUG |
55 ++observer_counts_[type.value]; | 55 ++observer_counts_[type.value]; |
56 #endif | 56 #endif |
57 } | 57 } |
58 | 58 |
59 void NotificationService::RemoveObserver(NotificationObserver* observer, | 59 void NotificationService::RemoveObserver(NotificationObserver* observer, |
60 NotificationType type, | 60 NotificationType type, |
61 const NotificationSource& source) { | 61 const NotificationSource& source) { |
62 DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT); | 62 DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT); |
63 DCHECK(HasKey(observers_[type.value], source)); | 63 |
| 64 // This is a very serious bug. An object is most likely being deleted on |
| 65 // the wrong thread, and as a result another thread's NotificationService |
| 66 // has its deleted pointer in its map. A garbge object will be called in the |
| 67 // future. |
| 68 // NOTE: when this check shows crashes, use ChromeThread::DeleteOnIOThread or |
| 69 // other variants as the trait on the object. |
| 70 CHECK(HasKey(observers_[type.value], source)); |
64 | 71 |
65 NotificationObserverList* observer_list = | 72 NotificationObserverList* observer_list = |
66 observers_[type.value][source.map_key()]; | 73 observers_[type.value][source.map_key()]; |
67 if (observer_list) { | 74 if (observer_list) { |
68 observer_list->RemoveObserver(observer); | 75 observer_list->RemoveObserver(observer); |
69 #ifndef NDEBUG | 76 #ifndef NDEBUG |
70 --observer_counts_[type.value]; | 77 --observer_counts_[type.value]; |
71 #endif | 78 #endif |
72 } | 79 } |
73 | 80 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) { | 141 for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) { |
135 NotificationSourceMap omap = observers_[i]; | 142 NotificationSourceMap omap = observers_[i]; |
136 for (NotificationSourceMap::iterator it = omap.begin(); | 143 for (NotificationSourceMap::iterator it = omap.begin(); |
137 it != omap.end(); ++it) { | 144 it != omap.end(); ++it) { |
138 delete it->second; | 145 delete it->second; |
139 } | 146 } |
140 } | 147 } |
141 } | 148 } |
142 | 149 |
143 NotificationObserver::~NotificationObserver() {} | 150 NotificationObserver::~NotificationObserver() {} |
OLD | NEW |