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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 #include "base/basictypes.h" | 52 #include "base/basictypes.h" |
53 #include "base/bind.h" | 53 #include "base/bind.h" |
54 #include "base/callback_forward.h" | 54 #include "base/callback_forward.h" |
55 #include "base/compiler_specific.h" | 55 #include "base/compiler_specific.h" |
56 #include "base/gtest_prod_util.h" | 56 #include "base/gtest_prod_util.h" |
57 #include "base/location.h" | 57 #include "base/location.h" |
58 #include "base/logging.h" | 58 #include "base/logging.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 "sync/base/sync_export.h" | 62 #include "sync/base/sync_export.h" |
62 | 63 |
63 namespace base { | |
64 class MessageLoopProxy; | |
65 } // namespace base | |
66 | |
67 namespace tracked_objects { | 64 namespace tracked_objects { |
68 class Location; | 65 class Location; |
69 } // namespace tracked_objects | 66 } // namespace tracked_objects |
70 | 67 |
71 namespace syncer { | 68 namespace syncer { |
72 | 69 |
73 template <typename T> class WeakHandle; | 70 template <typename T> class WeakHandle; |
74 | 71 |
75 namespace internal { | 72 namespace internal { |
76 // These classes are part of the WeakHandle implementation. DO NOT | 73 // These classes are part of the WeakHandle implementation. DO NOT |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 protected: | 108 protected: |
112 // May be destroyed on any thread. | 109 // May be destroyed on any thread. |
113 ~WeakHandleCoreBase(); | 110 ~WeakHandleCoreBase(); |
114 | 111 |
115 // May be called on any thread. | 112 // May be called on any thread. |
116 void PostToOwnerThread(const tracked_objects::Location& from_here, | 113 void PostToOwnerThread(const tracked_objects::Location& from_here, |
117 const base::Closure& fn) const; | 114 const base::Closure& fn) const; |
118 | 115 |
119 private: | 116 private: |
120 // May be used on any thread. | 117 // May be used on any thread. |
121 const scoped_refptr<base::MessageLoopProxy> owner_loop_proxy_; | 118 const scoped_refptr<base::SingleThreadTaskRunner> owner_loop_task_runner_; |
122 | 119 |
123 DISALLOW_COPY_AND_ASSIGN(WeakHandleCoreBase); | 120 DISALLOW_COPY_AND_ASSIGN(WeakHandleCoreBase); |
124 }; | 121 }; |
125 | 122 |
126 // WeakHandleCore<T> contains all the logic for WeakHandle<T>. | 123 // WeakHandleCore<T> contains all the logic for WeakHandle<T>. |
127 template <typename T> | 124 template <typename T> |
128 class WeakHandleCore | 125 class WeakHandleCore |
129 : public WeakHandleCoreBase, | 126 : public WeakHandleCoreBase, |
130 public base::RefCountedThreadSafe<WeakHandleCore<T> > { | 127 public base::RefCountedThreadSafe<WeakHandleCore<T> > { |
131 public: | 128 public: |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 367 |
371 // Makes a WeakHandle from a WeakPtr. | 368 // Makes a WeakHandle from a WeakPtr. |
372 template <typename T> | 369 template <typename T> |
373 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { | 370 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { |
374 return WeakHandle<T>(ptr); | 371 return WeakHandle<T>(ptr); |
375 } | 372 } |
376 | 373 |
377 } // namespace syncer | 374 } // namespace syncer |
378 | 375 |
379 #endif // SYNC_UTIL_WEAK_HANDLE_H_ | 376 #endif // SYNC_UTIL_WEAK_HANDLE_H_ |
OLD | NEW |