Bug 592768 - When using async launch, the toplevel actor doesn't have a process handle. Set the process ID with a callback function (OnChannelConnected). r=cjones

--HG--
extra : rebase_source : aa7743035e9a21759d99b9b9fbaf6371b8c82395
This commit is contained in:
Benedict Hsieh 2010-10-08 16:24:36 -07:00
parent 3930901751
commit fba1d721da
7 changed files with 51 additions and 0 deletions

View File

@ -464,6 +464,14 @@ AsyncChannel::OnChannelOpened()
/*assert*/mTransport->Connect();
}
void
AsyncChannel::DispatchOnChannelConnected(int32 peer_pid)
{
AssertWorkerThread();
if (mListener)
mListener->OnChannelConnected(peer_pid);
}
void
AsyncChannel::OnChannelConnected(int32 peer_pid)
{
@ -477,6 +485,10 @@ AsyncChannel::OnChannelConnected(int32 peer_pid)
if(mExistingListener)
mExistingListener->OnChannelConnected(peer_pid);
mWorkerLoop->PostTask(FROM_HERE, NewRunnableMethod(this,
&AsyncChannel::DispatchOnChannelConnected,
peer_pid));
}
void

View File

@ -95,6 +95,7 @@ public:
virtual void OnChannelError() = 0;
virtual Result OnMessageReceived(const Message& aMessage) = 0;
virtual void OnProcessingError(Result aError) = 0;
virtual void OnChannelConnected(int32 peer_pid) {};
};
public:
@ -117,6 +118,9 @@ public:
// Asynchronously send a message to the other side of the channel
virtual bool Send(Message* msg);
// Send OnChannelConnected notification to listeners.
void DispatchOnChannelConnected(int32 peer_pid);
//
// These methods are called on the "IO" thread
//

View File

@ -84,6 +84,7 @@ public:
Message*& aReply) = 0;
virtual Result OnCallReceived(const Message& aMessage,
Message*& aReply) = 0;
virtual void OnChannelConnected(int32 peer_pid) {};
virtual void OnEnteredCxxStack()
{

View File

@ -67,6 +67,7 @@ public:
virtual bool OnReplyTimeout() = 0;
virtual Result OnMessageReceived(const Message& aMessage,
Message*& aReply) = 0;
virtual void OnChannelConnected(int32 peer_pid) {};
};
SyncChannel(SyncListener* aListener);

View File

@ -2816,6 +2816,13 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
_runtimeAbort("`OnError' called on non-toplevel actor"))
self.cls.addstmts([ onerror, Whitespace.NL ])
# OnChannelConnected()
onconnected = MethodDefn(MethodDecl('OnChannelConnected'))
if not ptype.isToplevel():
onconnected.addstmt(
_runtimeAbort("'OnConnected' called on non-toplevel actor"))
self.cls.addstmts([ onconnected, Whitespace.NL ])
# FIXME/bug 535053: only manager protocols and non-manager
# protocols with union types need Lookup(). we'll give it to
# all for the time being (simpler)
@ -2844,6 +2851,16 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
self.cls.addstmts([ processnative, Whitespace.NL ])
if ptype.isToplevel() and self.side is 'parent':
## void SetOtherProcess(ProcessHandle pid)
otherprocessvar = ExprVar('aOtherProcess')
setotherprocess = MethodDefn(MethodDecl(
'SetOtherProcess',
params=[ Decl(Type('ProcessHandle'), otherprocessvar.name)]))
setotherprocess.addstmt(StmtExpr(ExprAssn(p.otherProcessVar(), otherprocessvar)))
self.cls.addstmts([
setotherprocess,
Whitespace.NL])
## bool GetMinidump(nsIFile** dump)
self.cls.addstmt(Label.PROTECTED)

View File

@ -37,6 +37,7 @@
#include "mozilla/jetpack/JetpackParent.h"
#include "mozilla/jetpack/Handle.h"
#include "base/process_util.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
@ -60,6 +61,9 @@ JetpackParent::~JetpackParent()
{
if (mSubprocess)
Destroy();
if (OtherProcess())
base::CloseProcessHandle(OtherProcess());
}
NS_IMPL_ISUPPORTS1(JetpackParent, nsIJetpack)
@ -242,5 +246,15 @@ JetpackParent::DeallocPHandle(PHandleParent* actor)
return true;
}
void
JetpackParent::OnChannelConnected(int32 pid)
{
ProcessHandle handle;
if (!base::OpenPrivilegedProcessHandle(pid, &handle))
NS_RUNTIMEABORT("can't open handle to child process");
SetOtherProcess(handle);
}
} // namespace jetpack
} // namespace mozilla

View File

@ -65,6 +65,8 @@ public:
JetpackParent(JSContext* cx);
~JetpackParent();
void OnChannelConnected(int32 pid);
protected:
NS_OVERRIDE virtual bool RecvSendMessage(const nsString& messageName,
const InfallibleTArray<Variant>& data);