| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Weak handles provides a way to refer to weak pointers from another | 5 // Weak handles provides a way to refer to weak pointers from another |
| 6 // thread. This is useful because it is not safe to reference a weak | 6 // thread. This is useful because it is not safe to reference a weak |
| 7 // pointer from a thread other than the thread on which it was | 7 // pointer from a thread other than the thread on which it was |
| 8 // created. | 8 // created. |
| 9 // | 9 // |
| 10 // Weak handles can be passed across threads, so for example, you can | 10 // Weak handles can be passed across threads, so for example, you can |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 : core_(new internal::WeakHandleCore<T>(ptr)) {} | 151 : core_(new internal::WeakHandleCore<T>(ptr)) {} |
| 152 | 152 |
| 153 // Allow conversion from WeakHandle<U> to WeakHandle<T> if U is | 153 // Allow conversion from WeakHandle<U> to WeakHandle<T> if U is |
| 154 // convertible to T, but we *must* be on |other|'s owner thread. | 154 // convertible to T, but we *must* be on |other|'s owner thread. |
| 155 // Note that this doesn't override the regular copy constructor, so | 155 // Note that this doesn't override the regular copy constructor, so |
| 156 // that one can be called on any thread. | 156 // that one can be called on any thread. |
| 157 template <typename U> | 157 template <typename U> |
| 158 WeakHandle(const WeakHandle<U>& other) // NOLINT | 158 WeakHandle(const WeakHandle<U>& other) // NOLINT |
| 159 : core_(other.IsInitialized() | 159 : core_(other.IsInitialized() |
| 160 ? new internal::WeakHandleCore<T>(other.Get()) | 160 ? new internal::WeakHandleCore<T>(other.Get()) |
| 161 : NULL) {} | 161 : nullptr) {} |
| 162 | 162 |
| 163 // Returns true iff this WeakHandle is initialized. Note that being | 163 // Returns true iff this WeakHandle is initialized. Note that being |
| 164 // initialized isn't a guarantee that the underlying object is still | 164 // initialized isn't a guarantee that the underlying object is still |
| 165 // alive. | 165 // alive. |
| 166 bool IsInitialized() const { return core_.get() != NULL; } | 166 bool IsInitialized() const { return core_.get() != nullptr; } |
| 167 | 167 |
| 168 // Resets to an uninitialized WeakHandle. | 168 // Resets to an uninitialized WeakHandle. |
| 169 void Reset() { core_ = NULL; } | 169 void Reset() { core_ = nullptr; } |
| 170 | 170 |
| 171 // Must be called only on the underlying object's owner thread. | 171 // Must be called only on the underlying object's owner thread. |
| 172 base::WeakPtr<T> Get() const { | 172 base::WeakPtr<T> Get() const { |
| 173 CHECK(IsInitialized()); | 173 CHECK(IsInitialized()); |
| 174 CHECK(core_->IsOnOwnerThread()); | 174 CHECK(core_->IsOnOwnerThread()); |
| 175 return core_->Get(); | 175 return core_->Get(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Call(...) may be called on any thread, but all its arguments | 178 // Call(...) may be called on any thread, but all its arguments |
| 179 // should be safe to be bound and copied across threads. | 179 // should be safe to be bound and copied across threads. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 194 | 194 |
| 195 // Makes a WeakHandle from a WeakPtr. | 195 // Makes a WeakHandle from a WeakPtr. |
| 196 template <typename T> | 196 template <typename T> |
| 197 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { | 197 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { |
| 198 return WeakHandle<T>(ptr); | 198 return WeakHandle<T>(ptr); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace syncer | 201 } // namespace syncer |
| 202 | 202 |
| 203 #endif // COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ | 203 #endif // COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ |
| OLD | NEW |