Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2441)

Unified Diff: base/memory/ref_counted_delete_on_sequence.h

Issue 2591963004: Transform RefCountedDeleteOnMessageLoop to RefCountedDeleteOnSequence. (Closed)
Patch Set: similarity Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/memory/ref_counted_delete_on_sequence.h
diff --git a/base/memory/ref_counted_delete_on_message_loop.h b/base/memory/ref_counted_delete_on_sequence.h
similarity index 36%
rename from base/memory/ref_counted_delete_on_message_loop.h
rename to base/memory/ref_counted_delete_on_sequence.h
index eac1add50fe556f3e17d16810ebaec70aab83701..a7600f9f8546068f5bcba4b124e61d0e95b1c6c7 100644
--- a/base/memory/ref_counted_delete_on_message_loop.h
+++ b/base/memory/ref_counted_delete_on_sequence.h
@@ -2,72 +2,69 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_
-#define BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_
+#ifndef BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_
+#define BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_
+
+#include <utility>
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/single_thread_task_runner.h"
+#include "base/sequenced_task_runner.h"
namespace base {
-// RefCountedDeleteOnMessageLoop is similar to RefCountedThreadSafe, and ensures
-// that the object will be deleted on a specified message loop.
+// RefCountedDeleteOnSequence is similar to RefCountedThreadSafe, and ensures
+// that the object will be deleted on a specified sequence.
//
// Sample usage:
-// class Foo : public RefCountedDeleteOnMessageLoop<Foo> {
+// class Foo : public RefCountedDeleteOnSequence<Foo> {
//
-// Foo(scoped_refptr<SingleThreadTaskRunner> loop)
-// : RefCountedDeleteOnMessageLoop<Foo>(std::move(loop)) {}
+// Foo(scoped_refptr<SequencedTaskRunner> task_runner)
+// : RefCountedDeleteOnSequence<Foo>(std::move(task_runner)) {}
// ...
// private:
-// friend class RefCountedDeleteOnMessageLoop<Foo>;
+// friend class RefCountedDeleteOnSequence<Foo>;
// friend class DeleteHelper<Foo>;
//
// ~Foo();
// };
-
-// TODO(skyostil): Rename this to RefCountedDeleteOnTaskRunner.
template <class T>
-class RefCountedDeleteOnMessageLoop : public subtle::RefCountedThreadSafeBase {
+class RefCountedDeleteOnSequence : public subtle::RefCountedThreadSafeBase {
public:
- // A SingleThreadTaskRunner for the current thread can be acquired by calling
- // ThreadTaskRunnerHandle::Get().
- RefCountedDeleteOnMessageLoop(
- scoped_refptr<SingleThreadTaskRunner> task_runner)
+ // A SequencedTaskRunner for the current sequence can be acquired by calling
+ // SequencedTaskRunnerHandle::Get().
+ RefCountedDeleteOnSequence(scoped_refptr<SequencedTaskRunner> task_runner)
: task_runner_(std::move(task_runner)) {
DCHECK(task_runner_);
}
- void AddRef() const {
- subtle::RefCountedThreadSafeBase::AddRef();
- }
+ void AddRef() const { subtle::RefCountedThreadSafeBase::AddRef(); }
void Release() const {
if (subtle::RefCountedThreadSafeBase::Release())
- DestructOnMessageLoop();
+ DestructOnSequence();
}
protected:
- friend class DeleteHelper<RefCountedDeleteOnMessageLoop>;
- ~RefCountedDeleteOnMessageLoop() {}
+ friend class DeleteHelper<RefCountedDeleteOnSequence>;
+ ~RefCountedDeleteOnSequence() = default;
- void DestructOnMessageLoop() const {
+ private:
+ void DestructOnSequence() const {
const T* t = static_cast<const T*>(this);
- if (task_runner_->BelongsToCurrentThread())
+ if (task_runner_->RunsTasksOnCurrentThread())
delete t;
else
task_runner_->DeleteSoon(FROM_HERE, t);
}
- scoped_refptr<SingleThreadTaskRunner> task_runner_;
+ const scoped_refptr<SequencedTaskRunner> task_runner_;
- private:
- DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnMessageLoop);
+ DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnSequence);
};
} // namespace base
-#endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_
+#endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_SEQUENCE_H_

Powered by Google App Engine
This is Rietveld 408576698