broker_host.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef MOJO_CORE_BROKER_HOST_H_
  5. #define MOJO_CORE_BROKER_HOST_H_
  6. #include <stdint.h>
  7. #include <vector>
  8. #include "base/process/process.h"
  9. #include "base/process/process_handle.h"
  10. #include "base/strings/string_piece.h"
  11. #include "base/task/current_thread.h"
  12. #include "build/build_config.h"
  13. #include "mojo/core/channel.h"
  14. #include "mojo/core/connection_params.h"
  15. #include "mojo/core/embedder/process_error_callback.h"
  16. #include "mojo/core/platform_handle_in_transit.h"
  17. #include "mojo/public/cpp/platform/platform_handle.h"
  18. namespace mojo {
  19. namespace core {
  20. // The BrokerHost is a channel to a broker client process, servicing synchronous
  21. // IPCs issued by the client.
  22. class BrokerHost : public Channel::Delegate,
  23. public base::CurrentThread::DestructionObserver {
  24. public:
  25. BrokerHost(base::Process client_process,
  26. ConnectionParams connection_params,
  27. const ProcessErrorCallback& process_error_callback);
  28. BrokerHost(const BrokerHost&) = delete;
  29. BrokerHost& operator=(const BrokerHost&) = delete;
  30. // Send |handle| to the client, to be used to establish a NodeChannel to us.
  31. bool SendChannel(PlatformHandle handle);
  32. #if BUILDFLAG(IS_WIN)
  33. // Sends a named channel to the client. Like above, but for named pipes.
  34. void SendNamedChannel(base::WStringPiece pipe_name);
  35. #endif
  36. private:
  37. ~BrokerHost() override;
  38. bool PrepareHandlesForClient(std::vector<PlatformHandleInTransit>* handles);
  39. // Channel::Delegate:
  40. void OnChannelMessage(const void* payload,
  41. size_t payload_size,
  42. std::vector<PlatformHandle> handles) override;
  43. void OnChannelError(Channel::Error error) override;
  44. // base::CurrentThread::DestructionObserver:
  45. void WillDestroyCurrentMessageLoop() override;
  46. void OnBufferRequest(uint32_t num_bytes);
  47. const ProcessErrorCallback process_error_callback_;
  48. #if BUILDFLAG(IS_WIN)
  49. base::Process client_process_;
  50. #endif
  51. scoped_refptr<Channel> channel_;
  52. };
  53. } // namespace core
  54. } // namespace mojo
  55. #endif // MOJO_CORE_BROKER_HOST_H_