| 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_registrar.h" | 5 #include "chrome/common/notification_registrar.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 NotificationService::current()->AddObserver(observer, type, source); | 41 NotificationService::current()->AddObserver(observer, type, source); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void NotificationRegistrar::Remove(NotificationObserver* observer, | 44 void NotificationRegistrar::Remove(NotificationObserver* observer, |
| 45 NotificationType type, | 45 NotificationType type, |
| 46 const NotificationSource& source) { | 46 const NotificationSource& source) { |
| 47 Record record = { observer, type, source }; | 47 Record record = { observer, type, source }; |
| 48 RecordVector::iterator found = std::find( | 48 RecordVector::iterator found = std::find( |
| 49 registered_.begin(), registered_.end(), record); | 49 registered_.begin(), registered_.end(), record); |
| 50 if (found == registered_.end()) { | 50 if (found == registered_.end()) { |
| 51 NOTREACHED(); | 51 NOTREACHED() << "Trying to remove unregistered observer of type " << |
| 52 type.value << " from list of size " << registered_.size() << "."; |
| 52 return; | 53 return; |
| 53 } | 54 } |
| 54 registered_.erase(found); | 55 registered_.erase(found); |
| 55 | 56 |
| 56 // This can be NULL if our owner outlives the NotificationService, e.g. if our | 57 // This can be NULL if our owner outlives the NotificationService, e.g. if our |
| 57 // owner is a Singleton. | 58 // owner is a Singleton. |
| 58 NotificationService* service = NotificationService::current(); | 59 NotificationService* service = NotificationService::current(); |
| 59 if (service) | 60 if (service) |
| 60 service->RemoveObserver(observer, type, source); | 61 service->RemoveObserver(observer, type, source); |
| 61 } | 62 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 79 registered_[i].type, | 80 registered_[i].type, |
| 80 registered_[i].source); | 81 registered_[i].source); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 registered_.clear(); | 84 registered_.clear(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 bool NotificationRegistrar::IsEmpty() const { | 87 bool NotificationRegistrar::IsEmpty() const { |
| 87 return registered_.empty(); | 88 return registered_.empty(); |
| 88 } | 89 } |
| OLD | NEW |