ipc_listener.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2012 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 IPC_IPC_LISTENER_H_
  5. #define IPC_IPC_LISTENER_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/component_export.h"
  9. #include "build/build_config.h"
  10. #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
  11. namespace IPC {
  12. class Message;
  13. // Implemented by consumers of a Channel to receive messages.
  14. class COMPONENT_EXPORT(IPC) Listener {
  15. public:
  16. // Called when a message is received. Returns true iff the message was
  17. // handled.
  18. virtual bool OnMessageReceived(const Message& message) = 0;
  19. // Called when the channel is connected and we have received the internal
  20. // Hello message from the peer.
  21. virtual void OnChannelConnected(int32_t peer_pid) {}
  22. // Called when an error is detected that causes the channel to close.
  23. // This method is not called when a channel is closed normally.
  24. virtual void OnChannelError() {}
  25. // Called when a message's deserialization failed.
  26. virtual void OnBadMessageReceived(const Message& message) {}
  27. // Called when an associated interface request is received on a Channel and
  28. // the Channel has no registered handler for it.
  29. virtual void OnAssociatedInterfaceRequest(
  30. const std::string& interface_name,
  31. mojo::ScopedInterfaceEndpointHandle handle) {}
  32. #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
  33. // Called on the server side when a channel that listens for connections
  34. // denies an attempt to connect.
  35. virtual void OnChannelDenied() {}
  36. // Called on the server side when a channel that listens for connections
  37. // has an error that causes the listening channel to close.
  38. virtual void OnChannelListenError() {}
  39. #endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
  40. // Debugging helper for identifying what kind of a Listener this is.
  41. // TODO(https://crbug.com/1113159): Remove this method once the bug is fixed.
  42. virtual std::string ToDebugString();
  43. protected:
  44. virtual ~Listener() {}
  45. };
  46. } // namespace IPC
  47. #endif // IPC_IPC_LISTENER_H_