| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 do_notifies_(notify), | 117 do_notifies_(notify), |
| 118 weak_factory_(this) { | 118 weak_factory_(this) { |
| 119 } | 119 } |
| 120 | 120 |
| 121 ~AddRemoveThread() override {} | 121 ~AddRemoveThread() override {} |
| 122 | 122 |
| 123 void ThreadMain() override { | 123 void ThreadMain() override { |
| 124 loop_ = new MessageLoop(); // Fire up a message loop. | 124 loop_ = new MessageLoop(); // Fire up a message loop. |
| 125 loop_->task_runner()->PostTask( | 125 loop_->task_runner()->PostTask( |
| 126 FROM_HERE, | 126 FROM_HERE, |
| 127 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); | 127 base::BindOnce(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); |
| 128 RunLoop().Run(); | 128 RunLoop().Run(); |
| 129 delete loop_; | 129 delete loop_; |
| 130 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); | 130 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); |
| 131 delete this; | 131 delete this; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // This task just keeps posting to itself in an attempt | 134 // This task just keeps posting to itself in an attempt |
| 135 // to race with the notifier. | 135 // to race with the notifier. |
| 136 void AddTask() { | 136 void AddTask() { |
| 137 count_addtask_++; | 137 count_addtask_++; |
| 138 | 138 |
| 139 if ((Time::Now() - start_).InMilliseconds() > kThreadRunTime) { | 139 if ((Time::Now() - start_).InMilliseconds() > kThreadRunTime) { |
| 140 VLOG(1) << "DONE!"; | 140 VLOG(1) << "DONE!"; |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 | 143 |
| 144 if (!in_list_) { | 144 if (!in_list_) { |
| 145 list_->AddObserver(this); | 145 list_->AddObserver(this); |
| 146 in_list_ = true; | 146 in_list_ = true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 if (do_notifies_) { | 149 if (do_notifies_) { |
| 150 list_->Notify(FROM_HERE, &Foo::Observe, 10); | 150 list_->Notify(FROM_HERE, &Foo::Observe, 10); |
| 151 } | 151 } |
| 152 | 152 |
| 153 loop_->task_runner()->PostTask( | 153 loop_->task_runner()->PostTask( |
| 154 FROM_HERE, | 154 FROM_HERE, |
| 155 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); | 155 base::BindOnce(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void Quit() { | 158 void Quit() { |
| 159 loop_->task_runner()->PostTask(FROM_HERE, | 159 loop_->task_runner()->PostTask(FROM_HERE, |
| 160 MessageLoop::QuitWhenIdleClosure()); | 160 MessageLoop::QuitWhenIdleClosure()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void Observe(int x) override { | 163 void Observe(int x) override { |
| 164 count_observes_++; | 164 count_observes_++; |
| 165 | 165 |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 // However, the first Observe() call will add a second observer: at this | 926 // However, the first Observe() call will add a second observer: at this |
| 927 // point, it != observer_list.end() should be true, and Observe() should be | 927 // point, it != observer_list.end() should be true, and Observe() should be |
| 928 // called on the newly added observer on the next iteration of the loop. | 928 // called on the newly added observer on the next iteration of the loop. |
| 929 observer.Observe(10); | 929 observer.Observe(10); |
| 930 } | 930 } |
| 931 | 931 |
| 932 EXPECT_EQ(-10, b.total); | 932 EXPECT_EQ(-10, b.total); |
| 933 } | 933 } |
| 934 | 934 |
| 935 } // namespace base | 935 } // namespace base |
| OLD | NEW |