| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_EDK_SYSTEM_REMOTE_MESSAGE_PIPE_BOOTSTRAP_H_ | |
| 6 #define MOJO_EDK_SYSTEM_REMOTE_MESSAGE_PIPE_BOOTSTRAP_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/task_runner.h" | |
| 14 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
| 15 #include "mojo/edk/system/channel.h" | |
| 16 #include "mojo/edk/system/ports/name.h" | |
| 17 #include "mojo/edk/system/ports/port_ref.h" | |
| 18 | |
| 19 namespace mojo { | |
| 20 namespace edk { | |
| 21 | |
| 22 class NodeController; | |
| 23 | |
| 24 // This is used by Core to negotiate a new cross-process message pipe given | |
| 25 // an arbitrary platform channel. Both ends of the channel must be passed to | |
| 26 // RemoteMessagePipeBootstrap::Create() in their respective processes. | |
| 27 // | |
| 28 // The bootstrapping procedure the same on either end: | |
| 29 // | |
| 30 // 1. Select a local port P to be merged with a remote port. | |
| 31 // 2. Write the local node name and P's name to the bootstrap pipe. | |
| 32 // 3. When a message is read from the pipe: | |
| 33 // - If it's the first message read, extract the remote node+port name and | |
| 34 // and send an empty ACK message on the pipe. | |
| 35 // - If it's the second message read, close the channel, and delete |this|. | |
| 36 // 4. When an error occus on the pipe, delete |this|. | |
| 37 // | |
| 38 // Excluding irrecoverable error conditions such as either process dying, | |
| 39 // armageddon, etc., this ensures neither end closes the channel until both ends | |
| 40 // are aware of each other's port-to-merge. | |
| 41 // | |
| 42 // At step 3, one side of the channel is chosen to issue a message at the Ports | |
| 43 // layer which eventually merges the two ports. | |
| 44 class RemoteMessagePipeBootstrap | |
| 45 : public Channel::Delegate, | |
| 46 public base::MessageLoop::DestructionObserver { | |
| 47 public: | |
| 48 ~RemoteMessagePipeBootstrap() override; | |
| 49 | |
| 50 // |port| must be a reference to an uninitialized local port. | |
| 51 static void Create(NodeController* node_controller, | |
| 52 ScopedPlatformHandle platform_handle, | |
| 53 const ports::PortRef& port); | |
| 54 | |
| 55 protected: | |
| 56 explicit RemoteMessagePipeBootstrap(NodeController* node_controller, | |
| 57 ScopedPlatformHandle platform_handle, | |
| 58 const ports::PortRef& port); | |
| 59 | |
| 60 void ShutDown(); | |
| 61 | |
| 62 bool shutting_down_ = false; | |
| 63 NodeController* node_controller_; | |
| 64 const ports::PortRef local_port_; | |
| 65 | |
| 66 scoped_refptr<base::TaskRunner> io_task_runner_; | |
| 67 scoped_refptr<Channel> channel_; | |
| 68 | |
| 69 bool peer_info_received_ = false; | |
| 70 | |
| 71 private: | |
| 72 // base::MessageLoop::DestructionObserver: | |
| 73 void WillDestroyCurrentMessageLoop() override; | |
| 74 | |
| 75 // Channel::Delegate: | |
| 76 void OnChannelMessage(const void* payload, | |
| 77 size_t payload_size, | |
| 78 ScopedPlatformHandleVectorPtr handles) override; | |
| 79 void OnChannelError() override; | |
| 80 | |
| 81 void ShutDownNow(); | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeBootstrap); | |
| 84 }; | |
| 85 | |
| 86 } // namespace edk | |
| 87 } // namespace mojo | |
| 88 | |
| 89 #endif // MOJO_EDK_SYSTEM_REMOTE_MESSAGE_PIPE_BOOTSTRAP_H_ | |
| OLD | NEW |