mojo_server_endpoint_connector_linux.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_MOJO_SERVER_ENDPOINT_CONNECTOR_LINUX_H_
  5. #define REMOTING_HOST_MOJO_IPC_MOJO_SERVER_ENDPOINT_CONNECTOR_LINUX_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/message_loop/message_pump_for_io.h"
  8. #include "base/sequence_checker.h"
  9. #include "base/thread_annotations.h"
  10. #include "remoting/host/mojo_ipc/mojo_server_endpoint_connector.h"
  11. namespace remoting {
  12. // Linux implementation for MojoServerEndpointConnector.
  13. class MojoServerEndpointConnectorLinux final
  14. : public MojoServerEndpointConnector,
  15. public base::MessagePumpForIO::FdWatcher {
  16. public:
  17. explicit MojoServerEndpointConnectorLinux(Delegate* delegate);
  18. MojoServerEndpointConnectorLinux(const MojoServerEndpointConnectorLinux&) =
  19. delete;
  20. MojoServerEndpointConnectorLinux& operator=(
  21. const MojoServerEndpointConnectorLinux&) = delete;
  22. ~MojoServerEndpointConnectorLinux() override;
  23. // MojoServerEndpointConnector implementation.
  24. void Connect(mojo::PlatformChannelServerEndpoint server_endpoint) override;
  25. private:
  26. // base::MessagePumpForIO::FdWatcher implementation.
  27. void OnFileCanReadWithoutBlocking(int fd) override;
  28. void OnFileCanWriteWithoutBlocking(int fd) override;
  29. SEQUENCE_CHECKER(sequence_checker_);
  30. raw_ptr<Delegate> delegate_ GUARDED_BY_CONTEXT(sequence_checker_);
  31. // These are only valid/non-null when there is a pending connection.
  32. // Note that |pending_server_endpoint_| must outlive |read_watcher_|;
  33. // otherwise a bad file descriptor error will occur at destruction.
  34. mojo::PlatformChannelServerEndpoint pending_server_endpoint_
  35. GUARDED_BY_CONTEXT(sequence_checker_);
  36. std::unique_ptr<base::MessagePumpForIO::FdWatchController> read_watcher_
  37. GUARDED_BY_CONTEXT(sequence_checker_);
  38. };
  39. } // namespace remoting
  40. #endif // REMOTING_HOST_MOJO_IPC_MOJO_SERVER_ENDPOINT_CONNECTOR_LINUX_H_