2011-12-16 07:34:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2011-12-16 07:34:24 +00:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_filemanager_h__
|
|
|
|
#define mozilla_dom_indexeddb_filemanager_h__
|
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2020-03-16 09:50:38 +00:00
|
|
|
#include "FileManagerBase.h"
|
2020-03-19 11:30:26 +00:00
|
|
|
#include "InitializedOnce.h"
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class nsIFile;
|
2011-12-16 07:34:24 +00:00
|
|
|
class mozIStorageConnection;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Implemented in ActorsParent.cpp.
|
2020-03-17 11:50:58 +00:00
|
|
|
class FileManager final : public FileManagerBase<FileManager> {
|
|
|
|
using PersistenceType = mozilla::dom::quota::PersistenceType;
|
|
|
|
using FileManagerBase<FileManager>::MutexType;
|
2013-03-26 11:13:17 +00:00
|
|
|
|
2020-02-26 10:08:38 +00:00
|
|
|
const PersistenceType mPersistenceType;
|
|
|
|
const nsCString mGroup;
|
|
|
|
const nsCString mOrigin;
|
|
|
|
const nsString mDatabaseName;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2020-03-19 11:30:26 +00:00
|
|
|
InitializedOnce<const nsString, LazyInit::Allow> mDirectoryPath;
|
|
|
|
InitializedOnce<const nsString, LazyInit::Allow> mJournalDirectoryPath;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-10-28 19:06:54 +00:00
|
|
|
const bool mEnforcingQuota;
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2020-03-17 11:50:58 +00:00
|
|
|
// Lock protecting FileManager.mFileInfos.
|
|
|
|
// It's s also used to atomically update FileInfo.mRefCnt and
|
|
|
|
// FileInfo.mDBRefCnt
|
|
|
|
static MutexType sMutex;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
public:
|
2019-12-16 13:17:46 +00:00
|
|
|
static MOZ_MUST_USE nsCOMPtr<nsIFile> GetFileForId(nsIFile* aDirectory,
|
|
|
|
int64_t aId);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2019-12-16 13:17:46 +00:00
|
|
|
static MOZ_MUST_USE nsCOMPtr<nsIFile> GetCheckedFileForId(nsIFile* aDirectory,
|
|
|
|
int64_t aId);
|
2016-10-25 19:18:58 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static nsresult InitDirectory(nsIFile* aDirectory, nsIFile* aDatabaseFile,
|
2015-05-19 16:25:50 +00:00
|
|
|
const nsACString& aOrigin,
|
|
|
|
uint32_t aTelemetryId);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2019-08-22 20:52:09 +00:00
|
|
|
static nsresult GetUsage(nsIFile* aDirectory, Maybe<uint64_t>& aUsage);
|
|
|
|
|
|
|
|
static nsresult GetUsage(nsIFile* aDirectory, uint64_t& aUsage);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
FileManager(PersistenceType aPersistenceType, const nsACString& aGroup,
|
2014-10-28 19:06:54 +00:00
|
|
|
const nsACString& aOrigin, const nsAString& aDatabaseName,
|
|
|
|
bool aEnforcingQuota);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
PersistenceType Type() const { return mPersistenceType; }
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsACString& Group() const { return mGroup; }
|
2013-09-11 04:18:36 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsACString& Origin() const { return mOrigin; }
|
2011-12-16 07:34:24 +00:00
|
|
|
|
|
|
|
const nsAString& DatabaseName() const { return mDatabaseName; }
|
|
|
|
|
2014-10-28 19:06:54 +00:00
|
|
|
bool EnforcingQuota() const { return mEnforcingQuota; }
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsresult Init(nsIFile* aDirectory, mozIStorageConnection* aConnection);
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2019-12-16 13:17:46 +00:00
|
|
|
MOZ_MUST_USE nsCOMPtr<nsIFile> GetDirectory();
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2019-12-16 13:17:46 +00:00
|
|
|
MOZ_MUST_USE nsCOMPtr<nsIFile> GetCheckedDirectory();
|
2016-10-25 19:18:58 +00:00
|
|
|
|
2019-12-16 13:17:46 +00:00
|
|
|
MOZ_MUST_USE nsCOMPtr<nsIFile> GetJournalDirectory();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2019-12-16 13:17:46 +00:00
|
|
|
MOZ_MUST_USE nsCOMPtr<nsIFile> EnsureJournalDirectory();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2020-03-16 09:48:46 +00:00
|
|
|
MOZ_MUST_USE nsresult SyncDeleteFile(int64_t aId);
|
|
|
|
|
2020-03-19 14:40:04 +00:00
|
|
|
// XXX When getting rid of FileHelper, this method should be removed/made
|
|
|
|
// private.
|
|
|
|
MOZ_MUST_USE nsresult SyncDeleteFile(nsIFile& aFile, nsIFile& aJournalFile);
|
|
|
|
|
2020-03-16 09:49:47 +00:00
|
|
|
MOZ_MUST_USE nsresult AsyncDeleteFile(int64_t aFileId);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileManager)
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2020-03-17 11:50:58 +00:00
|
|
|
static StaticMutex& Mutex() { return sMutex; }
|
|
|
|
|
2011-12-16 07:34:24 +00:00
|
|
|
private:
|
2016-11-14 09:40:37 +00:00
|
|
|
~FileManager() = default;
|
2011-12-16 07:34:24 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-12-16 07:34:24 +00:00
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_filemanager_h__
|