Bug 1550422 - P5. Sync preferences with RDD process when then changed. r=mattwoodrow,mjf

Differential Revision: https://phabricator.services.mozilla.com/D30590

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2019-05-23 04:13:06 +00:00
Родитель 74921b190e
Коммит ae9b00180b
5 изменённых файлов: 46 добавлений и 1 удалений

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

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include MemoryReportTypes;
include PrefsTypes;
include protocol PProfiler;
include protocol PRemoteDecoderManager;
@ -32,6 +33,8 @@ parent:
bool minimizeMemoryUsage,
FileDescriptor? DMDFile);
async PreferenceUpdate(Pref pref);
child:
// args TBD, sent when init complete. Occurs once, after Init().
async InitComplete();

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

@ -175,6 +175,11 @@ mozilla::ipc::IPCResult RDDParent::RecvRequestMemoryReport(
return IPC_OK();
}
mozilla::ipc::IPCResult RDDParent::RecvPreferenceUpdate(const Pref& aPref) {
Preferences::SetPreference(aPref);
return IPC_OK();
}
void RDDParent::ActorDestroy(ActorDestroyReason aWhy) {
if (AbnormalShutdown == aWhy) {
NS_WARNING("Shutting down RDD process early due to a crash!");

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

@ -35,6 +35,7 @@ class RDDParent final : public PRDDParent {
const uint32_t& generation, const bool& anonymize,
const bool& minimizeMemoryUsage,
const Maybe<ipc::FileDescriptor>& DMDFile);
mozilla::ipc::IPCResult RecvPreferenceUpdate(const Pref& pref);
void ActorDestroy(ActorDestroyReason aWhy) override;

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

@ -8,8 +8,9 @@
#include "mozilla/MemoryReportingProcess.h"
#include "mozilla/RemoteDecoderManagerChild.h"
#include "mozilla/RemoteDecoderManagerParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/dom/ContentParent.h"
#include "nsAppRunner.h"
#include "nsContentUtils.h"
#include "RDDChild.h"
@ -40,6 +41,7 @@ RDDProcessManager::RDDProcessManager()
mObserver = new Observer(this);
nsContentUtils::RegisterShutdownObserver(mObserver);
Preferences::AddStrongObserver(mObserver, "");
}
RDDProcessManager::~RDDProcessManager() {
@ -62,6 +64,8 @@ RDDProcessManager::Observer::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
mManager->OnXPCOMShutdown();
} else if (!strcmp(aTopic, "nsPref:changed")) {
mManager->OnPreferenceChange(aData);
}
return NS_OK;
}
@ -69,12 +73,32 @@ RDDProcessManager::Observer::Observe(nsISupports* aSubject, const char* aTopic,
void RDDProcessManager::OnXPCOMShutdown() {
if (mObserver) {
nsContentUtils::UnregisterShutdownObserver(mObserver);
Preferences::RemoveObserver(mObserver, "");
mObserver = nullptr;
}
CleanShutdown();
}
void RDDProcessManager::OnPreferenceChange(const char16_t* aData) {
// A pref changed. If it's not on the blacklist, inform child processes.
if (!dom::ContentParent::ShouldSyncPreference(aData)) {
return;
}
// We know prefs are ASCII here.
NS_LossyConvertUTF16toASCII strData(aData);
mozilla::dom::Pref pref(strData, /* isLocked */ false, Nothing(), Nothing());
Preferences::GetPreference(&pref);
if (!!mRDDChild) {
MOZ_ASSERT(mQueuedPrefs.IsEmpty());
mRDDChild->SendPreferenceUpdate(pref);
} else {
mQueuedPrefs.AppendElement(pref);
}
}
void RDDProcessManager::LaunchRDDProcess() {
if (mProcess) {
return;
@ -129,6 +153,13 @@ void RDDProcessManager::OnProcessLaunchComplete(RDDProcessHost* aHost) {
mRDDChild = mProcess->GetActor();
mProcessToken = mProcess->GetProcessToken();
// Flush any pref updates that happened during launch and weren't
// included in the blobs set up in LaunchRDDProcess.
for (const mozilla::dom::Pref& pref : mQueuedPrefs) {
Unused << NS_WARN_IF(!mRDDChild->SendPreferenceUpdate(pref));
}
mQueuedPrefs.Clear();
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::RDDProcessStatus,
NS_LITERAL_CSTRING("Running"));

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

@ -64,6 +64,7 @@ class RDDProcessManager final : public RDDProcessHost::Listener {
private:
// Called from our xpcom-shutdown observer.
void OnXPCOMShutdown();
void OnPreferenceChange(const char16_t* aData);
RDDProcessManager();
@ -95,6 +96,10 @@ class RDDProcessManager final : public RDDProcessHost::Listener {
RDDProcessHost* mProcess;
uint64_t mProcessToken;
RDDChild* mRDDChild;
// Collects any pref changes that occur during process launch (after
// the initial map is passed in command-line arguments) to be sent
// when the process can receive IPC messages.
nsTArray<mozilla::dom::Pref> mQueuedPrefs;
};
} // namespace mozilla