blob: d7ad75c321b93fb9b92ba2fa5b0f2cf0f729312f [file] [log] [blame]
Luis Hector Chavez645501c2016-12-28 10:56:26 -08001// 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
5#ifndef IPC_IPC_LISTENER_H_
6#define IPC_IPC_LISTENER_H_
7
8#include <stdint.h>
9
Jay Civellicfc1eaa2017-08-21 17:18:10 -070010#include <string>
11
Luis Hector Chavez645501c2016-12-28 10:56:26 -080012#include "build/build_config.h"
13#include "ipc/ipc_export.h"
Jay Civellicfc1eaa2017-08-21 17:18:10 -070014#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
Luis Hector Chavez645501c2016-12-28 10:56:26 -080015
16namespace IPC {
17
18class Message;
19
20// Implemented by consumers of a Channel to receive messages.
21class IPC_EXPORT Listener {
22 public:
23 // Called when a message is received. Returns true iff the message was
24 // handled.
25 virtual bool OnMessageReceived(const Message& message) = 0;
26
27 // Called when the channel is connected and we have received the internal
28 // Hello message from the peer.
29 virtual void OnChannelConnected(int32_t peer_pid) {}
30
31 // Called when an error is detected that causes the channel to close.
32 // This method is not called when a channel is closed normally.
33 virtual void OnChannelError() {}
34
35 // Called when a message's deserialization failed.
36 virtual void OnBadMessageReceived(const Message& message) {}
37
Jay Civellicfc1eaa2017-08-21 17:18:10 -070038 // Called when an associated interface request is received on a Channel and
39 // the Channel has no registered handler for it.
40 virtual void OnAssociatedInterfaceRequest(
41 const std::string& interface_name,
42 mojo::ScopedInterfaceEndpointHandle handle) {}
43
Luis Hector Chavez645501c2016-12-28 10:56:26 -080044#if defined(OS_POSIX)
45 // Called on the server side when a channel that listens for connections
46 // denies an attempt to connect.
47 virtual void OnChannelDenied() {}
48
49 // Called on the server side when a channel that listens for connections
50 // has an error that causes the listening channel to close.
51 virtual void OnChannelListenError() {}
52#endif // OS_POSIX
53
54 protected:
55 virtual ~Listener() {}
56};
57
58} // namespace IPC
59
60#endif // IPC_IPC_LISTENER_H_