Bug 1648270: Get rid of unused ContentParent 'opener' field. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D80971
This commit is contained in:
Kris Maglione 2020-06-25 17:53:39 +00:00
Родитель 183aa61185
Коммит f465a90bb0
5 изменённых файлов: 41 добавлений и 86 удалений

Просмотреть файл

@ -776,7 +776,6 @@ CanonicalBrowsingContext::ChangeRemoteness(const nsAString& aRemoteType,
/* aFrameElement = */ nullptr,
/* aRemoteType = */ aRemoteType,
/* aPriority = */ hal::PROCESS_PRIORITY_FOREGROUND,
/* aOpener = */ nullptr,
/* aPreferUsed = */ false);
if (!change->mContentParent) {
change->Cancel(NS_ERROR_FAILURE);

Просмотреть файл

@ -10,23 +10,12 @@ RandomSelector.prototype = {
classID: Components.ID("{c616fcfd-9737-41f1-aa74-cee72a38f91b}"),
QueryInterface: ChromeUtils.generateQI([Ci.nsIContentProcessProvider]),
provideProcess(aType, aOpener, aProcesses, aMaxCount) {
provideProcess(aType, aProcesses, aMaxCount) {
if (aProcesses.length < aMaxCount) {
return Ci.nsIContentProcessProvider.NEW_PROCESS;
}
let startIdx = Math.floor(Math.random() * aMaxCount);
let curIdx = startIdx;
do {
if (aProcesses[curIdx].opener === aOpener) {
return curIdx;
}
curIdx = (curIdx + 1) % aMaxCount;
} while (curIdx !== startIdx);
return Ci.nsIContentProcessProvider.NEW_PROCESS;
return Math.floor(Math.random() * aMaxCount);
},
};
@ -38,7 +27,7 @@ MinTabSelector.prototype = {
classID: Components.ID("{2dc08eaf-6eef-4394-b1df-a3a927c1290b}"),
QueryInterface: ChromeUtils.generateQI([Ci.nsIContentProcessProvider]),
provideProcess(aType, aOpener, aProcesses, aMaxCount) {
provideProcess(aType, aProcesses, aMaxCount) {
if (aProcesses.length < aMaxCount) {
return Ci.nsIContentProcessProvider.NEW_PROCESS;
}
@ -54,7 +43,7 @@ MinTabSelector.prototype = {
for (let i = 0; i < aMaxCount; i++) {
let process = aProcesses[i];
let tabCount = process.tabCount;
if (process.opener === aOpener && tabCount < min) {
if (tabCount < min) {
min = tabCount;
candidate = i;
}

Просмотреть файл

@ -20,11 +20,6 @@ interface nsIContentProcessInfo : nsISupports
*/
readonly attribute int32_t processId;
/**
* This content process's opener.
*/
readonly attribute nsIContentProcessInfo opener;
/**
* Number of opened tabs living in this content process.
*/
@ -46,11 +41,11 @@ interface nsIContentProcessProvider : nsISupports
const int32_t NEW_PROCESS = -1;
/**
* Given aAliveProcesses (with an opener aOpener), choose which process of
* aType to use. Return nsIContentProcessProvider.NEW_PROCESS to ask the
* caller to create a new content process.
* Given aAliveProcesses, choose which process of aType to use. Return
* nsIContentProcessProvider.NEW_PROCESS to ask the caller to create a new
* content process.
*/
int32_t provideProcess(in AString aType, in nsIContentProcessInfo aOpener,
int32_t provideProcess(in AString aType,
in Array<nsIContentProcessInfo> aAliveProcesses,
in uint32_t aMaxCount);
};

Просмотреть файл

@ -545,20 +545,6 @@ ScriptableCPInfo::GetProcessId(int32_t* aPID) {
return NS_OK;
}
NS_IMETHODIMP
ScriptableCPInfo::GetOpener(nsIContentProcessInfo** aInfo) {
*aInfo = nullptr;
if (!mContentParent) {
return NS_ERROR_NOT_INITIALIZED;
}
if (ContentParent* opener = mContentParent->Opener()) {
nsCOMPtr<nsIContentProcessInfo> info = opener->ScriptableHelper();
info.forget(aInfo);
}
return NS_OK;
}
NS_IMETHODIMP
ScriptableCPInfo::GetTabCount(int32_t* aTabCount) {
if (!mContentParent) {
@ -651,8 +637,8 @@ static const char* sObserverTopics[] = {
// ContentParent then takes this process back within GetNewOrUsedBrowserProcess.
/*static*/ RefPtr<ContentParent::LaunchPromise>
ContentParent::PreallocateProcess() {
RefPtr<ContentParent> process = new ContentParent(
/* aOpener = */ nullptr, NS_LITERAL_STRING(PREALLOC_REMOTE_TYPE));
RefPtr<ContentParent> process =
new ContentParent(NS_LITERAL_STRING(PREALLOC_REMOTE_TYPE));
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("Preallocating process of type " PREALLOC_REMOTE_TYPE));
@ -841,7 +827,7 @@ void ContentParent::ReleaseCachedProcesses() {
/*static*/
already_AddRefed<ContentParent> ContentParent::MinTabSelect(
const nsTArray<ContentParent*>& aContentParents, ContentParent* aOpener,
const nsTArray<ContentParent*>& aContentParents,
int32_t aMaxContentParents) {
uint32_t maxSelectable =
std::min(static_cast<uint32_t>(aContentParents.Length()),
@ -854,12 +840,11 @@ already_AddRefed<ContentParent> ContentParent::MinTabSelect(
ContentParent* p = aContentParents[i];
MOZ_DIAGNOSTIC_ASSERT(!p->IsDead());
MOZ_DIAGNOSTIC_ASSERT(!p->mShutdownPending);
if (p->mOpener == aOpener) {
uint32_t tabCount = cpm->GetBrowserParentCountByProcessId(p->ChildID());
if (tabCount < min) {
candidate = p;
min = tabCount;
}
uint32_t tabCount = cpm->GetBrowserParentCountByProcessId(p->ChildID());
if (tabCount < min) {
candidate = p;
min = tabCount;
}
}
@ -868,9 +853,8 @@ already_AddRefed<ContentParent> ContentParent::MinTabSelect(
/*static*/
already_AddRefed<ContentParent> ContentParent::GetUsedBrowserProcess(
ContentParent* aOpener, const nsAString& aRemoteType,
nsTArray<ContentParent*>& aContentParents, uint32_t aMaxContentParents,
bool aPreferUsed) {
const nsAString& aRemoteType, nsTArray<ContentParent*>& aContentParents,
uint32_t aMaxContentParents, bool aPreferUsed) {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
AutoRestore ar(sInProcessSelector);
sInProcessSelector = true;
@ -890,10 +874,8 @@ already_AddRefed<ContentParent> ContentParent::GetUsedBrowserProcess(
nsCOMPtr<nsIContentProcessProvider> cpp =
do_GetService("@mozilla.org/ipc/processselector;1");
nsIContentProcessInfo* openerInfo =
aOpener ? aOpener->mScriptableHelper.get() : nullptr;
int32_t index;
if (cpp && NS_SUCCEEDED(cpp->ProvideProcess(aRemoteType, openerInfo, infos,
if (cpp && NS_SUCCEEDED(cpp->ProvideProcess(aRemoteType, infos,
aMaxContentParents, &index))) {
// If the provider returned an existing ContentParent, use that one.
if (0 <= index && static_cast<uint32_t>(index) <= aMaxContentParents) {
@ -920,7 +902,7 @@ already_AddRefed<ContentParent> ContentParent::GetUsedBrowserProcess(
NS_WARNING("nsIContentProcessProvider failed to return a process");
RefPtr<ContentParent> random;
if (aContentParents.Length() >= aMaxContentParents &&
(random = MinTabSelect(aContentParents, aOpener, aMaxContentParents))) {
(random = MinTabSelect(aContentParents, aMaxContentParents))) {
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("GetUsedProcess: Reused random process %p (%d) for %s",
random.get(), (unsigned int)random->ChildID(),
@ -961,7 +943,6 @@ already_AddRefed<ContentParent> ContentParent::GetUsedBrowserProcess(
("Adopted %s process %p for type %s",
preallocated ? "preallocated" : "reused web", p.get(),
NS_ConvertUTF16toUTF8(aRemoteType).get()));
p->mOpener = aOpener;
p->mActivateTS = TimeStamp::Now();
p->AddToPool(aContentParents);
if (preallocated) {
@ -995,7 +976,6 @@ already_AddRefed<ContentParent>
ContentParent::GetNewOrUsedLaunchingBrowserProcess(Element* aFrameElement,
const nsAString& aRemoteType,
ProcessPriority aPriority,
ContentParent* aOpener,
bool aPreferUsed) {
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
("GetNewOrUsedProcess for type %s",
@ -1010,12 +990,12 @@ ContentParent::GetNewOrUsedLaunchingBrowserProcess(Element* aFrameElement,
("GetNewOrUsedProcess: returning Large Used process"));
return GetNewOrUsedLaunchingBrowserProcess(
aFrameElement, NS_LITERAL_STRING(DEFAULT_REMOTE_TYPE), aPriority,
aOpener, /*aPreferUsed =*/false);
/*aPreferUsed =*/false);
}
// Let's try and reuse an existing process.
RefPtr<ContentParent> contentParent = GetUsedBrowserProcess(
aOpener, aRemoteType, contentParents, maxContentParents, aPreferUsed);
aRemoteType, contentParents, maxContentParents, aPreferUsed);
if (contentParent) {
// We have located a process. It may not have finished initializing,
@ -1033,7 +1013,7 @@ ContentParent::GetNewOrUsedLaunchingBrowserProcess(Element* aFrameElement,
("Launching new process immediately for type %s",
NS_ConvertUTF16toUTF8(aRemoteType).get()));
contentParent = new ContentParent(aOpener, aRemoteType);
contentParent = new ContentParent(aRemoteType);
if (!contentParent->BeginSubprocessLaunch(aPriority)) {
// Launch aborted because of shutdown. Bailout.
contentParent->LaunchSubprocessReject();
@ -1060,11 +1040,10 @@ RefPtr<ContentParent::LaunchPromise>
ContentParent::GetNewOrUsedBrowserProcessAsync(Element* aFrameElement,
const nsAString& aRemoteType,
ProcessPriority aPriority,
ContentParent* aOpener,
bool aPreferUsed) {
// Obtain a `ContentParent` launched asynchronously.
RefPtr<ContentParent> contentParent = GetNewOrUsedLaunchingBrowserProcess(
aFrameElement, aRemoteType, aPriority, aOpener, aPreferUsed);
aFrameElement, aRemoteType, aPriority, aPreferUsed);
if (!contentParent) {
// In case of launch error, stop here.
return LaunchPromise::CreateAndReject(LaunchError(), __func__);
@ -1075,9 +1054,9 @@ ContentParent::GetNewOrUsedBrowserProcessAsync(Element* aFrameElement,
/*static*/
already_AddRefed<ContentParent> ContentParent::GetNewOrUsedBrowserProcess(
Element* aFrameElement, const nsAString& aRemoteType,
ProcessPriority aPriority, ContentParent* aOpener, bool aPreferUsed) {
ProcessPriority aPriority, bool aPreferUsed) {
RefPtr<ContentParent> contentParent = GetNewOrUsedLaunchingBrowserProcess(
aFrameElement, aRemoteType, aPriority, aOpener, aPreferUsed);
aFrameElement, aRemoteType, aPriority, aPreferUsed);
if (!contentParent || !contentParent->WaitForLaunchSync(aPriority)) {
// In case of launch error, stop here.
return nullptr;
@ -1362,9 +1341,8 @@ already_AddRefed<RemoteBrowser> ContentParent::CreateBrowser(
constructorSender =
GetNewOrUsedJSPluginProcess(aContext.JSPluginId(), initialPriority);
} else {
constructorSender =
GetNewOrUsedBrowserProcess(aFrameElement, remoteType, initialPriority,
nullptr, isPreloadBrowser);
constructorSender = GetNewOrUsedBrowserProcess(
aFrameElement, remoteType, initialPriority, isPreloadBrowser);
}
if (!constructorSender) {
return nullptr;
@ -2474,14 +2452,12 @@ RefPtr<ContentParent::LaunchPromise> ContentParent::LaunchSubprocessAsync(
});
}
ContentParent::ContentParent(ContentParent* aOpener,
const nsAString& aRemoteType, int32_t aJSPluginID)
ContentParent::ContentParent(const nsAString& aRemoteType, int32_t aJSPluginID)
: mSelfRef(nullptr),
mSubprocess(nullptr),
mLaunchTS(TimeStamp::Now()),
mLaunchYieldTS(mLaunchTS),
mActivateTS(mLaunchTS),
mOpener(aOpener),
mIsAPreallocBlocker(false),
mRemoteType(aRemoteType),
mChildID(gContentChildID++),

Просмотреть файл

@ -188,12 +188,12 @@ class ContentParent final
static void ReleaseCachedProcesses();
/**
* Picks a random content parent from |aContentParents| with a given |aOpener|
* respecting the index limit set by |aMaxContentParents|.
* Picks a random content parent from |aContentParents| respecting the index
* limit set by |aMaxContentParents|.
* Returns null if non available.
*/
static already_AddRefed<ContentParent> MinTabSelect(
const nsTArray<ContentParent*>& aContentParents, ContentParent* aOpener,
const nsTArray<ContentParent*>& aContentParents,
int32_t maxContentParents);
/**
@ -206,12 +206,12 @@ class ContentParent final
Element* aFrameElement, const nsAString& aRemoteType,
hal::ProcessPriority aPriority =
hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
ContentParent* aOpener = nullptr, bool aPreferUsed = false);
bool aPreferUsed = false);
static already_AddRefed<ContentParent> GetNewOrUsedBrowserProcess(
Element* aFrameElement, const nsAString& aRemoteType,
hal::ProcessPriority aPriority =
hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
ContentParent* aOpener = nullptr, bool aPreferUsed = false);
bool aPreferUsed = false);
/**
* Get or create a content process, but without waiting for the process
@ -227,7 +227,7 @@ class ContentParent final
Element* aFrameElement, const nsAString& aRemoteType,
hal::ProcessPriority aPriority =
hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
ContentParent* aOpener = nullptr, bool aPreferUsed = false);
bool aPreferUsed = false);
RefPtr<ContentParent::LaunchPromise> WaitForLaunchAsync(
hal::ProcessPriority aPriority =
@ -416,7 +416,6 @@ class ContentParent final
GeckoChildProcessHost* Process() const { return mSubprocess; }
ContentParent* Opener() const { return mOpener; }
nsIContentProcessInfo* ScriptableHelper() const { return mScriptableHelper; }
mozilla::dom::ProcessMessageManager* GetMessageManager() const {
@ -755,12 +754,11 @@ class ContentParent final
const OriginAttributes& aOriginAttributes);
explicit ContentParent(int32_t aPluginID)
: ContentParent(nullptr, EmptyString(), aPluginID) {}
ContentParent(ContentParent* aOpener, const nsAString& aRemoteType)
: ContentParent(aOpener, aRemoteType, nsFakePluginTag::NOT_JSPLUGIN) {}
: ContentParent(EmptyString(), aPluginID) {}
ContentParent(const nsAString& aRemoteType)
: ContentParent(aRemoteType, nsFakePluginTag::NOT_JSPLUGIN) {}
ContentParent(ContentParent* aOpener, const nsAString& aRemoteType,
int32_t aPluginID);
ContentParent(const nsAString& aRemoteType, int32_t aPluginID);
// Launch the subprocess and associated initialization.
// Returns false if the process fails to start.
@ -1354,9 +1352,8 @@ class ContentParent final
private:
// Return an existing ContentParent if possible. Otherwise, `nullptr`.
static already_AddRefed<ContentParent> GetUsedBrowserProcess(
ContentParent* aOpener, const nsAString& aRemoteType,
nsTArray<ContentParent*>& aContentParents, uint32_t aMaxContentParents,
bool aPreferUsed);
const nsAString& aRemoteType, nsTArray<ContentParent*>& aContentParents,
uint32_t aMaxContentParents, bool aPreferUsed);
// Get a JS actor object by name.
already_AddRefed<JSProcessActorParent> GetActor(const nsACString& aName,
@ -1383,7 +1380,6 @@ class ContentParent final
const TimeStamp mLaunchTS; // used to calculate time to start content process
TimeStamp mLaunchYieldTS; // used to calculate async launch main thread time
TimeStamp mActivateTS;
ContentParent* mOpener;
bool mIsAPreallocBlocker; // We called AddBlocker for this ContentParent