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

Unified Diff: ipc/mojo/ipc_channel_mojo_host.cc

Issue 955813002: Make ChannelMojoHost::ChannelDelegate a RefContedThreadSafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing Created 5 years, 10 months 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
« no previous file with comments | « ipc/mojo/ipc_channel_mojo_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/mojo/ipc_channel_mojo_host.cc
diff --git a/ipc/mojo/ipc_channel_mojo_host.cc b/ipc/mojo/ipc_channel_mojo_host.cc
index beb18ee5e99ffc53d7159d1b6cb4c68b8cdcd398..7e1bff9427561110c763cec46747b853d83f645b 100644
--- a/ipc/mojo/ipc_channel_mojo_host.cc
+++ b/ipc/mojo/ipc_channel_mojo_host.cc
@@ -10,14 +10,22 @@
namespace IPC {
+class ChannelMojoHost::ChannelDelegateTraits {
+ public:
+ static void Destruct(const ChannelMojoHost::ChannelDelegate* ptr);
+};
+
// The delete class lives on the IO thread to talk to ChannelMojo on
// behalf of ChannelMojoHost.
//
// The object must be touched only on the IO thread.
-class ChannelMojoHost::ChannelDelegate : public ChannelMojo::Delegate {
+class ChannelMojoHost::ChannelDelegate
+ : public base::RefCountedThreadSafe<ChannelMojoHost::ChannelDelegate,
+ ChannelMojoHost::ChannelDelegateTraits>,
+ public ChannelMojo::Delegate {
public:
- explicit ChannelDelegate(scoped_refptr<base::TaskRunner> io_task_runner);
- ~ChannelDelegate() override;
+ explicit ChannelDelegate(
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner);
// ChannelMojo::Delegate
base::WeakPtr<Delegate> ToWeakPtr() override;
@@ -27,10 +35,14 @@ class ChannelMojoHost::ChannelDelegate : public ChannelMojo::Delegate {
// Returns an weak ptr of ChannelDelegate instead of Delegate
base::WeakPtr<ChannelDelegate> GetWeakPtr();
void OnClientLaunched(base::ProcessHandle process);
- void DeleteThisSoon();
+ void DeleteThisSoon() const;
private:
- scoped_refptr<base::TaskRunner> io_task_runner_;
+ friend class base::DeleteHelper<ChannelDelegate>;
+
+ ~ChannelDelegate() override;
+
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
base::WeakPtr<ChannelMojo> channel_;
base::WeakPtrFactory<ChannelDelegate> weak_factory_;
@@ -38,7 +50,7 @@ class ChannelMojoHost::ChannelDelegate : public ChannelMojo::Delegate {
};
ChannelMojoHost::ChannelDelegate::ChannelDelegate(
- scoped_refptr<base::TaskRunner> io_task_runner)
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner)
: io_task_runner_(io_task_runner), weak_factory_(this) {
}
@@ -72,18 +84,16 @@ void ChannelMojoHost::ChannelDelegate::OnClientLaunched(
channel_->OnClientLaunched(process);
}
-void ChannelMojoHost::ChannelDelegate::DeleteThisSoon() {
- io_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&base::DeletePointer<ChannelMojoHost::ChannelDelegate>,
- base::Unretained(this)));
+void ChannelMojoHost::ChannelDelegate::DeleteThisSoon() const {
+ io_task_runner_->DeleteSoon(FROM_HERE, this);
}
//
// ChannelMojoHost
//
-ChannelMojoHost::ChannelMojoHost(scoped_refptr<base::TaskRunner> io_task_runner)
+ChannelMojoHost::ChannelMojoHost(
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner)
: io_task_runner_(io_task_runner),
channel_delegate_(new ChannelDelegate(io_task_runner)),
weak_factory_(this) {
@@ -98,8 +108,7 @@ void ChannelMojoHost::OnClientLaunched(base::ProcessHandle process) {
} else {
io_task_runner_->PostTask(FROM_HERE,
base::Bind(&ChannelDelegate::OnClientLaunched,
- channel_delegate_->GetWeakPtr(),
- process));
+ channel_delegate_, process));
}
}
@@ -107,8 +116,9 @@ ChannelMojo::Delegate* ChannelMojoHost::channel_delegate() const {
return channel_delegate_.get();
}
-void ChannelMojoHost::DelegateDeleter::operator()(
- ChannelMojoHost::ChannelDelegate* ptr) const {
+// static
+void ChannelMojoHost::ChannelDelegateTraits::Destruct(
+ const ChannelMojoHost::ChannelDelegate* ptr) {
ptr->DeleteThisSoon();
}
« no previous file with comments | « ipc/mojo/ipc_channel_mojo_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698