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. | |
36 template <class T> | 35 template <class T> |
37 class RefCountedDeleteOnMessageLoop : public subtle::RefCountedThreadSafeBase { | 36 class RefCountedDeleteOnMessageLoop : public subtle::RefCountedThreadSafeBase { |
38 public: | 37 public: |
39 // This constructor will accept a MessageL00pProxy object, but new code should | 38 // This constructor will accept a MessageL00pProxy object, but new code should |
40 // prefer a SingleThreadTaskRunner. A SingleThreadTaskRunner for the | 39 // prefer a SingleThreadTaskRunner. A SingleThreadTaskRunner for the |
41 // MessageLoop on the current thread can be acquired by calling | 40 // MessageLoop on the current thread can be acquired by calling |
42 // MessageLoop::current()->task_runner(). | 41 // MessageLoop::current()->task_runner(). |
43 RefCountedDeleteOnMessageLoop( | 42 RefCountedDeleteOnMessageLoop( |
44 const scoped_refptr<SingleThreadTaskRunner>& task_runner) | 43 const scoped_refptr<SingleThreadTaskRunner>& task_runner) |
45 : task_runner_(task_runner) { | 44 : task_runner_(task_runner) { |
46 DCHECK(task_runner_); | 45 DCHECK(task_runner_.get()); |
47 } | 46 } |
48 | 47 |
49 void AddRef() const { | 48 void AddRef() const { |
50 subtle::RefCountedThreadSafeBase::AddRef(); | 49 subtle::RefCountedThreadSafeBase::AddRef(); |
51 } | 50 } |
52 | 51 |
53 void Release() const { | 52 void Release() const { |
54 if (subtle::RefCountedThreadSafeBase::Release()) | 53 if (subtle::RefCountedThreadSafeBase::Release()) |
55 DestructOnMessageLoop(); | 54 DestructOnMessageLoop(); |
56 } | 55 } |
(...skipping 12 matching lines...) Expand all Loading... |
69 | 68 |
70 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 69 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
71 | 70 |
72 private: | 71 private: |
73 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnMessageLoop); | 72 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnMessageLoop); |
74 }; | 73 }; |
75 | 74 |
76 } // namespace base | 75 } // namespace base |
77 | 76 |
78 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ | 77 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_ |
OLD | NEW |