| 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 pointers help in cases where you have many objects referring back to a | 5 // Weak pointers help in cases where you have many objects referring back to a |
| 6 // shared object and you wish for the lifetime of the shared object to not be | 6 // shared object and you wish for the lifetime of the shared object to not be |
| 7 // bound to the lifetime of the referrers. In other words, this is useful when | 7 // bound to the lifetime of the referrers. In other words, this is useful when |
| 8 // reference counting is not a good fit. | 8 // reference counting is not a good fit. |
| 9 // | 9 // |
| 10 // Thread-safety notes: | 10 // Thread-safety notes: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // Given the above classes, a consumer may allocate a Controller object, call | 50 // Given the above classes, a consumer may allocate a Controller object, call |
| 51 // SpawnWorker several times, and then destroy the Controller object before all | 51 // SpawnWorker several times, and then destroy the Controller object before all |
| 52 // of the workers have completed. Because the Worker class only holds a weak | 52 // of the workers have completed. Because the Worker class only holds a weak |
| 53 // pointer to the Controller, we don't have to worry about the Worker | 53 // pointer to the Controller, we don't have to worry about the Worker |
| 54 // dereferencing the Controller back pointer after the Controller has been | 54 // dereferencing the Controller back pointer after the Controller has been |
| 55 // destroyed. | 55 // destroyed. |
| 56 // | 56 // |
| 57 | 57 |
| 58 #ifndef BASE_MEMORY_WEAK_PTR_H_ | 58 #ifndef BASE_MEMORY_WEAK_PTR_H_ |
| 59 #define BASE_MEMORY_WEAK_PTR_H_ | 59 #define BASE_MEMORY_WEAK_PTR_H_ |
| 60 #pragma once | |
| 61 | 60 |
| 62 #include "base/basictypes.h" | 61 #include "base/basictypes.h" |
| 63 #include "base/base_export.h" | 62 #include "base/base_export.h" |
| 64 #include "base/logging.h" | 63 #include "base/logging.h" |
| 65 #include "base/memory/ref_counted.h" | 64 #include "base/memory/ref_counted.h" |
| 66 #include "base/template_util.h" | 65 #include "base/template_util.h" |
| 67 #include "base/threading/thread_checker.h" | 66 #include "base/threading/thread_checker.h" |
| 68 | 67 |
| 69 namespace base { | 68 namespace base { |
| 70 | 69 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 321 |
| 323 private: | 322 private: |
| 324 internal::WeakReferenceOwner weak_reference_owner_; | 323 internal::WeakReferenceOwner weak_reference_owner_; |
| 325 T* ptr_; | 324 T* ptr_; |
| 326 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory); | 325 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory); |
| 327 }; | 326 }; |
| 328 | 327 |
| 329 } // namespace base | 328 } // namespace base |
| 330 | 329 |
| 331 #endif // BASE_MEMORY_WEAK_PTR_H_ | 330 #endif // BASE_MEMORY_WEAK_PTR_H_ |
| OLD | NEW |