Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 21 - Get rid of WorkerPrefs.h, r=asuth

This commit is contained in:
Andrea Marchesini 2017-12-13 14:02:47 -06:00
Родитель d8578641ad
Коммит 13441b7385
8 изменённых файлов: 24 добавлений и 181 удалений

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

@ -1442,7 +1442,6 @@ struct RuntimeService::IdleThreadInfo
// This is only touched on the main thread. Initialized in Init() below.
JSSettings RuntimeService::sDefaultJSSettings;
bool RuntimeService::sDefaultPreferences[WORKERPREF_COUNT] = { false };
RuntimeService::RuntimeService()
: mMutex("RuntimeService::mMutex"), mObserved(false),
@ -1966,17 +1965,17 @@ RuntimeService::Init()
PREF_JS_OPTIONS_PREFIX PREF_GCZEAL)) ||
#endif
#define WORKER_SIMPLE_PREF(name, getter, NAME) \
NS_FAILED(Preferences::RegisterCallbackAndCall( \
WorkerPrefChanged, \
name, \
reinterpret_cast<void*>(WORKERPREF_##NAME))) ||
#define WORKER_PREF(name, callback) \
NS_FAILED(Preferences::RegisterCallbackAndCall( \
callback, \
name)) ||
#include "WorkerPrefs.h"
#undef WORKER_SIMPLE_PREF
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
WORKER_PREF("general.appname.override", AppNameOverrideChanged)
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
WORKER_PREF("general.platform.override", PlatformOverrideChanged)
#ifdef JS_GC_ZEAL
WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions)
#endif
#undef WORKER_PREF
NS_FAILED(Preferences::RegisterPrefixCallbackAndCall(
@ -2262,17 +2261,17 @@ RuntimeService::Cleanup()
NS_FAILED(Preferences::UnregisterPrefixCallback(LoadContextOptions,
PREF_WORKERS_OPTIONS_PREFIX)) ||
#define WORKER_SIMPLE_PREF(name, getter, NAME) \
NS_FAILED(Preferences::UnregisterCallback( \
WorkerPrefChanged, \
name, \
reinterpret_cast<void*>(WORKERPREF_##NAME))) ||
#define WORKER_PREF(name, callback) \
NS_FAILED(Preferences::UnregisterCallback( \
callback, \
name)) ||
#include "WorkerPrefs.h"
#undef WORKER_SIMPLE_PREF
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
WORKER_PREF("general.appname.override", AppNameOverrideChanged)
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
WORKER_PREF("general.platform.override", PlatformOverrideChanged)
#ifdef JS_GC_ZEAL
WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions)
#endif
#undef WORKER_PREF
#ifdef JS_GC_ZEAL
@ -2672,12 +2671,6 @@ RuntimeService::UpdatePlatformOverridePreference(const nsAString& aValue)
mNavigatorProperties.mPlatformOverridden = aValue;
}
void
RuntimeService::UpdateAllWorkerPreference(WorkerPreference aPref, bool aValue)
{
BROADCAST_ALL_WORKERS(UpdatePreference, aPref, aValue);
}
void
RuntimeService::UpdateAllWorkerLanguages(const nsTArray<nsString>& aLanguages)
{
@ -2797,34 +2790,6 @@ RuntimeService::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
/* static */ void
RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure)
{
AssertIsOnMainThread();
const WorkerPreference key =
static_cast<WorkerPreference>(reinterpret_cast<uintptr_t>(aClosure));
switch (key) {
#define WORKER_SIMPLE_PREF(name, getter, NAME) case WORKERPREF_##NAME:
#define WORKER_PREF(name, callback)
#include "WorkerPrefs.h"
#undef WORKER_SIMPLE_PREF
#undef WORKER_PREF
sDefaultPreferences[key] = Preferences::GetBool(aPrefName, false);
break;
default:
MOZ_ASSERT_UNREACHABLE("Invalid pref key");
break;
}
RuntimeService* rts = RuntimeService::GetService();
if (rts) {
rts->UpdateAllWorkerPreference(key, sDefaultPreferences[key]);
}
}
bool
LogViolationDetailsRunnable::MainThreadRun()
{

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

@ -91,7 +91,6 @@ class RuntimeService final : public nsIObserver
nsCOMPtr<nsITimer> mIdleThreadTimer;
static JSSettings sDefaultJSSettings;
static bool sDefaultPreferences[WORKERPREF_COUNT];
public:
struct NavigatorProperties
@ -173,13 +172,6 @@ public:
aSettings = sDefaultJSSettings;
}
static void
GetDefaultPreferences(bool aPreferences[WORKERPREF_COUNT])
{
AssertIsOnMainThread();
memcpy(aPreferences, sDefaultPreferences, WORKERPREF_COUNT * sizeof(bool));
}
static void
SetDefaultContextOptions(const JS::ContextOptions& aContextOptions)
{
@ -202,9 +194,6 @@ public:
void
UpdateAllWorkerLanguages(const nsTArray<nsString>& aLanguages);
void
UpdateAllWorkerPreference(WorkerPreference aPref, bool aValue);
static void
SetDefaultJSGCSettings(JSGCParamKey aKey, uint32_t aValue)
{
@ -270,9 +259,6 @@ private:
static void
ShutdownIdleThreads(nsITimer* aTimer, void* aClosure);
static void
WorkerPrefChanged(const char* aPrefName, void* aClosure);
nsresult
CreateSharedWorkerFromLoadInfo(JSContext* aCx,
WorkerLoadInfo* aLoadInfo,

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

@ -1,30 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This is the list of the preferences that are exposed to workers.
// The format is as follows:
//
// WORKER_SIMPLE_PREF("foo.bar", FooBar, FOO_BAR, UpdaterFunction)
//
// * First argument is the name of the pref.
// * The name of the getter function. This defines a FindName()
// function that returns the value of the pref on WorkerPrivate.
// * The macro version of the name. This defines a WORKERPREF_FOO_BAR
// macro in Workers.h.
// * The name of the function that updates the new value of a pref.
//
// WORKER_PREF("foo.bar", UpdaterFunction)
//
// * First argument is the name of the pref.
// * The name of the function that updates the new value of a pref.
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
WORKER_PREF("general.appname.override", AppNameOverrideChanged)
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
WORKER_PREF("general.platform.override", PlatformOverrideChanged)
#ifdef JS_GC_ZEAL
WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions)
#endif

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

@ -1377,28 +1377,6 @@ private:
}
};
class UpdatePreferenceRunnable final : public WorkerControlRunnable
{
WorkerPreference mPref;
bool mValue;
public:
UpdatePreferenceRunnable(WorkerPrivate* aWorkerPrivate,
WorkerPreference aPref,
bool aValue)
: WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount),
mPref(aPref),
mValue(aValue)
{ }
virtual bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
{
aWorkerPrivate->UpdatePreferenceInternal(mPref, mValue);
return true;
}
};
class UpdateLanguagesRunnable final : public WorkerRunnable
{
nsTArray<nsString> mLanguages;
@ -3512,20 +3490,6 @@ WorkerPrivateParent<Derived>::UpdateContextOptions(
}
}
template <class Derived>
void
WorkerPrivateParent<Derived>::UpdatePreference(WorkerPreference aPref, bool aValue)
{
AssertIsOnParentThread();
MOZ_ASSERT(aPref >= 0 && aPref < WORKERPREF_COUNT);
RefPtr<UpdatePreferenceRunnable> runnable =
new UpdatePreferenceRunnable(ParentAsWorkerPrivate(), aPref, aValue);
if (!runnable->Dispatch()) {
NS_WARNING("Failed to update worker preferences!");
}
}
template <class Derived>
void
WorkerPrivateParent<Derived>::UpdateLanguages(const nsTArray<nsString>& aLanguages)
@ -4540,12 +4504,10 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent,
{
if (aParent) {
aParent->AssertIsOnWorkerThread();
aParent->GetAllPreferences(mPreferences);
mOnLine = aParent->OnLine();
}
else {
AssertIsOnMainThread();
RuntimeService::GetDefaultPreferences(mPreferences);
mOnLine = !NS_IsOffline();
}
@ -6863,19 +6825,6 @@ WorkerPrivate::UpdateLanguagesInternal(const nsTArray<nsString>& aLanguages)
}
}
void
WorkerPrivate::UpdatePreferenceInternal(WorkerPreference aPref, bool aValue)
{
AssertIsOnWorkerThread();
MOZ_ASSERT(aPref >= 0 && aPref < WORKERPREF_COUNT);
mPreferences[aPref] = aValue;
for (uint32_t index = 0; index < mChildWorkers.Length(); index++) {
mChildWorkers[index]->UpdatePreference(aPref, aValue);
}
}
void
WorkerPrivate::UpdateJSWorkerMemoryParameterInternal(JSContext* aCx,
JSGCParamKey aKey,

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

@ -409,9 +409,6 @@ public:
void
UpdateLanguages(const nsTArray<nsString>& aLanguages);
void
UpdatePreference(WorkerPreference aPref, bool aValue);
void
UpdateJSWorkerMemoryParameter(JSGCParamKey key, uint32_t value);
@ -1079,7 +1076,6 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
bool mIdleGCTimerRunning;
bool mWorkerScriptExecutedSuccessfully;
bool mFetchHandlerWasAdded;
bool mPreferences[WORKERPREF_COUNT];
bool mOnLine;
protected:
@ -1286,9 +1282,6 @@ public:
void
UpdateLanguagesInternal(const nsTArray<nsString>& aLanguages);
void
UpdatePreferenceInternal(WorkerPreference aPref, bool aValue);
void
UpdateJSWorkerMemoryParameterInternal(JSContext* aCx, JSGCParamKey key, uint32_t aValue);
@ -1411,18 +1404,6 @@ public:
bool
RegisterDebuggerBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
#define WORKER_SIMPLE_PREF(name, getter, NAME) \
bool \
getter() const \
{ \
AssertIsOnWorkerThread(); \
return mPreferences[WORKERPREF_##NAME]; \
}
#define WORKER_PREF(name, callback)
#include "WorkerPrefs.h"
#undef WORKER_SIMPLE_PREF
#undef WORKER_PREF
bool
OnLine() const
{
@ -1583,13 +1564,6 @@ private:
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
void
GetAllPreferences(bool aPreferences[WORKERPREF_COUNT]) const
{
AssertIsOnWorkerThread();
memcpy(aPreferences, mPreferences, WORKERPREF_COUNT * sizeof(bool));
}
// If the worker shutdown status is equal or greater then aFailStatus, this
// operation will fail and nullptr will be returned. See WorkerHolder.h for
// more information about the correct value to use.

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

@ -186,16 +186,6 @@ struct JSSettings
}
};
enum WorkerPreference
{
#define WORKER_SIMPLE_PREF(name, getter, NAME) WORKERPREF_ ## NAME,
#define WORKER_PREF(name, callback)
#include "mozilla/dom/WorkerPrefs.h"
#undef WORKER_SIMPLE_PREF
#undef WORKER_PREF
WORKERPREF_COUNT
};
// Implemented in WorkerPrivate.cpp
struct WorkerLoadInfo

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

@ -19,7 +19,6 @@ EXPORTS.mozilla.dom += [
'ServiceWorkerRegistration.h',
'WorkerLocation.h',
'WorkerNavigator.h',
'WorkerPrefs.h',
'WorkerPrivate.h',
'WorkerRunnable.h',
'WorkerScope.h',

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

@ -4989,6 +4989,16 @@ Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, Relaxed>*, const char*, bool);
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, ReleaseAcquire>*,
const char*,
bool);
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, SequentiallyConsistent>*,
const char*,
bool);
template nsresult
Preferences::AddAtomicIntVarCache(Atomic<int32_t, Relaxed>*,
const char*,