Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/observer_list.h" | 5 #include "base/observer_list.h" |
| 6 #include "base/observer_list_threadsafe.h" | 6 #include "base/observer_list_threadsafe.h" |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 TEST(ObserverListTest, AddObserverInTheLastObserve) { | 898 TEST(ObserverListTest, AddObserverInTheLastObserve) { |
| 899 using FooList = ObserverList<Foo>; | 899 using FooList = ObserverList<Foo>; |
| 900 FooList observer_list; | 900 FooList observer_list; |
| 901 | 901 |
| 902 AddInObserve<FooList> a(&observer_list); | 902 AddInObserve<FooList> a(&observer_list); |
| 903 Adder b(-1); | 903 Adder b(-1); |
| 904 | 904 |
| 905 a.SetToAdd(&b); | 905 a.SetToAdd(&b); |
| 906 observer_list.AddObserver(&a); | 906 observer_list.AddObserver(&a); |
| 907 | 907 |
| 908 FooList::Iterator it(&observer_list); | 908 auto it = observer_list.begin(); |
| 909 Foo* foo; | 909 while (it != observer_list.end()) { |
|
loyso (OOO)
2016/10/16 23:20:17
nit: you recreate the end iterator many times here
| |
| 910 while ((foo = it.GetNext()) != nullptr) | 910 auto& observer = *it; |
| 911 foo->Observe(10); | 911 // Intentionally increment the iterator before calling Observe(). The |
| 912 // ObserverList starts with only one observer, and it == observer_list.end() | |
| 913 // should be true after the next line. | |
| 914 ++it; | |
| 915 // However, the first Observe() call will add a second observer: at this | |
| 916 // point, it != observer_list.end() should be true, and Observe() should be | |
| 917 // called on the newly added observer on the next iteration of the loop. | |
| 918 observer.Observe(10); | |
| 919 } | |
| 912 | 920 |
| 913 EXPECT_EQ(-10, b.total); | 921 EXPECT_EQ(-10, b.total); |
| 914 } | 922 } |
| 915 | 923 |
| 916 } // namespace base | 924 } // namespace base |
| OLD | NEW |