mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Backed out 2 changesets (bug 1644896) for XPCshell failures on widget/headless/tests/test_headless.js. CLOSED TREE
Backed out changeset f501e7db25a8 (bug 1644896) Backed out changeset 2d984add3abb (bug 1644896)
This commit is contained in:
parent
450b9818d6
commit
e0ac748fab
@ -34,7 +34,6 @@
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIURIMutator.h"
|
||||
#include "nsIWritablePropertyBag2.h"
|
||||
#include "nsReadLine.h"
|
||||
#include "nsToolkitCompsCID.h"
|
||||
|
||||
@ -612,13 +611,12 @@ void PermissionManager::Startup() {
|
||||
// PermissionManager Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS(PermissionManager, nsIPermissionManager, nsIObserver,
|
||||
nsISupportsWeakReference, nsIAsyncShutdownBlocker)
|
||||
nsISupportsWeakReference)
|
||||
|
||||
PermissionManager::PermissionManager()
|
||||
: mMonitor("PermissionManager::mMonitor"),
|
||||
mState(eInitializing),
|
||||
mMemoryOnlyDB(false),
|
||||
mBlockerAdded(false),
|
||||
mLargestID(0) {}
|
||||
|
||||
PermissionManager::~PermissionManager() {
|
||||
@ -631,6 +629,12 @@ PermissionManager::~PermissionManager() {
|
||||
}
|
||||
mPermissionKeyPromiseMap.Clear();
|
||||
|
||||
RemoveAllFromMemory();
|
||||
if (gPermissionManager) {
|
||||
MOZ_ASSERT(gPermissionManager == this);
|
||||
gPermissionManager = nullptr;
|
||||
}
|
||||
|
||||
if (mThread) {
|
||||
mThread->Shutdown();
|
||||
mThread = nullptr;
|
||||
@ -651,7 +655,9 @@ already_AddRefed<nsIPermissionManager> PermissionManager::GetXPCOMSingleton() {
|
||||
// See bug 209571.
|
||||
auto permManager = MakeRefPtr<PermissionManager>();
|
||||
if (NS_SUCCEEDED(permManager->Init())) {
|
||||
// Note: This is cleared in the PermissionManager destructor.
|
||||
gPermissionManager = permManager.get();
|
||||
ClearOnShutdown(&gPermissionManager);
|
||||
return permManager.forget();
|
||||
}
|
||||
|
||||
@ -686,16 +692,12 @@ nsresult PermissionManager::Init() {
|
||||
// Stop here; we don't need the DB in the child process. Instead we will be
|
||||
// sent permissions as we need them by our parent process.
|
||||
mState = eReady;
|
||||
|
||||
// We use ClearOnShutdown on the content process only because on the parent
|
||||
// process we need to block the shutdown for the final closeDB() call.
|
||||
ClearOnShutdown(&gPermissionManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
|
||||
if (observerService) {
|
||||
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
|
||||
observerService->AddObserver(this, "profile-before-change", true);
|
||||
observerService->AddObserver(this, "profile-do-change", true);
|
||||
observerService->AddObserver(this, "testonly-reload-permissions-from-disk",
|
||||
true);
|
||||
@ -740,25 +742,6 @@ nsresult PermissionManager::OpenDatabase(nsIFile* aPermissionsFile) {
|
||||
void PermissionManager::InitDB(bool aRemoveFile) {
|
||||
mState = eInitializing;
|
||||
|
||||
if (XRE_IsParentProcess() && !mBlockerAdded) {
|
||||
nsCOMPtr<nsIAsyncShutdownClient> asc = GetShutdownPhase();
|
||||
if (asc) {
|
||||
nsAutoString blockerName;
|
||||
MOZ_ALWAYS_SUCCEEDS(GetName(blockerName));
|
||||
|
||||
// This method can fail during some xpcshell-tests because InitDB() is
|
||||
// called over and over again outside the init browser phase, or without
|
||||
// having a uer-profile directory.
|
||||
nsresult rv =
|
||||
asc->AddBlocker(this, NS_LITERAL_STRING_FROM_CSTRING(__FILE__),
|
||||
__LINE__, blockerName);
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mBlockerAdded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
MonitorAutoLock lock(mMonitor);
|
||||
mReadEntries.Clear();
|
||||
@ -1936,6 +1919,8 @@ PermissionManager::RemoveAllSince(int64_t aSince) {
|
||||
|
||||
template <class T>
|
||||
nsresult PermissionManager::RemovePermissionEntries(T aCondition) {
|
||||
EnsureReadCompleted();
|
||||
|
||||
Vector<Tuple<nsCOMPtr<nsIPrincipal>, nsCString, nsCString>, 10> array;
|
||||
for (auto iter = mPermissionTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
PermissionHashKey* entry = iter.Get();
|
||||
@ -2010,19 +1995,20 @@ PermissionManager::RemoveByTypeSince(const nsACString& aType,
|
||||
});
|
||||
}
|
||||
|
||||
void PermissionManager::CloseDB(CloseDBNextOp aNextOp) {
|
||||
void PermissionManager::CloseDB(bool aRebuildOnSuccess) {
|
||||
EnsureReadCompleted();
|
||||
|
||||
mState = eClosed;
|
||||
|
||||
nsCOMPtr<nsIInputStream> defaultsInputStream;
|
||||
if (aNextOp == eRebuldOnSuccess) {
|
||||
if (aRebuildOnSuccess) {
|
||||
defaultsInputStream = GetDefaultsInputStream();
|
||||
}
|
||||
|
||||
RefPtr<PermissionManager> self = this;
|
||||
mThread->Dispatch(NS_NewRunnableFunction(
|
||||
"PermissionManager::CloseDB", [self, aNextOp, defaultsInputStream] {
|
||||
"PermissionManager::CloseDB",
|
||||
[self, aRebuildOnSuccess, defaultsInputStream] {
|
||||
auto data = self->mThreadBoundData.Access();
|
||||
// Null the statements, this will finalize them.
|
||||
data->mStmtInsert = nullptr;
|
||||
@ -2033,16 +2019,10 @@ void PermissionManager::CloseDB(CloseDBNextOp aNextOp) {
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
data->mDBConn = nullptr;
|
||||
|
||||
if (aNextOp == eRebuldOnSuccess) {
|
||||
if (aRebuildOnSuccess) {
|
||||
self->TryInitDB(true, defaultsInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
if (aNextOp == eShutdown) {
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"PermissionManager::MaybeCompleteShutdown",
|
||||
[self] { self->MaybeCompleteShutdown(); }));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@ -2096,7 +2076,7 @@ nsresult PermissionManager::RemoveAllInternal(bool aNotifyObservers) {
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"PermissionManager::RemoveAllInternal-Failure",
|
||||
[self] { self->CloseDB(eRebuldOnSuccess); }));
|
||||
[self] { self->CloseDB(true); }));
|
||||
}
|
||||
}));
|
||||
|
||||
@ -2377,12 +2357,12 @@ NS_IMETHODIMP PermissionManager::Observe(nsISupports* aSubject,
|
||||
const char16_t* someData) {
|
||||
ENSURE_NOT_CHILD_PROCESS;
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
// In some xpcshell tests, without profile, we are not able to register the
|
||||
// shutdown-blocker. If this happens, let's shutdown the service manually.
|
||||
if (!mBlockerAdded) {
|
||||
BlockShutdown(nullptr);
|
||||
}
|
||||
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
|
||||
// The profile is about to change,
|
||||
// or is going away because the application is shutting down.
|
||||
RemoveIdleDailyMaintenanceJob();
|
||||
RemoveAllFromMemory();
|
||||
CloseDB(false);
|
||||
} else if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
|
||||
// the profile has already changed; init the db from the new location
|
||||
InitDB(false);
|
||||
@ -2395,7 +2375,7 @@ NS_IMETHODIMP PermissionManager::Observe(nsISupports* aSubject,
|
||||
// always being initialized. This is not guarded by a pref because it's not
|
||||
// dangerous to reload permissions from disk, just bad for performance.
|
||||
RemoveAllFromMemory();
|
||||
CloseDB(eNone);
|
||||
CloseDB(false);
|
||||
InitDB(false);
|
||||
} else if (!nsCRT::strcmp(aTopic, OBSERVER_TOPIC_IDLE_DAILY)) {
|
||||
PerformIdleDailyMaintenance();
|
||||
@ -2426,6 +2406,8 @@ PermissionManager::RemovePermissionsWithAttributes(const nsAString& aPattern) {
|
||||
|
||||
nsresult PermissionManager::RemovePermissionsWithAttributes(
|
||||
OriginAttributesPattern& aPattern) {
|
||||
EnsureReadCompleted();
|
||||
|
||||
Vector<Tuple<nsCOMPtr<nsIPrincipal>, nsCString, nsCString>, 10> permissions;
|
||||
for (auto iter = mPermissionTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
PermissionHashKey* entry = iter.Get();
|
||||
@ -3564,61 +3546,4 @@ nsresult PermissionManager::TestPermissionWithoutDefaultsFromPrincipal(
|
||||
true);
|
||||
}
|
||||
|
||||
void PermissionManager::MaybeCompleteShutdown() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIAsyncShutdownClient> asc = GetShutdownPhase();
|
||||
MOZ_ASSERT(asc);
|
||||
|
||||
DebugOnly<nsresult> rv = asc->RemoveBlocker(this);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
}
|
||||
|
||||
// Async shutdown blocker methods
|
||||
|
||||
NS_IMETHODIMP PermissionManager::GetName(nsAString& aName) {
|
||||
aName = u"PermissionManager: Flushing data"_ns;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PermissionManager::BlockShutdown(
|
||||
nsIAsyncShutdownClient* aClient) {
|
||||
RemoveIdleDailyMaintenanceJob();
|
||||
RemoveAllFromMemory();
|
||||
CloseDB(eShutdown);
|
||||
|
||||
gPermissionManager = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PermissionManager::GetState(nsIPropertyBag** aBagOut) {
|
||||
nsCOMPtr<nsIWritablePropertyBag2> propertyBag =
|
||||
do_CreateInstance("@mozilla.org/hash-property-bag;1");
|
||||
|
||||
nsresult rv = propertyBag->SetPropertyAsInt32(u"state"_ns, mState);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
propertyBag.forget(aBagOut);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAsyncShutdownClient> PermissionManager::GetShutdownPhase() const {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAsyncShutdownService> svc =
|
||||
do_GetService("@mozilla.org/async-shutdown-service;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAsyncShutdownClient> client;
|
||||
rv = svc->GetProfileBeforeChange(getter_AddRefs(client));
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -8,7 +8,6 @@
|
||||
#define mozilla_PermissionManager_h
|
||||
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIAsyncShutdown.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -47,8 +46,7 @@ class ContentChild;
|
||||
|
||||
class PermissionManager final : public nsIPermissionManager,
|
||||
public nsIObserver,
|
||||
public nsSupportsWeakReference,
|
||||
public nsIAsyncShutdownBlocker {
|
||||
public nsSupportsWeakReference {
|
||||
friend class dom::ContentChild;
|
||||
|
||||
public:
|
||||
@ -160,7 +158,6 @@ class PermissionManager final : public nsIPermissionManager,
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIPERMISSIONMANAGER
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIASYNCSHUTDOWNBLOCKER
|
||||
|
||||
PermissionManager();
|
||||
static already_AddRefed<nsIPermissionManager> GetXPCOMSingleton();
|
||||
@ -448,12 +445,8 @@ class PermissionManager final : public nsIPermissionManager,
|
||||
void NotifyObservers(nsIPermission* aPermission, const char16_t* aData);
|
||||
|
||||
// Finalize all statements, close the DB and null it.
|
||||
enum CloseDBNextOp {
|
||||
eNone,
|
||||
eRebuldOnSuccess,
|
||||
eShutdown,
|
||||
};
|
||||
void CloseDB(CloseDBNextOp aNextOp);
|
||||
// if aRebuildOnSuccess, reinitialize database
|
||||
void CloseDB(bool aRebuildOnSuccess = false);
|
||||
|
||||
nsresult RemoveAllInternal(bool aNotifyObservers);
|
||||
nsresult RemoveAllFromMemory();
|
||||
@ -490,10 +483,6 @@ class PermissionManager final : public nsIPermissionManager,
|
||||
uint32_t aExpireType, int64_t aExpireTime,
|
||||
int64_t aModificationTime, int64_t aId);
|
||||
|
||||
nsCOMPtr<nsIAsyncShutdownClient> GetShutdownPhase() const;
|
||||
|
||||
void MaybeCompleteShutdown();
|
||||
|
||||
nsRefPtrHashtable<nsCStringHashKey, GenericNonExclusivePromise::Private>
|
||||
mPermissionKeyPromiseMap;
|
||||
|
||||
@ -607,8 +596,6 @@ class PermissionManager final : public nsIPermissionManager,
|
||||
|
||||
bool mMemoryOnlyDB;
|
||||
|
||||
bool mBlockerAdded;
|
||||
|
||||
nsTHashtable<PermissionHashKey> mPermissionTable;
|
||||
// a unique, monotonically increasing id used to identify each database entry
|
||||
int64_t mLargestID;
|
||||
|
Loading…
Reference in New Issue
Block a user