OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "ipc/mojo/ipc_channel_mojo_host.h" | 5 #include "ipc/mojo/ipc_channel_mojo_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "ipc/mojo/ipc_channel_mojo.h" | 9 #include "ipc/mojo/ipc_channel_mojo.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) override; | 24 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) override; |
25 virtual scoped_refptr<base::TaskRunner> GetIOTaskRunner() override; | 25 virtual scoped_refptr<base::TaskRunner> GetIOTaskRunner() override; |
26 | 26 |
27 // Returns an weak ptr of ChannelDelegate instead of Delegate | 27 // Returns an weak ptr of ChannelDelegate instead of Delegate |
28 base::WeakPtr<ChannelDelegate> GetWeakPtr(); | 28 base::WeakPtr<ChannelDelegate> GetWeakPtr(); |
29 void OnClientLaunched(base::ProcessHandle process); | 29 void OnClientLaunched(base::ProcessHandle process); |
30 void DeleteThisSoon(); | 30 void DeleteThisSoon(); |
31 | 31 |
32 private: | 32 private: |
33 scoped_refptr<base::TaskRunner> io_task_runner_; | 33 scoped_refptr<base::TaskRunner> io_task_runner_; |
| 34 base::WeakPtr<ChannelMojo> channel_; |
34 base::WeakPtrFactory<ChannelDelegate> weak_factory_; | 35 base::WeakPtrFactory<ChannelDelegate> weak_factory_; |
35 base::WeakPtr<ChannelMojo> channel_; | |
36 | 36 |
37 DISALLOW_COPY_AND_ASSIGN(ChannelDelegate); | 37 DISALLOW_COPY_AND_ASSIGN(ChannelDelegate); |
38 }; | 38 }; |
39 | 39 |
40 ChannelMojoHost::ChannelDelegate::ChannelDelegate( | 40 ChannelMojoHost::ChannelDelegate::ChannelDelegate( |
41 scoped_refptr<base::TaskRunner> io_task_runner) | 41 scoped_refptr<base::TaskRunner> io_task_runner) |
42 : io_task_runner_(io_task_runner), weak_factory_(this) { | 42 : io_task_runner_(io_task_runner), weak_factory_(this) { |
43 } | 43 } |
44 | 44 |
45 ChannelMojoHost::ChannelDelegate::~ChannelDelegate() { | 45 ChannelMojoHost::ChannelDelegate::~ChannelDelegate() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 FROM_HERE, | 77 FROM_HERE, |
78 base::Bind(&base::DeletePointer<ChannelMojoHost::ChannelDelegate>, | 78 base::Bind(&base::DeletePointer<ChannelMojoHost::ChannelDelegate>, |
79 base::Unretained(this))); | 79 base::Unretained(this))); |
80 } | 80 } |
81 | 81 |
82 // | 82 // |
83 // ChannelMojoHost | 83 // ChannelMojoHost |
84 // | 84 // |
85 | 85 |
86 ChannelMojoHost::ChannelMojoHost(scoped_refptr<base::TaskRunner> io_task_runner) | 86 ChannelMojoHost::ChannelMojoHost(scoped_refptr<base::TaskRunner> io_task_runner) |
87 : weak_factory_(this), | 87 : io_task_runner_(io_task_runner), |
88 io_task_runner_(io_task_runner), | 88 channel_delegate_(new ChannelDelegate(io_task_runner)), |
89 channel_delegate_(new ChannelDelegate(io_task_runner)) { | 89 weak_factory_(this) { |
90 } | 90 } |
91 | 91 |
92 ChannelMojoHost::~ChannelMojoHost() { | 92 ChannelMojoHost::~ChannelMojoHost() { |
93 } | 93 } |
94 | 94 |
95 void ChannelMojoHost::OnClientLaunched(base::ProcessHandle process) { | 95 void ChannelMojoHost::OnClientLaunched(base::ProcessHandle process) { |
96 if (io_task_runner_ == base::MessageLoop::current()->message_loop_proxy()) { | 96 if (io_task_runner_ == base::MessageLoop::current()->message_loop_proxy()) { |
97 channel_delegate_->OnClientLaunched(process); | 97 channel_delegate_->OnClientLaunched(process); |
98 } else { | 98 } else { |
99 io_task_runner_->PostTask(FROM_HERE, | 99 io_task_runner_->PostTask(FROM_HERE, |
100 base::Bind(&ChannelDelegate::OnClientLaunched, | 100 base::Bind(&ChannelDelegate::OnClientLaunched, |
101 channel_delegate_->GetWeakPtr(), | 101 channel_delegate_->GetWeakPtr(), |
102 process)); | 102 process)); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 ChannelMojo::Delegate* ChannelMojoHost::channel_delegate() const { | 106 ChannelMojo::Delegate* ChannelMojoHost::channel_delegate() const { |
107 return channel_delegate_.get(); | 107 return channel_delegate_.get(); |
108 } | 108 } |
109 | 109 |
110 void ChannelMojoHost::DelegateDeleter::operator()( | 110 void ChannelMojoHost::DelegateDeleter::operator()( |
111 ChannelMojoHost::ChannelDelegate* ptr) const { | 111 ChannelMojoHost::ChannelDelegate* ptr) const { |
112 ptr->DeleteThisSoon(); | 112 ptr->DeleteThisSoon(); |
113 } | 113 } |
114 | 114 |
115 } // namespace IPC | 115 } // namespace IPC |
OLD | NEW |