summaryrefslogtreecommitdiffstats
path: root/base/observer_list.h
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-05 07:07:12 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-05 07:07:12 +0000
commit631739f16f16c09b1a08d219c5bcb0c776dddb42 (patch)
treea55bd5f12a95aaefba7de858e9dfa084f40632a8 /base/observer_list.h
parent219b9b974fe4adf8069db2cb2d611c07f14798cc (diff)
downloadchromium_src-631739f16f16c09b1a08d219c5bcb0c776dddb42.zip
chromium_src-631739f16f16c09b1a08d219c5bcb0c776dddb42.tar.gz
chromium_src-631739f16f16c09b1a08d219c5bcb0c776dddb42.tar.bz2
Fix bug in ObserverListThreadsafe::RemoveObserver
Like ObserverList, ObserverListThreadSafe::RemoveObserver should do nothing if the observer isn't in the list. Instead, it causes weird bugs if the list has 0 or 1 existing elements. Add comments clarifying semantics of AddObserver/RemoveObserver. Change AddObserver to do nothing in release mode if it tries to add an existing observer. BUG=84922 TEST= Review URL: http://codereview.chromium.org/7024037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/observer_list.h')
-rw-r--r--base/observer_list.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/base/observer_list.h b/base/observer_list.h
index ca4b3fd..b8c2ae4 100644
--- a/base/observer_list.h
+++ b/base/observer_list.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -111,14 +111,18 @@ class ObserverListBase {
explicit ObserverListBase(NotificationType type)
: notify_depth_(0), type_(type) {}
- // Add an observer to the list.
+ // Add an observer to the list. An observer should not be added to
+ // the same list more than once.
void AddObserver(ObserverType* obs) {
- DCHECK(find(observers_.begin(), observers_.end(), obs) == observers_.end())
- << "Observers can only be added once!";
+ if (std::find(observers_.begin(), observers_.end(), obs)
+ != observers_.end()) {
+ NOTREACHED() << "Observers can only be added once!";
+ return;
+ }
observers_.push_back(obs);
}
- // Remove an observer from the list.
+ // Remove an observer from the list if it is in the list.
void RemoveObserver(ObserverType* obs) {
typename ListType::iterator it =
std::find(observers_.begin(), observers_.end(), obs);