| 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 // 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 // Creates an initialized WeakHandle from |ptr|. | 279 // Creates an initialized WeakHandle from |ptr|. |
| 280 explicit WeakHandle(const base::WeakPtr<T>& ptr) | 280 explicit WeakHandle(const base::WeakPtr<T>& ptr) |
| 281 : core_(new internal::WeakHandleCore<T>(ptr)) {} | 281 : core_(new internal::WeakHandleCore<T>(ptr)) {} |
| 282 | 282 |
| 283 // Allow conversion from WeakHandle<U> to WeakHandle<T> if U is | 283 // Allow conversion from WeakHandle<U> to WeakHandle<T> if U is |
| 284 // convertible to T, but we *must* be on |other|'s owner thread. | 284 // convertible to T, but we *must* be on |other|'s owner thread. |
| 285 // Note that this doesn't override the regular copy constructor, so | 285 // Note that this doesn't override the regular copy constructor, so |
| 286 // that one can be called on any thread. | 286 // that one can be called on any thread. |
| 287 template <typename U> | 287 template <typename U> |
| 288 WeakHandle(const syncer::WeakHandle<U>& other) // NOLINT | 288 WeakHandle(const WeakHandle<U>& other) // NOLINT |
| 289 : core_( | 289 : core_( |
| 290 other.IsInitialized() ? | 290 other.IsInitialized() ? |
| 291 new internal::WeakHandleCore<T>(other.Get()) : | 291 new internal::WeakHandleCore<T>(other.Get()) : |
| 292 NULL) {} | 292 NULL) {} |
| 293 | 293 |
| 294 // Returns true iff this WeakHandle is initialized. Note that being | 294 // Returns true iff this WeakHandle is initialized. Note that being |
| 295 // initialized isn't a guarantee that the underlying object is still | 295 // initialized isn't a guarantee that the underlying object is still |
| 296 // alive. | 296 // alive. |
| 297 bool IsInitialized() const { | 297 bool IsInitialized() const { |
| 298 return core_.get() != NULL; | 298 return core_.get() != NULL; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 369 |
| 370 // Makes a WeakHandle from a WeakPtr. | 370 // Makes a WeakHandle from a WeakPtr. |
| 371 template <typename T> | 371 template <typename T> |
| 372 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { | 372 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { |
| 373 return WeakHandle<T>(ptr); | 373 return WeakHandle<T>(ptr); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace syncer | 376 } // namespace syncer |
| 377 | 377 |
| 378 #endif // SYNC_UTIL_WEAK_HANDLE_H_ | 378 #endif // SYNC_UTIL_WEAK_HANDLE_H_ |
| OLD | NEW |