mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1617170 - Pull up parts of FileManager that are used by FileInfo into FileManagerBase. r=janv,dom-workers-and-storage-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D65115 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
cbe93e61b5
commit
b0852dd36d
@ -16465,7 +16465,6 @@ FileManager::FileManager(PersistenceType aPersistenceType,
|
||||
mGroup(aGroup),
|
||||
mOrigin(aOrigin),
|
||||
mDatabaseName(aDatabaseName),
|
||||
mLastFileId(0),
|
||||
mEnforcingQuota(aEnforcingQuota) {}
|
||||
|
||||
nsresult FileManager::Init(nsIFile* aDirectory,
|
||||
@ -16581,26 +16580,6 @@ nsresult FileManager::Init(nsIFile* aDirectory,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult FileManager::Invalidate() {
|
||||
if (IndexedDatabaseManager::IsClosed()) {
|
||||
MOZ_ASSERT(false, "Shouldn't be called after shutdown!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
||||
|
||||
mInvalidated.Flip();
|
||||
|
||||
mFileInfos.RemoveIf([](const auto& iter) {
|
||||
FileInfo* info = iter.Data();
|
||||
MOZ_ASSERT(info);
|
||||
|
||||
return !info->LockedClearDBRefs();
|
||||
});
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> FileManager::GetDirectory() {
|
||||
return GetFileForPath(*mDirectoryPath);
|
||||
}
|
||||
@ -16661,46 +16640,6 @@ nsCOMPtr<nsIFile> FileManager::EnsureJournalDirectory() {
|
||||
return journalDirectory;
|
||||
}
|
||||
|
||||
RefPtr<FileInfo> FileManager::GetFileInfo(int64_t aId) const {
|
||||
if (IndexedDatabaseManager::IsClosed()) {
|
||||
MOZ_ASSERT(false, "Shouldn't be called after shutdown!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: We cannot simply change this to RefPtr<FileInfo>, because
|
||||
// FileInfo::AddRef also acquires the IndexedDatabaseManager::FileMutex. This
|
||||
// looks quirky at least.
|
||||
FileInfo* fileInfo;
|
||||
{
|
||||
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
||||
fileInfo = mFileInfos.Get(aId);
|
||||
}
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
RefPtr<FileInfo> FileManager::CreateFileInfo() {
|
||||
MOZ_ASSERT(!IndexedDatabaseManager::IsClosed());
|
||||
|
||||
// TODO: We cannot simply change this to RefPtr<FileInfo>, because
|
||||
// FileInfo::AddRef also acquires the IndexedDatabaseManager::FileMutex. This
|
||||
// looks quirky at least.
|
||||
FileInfo* fileInfo;
|
||||
{
|
||||
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
||||
|
||||
int64_t id = mLastFileId + 1;
|
||||
|
||||
fileInfo = new FileInfo(this, id);
|
||||
|
||||
mFileInfos.Put(id, fileInfo);
|
||||
|
||||
mLastFileId = id;
|
||||
}
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
// static
|
||||
nsCOMPtr<nsIFile> FileManager::GetFileForId(nsIFile* aDirectory, int64_t aId) {
|
||||
MOZ_ASSERT(aDirectory);
|
||||
@ -17031,14 +16970,6 @@ nsresult FileManager::SyncDeleteFile(const int64_t aId) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void FileManager::RemoveFileInfo(const int64_t aId,
|
||||
const MutexAutoLock& aFilesMutexLock) {
|
||||
#ifdef DEBUG
|
||||
aFilesMutexLock.AssertOwns(IndexedDatabaseManager::FileMutex());
|
||||
#endif
|
||||
mFileInfos.Remove(aId);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* QuotaClient
|
||||
******************************************************************************/
|
||||
|
@ -16,7 +16,8 @@ namespace indexedDB {
|
||||
class FileManager;
|
||||
|
||||
class FileInfo final {
|
||||
friend class FileManager;
|
||||
template <typename FileManager, typename IndexedDatabaseManager>
|
||||
friend class FileManagerBase;
|
||||
|
||||
const int64_t mFileId;
|
||||
|
||||
|
@ -7,13 +7,9 @@
|
||||
#ifndef mozilla_dom_indexeddb_filemanager_h__
|
||||
#define mozilla_dom_indexeddb_filemanager_h__
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/dom/quota/PersistenceType.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "FlippedOnce.h"
|
||||
#include "FileManagerBase.h"
|
||||
#include "IndexedDatabaseManager.h"
|
||||
#include "InitializedOnce.h"
|
||||
|
||||
class nsIFile;
|
||||
@ -23,10 +19,9 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
namespace indexedDB {
|
||||
|
||||
class FileInfo;
|
||||
|
||||
// Implemented in ActorsParent.cpp.
|
||||
class FileManager final {
|
||||
class FileManager final
|
||||
: public FileManagerBase<FileManager, dom::IndexedDatabaseManager> {
|
||||
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
||||
|
||||
const PersistenceType mPersistenceType;
|
||||
@ -37,13 +32,7 @@ class FileManager final {
|
||||
InitializedOnce<const nsString, LazyInit::Allow> mDirectoryPath;
|
||||
InitializedOnce<const nsString, LazyInit::Allow> mJournalDirectoryPath;
|
||||
|
||||
int64_t mLastFileId;
|
||||
|
||||
// Protected by IndexedDatabaseManager::FileMutex()
|
||||
nsDataHashtable<nsUint64HashKey, FileInfo*> mFileInfos;
|
||||
|
||||
const bool mEnforcingQuota;
|
||||
FlippedOnce<false> mInvalidated;
|
||||
|
||||
public:
|
||||
static MOZ_MUST_USE nsCOMPtr<nsIFile> GetFileForId(nsIFile* aDirectory,
|
||||
@ -74,12 +63,8 @@ class FileManager final {
|
||||
|
||||
bool EnforcingQuota() const { return mEnforcingQuota; }
|
||||
|
||||
bool Invalidated() const { return mInvalidated; }
|
||||
|
||||
nsresult Init(nsIFile* aDirectory, mozIStorageConnection* aConnection);
|
||||
|
||||
nsresult Invalidate();
|
||||
|
||||
MOZ_MUST_USE nsCOMPtr<nsIFile> GetDirectory();
|
||||
|
||||
MOZ_MUST_USE nsCOMPtr<nsIFile> GetCheckedDirectory();
|
||||
@ -88,12 +73,6 @@ class FileManager final {
|
||||
|
||||
MOZ_MUST_USE nsCOMPtr<nsIFile> EnsureJournalDirectory();
|
||||
|
||||
MOZ_MUST_USE RefPtr<FileInfo> GetFileInfo(int64_t aId) const;
|
||||
|
||||
MOZ_MUST_USE RefPtr<FileInfo> CreateFileInfo();
|
||||
|
||||
void RemoveFileInfo(int64_t aId, const MutexAutoLock& aFilesMutexLock);
|
||||
|
||||
MOZ_MUST_USE nsresult SyncDeleteFile(int64_t aId);
|
||||
|
||||
MOZ_MUST_USE nsresult AsyncDeleteFile(int64_t aFileId);
|
||||
|
116
dom/indexedDB/FileManagerBase.h
Normal file
116
dom/indexedDB/FileManagerBase.h
Normal file
@ -0,0 +1,116 @@
|
||||
/* -*- 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 mozilla_dom_indexeddb_filemanagerbase_h__
|
||||
#define mozilla_dom_indexeddb_filemanagerbase_h__
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "FlippedOnce.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace indexedDB {
|
||||
|
||||
class FileInfo;
|
||||
|
||||
template <typename FileManager, typename IndexedDatabaseManager>
|
||||
class FileManagerBase {
|
||||
public:
|
||||
using FileInfo = indexedDB::FileInfo;
|
||||
using MutexType = decltype(IndexedDatabaseManager::FileMutex());
|
||||
using AutoLock = mozilla::detail::BaseAutoLock<MutexType>;
|
||||
|
||||
MOZ_MUST_USE RefPtr<FileInfo> GetFileInfo(int64_t aId) const {
|
||||
if (IndexedDatabaseManager::IsClosed()) {
|
||||
MOZ_ASSERT(false, "Shouldn't be called after shutdown!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: We cannot simply change this to RefPtr<FileInfo>, because
|
||||
// FileInfo::AddRef also acquires the IndexedDatabaseManager::FileMutex.
|
||||
// This looks quirky at least.
|
||||
FileInfo* fileInfo;
|
||||
{
|
||||
AutoLock lock(IndexedDatabaseManager::FileMutex());
|
||||
fileInfo = mFileInfos.Get(aId);
|
||||
}
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
MOZ_MUST_USE RefPtr<FileInfo> CreateFileInfo() {
|
||||
MOZ_ASSERT(!IndexedDatabaseManager::IsClosed());
|
||||
|
||||
// TODO: We cannot simply change this to RefPtr<FileInfo>, because
|
||||
// FileInfo::AddRef also acquires the IndexedDatabaseManager::FileMutex.
|
||||
// This looks quirky at least.
|
||||
FileInfo* fileInfo;
|
||||
{
|
||||
AutoLock lock(IndexedDatabaseManager::FileMutex());
|
||||
|
||||
const int64_t id = ++mLastFileId;
|
||||
|
||||
fileInfo = new FileInfo(static_cast<FileManager*>(this), id);
|
||||
|
||||
mFileInfos.Put(id, fileInfo);
|
||||
}
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
void RemoveFileInfo(const int64_t aId, const AutoLock& aFilesMutexLock) {
|
||||
#ifdef DEBUG
|
||||
aFilesMutexLock.AssertOwns(IndexedDatabaseManager::FileMutex());
|
||||
#endif
|
||||
mFileInfos.Remove(aId);
|
||||
}
|
||||
|
||||
nsresult Invalidate() {
|
||||
if (IndexedDatabaseManager::IsClosed()) {
|
||||
MOZ_ASSERT(false, "Shouldn't be called after shutdown!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
AutoLock lock(IndexedDatabaseManager::FileMutex());
|
||||
|
||||
mInvalidated.Flip();
|
||||
|
||||
mFileInfos.RemoveIf([](const auto& iter) {
|
||||
FileInfo* info = iter.Data();
|
||||
MOZ_ASSERT(info);
|
||||
|
||||
return !info->LockedClearDBRefs();
|
||||
});
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool Invalidated() const { return mInvalidated; }
|
||||
|
||||
class FileManagerGuard {
|
||||
FileManagerGuard() = default;
|
||||
};
|
||||
|
||||
protected:
|
||||
~FileManagerBase() = default;
|
||||
|
||||
// Access to the following fields must be protected by
|
||||
// IndexedDatabaseManager::FileMutex()
|
||||
int64_t mLastFileId = 0;
|
||||
nsDataHashtable<nsUint64HashKey, FileInfo*> mFileInfos;
|
||||
|
||||
FlippedOnce<false> mInvalidated;
|
||||
};
|
||||
|
||||
} // namespace indexedDB
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_indexeddb_filemanagerbase_h__
|
Loading…
Reference in New Issue
Block a user