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