OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/thread.h" | 7 #include "base/thread.h" |
8 #include "base/scoped_ptr.h" | |
9 #include "base/weak_ptr.h" | 8 #include "base/weak_ptr.h" |
10 | 9 |
11 namespace base { | 10 namespace base { |
12 namespace { | 11 namespace { |
13 | 12 |
14 template <class T> | 13 template <class T> |
15 class OffThreadObjectCreator { | 14 class OffThreadObjectCreator { |
16 public: | 15 public: |
17 static T* NewObject() { | 16 static T* NewObject() { |
18 T* result; | 17 T* result; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Test that it is OK to create a class that has a WeakPtr member on one | 127 // Test that it is OK to create a class that has a WeakPtr member on one |
129 // thread, but use it on another. This tests that we do not trip runtime | 128 // thread, but use it on another. This tests that we do not trip runtime |
130 // checks that ensure that a weak reference is not used by multiple threads. | 129 // checks that ensure that a weak reference is not used by multiple threads. |
131 scoped_ptr<Consumer> consumer(OffThreadObjectCreator<Consumer>::NewObject()); | 130 scoped_ptr<Consumer> consumer(OffThreadObjectCreator<Consumer>::NewObject()); |
132 Producer producer; | 131 Producer producer; |
133 consumer->producer = producer.AsWeakPtr(); | 132 consumer->producer = producer.AsWeakPtr(); |
134 EXPECT_EQ(&producer, consumer->producer.get()); | 133 EXPECT_EQ(&producer, consumer->producer.get()); |
135 } | 134 } |
136 | 135 |
137 } // namespace base | 136 } // namespace base |
OLD | NEW |