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" | |
62 #include "base/thread_task_runner_handle.h" | |
maniscalco
2015/04/28 18:27:29
Is this include needed?
anujsharma
2015/04/29 05:08:05
Removed!!
| |
61 #include "sync/base/sync_export.h" | 63 #include "sync/base/sync_export.h" |
62 | 64 |
63 namespace base { | 65 namespace base { |
64 class MessageLoopProxy; | 66 class SingleThreadTaskRunner; |
maniscalco
2015/04/28 18:27:29
Given this forward declaration, is the include for
anujsharma
2015/04/29 05:08:05
Yes, it is required.
maniscalco
2015/04/29 15:23:16
Cool, since we're including the header you should
| |
65 } // namespace base | 67 } // namespace base |
66 | 68 |
67 namespace tracked_objects { | 69 namespace tracked_objects { |
68 class Location; | 70 class Location; |
69 } // namespace tracked_objects | 71 } // namespace tracked_objects |
70 | 72 |
71 namespace syncer { | 73 namespace syncer { |
72 | 74 |
73 template <typename T> class WeakHandle; | 75 template <typename T> class WeakHandle; |
74 | 76 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 protected: | 113 protected: |
112 // May be destroyed on any thread. | 114 // May be destroyed on any thread. |
113 ~WeakHandleCoreBase(); | 115 ~WeakHandleCoreBase(); |
114 | 116 |
115 // May be called on any thread. | 117 // May be called on any thread. |
116 void PostToOwnerThread(const tracked_objects::Location& from_here, | 118 void PostToOwnerThread(const tracked_objects::Location& from_here, |
117 const base::Closure& fn) const; | 119 const base::Closure& fn) const; |
118 | 120 |
119 private: | 121 private: |
120 // May be used on any thread. | 122 // May be used on any thread. |
121 const scoped_refptr<base::MessageLoopProxy> owner_loop_proxy_; | 123 const scoped_refptr<base::SingleThreadTaskRunner> owner_loop_proxy_; |
maniscalco
2015/04/28 18:27:29
How about renaming to owner_loop_task_runner_ ?
anujsharma
2015/04/29 05:08:05
Done.
| |
122 | 124 |
123 DISALLOW_COPY_AND_ASSIGN(WeakHandleCoreBase); | 125 DISALLOW_COPY_AND_ASSIGN(WeakHandleCoreBase); |
124 }; | 126 }; |
125 | 127 |
126 // WeakHandleCore<T> contains all the logic for WeakHandle<T>. | 128 // WeakHandleCore<T> contains all the logic for WeakHandle<T>. |
127 template <typename T> | 129 template <typename T> |
128 class WeakHandleCore | 130 class WeakHandleCore |
129 : public WeakHandleCoreBase, | 131 : public WeakHandleCoreBase, |
130 public base::RefCountedThreadSafe<WeakHandleCore<T> > { | 132 public base::RefCountedThreadSafe<WeakHandleCore<T> > { |
131 public: | 133 public: |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 | 372 |
371 // Makes a WeakHandle from a WeakPtr. | 373 // Makes a WeakHandle from a WeakPtr. |
372 template <typename T> | 374 template <typename T> |
373 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { | 375 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { |
374 return WeakHandle<T>(ptr); | 376 return WeakHandle<T>(ptr); |
375 } | 377 } |
376 | 378 |
377 } // namespace syncer | 379 } // namespace syncer |
378 | 380 |
379 #endif // SYNC_UTIL_WEAK_HANDLE_H_ | 381 #endif // SYNC_UTIL_WEAK_HANDLE_H_ |
OLD | NEW |