| 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_SEQUENCE_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_ |
| 6 #define BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_ | 6 #define BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // ... | 26 // ... |
| 27 // private: | 27 // private: |
| 28 // friend class RefCountedDeleteOnSequence<Foo>; | 28 // friend class RefCountedDeleteOnSequence<Foo>; |
| 29 // friend class DeleteHelper<Foo>; | 29 // friend class DeleteHelper<Foo>; |
| 30 // | 30 // |
| 31 // ~Foo(); | 31 // ~Foo(); |
| 32 // }; | 32 // }; |
| 33 template <class T> | 33 template <class T> |
| 34 class RefCountedDeleteOnSequence : public subtle::RefCountedThreadSafeBase { | 34 class RefCountedDeleteOnSequence : public subtle::RefCountedThreadSafeBase { |
| 35 public: | 35 public: |
| 36 static constexpr subtle::StartRefCountFromZeroTag kRefCountPreference = |
| 37 subtle::kStartRefCountFromZeroTag; |
| 38 |
| 36 // A SequencedTaskRunner for the current sequence can be acquired by calling | 39 // A SequencedTaskRunner for the current sequence can be acquired by calling |
| 37 // SequencedTaskRunnerHandle::Get(). | 40 // SequencedTaskRunnerHandle::Get(). |
| 38 RefCountedDeleteOnSequence(scoped_refptr<SequencedTaskRunner> task_runner) | 41 RefCountedDeleteOnSequence(scoped_refptr<SequencedTaskRunner> task_runner) |
| 39 : task_runner_(std::move(task_runner)) { | 42 : subtle::RefCountedThreadSafeBase(T::kRefCountPreference), |
| 43 task_runner_(std::move(task_runner)) { |
| 40 DCHECK(task_runner_); | 44 DCHECK(task_runner_); |
| 41 } | 45 } |
| 42 | 46 |
| 43 void AddRef() const { subtle::RefCountedThreadSafeBase::AddRef(); } | 47 void AddRef() const { subtle::RefCountedThreadSafeBase::AddRef(); } |
| 44 | 48 |
| 45 void Release() const { | 49 void Release() const { |
| 46 if (subtle::RefCountedThreadSafeBase::Release()) | 50 if (subtle::RefCountedThreadSafeBase::Release()) |
| 47 DestructOnSequence(); | 51 DestructOnSequence(); |
| 48 } | 52 } |
| 49 | 53 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 61 } | 65 } |
| 62 | 66 |
| 63 const scoped_refptr<SequencedTaskRunner> task_runner_; | 67 const scoped_refptr<SequencedTaskRunner> task_runner_; |
| 64 | 68 |
| 65 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnSequence); | 69 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnSequence); |
| 66 }; | 70 }; |
| 67 | 71 |
| 68 } // namespace base | 72 } // namespace base |
| 69 | 73 |
| 70 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_ | 74 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_ |
| OLD | NEW |