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_message_pipe_reader.h" | 5 #include "ipc/mojo/ipc_message_pipe_reader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "ipc/mojo/async_handle_waiter.h" | |
13 #include "ipc/mojo/ipc_channel_mojo.h" | 12 #include "ipc/mojo/ipc_channel_mojo.h" |
14 | 13 |
15 namespace IPC { | 14 namespace IPC { |
16 namespace internal { | 15 namespace internal { |
17 | 16 |
18 MessagePipeReader::MessagePipeReader(mojo::ScopedMessagePipeHandle handle, | 17 MessagePipeReader::MessagePipeReader(mojo::ScopedMessagePipeHandle handle, |
19 MessagePipeReader::Delegate* delegate) | 18 MessagePipeReader::Delegate* delegate) |
20 : pipe_(handle.Pass()), | 19 : pipe_(handle.Pass()), |
21 delegate_(delegate), | 20 delegate_(delegate), |
22 async_waiter_( | 21 async_waiter_(new AsyncHandleWaiter(this)) { |
23 new AsyncHandleWaiter(base::Bind(&MessagePipeReader::PipeIsReady, | 22 async_waiter_->SetMessageCallback(pipe_.get().value()); |
24 base::Unretained(this)))) { | |
25 } | 23 } |
26 | 24 |
27 MessagePipeReader::~MessagePipeReader() { | 25 MessagePipeReader::~MessagePipeReader() { |
28 CHECK(!IsValid()); | 26 CHECK(!IsValid()); |
29 } | 27 } |
30 | 28 |
31 void MessagePipeReader::Close() { | 29 void MessagePipeReader::Close() { |
| 30 if (async_waiter_) |
| 31 async_waiter_->ClearMessageCallback(pipe_.get().value()); |
32 async_waiter_.reset(); | 32 async_waiter_.reset(); |
33 pipe_.reset(); | 33 pipe_.reset(); |
34 OnPipeClosed(); | 34 OnPipeClosed(); |
35 } | 35 } |
36 | 36 |
37 void MessagePipeReader::CloseWithError(MojoResult error) { | 37 void MessagePipeReader::CloseWithError(MojoResult error) { |
38 OnPipeError(error); | 38 OnPipeError(error); |
39 Close(); | 39 Close(); |
40 } | 40 } |
41 | 41 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 OnPipeError(wait_result); | 188 OnPipeError(wait_result); |
189 } | 189 } |
190 | 190 |
191 Close(); | 191 Close(); |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 ReadMessagesThenWait(); | 195 ReadMessagesThenWait(); |
196 } | 196 } |
197 | 197 |
| 198 void MessagePipeReader::MessageWasArrived(const void* bytes, |
| 199 uint32_t num_bytes) { |
| 200 Message message(reinterpret_cast<const char*>(bytes), |
| 201 static_cast<int>(num_bytes)); |
| 202 delegate_->OnMessageReceived(message); |
| 203 } |
| 204 |
198 void MessagePipeReader::DelayedDeleter::operator()( | 205 void MessagePipeReader::DelayedDeleter::operator()( |
199 MessagePipeReader* ptr) const { | 206 MessagePipeReader* ptr) const { |
200 ptr->Close(); | 207 ptr->Close(); |
201 base::MessageLoopProxy::current()->PostTask( | 208 base::MessageLoopProxy::current()->PostTask( |
202 FROM_HERE, base::Bind(&DeleteNow, ptr)); | 209 FROM_HERE, base::Bind(&DeleteNow, ptr)); |
203 } | 210 } |
204 | 211 |
205 } // namespace internal | 212 } // namespace internal |
206 } // namespace IPC | 213 } // namespace IPC |
OLD | NEW |