| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 do_notifies_(notify), | 111 do_notifies_(notify), |
| 112 weak_factory_(this) { | 112 weak_factory_(this) { |
| 113 } | 113 } |
| 114 | 114 |
| 115 ~AddRemoveThread() override {} | 115 ~AddRemoveThread() override {} |
| 116 | 116 |
| 117 void ThreadMain() override { | 117 void ThreadMain() override { |
| 118 loop_ = new MessageLoop(); // Fire up a message loop. | 118 loop_ = new MessageLoop(); // Fire up a message loop. |
| 119 loop_->task_runner()->PostTask( | 119 loop_->task_runner()->PostTask( |
| 120 FROM_HERE, | 120 FROM_HERE, |
| 121 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); | 121 base::BindOnce(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); |
| 122 RunLoop().Run(); | 122 RunLoop().Run(); |
| 123 delete loop_; | 123 delete loop_; |
| 124 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); | 124 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); |
| 125 delete this; | 125 delete this; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // This task just keeps posting to itself in an attempt | 128 // This task just keeps posting to itself in an attempt |
| 129 // to race with the notifier. | 129 // to race with the notifier. |
| 130 void AddTask() { | 130 void AddTask() { |
| 131 count_addtask_++; | 131 count_addtask_++; |
| 132 | 132 |
| 133 if ((Time::Now() - start_).InMilliseconds() > kThreadRunTime) { | 133 if ((Time::Now() - start_).InMilliseconds() > kThreadRunTime) { |
| 134 VLOG(1) << "DONE!"; | 134 VLOG(1) << "DONE!"; |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 if (!in_list_) { | 138 if (!in_list_) { |
| 139 list_->AddObserver(this); | 139 list_->AddObserver(this); |
| 140 in_list_ = true; | 140 in_list_ = true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 if (do_notifies_) { | 143 if (do_notifies_) { |
| 144 list_->Notify(FROM_HERE, &Foo::Observe, 10); | 144 list_->Notify(FROM_HERE, &Foo::Observe, 10); |
| 145 } | 145 } |
| 146 | 146 |
| 147 loop_->task_runner()->PostTask( | 147 loop_->task_runner()->PostTask( |
| 148 FROM_HERE, | 148 FROM_HERE, |
| 149 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); | 149 base::BindOnce(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void Quit() { | 152 void Quit() { |
| 153 loop_->task_runner()->PostTask(FROM_HERE, | 153 loop_->task_runner()->PostTask(FROM_HERE, |
| 154 MessageLoop::QuitWhenIdleClosure()); | 154 MessageLoop::QuitWhenIdleClosure()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void Observe(int x) override { | 157 void Observe(int x) override { |
| 158 count_observes_++; | 158 count_observes_++; |
| 159 | 159 |
| (...skipping 888 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 |