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/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/task_runner.h" |
| 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 16 #include "mojo/edk/system/channel.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. One end of the channel must be passed to |
| 26 // CreateForParent() in the parent process, and the other end must be passed to |
| 27 // CreateForChild() in the child process. |
| 28 class RemoteMessagePipeBootstrap |
| 29 : public Channel::Delegate, |
| 30 public base::MessageLoop::DestructionObserver { |
| 31 public: |
| 32 ~RemoteMessagePipeBootstrap() override; |
| 33 |
| 34 // The NodeController should already have reserved a local port for |token| |
| 35 // before calling this method. |
| 36 static void CreateForParent(NodeController* node_controller, |
| 37 ScopedPlatformHandle platform_handle, |
| 38 const std::string& token); |
| 39 |
| 40 // |port| must be a reference to an uninitialized local port. |
| 41 static void CreateForChild(NodeController* node_controller, |
| 42 ScopedPlatformHandle platform_handle, |
| 43 const ports::PortRef& port, |
| 44 const base::Closure& callback); |
| 45 |
| 46 // Handle a received token. |
| 47 virtual void OnTokenReceived(const std::string& token) = 0; |
| 48 |
| 49 protected: |
| 50 explicit RemoteMessagePipeBootstrap(ScopedPlatformHandle platform_handle); |
| 51 |
| 52 void ShutDown(); |
| 53 |
| 54 bool shutting_down_ = false; |
| 55 scoped_refptr<base::TaskRunner> io_task_runner_; |
| 56 scoped_refptr<Channel> channel_; |
| 57 |
| 58 private: |
| 59 // base::MessageLoop::DestructionObserver: |
| 60 void WillDestroyCurrentMessageLoop() override; |
| 61 |
| 62 // Channel::Delegate: |
| 63 void OnChannelMessage(const void* payload, |
| 64 size_t payload_size, |
| 65 ScopedPlatformHandleVectorPtr handles) override; |
| 66 void OnChannelError() override; |
| 67 |
| 68 void ShutDownNow(); |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeBootstrap); |
| 71 }; |
| 72 |
| 73 } // namespace edk |
| 74 } // namespace mojo |
| 75 |
| 76 #endif // MOJO_EDK_SYSTEM_REMOTE_MESSAGE_PIPE_BOOTSTRAP_H_ |
OLD | NEW |