summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/IndexedDatabaseManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/indexedDB/IndexedDatabaseManager.cpp')
-rw-r--r--dom/indexedDB/IndexedDatabaseManager.cpp84
1 files changed, 75 insertions, 9 deletions
diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp
index 0558c38826..e63dd793cf 100644
--- a/dom/indexedDB/IndexedDatabaseManager.cpp
+++ b/dom/indexedDB/IndexedDatabaseManager.cpp
@@ -67,6 +67,13 @@ class FileManagerInfo {
[[nodiscard]] SafeRefPtr<DatabaseFileManager> GetFileManager(
PersistenceType aPersistenceType, const nsAString& aName) const;
+ [[nodiscard]] SafeRefPtr<DatabaseFileManager>
+ GetFileManagerByDatabaseFilePath(PersistenceType aPersistenceType,
+ const nsAString& aDatabaseFilePath) const;
+
+ const nsTArray<SafeRefPtr<DatabaseFileManager>>& GetFileManagers(
+ PersistenceType aPersistenceType) const;
+
void AddFileManager(SafeRefPtr<DatabaseFileManager> aFileManager);
bool HasFileManagers() const {
@@ -86,18 +93,18 @@ class FileManagerInfo {
const nsAString& aName);
private:
- nsTArray<SafeRefPtr<DatabaseFileManager> >& GetArray(
+ nsTArray<SafeRefPtr<DatabaseFileManager>>& GetArray(
PersistenceType aPersistenceType);
- const nsTArray<SafeRefPtr<DatabaseFileManager> >& GetImmutableArray(
+ const nsTArray<SafeRefPtr<DatabaseFileManager>>& GetImmutableArray(
PersistenceType aPersistenceType) const {
return const_cast<FileManagerInfo*>(this)->GetArray(aPersistenceType);
}
- nsTArray<SafeRefPtr<DatabaseFileManager> > mPersistentStorageFileManagers;
- nsTArray<SafeRefPtr<DatabaseFileManager> > mTemporaryStorageFileManagers;
- nsTArray<SafeRefPtr<DatabaseFileManager> > mDefaultStorageFileManagers;
- nsTArray<SafeRefPtr<DatabaseFileManager> > mPrivateStorageFileManagers;
+ nsTArray<SafeRefPtr<DatabaseFileManager>> mPersistentStorageFileManagers;
+ nsTArray<SafeRefPtr<DatabaseFileManager>> mTemporaryStorageFileManagers;
+ nsTArray<SafeRefPtr<DatabaseFileManager>> mDefaultStorageFileManagers;
+ nsTArray<SafeRefPtr<DatabaseFileManager>> mPrivateStorageFileManagers;
};
} // namespace indexedDB
@@ -199,6 +206,13 @@ auto DatabaseNameMatchPredicate(const nsAString* const aName) {
};
}
+auto DatabaseFilePathMatchPredicate(const nsAString* const aDatabaseFilePath) {
+ MOZ_ASSERT(aDatabaseFilePath);
+ return [aDatabaseFilePath](const auto& fileManager) {
+ return fileManager->DatabaseFilePath() == *aDatabaseFilePath;
+ };
+}
+
} // namespace
IndexedDatabaseManager::IndexedDatabaseManager() : mBackgroundActor(nullptr) {
@@ -476,6 +490,35 @@ SafeRefPtr<DatabaseFileManager> IndexedDatabaseManager::GetFileManager(
return info->GetFileManager(aPersistenceType, aDatabaseName);
}
+SafeRefPtr<DatabaseFileManager>
+IndexedDatabaseManager::GetFileManagerByDatabaseFilePath(
+ PersistenceType aPersistenceType, const nsACString& aOrigin,
+ const nsAString& aDatabaseFilePath) {
+ AssertIsOnIOThread();
+
+ FileManagerInfo* info;
+ if (!mFileManagerInfos.Get(aOrigin, &info)) {
+ return nullptr;
+ }
+
+ return info->GetFileManagerByDatabaseFilePath(aPersistenceType,
+ aDatabaseFilePath);
+}
+
+const nsTArray<SafeRefPtr<DatabaseFileManager>>&
+IndexedDatabaseManager::GetFileManagers(PersistenceType aPersistenceType,
+ const nsACString& aOrigin) {
+ AssertIsOnIOThread();
+
+ FileManagerInfo* info;
+ if (!mFileManagerInfos.Get(aOrigin, &info)) {
+ static nsTArray<SafeRefPtr<DatabaseFileManager>> emptyArray;
+ return emptyArray;
+ }
+
+ return info->GetFileManagers(aPersistenceType);
+}
+
void IndexedDatabaseManager::AddFileManager(
SafeRefPtr<DatabaseFileManager> aFileManager) {
AssertIsOnIOThread();
@@ -680,11 +723,34 @@ SafeRefPtr<DatabaseFileManager> FileManagerInfo::GetFileManager(
return foundIt != end ? foundIt->clonePtr() : nullptr;
}
+SafeRefPtr<DatabaseFileManager>
+FileManagerInfo::GetFileManagerByDatabaseFilePath(
+ PersistenceType aPersistenceType,
+ const nsAString& aDatabaseFilePath) const {
+ AssertIsOnIOThread();
+
+ const auto& managers = GetImmutableArray(aPersistenceType);
+
+ const auto end = managers.cend();
+ const auto foundIt =
+ std::find_if(managers.cbegin(), end,
+ DatabaseFilePathMatchPredicate(&aDatabaseFilePath));
+
+ return foundIt != end ? foundIt->clonePtr() : nullptr;
+}
+
+const nsTArray<SafeRefPtr<DatabaseFileManager>>&
+FileManagerInfo::GetFileManagers(PersistenceType aPersistenceType) const {
+ AssertIsOnIOThread();
+
+ return GetImmutableArray(aPersistenceType);
+}
+
void FileManagerInfo::AddFileManager(
SafeRefPtr<DatabaseFileManager> aFileManager) {
AssertIsOnIOThread();
- nsTArray<SafeRefPtr<DatabaseFileManager> >& managers =
+ nsTArray<SafeRefPtr<DatabaseFileManager>>& managers =
GetArray(aFileManager->Type());
NS_ASSERTION(!managers.Contains(aFileManager), "Adding more than once?!");
@@ -718,7 +784,7 @@ void FileManagerInfo::InvalidateAndRemoveFileManagers(
PersistenceType aPersistenceType) {
AssertIsOnIOThread();
- nsTArray<SafeRefPtr<DatabaseFileManager> >& managers =
+ nsTArray<SafeRefPtr<DatabaseFileManager>>& managers =
GetArray(aPersistenceType);
for (uint32_t i = 0; i < managers.Length(); i++) {
@@ -743,7 +809,7 @@ void FileManagerInfo::InvalidateAndRemoveFileManager(
}
}
-nsTArray<SafeRefPtr<DatabaseFileManager> >& FileManagerInfo::GetArray(
+nsTArray<SafeRefPtr<DatabaseFileManager>>& FileManagerInfo::GetArray(
PersistenceType aPersistenceType) {
switch (aPersistenceType) {
case PERSISTENCE_TYPE_PERSISTENT: