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/ipc_channel_mojo.h" | 5 #include "ipc/ipc_channel_mojo.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // avoid deadlock when freeing it below. | 287 // avoid deadlock when freeing it below. |
288 std::swap(message_reader_, reader); | 288 std::swap(message_reader_, reader); |
289 | 289 |
290 // We might Close() before we Connect(). | 290 // We might Close() before we Connect(). |
291 waiting_connect_ = false; | 291 waiting_connect_ = false; |
292 } | 292 } |
293 | 293 |
294 reader.reset(); | 294 reader.reset(); |
295 } | 295 } |
296 | 296 |
| 297 mojo::AssociatedGroup* ChannelMojo::GetAssociatedGroup() { |
| 298 DCHECK(bootstrap_); |
| 299 return bootstrap_->GetAssociatedGroup(); |
| 300 } |
| 301 |
| 302 void ChannelMojo::AddGenericAssociatedInterface( |
| 303 const std::string& name, |
| 304 const GenericAssociatedInterfaceFactory& factory) { |
| 305 auto result = associated_interfaces_.insert({ name, factory }); |
| 306 DCHECK(result.second); |
| 307 } |
| 308 |
| 309 void ChannelMojo::GetGenericRemoteAssociatedInterface( |
| 310 const std::string& name, |
| 311 mojo::ScopedInterfaceEndpointHandle handle) { |
| 312 DCHECK(message_reader_); |
| 313 message_reader_->GetRemoteInterface(name, std::move(handle)); |
| 314 } |
| 315 |
297 // MojoBootstrap::Delegate implementation | 316 // MojoBootstrap::Delegate implementation |
298 void ChannelMojo::OnPipesAvailable( | 317 void ChannelMojo::OnPipesAvailable( |
299 mojom::ChannelAssociatedPtrInfo send_channel, | 318 mojom::ChannelAssociatedPtrInfo send_channel, |
300 mojom::ChannelAssociatedRequest receive_channel, | 319 mojom::ChannelAssociatedRequest receive_channel, |
301 int32_t peer_pid) { | 320 int32_t peer_pid) { |
302 InitMessageReader(std::move(send_channel), std::move(receive_channel), | 321 InitMessageReader(std::move(send_channel), std::move(receive_channel), |
303 peer_pid); | 322 peer_pid); |
304 } | 323 } |
305 | 324 |
306 void ChannelMojo::OnBootstrapError() { | 325 void ChannelMojo::OnBootstrapError() { |
307 listener_->OnChannelError(); | 326 listener_->OnChannelError(); |
308 } | 327 } |
309 | 328 |
| 329 void ChannelMojo::OnAssociatedInterfaceRequest( |
| 330 const std::string& name, |
| 331 mojo::ScopedInterfaceEndpointHandle handle) { |
| 332 auto iter = associated_interfaces_.find(name); |
| 333 if (iter != associated_interfaces_.end()) |
| 334 iter->second.Run(std::move(handle)); |
| 335 } |
| 336 |
310 void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, | 337 void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, |
311 mojom::ChannelAssociatedRequest receiver, | 338 mojom::ChannelAssociatedRequest receiver, |
312 base::ProcessId peer_pid) { | 339 base::ProcessId peer_pid) { |
313 mojom::ChannelAssociatedPtr sender_ptr; | 340 mojom::ChannelAssociatedPtr sender_ptr; |
314 sender_ptr.Bind(std::move(sender)); | 341 sender_ptr.Bind(std::move(sender)); |
315 std::unique_ptr<internal::MessagePipeReader, ChannelMojo::ReaderDeleter> | 342 std::unique_ptr<internal::MessagePipeReader, ChannelMojo::ReaderDeleter> |
316 reader(new internal::MessagePipeReader( | 343 reader(new internal::MessagePipeReader( |
317 pipe_, std::move(sender_ptr), std::move(receiver), peer_pid, this)); | 344 pipe_, std::move(sender_ptr), std::move(receiver), peer_pid, this)); |
318 | 345 |
319 bool connected = true; | 346 bool connected = true; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 DCHECK(ok); | 489 DCHECK(ok); |
463 if (!ok) { | 490 if (!ok) { |
464 LOG(ERROR) << "Failed to add new Mojo handle."; | 491 LOG(ERROR) << "Failed to add new Mojo handle."; |
465 return MOJO_RESULT_UNKNOWN; | 492 return MOJO_RESULT_UNKNOWN; |
466 } | 493 } |
467 } | 494 } |
468 return MOJO_RESULT_OK; | 495 return MOJO_RESULT_OK; |
469 } | 496 } |
470 | 497 |
471 } // namespace IPC | 498 } // namespace IPC |
OLD | NEW |