| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 do_notifies_(notify) { | 100 do_notifies_(notify) { |
| 101 factory_ = new ScopedRunnableMethodFactory<AddRemoveThread>(this); | 101 factory_ = new ScopedRunnableMethodFactory<AddRemoveThread>(this); |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual ~AddRemoveThread() { | 104 virtual ~AddRemoveThread() { |
| 105 delete factory_; | 105 delete factory_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ThreadMain() { | 108 void ThreadMain() { |
| 109 loop_ = new MessageLoop(); // Fire up a message loop. | 109 loop_ = new MessageLoop(); // Fire up a message loop. |
| 110 loop_->PostTask(FROM_HERE, | 110 loop_->PostTask( |
| 111 factory_->NewRunnableMethod(&AddRemoveThread::AddTask)); | 111 FROM_HERE, factory_->NewRunnableMethod(&AddRemoveThread::AddTask)); |
| 112 loop_->Run(); | 112 loop_->Run(); |
| 113 //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " << | 113 //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " << |
| 114 // count_observes_ << ", " << count_addtask_; | 114 // count_observes_ << ", " << count_addtask_; |
| 115 delete loop_; | 115 delete loop_; |
| 116 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); | 116 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef); |
| 117 delete this; | 117 delete this; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // This task just keeps posting to itself in an attempt | 120 // This task just keeps posting to itself in an attempt |
| 121 // to race with the notifier. | 121 // to race with the notifier. |
| (...skipping 175 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 |