| 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/observer_list.h" | 6 #include "base/observer_list.h" |
| 7 #include "base/observer_list_threadsafe.h" | 7 #include "base/observer_list_threadsafe.h" |
| 8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 virtual void Observe(int x) { | 55 virtual void Observe(int x) { |
| 56 list_->RemoveObserver(doomed_); | 56 list_->RemoveObserver(doomed_); |
| 57 } | 57 } |
| 58 private: | 58 private: |
| 59 ObserverListThreadSafe<Foo>* list_; | 59 ObserverListThreadSafe<Foo>* list_; |
| 60 Foo* doomed_; | 60 Foo* doomed_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 class AddInObserve : public Foo { | 63 class AddInObserve : public Foo { |
| 64 public: | 64 public: |
| 65 AddInObserve(ObserverList<Foo>* observer_list) | 65 explicit AddInObserve(ObserverList<Foo>* observer_list) |
| 66 : added(false), | 66 : added(false), |
| 67 observer_list(observer_list), | 67 observer_list(observer_list), |
| 68 adder(1) { | 68 adder(1) { |
| 69 } | 69 } |
| 70 virtual void Observe(int x) { | 70 virtual void Observe(int x) { |
| 71 if (!added) { | 71 if (!added) { |
| 72 added = true; | 72 added = true; |
| 73 observer_list->AddObserver(&adder); | 73 observer_list->AddObserver(&adder); |
| 74 } | 74 } |
| 75 } | 75 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 EXPECT_TRUE(b.added); | 298 EXPECT_TRUE(b.added); |
| 299 // B's adder should not have been notified because it was added during | 299 // B's adder should not have been notified because it was added during |
| 300 // notificaiton. | 300 // notificaiton. |
| 301 EXPECT_EQ(0, b.adder.total); | 301 EXPECT_EQ(0, b.adder.total); |
| 302 | 302 |
| 303 // Notify again to make sure b's adder is notified. | 303 // Notify again to make sure b's adder is notified. |
| 304 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); | 304 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); |
| 305 EXPECT_EQ(1, b.adder.total); | 305 EXPECT_EQ(1, b.adder.total); |
| 306 } | 306 } |
| OLD | NEW |