1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef ipc_glue_MessageLink_h
9 #define ipc_glue_MessageLink_h
12 #include "base/message_loop.h"
13 #include "mojo/core/ports/node.h"
14 #include "mojo/core/ports/port_ref.h"
15 #include "mozilla/Assertions.h"
16 #include "mozilla/UniquePtr.h"
17 #include "mozilla/ipc/ScopedPort.h"
31 struct HasResultCodes
{
44 enum Side
: uint8_t { ParentSide
, ChildSide
, UnknownSide
};
46 const char* StringFromIPCSide(Side side
);
50 typedef IPC::Message Message
;
52 explicit MessageLink(MessageChannel
* aChan
);
53 virtual ~MessageLink();
55 // n.b.: These methods all require that the channel monitor is
56 // held when they are invoked.
57 virtual void SendMessage(mozilla::UniquePtr
<Message
> msg
) = 0;
59 // Synchronously close the connection, such that no further notifications will
60 // be delivered to the MessageChannel instance. Must be called with the
61 // channel monitor held.
62 virtual void Close() = 0;
64 virtual bool IsClosed() const = 0;
66 #ifdef FUZZING_SNAPSHOT
67 virtual Maybe
<mojo::core::ports::PortName
> GetPortName() { return Nothing(); }
71 MessageChannel
* mChan
;
74 class PortLink final
: public MessageLink
{
75 using PortRef
= mojo::core::ports::PortRef
;
76 using PortStatus
= mojo::core::ports::PortStatus
;
77 using UserMessage
= mojo::core::ports::UserMessage
;
78 using UserMessageEvent
= mojo::core::ports::UserMessageEvent
;
81 PortLink(MessageChannel
* aChan
, ScopedPort aPort
);
84 void SendMessage(UniquePtr
<Message
> aMessage
) override
;
85 void Close() override
;
87 bool IsClosed() const override
;
89 #ifdef FUZZING_SNAPSHOT
90 Maybe
<mojo::core::ports::PortName
> GetPortName() override
{
91 return Some(mPort
.name());
96 class PortObserverThunk
;
97 friend class PortObserverThunk
;
99 void OnPortStatusChanged();
101 // Called either when an error is detected on the port from the port observer,
102 // or when `SendClose()` is called.
105 const RefPtr
<NodeController
> mNode
;
108 RefPtr
<PortObserverThunk
> mObserver
;
112 } // namespace mozilla
114 #endif // ifndef ipc_glue_MessageLink_h