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 <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 | 593 |
594 WaitableEvent task_running(WaitableEvent::ResetPolicy::AUTOMATIC, | 594 WaitableEvent task_running(WaitableEvent::ResetPolicy::AUTOMATIC, |
595 WaitableEvent::InitialState::NOT_SIGNALED); | 595 WaitableEvent::InitialState::NOT_SIGNALED); |
596 WaitableEvent barrier(WaitableEvent::ResetPolicy::AUTOMATIC, | 596 WaitableEvent barrier(WaitableEvent::ResetPolicy::AUTOMATIC, |
597 WaitableEvent::InitialState::NOT_SIGNALED); | 597 WaitableEvent::InitialState::NOT_SIGNALED); |
598 | 598 |
599 // This must be after the declaration of |barrier| so that tasks posted to | 599 // This must be after the declaration of |barrier| so that tasks posted to |
600 // TaskScheduler can safely use |barrier|. | 600 // TaskScheduler can safely use |barrier|. |
601 test::ScopedTaskEnvironment scoped_task_environment; | 601 test::ScopedTaskEnvironment scoped_task_environment; |
602 | 602 |
603 CreateSequencedTaskRunnerWithTraits(TaskTraits().WithBaseSyncPrimitives()) | 603 CreateSequencedTaskRunnerWithTraits({WithBaseSyncPrimitives()}) |
604 ->PostTask(FROM_HERE, | 604 ->PostTask(FROM_HERE, |
605 base::Bind(&ObserverListThreadSafe<Foo>::AddObserver, | 605 base::Bind(&ObserverListThreadSafe<Foo>::AddObserver, |
606 observer_list, Unretained(&observer))); | 606 observer_list, Unretained(&observer))); |
607 TaskScheduler::GetInstance()->FlushForTesting(); | 607 TaskScheduler::GetInstance()->FlushForTesting(); |
608 | 608 |
609 observer_list->Notify(FROM_HERE, &Foo::Observe, 1); | 609 observer_list->Notify(FROM_HERE, &Foo::Observe, 1); |
610 observer.WaitForNotificationRunning(); | 610 observer.WaitForNotificationRunning(); |
611 observer_list->RemoveObserver(&observer); | 611 observer_list->RemoveObserver(&observer); |
612 | 612 |
613 observer.Unblock(); | 613 observer.Unblock(); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 // However, the first Observe() call will add a second observer: at this | 1048 // However, the first Observe() call will add a second observer: at this |
1049 // point, it != observer_list.end() should be true, and Observe() should be | 1049 // point, it != observer_list.end() should be true, and Observe() should be |
1050 // called on the newly added observer on the next iteration of the loop. | 1050 // called on the newly added observer on the next iteration of the loop. |
1051 observer.Observe(10); | 1051 observer.Observe(10); |
1052 } | 1052 } |
1053 | 1053 |
1054 EXPECT_EQ(-10, b.total); | 1054 EXPECT_EQ(-10, b.total); |
1055 } | 1055 } |
1056 | 1056 |
1057 } // namespace base | 1057 } // namespace base |
OLD | NEW |