ipc_server.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 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 REMOTING_HOST_MOJO_IPC_IPC_SERVER_H_
  5. #define REMOTING_HOST_MOJO_IPC_IPC_SERVER_H_
  6. #include "base/callback.h"
  7. #include "base/process/process_handle.h"
  8. #include "mojo/public/cpp/bindings/receiver_set.h"
  9. namespace remoting {
  10. // An interface for MojoIpcServer to allow mocking in unittests.
  11. class IpcServer {
  12. public:
  13. virtual ~IpcServer() = default;
  14. // Starts sending out mojo invitations and accepting IPCs. No-op if the server
  15. // is already started.
  16. virtual void StartServer() = 0;
  17. // Stops sending out mojo invitations and accepting IPCs. No-op if the server
  18. // is already stopped.
  19. virtual void StopServer() = 0;
  20. // Close the receiver identified by |id| and disconnect the remote. No-op if
  21. // |id| doesn't exist or the receiver is already closed.
  22. virtual void Close(mojo::ReceiverId id) = 0;
  23. // Sets a callback to be invoked any time a receiver is disconnected. You may
  24. // find out which receiver is being disconnected by calling
  25. // |current_receiver()|.
  26. virtual void set_disconnect_handler(base::RepeatingClosure handler) = 0;
  27. // Call this method to learn which receiver has received the incoming IPC or
  28. // which receiver is being disconnected.
  29. virtual mojo::ReceiverId current_receiver() const = 0;
  30. // Call this method to learn the peer process' PID.
  31. virtual base::ProcessId current_peer_pid() const = 0;
  32. };
  33. } // namespace remoting
  34. #endif // REMOTING_HOST_MOJO_IPC_IPC_SERVER_H_