Bug 1226200: Don't assume a TCPSocket has only one managee (and rename LoneManagedOrNull) r=jdm

This commit is contained in:
Randell Jesup 2015-12-22 10:14:23 -05:00
parent 50f6d47f19
commit d163204665
12 changed files with 35 additions and 20 deletions

View File

@ -98,7 +98,7 @@ ContentBridgeChild::SendPBrowserConstructor(PBrowserChild* aActor,
jsipc::CPOWManager*
ContentBridgeChild::GetCPOWManager()
{
if (PJavaScriptChild* c = LoneManagedOrNull(ManagedPJavaScriptChild())) {
if (PJavaScriptChild* c = LoneManagedOrNullAsserts(ManagedPJavaScriptChild())) {
return CPOWManagerFor(c);
}
return CPOWManagerFor(SendPJavaScriptConstructor());

View File

@ -180,7 +180,7 @@ ContentBridgeParent::NotifyTabDestroyed()
jsipc::CPOWManager*
ContentBridgeParent::GetCPOWManager()
{
if (PJavaScriptParent* p = LoneManagedOrNull(ManagedPJavaScriptParent())) {
if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) {
return CPOWManagerFor(p);
}
return nullptr;

View File

@ -1723,7 +1723,7 @@ ContentChild::DeallocPTestShellChild(PTestShellChild* shell)
jsipc::CPOWManager*
ContentChild::GetCPOWManager()
{
if (PJavaScriptChild* c = LoneManagedOrNull(ManagedPJavaScriptChild())) {
if (PJavaScriptChild* c = LoneManagedOrNullAsserts(ManagedPJavaScriptChild())) {
return CPOWManagerFor(c);
}
return CPOWManagerFor(SendPJavaScriptConstructor());
@ -2226,7 +2226,7 @@ ContentChild::ProcessingError(Result aCode, const char* aReason)
}
#if defined(MOZ_CRASHREPORTER) && !defined(MOZ_B2G)
if (PCrashReporterChild* c = LoneManagedOrNull(ManagedPCrashReporterChild())) {
if (PCrashReporterChild* c = LoneManagedOrNullAsserts(ManagedPCrashReporterChild())) {
CrashReporterChild* crashReporter =
static_cast<CrashReporterChild*>(c);
nsDependentCString reason(aReason);

View File

@ -2169,7 +2169,7 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
// There's a window in which child processes can crash
// after IPC is established, but before a crash reporter
// is created.
if (PCrashReporterParent* p = LoneManagedOrNull(ManagedPCrashReporterParent())) {
if (PCrashReporterParent* p = LoneManagedOrNullAsserts(ManagedPCrashReporterParent())) {
CrashReporterParent* crashReporter =
static_cast<CrashReporterParent*>(p);
@ -2350,7 +2350,7 @@ ContentParent::NotifyTabDestroyed(const TabId& aTabId,
jsipc::CPOWManager*
ContentParent::GetCPOWManager()
{
if (PJavaScriptParent* p = LoneManagedOrNull(ManagedPJavaScriptParent())) {
if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) {
return CPOWManagerFor(p);
}
return nullptr;
@ -2371,7 +2371,7 @@ ContentParent::DestroyTestShell(TestShellParent* aTestShell)
TestShellParent*
ContentParent::GetTestShellSingleton()
{
PTestShellParent* p = LoneManagedOrNull(ManagedPTestShellParent());
PTestShellParent* p = LoneManagedOrNullAsserts(ManagedPTestShellParent());
return static_cast<TestShellParent*>(p);
}
@ -3656,7 +3656,7 @@ ContentParent::KillHard(const char* aReason)
// We're about to kill the child process associated with this content.
// Something has gone wrong to get us here, so we generate a minidump
// of the parent and child for submission to the crash server.
if (PCrashReporterParent* p = LoneManagedOrNull(ManagedPCrashReporterParent())) {
if (PCrashReporterParent* p = LoneManagedOrNullAsserts(ManagedPCrashReporterParent())) {
CrashReporterParent* crashReporter =
static_cast<CrashReporterParent*>(p);
// GeneratePairedMinidump creates two minidumps for us - the main

View File

@ -35,7 +35,7 @@ CrashReporterChild::GetCrashReporter()
if (!reporters) {
return nullptr;
}
return LoneManagedOrNull(*reporters);
return LoneManagedOrNullAsserts(*reporters);
}
} // namespace dom

View File

@ -2348,7 +2348,7 @@ TabParent::GetTabIdFrom(nsIDocShell *docShell)
RenderFrameParent*
TabParent::GetRenderFrame()
{
PRenderFrameParent* p = LoneManagedOrNull(ManagedPRenderFrameParent());
PRenderFrameParent* p = LoneManagedOrNullAsserts(ManagedPRenderFrameParent());
return static_cast<RenderFrameParent*>(p);
}

View File

@ -582,7 +582,7 @@ void
GMPParent::GetCrashID(nsString& aResult)
{
CrashReporterParent* cr =
static_cast<CrashReporterParent*>(LoneManagedOrNull(ManagedPCrashReporterParent()));
static_cast<CrashReporterParent*>(LoneManagedOrNullAsserts(ManagedPCrashReporterParent()));
if (NS_WARN_IF(!cr)) {
return;
}

View File

@ -66,7 +66,7 @@ uint32_t
TCPServerSocketParent::GetAppId()
{
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) {
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
TabParent *tab = TabParent::GetFrom(browser);
return tab->OwnAppId();
} else {
@ -78,7 +78,7 @@ bool
TCPServerSocketParent::GetInBrowser()
{
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) {
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
TabParent *tab = TabParent::GetFrom(browser);
return tab->IsBrowserElement();
} else {

View File

@ -68,7 +68,7 @@ uint32_t
TCPSocketParent::GetAppId()
{
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) {
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
TabParent *tab = TabParent::GetFrom(browser);
return tab->OwnAppId();
} else {
@ -80,7 +80,7 @@ bool
TCPSocketParent::GetInBrowser()
{
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) {
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
TabParent *tab = TabParent::GetFrom(browser);
return tab->IsBrowserElement();
} else {
@ -223,7 +223,9 @@ TCPSocketParent::RecvOpenBind(const nsCString& aRemoteHost,
uint32_t appId = nsIScriptSecurityManager::NO_APP_ID;
bool inBrowser = false;
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) {
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
// appId's are for B2G only currently, where managees.Count() == 1
// This is not guaranteed currently in Desktop, so skip this there.
TabParent *tab = TabParent::GetFrom(browser);
appId = tab->OwnAppId();
inBrowser = tab->IsBrowserElement();

View File

@ -1504,7 +1504,7 @@ PluginModuleChromeParent::OnHangUIContinue()
CrashReporterParent*
PluginModuleChromeParent::CrashReporter()
{
return static_cast<CrashReporterParent*>(LoneManagedOrNull(ManagedPCrashReporterParent()));
return static_cast<CrashReporterParent*>(LoneManagedOrNullAsserts(ManagedPCrashReporterParent()));
}
#ifdef MOZ_CRASHREPORTER_INJECTOR

View File

@ -336,7 +336,7 @@ using ManagedContainer = nsTHashtable<nsPtrHashKey<Protocol>>;
template<typename Protocol>
Protocol*
LoneManagedOrNull(const ManagedContainer<Protocol>& aManagees)
LoneManagedOrNullAsserts(const ManagedContainer<Protocol>& aManagees)
{
if (aManagees.IsEmpty()) {
return nullptr;
@ -345,6 +345,19 @@ LoneManagedOrNull(const ManagedContainer<Protocol>& aManagees)
return aManagees.ConstIter().Get()->GetKey();
}
// appId's are for B2G only currently, where managees.Count() == 1. This is
// not guaranteed currently in Desktop, so for paths used for desktop,
// don't assert there's one managee.
template<typename Protocol>
Protocol*
SingleManagedOrNull(const ManagedContainer<Protocol>& aManagees)
{
if (aManagees.Count() != 1) {
return nullptr;
}
return aManagees.ConstIter().Get()->GetKey();
}
} // namespace mozilla

View File

@ -78,10 +78,10 @@ TestMultiMgrsChild::RecvCheck()
TestMultiMgrsLeftChild* leftie =
static_cast<TestMultiMgrsLeftChild*>(
LoneManagedOrNull(ManagedPTestMultiMgrsLeftChild()));
LoneManagedOrNullAsserts(ManagedPTestMultiMgrsLeftChild()));
TestMultiMgrsRightChild* rightie =
static_cast<TestMultiMgrsRightChild*>(
LoneManagedOrNull(ManagedPTestMultiMgrsRightChild()));
LoneManagedOrNullAsserts(ManagedPTestMultiMgrsRightChild()));
if (!leftie->HasChild(mBottomL))
fail("leftie didn't have a child it was supposed to!");