Bug 1910848 - Move BackgroundThreadObject to separate files; r=dom-storage-reviewers,jari

This will allow to include QuotaCommon.h in header files less often.

Differential Revision: https://phabricator.services.mozilla.com/D194056
This commit is contained in:
Jan Varga
2024-08-07 07:53:13 +00:00
parent 74fab2a848
commit 88d6c89c01
7 changed files with 83 additions and 49 deletions

View File

@@ -885,32 +885,6 @@ Result<bool, nsresult> MaybeUpdateLastAccessTimeForOrigin(
} // namespace
BackgroundThreadObject::BackgroundThreadObject()
: mOwningThread(GetCurrentSerialEventTarget()) {
AssertIsOnOwningThread();
}
BackgroundThreadObject::BackgroundThreadObject(
nsISerialEventTarget* aOwningThread)
: mOwningThread(aOwningThread) {}
#ifdef DEBUG
void BackgroundThreadObject::AssertIsOnOwningThread() const {
AssertIsOnBackgroundThread();
MOZ_ASSERT(mOwningThread);
bool current;
MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)));
MOZ_ASSERT(current);
}
#endif // DEBUG
nsISerialEventTarget* BackgroundThreadObject::OwningThread() const {
MOZ_ASSERT(mOwningThread);
return mOwningThread;
}
void ReportInternalError(const char* aFile, uint32_t aLine, const char* aStr) {
// Get leaf of file path
for (const char* p = aFile; *p; ++p) {

View File

@@ -0,0 +1,40 @@
/* -*- 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/. */
#include "BackgroundThreadObject.h"
#include "nsThreadUtils.h"
#include "mozilla/ipc/BackgroundParent.h"
namespace mozilla::dom::quota {
BackgroundThreadObject::BackgroundThreadObject()
: mOwningThread(GetCurrentSerialEventTarget()) {
AssertIsOnOwningThread();
}
BackgroundThreadObject::BackgroundThreadObject(
nsISerialEventTarget* aOwningThread)
: mOwningThread(aOwningThread) {}
#ifdef DEBUG
void BackgroundThreadObject::AssertIsOnOwningThread() const {
mozilla::ipc::AssertIsOnBackgroundThread();
MOZ_ASSERT(mOwningThread);
bool current;
MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)));
MOZ_ASSERT(current);
}
#endif // DEBUG
nsISerialEventTarget* BackgroundThreadObject::OwningThread() const {
MOZ_ASSERT(mOwningThread);
return mOwningThread;
}
} // namespace mozilla::dom::quota

View File

@@ -0,0 +1,39 @@
/* -*- 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/. */
#ifndef DOM_QUOTA_BACKGROUNDTHREADOBJECT_H_
#define DOM_QUOTA_BACKGROUNDTHREADOBJECT_H_
#include "nsCOMPtr.h"
class nsISerialEventTarget;
namespace mozilla::dom::quota {
class BackgroundThreadObject {
protected:
nsCOMPtr<nsISerialEventTarget> mOwningThread;
public:
void AssertIsOnOwningThread() const
#ifdef DEBUG
;
#else
{
}
#endif
nsISerialEventTarget* OwningThread() const;
protected:
BackgroundThreadObject();
explicit BackgroundThreadObject(nsISerialEventTarget* aOwningThread);
};
} // namespace mozilla::dom::quota
#endif // DOM_QUOTA_BACKGROUNDTHREADOBJECT_H_

View File

@@ -10,10 +10,10 @@
#include "ErrorList.h"
#include "mozilla/NotNull.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/quota/BackgroundThreadObject.h"
#include "mozilla/dom/quota/Config.h"
#include "mozilla/dom/quota/ForwardDecls.h"
#include "mozilla/dom/quota/OriginOperationCallbacks.h"
#include "mozilla/dom/quota/QuotaCommon.h"
#include "mozilla/dom/quota/StringifyUtils.h"
#include "nsISupportsImpl.h"

View File

@@ -1280,27 +1280,6 @@ extern const nsLiteralCString kQuotaExternalError;
# define kQuotaExternalError
#endif
class BackgroundThreadObject {
protected:
nsCOMPtr<nsISerialEventTarget> mOwningThread;
public:
void AssertIsOnOwningThread() const
#ifdef DEBUG
;
#else
{
}
#endif
nsISerialEventTarget* OwningThread() const;
protected:
BackgroundThreadObject();
explicit BackgroundThreadObject(nsISerialEventTarget* aOwningThread);
};
MOZ_COLD void ReportInternalError(const char* aFile, uint32_t aLine,
const char* aStr);

View File

@@ -21,13 +21,13 @@
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/ipc/IdType.h"
#include "mozilla/dom/quota/Assertions.h"
#include "mozilla/dom/quota/BackgroundThreadObject.h"
#include "mozilla/dom/quota/CommonMetadata.h"
#include "mozilla/dom/quota/DirectoryLockCategory.h"
#include "mozilla/dom/quota/ForwardDecls.h"
#include "mozilla/dom/quota/InitializationTypes.h"
#include "mozilla/dom/quota/OriginOperationCallbacks.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/QuotaCommon.h"
#include "nsCOMPtr.h"
#include "nsClassHashtable.h"
#include "nsTHashMap.h"

View File

@@ -31,6 +31,7 @@ EXPORTS.mozilla.dom.quota += [
"ActorsParent.h",
"Assertions.h",
"AssertionsImpl.h",
"BackgroundThreadObject.h",
"CachingDatabaseConnection.h",
"CheckedUnsafePtr.h",
"CipherKeyManager.h",
@@ -93,6 +94,7 @@ UNIFIED_SOURCES += [
"ActorsChild.cpp",
"ActorsParent.cpp",
"Assertions.cpp",
"BackgroundThreadObject.cpp",
"CachingDatabaseConnection.cpp",
"CanonicalQuotaObject.cpp",
"Client.cpp",