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 20:30:33 +00:00
Родитель 07bb0b994c
Коммит f1d85755a8
5 изменённых файлов: 41 добавлений и 86 удалений

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

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

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

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

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

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

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

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

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

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