OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ |
6 #define BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ | 6 #define BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ |
7 | 7 |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // ... | 25 // ... |
26 // } | 26 // } |
27 // ... | 27 // ... |
28 // private: | 28 // private: |
29 // friend class RefCountedDeleteOnMessageLoop<Foo>; | 29 // friend class RefCountedDeleteOnMessageLoop<Foo>; |
30 // friend class DeleteHelper<Foo>; | 30 // friend class DeleteHelper<Foo>; |
31 // | 31 // |
32 // ~Foo(); | 32 // ~Foo(); |
33 // }; | 33 // }; |
34 | 34 |
| 35 // TODO(skyostil): Rename this to RefCountedDeleteOnTaskRunner. |
35 template <class T> | 36 template <class T> |
36 class RefCountedDeleteOnMessageLoop : public subtle::RefCountedThreadSafeBase { | 37 class RefCountedDeleteOnMessageLoop : public subtle::RefCountedThreadSafeBase { |
37 public: | 38 public: |
38 // This constructor will accept a MessageL00pProxy object, but new code should | 39 // This constructor will accept a MessageL00pProxy object, but new code should |
39 // prefer a SingleThreadTaskRunner. A SingleThreadTaskRunner for the | 40 // prefer a SingleThreadTaskRunner. A SingleThreadTaskRunner for the |
40 // MessageLoop on the current thread can be acquired by calling | 41 // MessageLoop on the current thread can be acquired by calling |
41 // MessageLoop::current()->task_runner(). | 42 // MessageLoop::current()->task_runner(). |
42 RefCountedDeleteOnMessageLoop( | 43 RefCountedDeleteOnMessageLoop( |
43 const scoped_refptr<SingleThreadTaskRunner>& task_runner) | 44 const scoped_refptr<SingleThreadTaskRunner>& task_runner) |
44 : task_runner_(task_runner) { | 45 : task_runner_(task_runner) { |
45 DCHECK(task_runner_.get()); | 46 DCHECK(task_runner_); |
46 } | 47 } |
47 | 48 |
48 void AddRef() const { | 49 void AddRef() const { |
49 subtle::RefCountedThreadSafeBase::AddRef(); | 50 subtle::RefCountedThreadSafeBase::AddRef(); |
50 } | 51 } |
51 | 52 |
52 void Release() const { | 53 void Release() const { |
53 if (subtle::RefCountedThreadSafeBase::Release()) | 54 if (subtle::RefCountedThreadSafeBase::Release()) |
54 DestructOnMessageLoop(); | 55 DestructOnMessageLoop(); |
55 } | 56 } |
(...skipping 12 matching lines...) Expand all Loading... |
68 | 69 |
69 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 70 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
70 | 71 |
71 private: | 72 private: |
72 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnMessageLoop); | 73 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnMessageLoop); |
73 }; | 74 }; |
74 | 75 |
75 } // namespace base | 76 } // namespace base |
76 | 77 |
77 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ | 78 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ |
OLD | NEW |