OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef BASE_IOS_WEAK_NSOBJECT_H_ | 5 #ifndef BASE_IOS_WEAK_NSOBJECT_H_ |
6 #define BASE_IOS_WEAK_NSOBJECT_H_ | 6 #define BASE_IOS_WEAK_NSOBJECT_H_ |
7 | 7 |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 NST get() const { | 112 NST get() const { |
113 DCHECK(checker_.CalledOnValidThread()); | 113 DCHECK(checker_.CalledOnValidThread()); |
114 if (!container_.get()) | 114 if (!container_.get()) |
115 return nil; | 115 return nil; |
116 return container_->object(); | 116 return container_->object(); |
117 } | 117 } |
118 | 118 |
119 WeakNSProtocol& operator=(const WeakNSProtocol<NST>& that) { | 119 WeakNSProtocol& operator=(const WeakNSProtocol<NST>& that) { |
120 DCHECK(checker_.CalledOnValidThread()); | 120 // A WeakNSProtocol object can be copied on one thread and used on |
| 121 // another. |
| 122 checker_.DetachFromThread(); |
121 container_ = that.container_; | 123 container_ = that.container_; |
122 return *this; | 124 return *this; |
123 } | 125 } |
124 | 126 |
125 bool operator==(NST that) const { | 127 bool operator==(NST that) const { |
126 DCHECK(checker_.CalledOnValidThread()); | 128 DCHECK(checker_.CalledOnValidThread()); |
127 return get() == that; | 129 return get() == that; |
128 } | 130 } |
129 | 131 |
130 bool operator!=(NST that) const { | 132 bool operator!=(NST that) const { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 180 |
179 WeakNSObject& operator=(const WeakNSObject<id>& that) { | 181 WeakNSObject& operator=(const WeakNSObject<id>& that) { |
180 WeakNSProtocol<id>::operator=(that); | 182 WeakNSProtocol<id>::operator=(that); |
181 return *this; | 183 return *this; |
182 } | 184 } |
183 }; | 185 }; |
184 | 186 |
185 } // namespace base | 187 } // namespace base |
186 | 188 |
187 #endif // BASE_IOS_WEAK_NSOBJECT_H_ | 189 #endif // BASE_IOS_WEAK_NSOBJECT_H_ |
OLD | NEW |