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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 #include "base/bind.h" | 53 #include "base/bind.h" |
54 #include "base/compiler_specific.h" | 54 #include "base/compiler_specific.h" |
55 #include "base/gtest_prod_util.h" | 55 #include "base/gtest_prod_util.h" |
56 #include "base/location.h" | 56 #include "base/location.h" |
57 #include "base/logging.h" | 57 #include "base/logging.h" |
58 #include "base/macros.h" | 58 #include "base/macros.h" |
59 #include "base/memory/ref_counted.h" | 59 #include "base/memory/ref_counted.h" |
60 #include "base/memory/weak_ptr.h" | 60 #include "base/memory/weak_ptr.h" |
61 #include "base/single_thread_task_runner.h" | 61 #include "base/single_thread_task_runner.h" |
62 #include "components/sync/base/sync_export.h" | |
63 | 62 |
64 namespace tracked_objects { | 63 namespace tracked_objects { |
65 class Location; | 64 class Location; |
66 } // namespace tracked_objects | 65 } // namespace tracked_objects |
67 | 66 |
68 namespace syncer { | 67 namespace syncer { |
69 | 68 |
70 template <typename T> | 69 template <typename T> |
71 class WeakHandle; | 70 class WeakHandle; |
72 | 71 |
73 namespace internal { | 72 namespace internal { |
74 // These classes are part of the WeakHandle implementation. DO NOT | 73 // These classes are part of the WeakHandle implementation. DO NOT |
75 // USE THESE CLASSES DIRECTLY YOURSELF. | 74 // USE THESE CLASSES DIRECTLY YOURSELF. |
76 | 75 |
77 // Base class for WeakHandleCore<T> to avoid template bloat. Handles | 76 // Base class for WeakHandleCore<T> to avoid template bloat. Handles |
78 // the interaction with the owner thread and its message loop. | 77 // the interaction with the owner thread and its message loop. |
79 class SYNC_EXPORT WeakHandleCoreBase { | 78 class WeakHandleCoreBase { |
80 public: | 79 public: |
81 // Assumes the current thread is the owner thread. | 80 // Assumes the current thread is the owner thread. |
82 WeakHandleCoreBase(); | 81 WeakHandleCoreBase(); |
83 | 82 |
84 // May be called on any thread. | 83 // May be called on any thread. |
85 bool IsOnOwnerThread() const; | 84 bool IsOnOwnerThread() const; |
86 | 85 |
87 protected: | 86 protected: |
88 // May be destroyed on any thread. | 87 // May be destroyed on any thread. |
89 ~WeakHandleCoreBase(); | 88 ~WeakHandleCoreBase(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 194 |
196 // Makes a WeakHandle from a WeakPtr. | 195 // Makes a WeakHandle from a WeakPtr. |
197 template <typename T> | 196 template <typename T> |
198 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { | 197 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { |
199 return WeakHandle<T>(ptr); | 198 return WeakHandle<T>(ptr); |
200 } | 199 } |
201 | 200 |
202 } // namespace syncer | 201 } // namespace syncer |
203 | 202 |
204 #endif // COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ | 203 #endif // COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ |
OLD | NEW |