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_BROKER_HOST_H_ 6 #define MOJO_EDK_SYSTEM_BROKER_HOST_H_ 7 8 #include <stdint.h> 9 10 #include "base/macros.h" 11 #include "base/message_loop/message_loop.h" 12 #include "base/process/process_handle.h" 13 #include "base/strings/string_piece.h" 14 #include "mojo/edk/embedder/platform_handle_vector.h" 15 #include "mojo/edk/embedder/scoped_platform_handle.h" 16 #include "mojo/edk/system/channel.h" 17 18 namespace mojo { 19 namespace edk { 20 21 // The BrokerHost is a channel to the child process, which services synchronous 22 // IPCs. 23 class BrokerHost : public Channel::Delegate, 24 public base::MessageLoop::DestructionObserver { 25 public: 26 BrokerHost(base::ProcessHandle client_process, ScopedPlatformHandle handle); 27 28 // Send |handle| to the child, to be used to establish a NodeChannel to us. 29 bool SendChannel(ScopedPlatformHandle handle); 30 31 #if defined(OS_WIN) 32 // Sends a named channel to the child. Like above, but for named pipes. 33 void SendNamedChannel(const base::StringPiece16& pipe_name); 34 #endif 35 36 private: 37 ~BrokerHost() override; 38 39 bool PrepareHandlesForClient(PlatformHandleVector* handles); 40 41 // Channel::Delegate: 42 void OnChannelMessage(const void* payload, 43 size_t payload_size, 44 ScopedPlatformHandleVectorPtr handles) override; 45 void OnChannelError() override; 46 47 // base::MessageLoop::DestructionObserver: 48 void WillDestroyCurrentMessageLoop() override; 49 50 void OnBufferRequest(uint32_t num_bytes); 51 52 #if defined(OS_WIN) 53 base::ProcessHandle client_process_; 54 #endif 55 56 scoped_refptr<Channel> channel_; 57 58 DISALLOW_COPY_AND_ASSIGN(BrokerHost); 59 }; 60 61 } // namespace edk 62 } // namespace mojo 63 64 #endif // MOJO_EDK_SYSTEM_BROKER_HOST_H_ 65