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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 weak_factory_(this) { | 104 weak_factory_(this) { |
105 } | 105 } |
106 | 106 |
107 ~AddRemoveThread() override {} | 107 ~AddRemoveThread() override {} |
108 | 108 |
109 void ThreadMain() override { | 109 void ThreadMain() override { |
110 loop_ = new MessageLoop(); // Fire up a message loop. | 110 loop_ = new MessageLoop(); // Fire up a message loop. |
111 loop_->task_runner()->PostTask( | 111 loop_->task_runner()->PostTask( |
112 FROM_HERE, | 112 FROM_HERE, |
113 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); | 113 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); |
114 loop_->Run(); | 114 RunLoop().Run(); |
115 //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " << | 115 //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " << |
116 // count_observes_ << ", " << count_addtask_; | 116 // count_observes_ << ", " << count_addtask_; |
117 delete loop_; | 117 delete loop_; |
118 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); | 118 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); |
119 delete this; | 119 delete this; |
120 } | 120 } |
121 | 121 |
122 // This task just keeps posting to itself in an attempt | 122 // This task just keeps posting to itself in an attempt |
123 // to race with the notifier. | 123 // to race with the notifier. |
124 void AddTask() { | 124 void AddTask() { |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 ListDestructor a(observer_list); | 536 ListDestructor a(observer_list); |
537 observer_list->AddObserver(&a); | 537 observer_list->AddObserver(&a); |
538 | 538 |
539 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); | 539 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); |
540 // If this test fails, there'll be Valgrind errors when this function goes out | 540 // If this test fails, there'll be Valgrind errors when this function goes out |
541 // of scope. | 541 // of scope. |
542 } | 542 } |
543 | 543 |
544 } // namespace | 544 } // namespace |
545 } // namespace base | 545 } // namespace base |
OLD | NEW |