Commit 1384172c authored by Chris Jones's avatar Chris Jones
Browse files

Bug 613442, part 3: Add AsyncChannel::Echo() to allow sending a message back...

Bug 613442, part 3: Add AsyncChannel::Echo() to allow sending a message back to the originating endpoint. r=bent
parent c97ee795
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -247,6 +247,33 @@ AsyncChannel::Send(Message* msg)
    return true;
}

bool
AsyncChannel::Echo(Message* msg)
{
    AssertWorkerThread();
    mMonitor.AssertNotCurrentThreadOwns();
    NS_ABORT_IF_FALSE(MSG_ROUTING_NONE != msg->routing_id(), "need a route");

    {
        MonitorAutoLock lock(mMonitor);

        if (!Connected()) {
            ReportConnectionError("AsyncChannel");
            return false;
        }

        // NB: Go through this OnMessageReceived indirection so that
        // echoing this message does the right thing for SyncChannel
        // and RPCChannel too
        mIOLoop->PostTask(
            FROM_HERE,
            NewRunnableMethod(this, &AsyncChannel::OnEchoMessage, msg));
        // OnEchoMessage takes ownership of |msg|
    }

    return true;
}

void
AsyncChannel::OnDispatchMessage(const Message& msg)
{
@@ -470,6 +497,14 @@ AsyncChannel::OnMessageReceived(const Message& msg)
            NewRunnableMethod(this, &AsyncChannel::OnDispatchMessage, msg));
}

void
AsyncChannel::OnEchoMessage(Message* msg)
{
    AssertIOThread();
    OnMessageReceived(*msg);
    delete msg;
}

void
AsyncChannel::OnChannelOpened()
{
+5 −0
Original line number Diff line number Diff line
@@ -117,6 +117,10 @@ public:
    // Asynchronously send a message to the other side of the channel
    virtual bool Send(Message* msg);

    // Asynchronously deliver a message back to this side of the
    // channel
    virtual bool Echo(Message* msg);

    // Send OnChannelConnected notification to listeners.
    void DispatchOnChannelConnected(int32 peer_pid);

@@ -177,6 +181,7 @@ protected:
    void OnChannelOpened();
    void OnCloseChannel();
    void PostErrorNotifyTask();
    void OnEchoMessage(Message* msg);

    // Return true if |msg| is a special message targeted at the IO
    // thread, in which case it shouldn't be delivered to the worker.