зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1713148 - Part 4: Remove ProcessLink, r=handyman
After the changes in part 3, this type is now dead code and can be fully removed. Differential Revision: https://phabricator.services.mozilla.com/D116671
This commit is contained in:
Родитель
758f8f7d8f
Коммит
03646b0682
|
@ -799,24 +799,6 @@ bool MessageChannel::Open(ScopedPort aPort, Side aSide,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MessageChannel::Open(mozilla::UniquePtr<Transport> aTransport,
|
||||
MessageLoop* aIOLoop, Side aSide) {
|
||||
MOZ_ASSERT(!mLink, "Open() called > once");
|
||||
|
||||
mMonitor = new RefCountedMonitor();
|
||||
mWorkerThread = GetCurrentSerialEventTarget();
|
||||
MOZ_ASSERT(mWorkerThread, "We should always be on a nsISerialEventTarget");
|
||||
mListener->OnIPCChannelOpened();
|
||||
|
||||
auto link = MakeUnique<ProcessLink>(this);
|
||||
link->Open(std::move(aTransport), aIOLoop,
|
||||
aSide); // :TODO: n.b.: sets mChild
|
||||
mLink = std::move(link);
|
||||
mIsCrossProcess = true;
|
||||
ChannelCountReporter::Increment(mName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MessageChannel::Open(MessageChannel* aTargetChan,
|
||||
nsISerialEventTarget* aEventTarget, Side aSide) {
|
||||
// Opens a connection to another thread in the same process.
|
||||
|
|
|
@ -169,14 +169,6 @@ class MessageChannel : HasResultCodes {
|
|||
bool Open(ScopedPort aPort, Side aSide,
|
||||
nsISerialEventTarget* aEventTarget = nullptr);
|
||||
|
||||
// "Open" from the perspective of the transport layer; the underlying
|
||||
// socketpair/pipe should already be created.
|
||||
//
|
||||
// Returns true if the transport layer was successfully connected,
|
||||
// i.e., mChannelState == ChannelConnected.
|
||||
bool Open(UniquePtr<Transport> aTransport, MessageLoop* aIOLoop = 0,
|
||||
Side aSide = UnknownSide);
|
||||
|
||||
// "Open" a connection to another thread in the same process.
|
||||
//
|
||||
// Returns true if the transport layer was successfully connected,
|
||||
|
|
|
@ -49,123 +49,6 @@ MessageLink::~MessageLink() {
|
|||
#endif
|
||||
}
|
||||
|
||||
ProcessLink::ProcessLink(MessageChannel* aChan)
|
||||
: MessageLink(aChan), mIOLoop(nullptr), mExistingListener(nullptr) {}
|
||||
|
||||
ProcessLink::~ProcessLink() {
|
||||
// Dispatch the delete of the transport to the IO thread.
|
||||
RefPtr<DeleteTask<IPC::Channel>> task =
|
||||
new DeleteTask<IPC::Channel>(mTransport.release());
|
||||
XRE_GetIOMessageLoop()->PostTask(task.forget());
|
||||
|
||||
#ifdef DEBUG
|
||||
mIOLoop = nullptr;
|
||||
mExistingListener = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProcessLink::Open(UniquePtr<Transport> aTransport, MessageLoop* aIOLoop,
|
||||
Side aSide) {
|
||||
mChan->AssertWorkerThread();
|
||||
|
||||
MOZ_ASSERT(aTransport, "need transport layer");
|
||||
|
||||
// FIXME need to check for valid channel
|
||||
|
||||
mTransport = std::move(aTransport);
|
||||
|
||||
// FIXME figure out whether we're in parent or child, grab IO loop
|
||||
// appropriately
|
||||
bool needOpen = true;
|
||||
if (aIOLoop) {
|
||||
// We're a child or using the new arguments. Either way, we
|
||||
// need an open.
|
||||
needOpen = true;
|
||||
mChan->mSide = (aSide == UnknownSide) ? ChildSide : aSide;
|
||||
} else {
|
||||
MOZ_ASSERT(aSide == UnknownSide, "expected default side arg");
|
||||
|
||||
// parent
|
||||
mChan->mSide = ParentSide;
|
||||
needOpen = false;
|
||||
aIOLoop = XRE_GetIOMessageLoop();
|
||||
}
|
||||
|
||||
mIOLoop = aIOLoop;
|
||||
|
||||
NS_ASSERTION(mIOLoop, "need an IO loop");
|
||||
NS_ASSERTION(mChan->mWorkerThread, "need a worker thread");
|
||||
|
||||
// If we were never able to open the transport, immediately post an error
|
||||
// message.
|
||||
if (mTransport->Unsound_IsClosed()) {
|
||||
mIOLoop->PostTask(
|
||||
NewNonOwningRunnableMethod("ipc::ProcessLink::OnChannelConnectError",
|
||||
this, &ProcessLink::OnChannelConnectError));
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
|
||||
if (needOpen) {
|
||||
// Transport::Connect() has not been called. Call it so
|
||||
// we start polling our pipe and processing outgoing
|
||||
// messages.
|
||||
mIOLoop->PostTask(
|
||||
NewNonOwningRunnableMethod("ipc::ProcessLink::OnChannelOpened", this,
|
||||
&ProcessLink::OnChannelOpened));
|
||||
} else {
|
||||
// Transport::Connect() has already been called. Take
|
||||
// over the channel from the previous listener and process
|
||||
// any queued messages.
|
||||
mIOLoop->PostTask(NewNonOwningRunnableMethod(
|
||||
"ipc::ProcessLink::OnTakeConnectedChannel", this,
|
||||
&ProcessLink::OnTakeConnectedChannel));
|
||||
}
|
||||
|
||||
// Wait until one of the runnables above changes the state of the
|
||||
// channel. Note that the state could be changed again after that (to
|
||||
// ChannelClosing, for example, by the IO thread). We can rely on it not
|
||||
// changing back to Closed: only the worker thread changes it to closed,
|
||||
// and we're on the worker thread, blocked.
|
||||
while (mChan->mChannelState == ChannelClosed) {
|
||||
mChan->mMonitor->Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessLink::SendMessage(UniquePtr<Message> msg) {
|
||||
if (msg->size() > IPC::Channel::kMaximumMessageSize) {
|
||||
CrashReporter::AnnotateCrashReport(
|
||||
CrashReporter::Annotation::IPCMessageName,
|
||||
nsDependentCString(msg->name()));
|
||||
CrashReporter::AnnotateCrashReport(
|
||||
CrashReporter::Annotation::IPCMessageSize,
|
||||
static_cast<unsigned int>(msg->size()));
|
||||
MOZ_CRASH("IPC message size is too large");
|
||||
}
|
||||
|
||||
if (!mChan->mIsPostponingSends) {
|
||||
mChan->AssertWorkerThread();
|
||||
}
|
||||
mChan->mMonitor->AssertCurrentThreadOwns();
|
||||
|
||||
msg->AssertAsLargeAsHeader();
|
||||
|
||||
mIOLoop->PostTask(NewNonOwningRunnableMethod<UniquePtr<Message>&&>(
|
||||
"IPC::Channel::Send", mTransport.get(), &Transport::Send,
|
||||
std::move(msg)));
|
||||
}
|
||||
|
||||
void ProcessLink::SendClose() {
|
||||
mChan->AssertWorkerThread();
|
||||
mChan->mMonitor->AssertCurrentThreadOwns();
|
||||
|
||||
mIOLoop->PostTask(NewNonOwningRunnableMethod(
|
||||
"ipc::ProcessLink::OnCloseChannel", this, &ProcessLink::OnCloseChannel));
|
||||
}
|
||||
|
||||
ThreadLink::ThreadLink(MessageChannel* aChan, MessageChannel* aTargetChan)
|
||||
: MessageLink(aChan), mTargetChan(aTargetChan) {}
|
||||
|
||||
|
@ -255,129 +138,6 @@ uint32_t ThreadLink::Unsound_NumQueuedMessages() const {
|
|||
// ThreadLinks don't have a message queue.
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// The methods below run in the context of the IO thread
|
||||
//
|
||||
|
||||
void ProcessLink::OnMessageReceived(Message&& msg) {
|
||||
AssertIOThread();
|
||||
NS_ASSERTION(mChan->mChannelState != ChannelError, "Shouldn't get here!");
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
mChan->OnMessageReceivedFromLink(std::move(msg));
|
||||
}
|
||||
|
||||
void ProcessLink::OnChannelOpened() {
|
||||
AssertIOThread();
|
||||
|
||||
{
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
|
||||
mExistingListener = mTransport->set_listener(this);
|
||||
#ifdef DEBUG
|
||||
if (mExistingListener) {
|
||||
std::queue<Message> pending;
|
||||
mExistingListener->GetQueuedMessages(pending);
|
||||
MOZ_ASSERT(pending.empty());
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
mChan->mChannelState = ChannelOpening;
|
||||
lock.Notify();
|
||||
}
|
||||
|
||||
if (!mTransport->Connect()) {
|
||||
mTransport->Close();
|
||||
OnChannelError();
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessLink::OnTakeConnectedChannel() {
|
||||
AssertIOThread();
|
||||
|
||||
std::queue<Message> pending;
|
||||
{
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
|
||||
mChan->mChannelState = ChannelConnected;
|
||||
|
||||
mExistingListener = mTransport->set_listener(this);
|
||||
if (mExistingListener) {
|
||||
mExistingListener->GetQueuedMessages(pending);
|
||||
}
|
||||
lock.Notify();
|
||||
}
|
||||
|
||||
// Dispatch whatever messages the previous listener had queued up.
|
||||
while (!pending.empty()) {
|
||||
OnMessageReceived(std::move(pending.front()));
|
||||
pending.pop();
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessLink::OnChannelConnected(int32_t peer_pid) {
|
||||
AssertIOThread();
|
||||
|
||||
{
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
// Do not force it into connected if it has errored out, started
|
||||
// closing, etc. Note that we can be in the Connected state already
|
||||
// since the parent starts out Connected.
|
||||
if (mChan->mChannelState == ChannelOpening ||
|
||||
mChan->mChannelState == ChannelConnected) {
|
||||
mChan->mChannelState = ChannelConnected;
|
||||
mChan->mMonitor->Notify();
|
||||
}
|
||||
}
|
||||
|
||||
if (mExistingListener) {
|
||||
mExistingListener->OnChannelConnected(peer_pid);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessLink::OnChannelConnectError() {
|
||||
AssertIOThread();
|
||||
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
|
||||
mChan->OnChannelErrorFromLink();
|
||||
}
|
||||
|
||||
void ProcessLink::OnChannelError() {
|
||||
AssertIOThread();
|
||||
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
|
||||
MOZ_ALWAYS_TRUE(this == mTransport->set_listener(mExistingListener));
|
||||
|
||||
mChan->OnChannelErrorFromLink();
|
||||
}
|
||||
|
||||
void ProcessLink::OnCloseChannel() {
|
||||
AssertIOThread();
|
||||
|
||||
mTransport->Close();
|
||||
|
||||
MonitorAutoLock lock(*mChan->mMonitor);
|
||||
|
||||
DebugOnly<IPC::Channel::Listener*> previousListener =
|
||||
mTransport->set_listener(mExistingListener);
|
||||
|
||||
// OnChannelError may have reset the listener already.
|
||||
MOZ_ASSERT(previousListener == this || previousListener == mExistingListener);
|
||||
|
||||
mChan->mChannelState = ChannelClosed;
|
||||
mChan->mMonitor->Notify();
|
||||
}
|
||||
|
||||
bool ProcessLink::Unsound_IsClosed() const {
|
||||
return mTransport->Unsound_IsClosed();
|
||||
}
|
||||
|
||||
uint32_t ProcessLink::Unsound_NumQueuedMessages() const {
|
||||
return mTransport->Unsound_NumQueuedMessages();
|
||||
}
|
||||
|
||||
class PortLink::PortObserverThunk : public NodeController::PortObserver {
|
||||
public:
|
||||
PortObserverThunk(RefCountedMonitor* aMonitor, PortLink* aLink)
|
||||
|
|
|
@ -65,51 +65,6 @@ class MessageLink {
|
|||
MessageChannel* mChan;
|
||||
};
|
||||
|
||||
class ProcessLink : public MessageLink, public Transport::Listener {
|
||||
void OnCloseChannel();
|
||||
void OnChannelOpened();
|
||||
void OnTakeConnectedChannel();
|
||||
|
||||
void AssertIOThread() const {
|
||||
MOZ_ASSERT(mIOLoop == MessageLoop::current(), "not on I/O thread!");
|
||||
}
|
||||
|
||||
public:
|
||||
explicit ProcessLink(MessageChannel* chan);
|
||||
virtual ~ProcessLink();
|
||||
|
||||
// The ProcessLink will register itself as the IPC::Channel::Listener on the
|
||||
// transport passed here. If the transport already has a listener registered
|
||||
// then a listener chain will be established (the ProcessLink listener
|
||||
// methods will be called first and may call some methods on the original
|
||||
// listener as well). Once the channel is closed (either via normal shutdown
|
||||
// or a pipe error) the chain will be destroyed and the original listener
|
||||
// will again be registered.
|
||||
void Open(UniquePtr<Transport> aTransport, MessageLoop* aIOLoop, Side aSide);
|
||||
|
||||
// Run on the I/O thread, only when using inter-process link.
|
||||
// These methods acquire the monitor and forward to the
|
||||
// similarly named methods in AsyncChannel below
|
||||
// (OnMessageReceivedFromLink(), etc)
|
||||
virtual void OnMessageReceived(Message&& msg) override;
|
||||
virtual void OnChannelConnected(int32_t peer_pid) override;
|
||||
virtual void OnChannelError() override;
|
||||
|
||||
virtual void SendMessage(mozilla::UniquePtr<Message> msg) override;
|
||||
virtual void SendClose() override;
|
||||
|
||||
virtual bool Unsound_IsClosed() const override;
|
||||
virtual uint32_t Unsound_NumQueuedMessages() const override;
|
||||
|
||||
protected:
|
||||
void OnChannelConnectError();
|
||||
|
||||
protected:
|
||||
UniquePtr<Transport> mTransport;
|
||||
MessageLoop* mIOLoop; // thread where IO happens
|
||||
Transport::Listener* mExistingListener; // channel's previous listener
|
||||
};
|
||||
|
||||
class ThreadLink : public MessageLink {
|
||||
public:
|
||||
ThreadLink(MessageChannel* aChan, MessageChannel* aTargetChan);
|
||||
|
|
|
@ -644,13 +644,6 @@ bool IToplevelProtocol::Open(ScopedPort aPort, base::ProcessId aOtherPid) {
|
|||
return GetIPCChannel()->Open(std::move(aPort), mSide);
|
||||
}
|
||||
|
||||
bool IToplevelProtocol::Open(UniquePtr<Transport> aTransport,
|
||||
base::ProcessId aOtherPid, MessageLoop* aThread,
|
||||
mozilla::ipc::Side aSide) {
|
||||
SetOtherProcessId(aOtherPid);
|
||||
return GetIPCChannel()->Open(std::move(aTransport), aThread, aSide);
|
||||
}
|
||||
|
||||
bool IToplevelProtocol::Open(MessageChannel* aChannel,
|
||||
nsISerialEventTarget* aEventTarget,
|
||||
mozilla::ipc::Side aSide) {
|
||||
|
|
|
@ -446,10 +446,6 @@ class IToplevelProtocol : public IProtocol {
|
|||
|
||||
bool Open(ScopedPort aPort, base::ProcessId aOtherPid);
|
||||
|
||||
bool Open(UniquePtr<Transport> aTransport, base::ProcessId aOtherPid,
|
||||
MessageLoop* aThread = nullptr,
|
||||
mozilla::ipc::Side aSide = mozilla::ipc::UnknownSide);
|
||||
|
||||
bool Open(MessageChannel* aChannel, nsISerialEventTarget* aEventTarget,
|
||||
mozilla::ipc::Side aSide = mozilla::ipc::UnknownSide);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче