| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_EDK_SYSTEM_BROKER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_BROKER_H_ |
| 6 #define MOJO_EDK_SYSTEM_BROKER_H_ | 6 #define MOJO_EDK_SYSTEM_BROKER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "mojo/edk/embedder/scoped_platform_handle.h" | 11 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace edk { | 14 namespace edk { |
| 15 class MessagePipeDispatcher; | 15 class MessagePipeDispatcher; |
| 16 class RawChannel; | 16 class RawChannel; |
| 17 class PlatformSharedBuffer; | |
| 18 | 17 |
| 19 // An interface for communicating to a central "broker" process from each | 18 // An interface for communicating to a central "broker" process from each |
| 20 // process using the EDK. It serves two purposes: | 19 // process using the EDK. It serves two purposes: |
| 21 // 1) Windows only: brokering to help child processes as they can't create | 20 // 1) Windows only: brokering to help child processes as they can't create |
| 22 // named pipes or duplicate handles. | 21 // named pipes or duplicate handles. |
| 23 // 2) All platforms: support multiplexed messages pipes. | 22 // 2) All platforms: support multiplexed messages pipes. |
| 24 | 23 |
| 25 class MOJO_SYSTEM_IMPL_EXPORT Broker { | 24 class MOJO_SYSTEM_IMPL_EXPORT Broker { |
| 26 public: | 25 public: |
| 27 virtual ~Broker() {} | 26 virtual ~Broker() {} |
| 28 | 27 |
| 29 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 30 // It is safe to call these three methods from any thread. | 29 // It is safe to call these three methods from any thread. |
| 31 | 30 |
| 32 // Create a PlatformChannelPair. | 31 // Create a PlatformChannelPair. |
| 33 virtual void CreatePlatformChannelPair(ScopedPlatformHandle* server, | 32 virtual void CreatePlatformChannelPair(ScopedPlatformHandle* server, |
| 34 ScopedPlatformHandle* client) = 0; | 33 ScopedPlatformHandle* client) = 0; |
| 35 | 34 |
| 36 // Converts the given platform handles to tokens. | 35 // Converts the given platform handles to tokens. |
| 37 // |tokens| should point to memory that is sizeof(uint64_t) * count; | 36 // |tokens| should point to memory that is sizeof(uint64_t) * count; |
| 38 virtual void HandleToToken(const PlatformHandle* platform_handles, | 37 virtual void HandleToToken(const PlatformHandle* platform_handles, |
| 39 size_t count, | 38 size_t count, |
| 40 uint64_t* tokens) = 0; | 39 uint64_t* tokens) = 0; |
| 41 | 40 |
| 42 // Converts the given tokens to platformhandles. | 41 // Converts the given tokens to platformhandles. |
| 43 // |handles| should point to memory that is sizeof(HANDLE) * count; | 42 // |handles| should point to memory that is sizeof(HANDLE) * count; |
| 44 virtual void TokenToHandle(const uint64_t* tokens, | 43 virtual void TokenToHandle(const uint64_t* tokens, |
| 45 size_t count, | 44 size_t count, |
| 46 PlatformHandle* handles) = 0; | 45 PlatformHandle* handles) = 0; |
| 47 #else | |
| 48 // Creates a shared buffer. | |
| 49 virtual scoped_refptr<PlatformSharedBuffer> CreateSharedBuffer( | |
| 50 size_t num_bytes) = 0; | |
| 51 #endif | 46 #endif |
| 52 | 47 |
| 53 // Multiplexing related methods. They are called from the IO thread only. | 48 // Multiplexing related methods. They are called from the IO thread only. |
| 54 | 49 |
| 55 // Called by |message_pipe| so that it receives messages for the given | 50 // Called by |message_pipe| so that it receives messages for the given |
| 56 // globally unique |pipe_id|. When the connection is established, | 51 // globally unique |pipe_id|. When the connection is established, |
| 57 // MessagePipeDispatcher::GotNonTransferableChannel is called with the channel | 52 // MessagePipeDispatcher::GotNonTransferableChannel is called with the channel |
| 58 // that it can use for sending messages. | 53 // that it can use for sending messages. |
| 59 virtual void ConnectMessagePipe(uint64_t pipe_id, | 54 virtual void ConnectMessagePipe(uint64_t pipe_id, |
| 60 MessagePipeDispatcher* message_pipe) = 0; | 55 MessagePipeDispatcher* message_pipe) = 0; |
| 61 | 56 |
| 62 // Called by |message_pipe| when it's closing so that its route can be | 57 // Called by |message_pipe| when it's closing so that its route can be |
| 63 // unregistered. | 58 // unregistered. |
| 64 // It's ok to call this from a callback (i.e. from OnError or | 59 // It's ok to call this from a callback (i.e. from OnError or |
| 65 // GotNonTransferableChannel). | 60 // GotNonTransferableChannel). |
| 66 virtual void CloseMessagePipe(uint64_t pipe_id, | 61 virtual void CloseMessagePipe(uint64_t pipe_id, |
| 67 MessagePipeDispatcher* message_pipe) = 0; | 62 MessagePipeDispatcher* message_pipe) = 0; |
| 68 }; | 63 }; |
| 69 | 64 |
| 70 } // namespace edk | 65 } // namespace edk |
| 71 } // namespace mojo | 66 } // namespace mojo |
| 72 | 67 |
| 73 #endif // MOJO_EDK_SYSTEM_BROKER_H_ | 68 #endif // MOJO_EDK_SYSTEM_BROKER_H_ |
| OLD | NEW |