1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/* -*- 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 "FileSystemQuotaClient.h"
#include "datamodel/FileSystemDatabaseManager.h"
#include "datamodel/FileSystemFileManager.h"
#include "mozilla/dom/FileSystemDataManager.h"
#include "mozilla/dom/quota/Assertions.h"
#include "mozilla/dom/quota/QuotaCommon.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozilla/dom/quota/ResultExtensions.h"
#include "mozilla/dom/quota/UsageInfo.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "nsIFile.h"
namespace mozilla::dom::fs {
namespace {
auto toNSResult = [](const auto& aRv) { return ToNSResult(aRv); };
} // namespace
FileSystemQuotaClient::FileSystemQuotaClient() {
::mozilla::ipc::AssertIsOnBackgroundThread();
}
quota::Client::Type FileSystemQuotaClient::GetType() {
return quota::Client::Type::FILESYSTEM;
}
Result<quota::UsageInfo, nsresult> FileSystemQuotaClient::InitOrigin(
quota::PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata, const AtomicBool& aCanceled) {
quota::AssertIsOnIOThread();
DebugOnly<quota::QuotaManager*> quotaManager = quota::QuotaManager::Get();
MOZ_ASSERT(quotaManager);
MOZ_ASSERT(
!quotaManager->IsTemporaryOriginInitializedInternal(aOriginMetadata));
{
QM_TRY_INSPECT(const nsCOMPtr<nsIFile>& databaseFile,
data::GetDatabaseFile(aOriginMetadata).mapErr(toNSResult));
bool exists = false;
QM_TRY(MOZ_TO_RESULT(databaseFile->Exists(&exists)));
// If database doesn't already exist, we do not create it
if (!exists) {
return quota::UsageInfo();
}
}
QM_TRY_INSPECT(
const ResultConnection& conn,
data::GetStorageConnection(aOriginMetadata, /* aDirectoryLockId */ -1)
.mapErr(toNSResult));
QM_TRY(MOZ_TO_RESULT(
data::FileSystemDatabaseManager::RescanUsages(conn, aOriginMetadata)));
return data::FileSystemDatabaseManager::GetUsage(conn, aOriginMetadata)
.mapErr(toNSResult);
}
nsresult FileSystemQuotaClient::InitOriginWithoutTracking(
quota::PersistenceType /* aPersistenceType */,
const quota::OriginMetadata& /* aOriginMetadata */,
const AtomicBool& /* aCanceled */) {
quota::AssertIsOnIOThread();
// This is called when a storage/permanent/${origin}/fs directory exists. Even
// though this shouldn't happen with a "good" profile, we shouldn't return an
// error here, since that would cause origin initialization to fail. We just
// warn and otherwise ignore that.
UNKNOWN_FILE_WARNING(
NS_LITERAL_STRING_FROM_CSTRING(FILESYSTEM_DIRECTORY_NAME));
return NS_OK;
}
Result<quota::UsageInfo, nsresult> FileSystemQuotaClient::GetUsageForOrigin(
quota::PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata,
const AtomicBool& /* aCanceled */) {
quota::AssertIsOnIOThread();
MOZ_ASSERT(aPersistenceType ==
quota::PersistenceType::PERSISTENCE_TYPE_DEFAULT);
quota::QuotaManager* quotaManager = quota::QuotaManager::Get();
MOZ_ASSERT(quotaManager);
MOZ_ASSERT(quotaManager->IsTemporaryStorageInitializedInternal());
// We can't open the database at this point because the quota manager may not
// allow it. Use the cached value instead.
return quotaManager->GetUsageForClient(aPersistenceType, aOriginMetadata,
quota::Client::FILESYSTEM);
}
void FileSystemQuotaClient::OnOriginClearCompleted(
const quota::OriginMetadata& aOriginMetadata) {
quota::AssertIsOnIOThread();
}
void FileSystemQuotaClient::OnRepositoryClearCompleted(
quota::PersistenceType aPersistenceType) {
quota::AssertIsOnIOThread();
}
void FileSystemQuotaClient::ReleaseIOThreadObjects() {
quota::AssertIsOnIOThread();
}
void FileSystemQuotaClient::AbortOperationsForLocks(
const DirectoryLockIdTable& aDirectoryLockIds) {
::mozilla::ipc::AssertIsOnBackgroundThread();
data::FileSystemDataManager::AbortOperationsForLocks(aDirectoryLockIds);
}
void FileSystemQuotaClient::AbortOperationsForProcess(
ContentParentId aContentParentId) {
::mozilla::ipc::AssertIsOnBackgroundThread();
}
void FileSystemQuotaClient::AbortAllOperations() {
::mozilla::ipc::AssertIsOnBackgroundThread();
}
void FileSystemQuotaClient::StartIdleMaintenance() {
::mozilla::ipc::AssertIsOnBackgroundThread();
}
void FileSystemQuotaClient::StopIdleMaintenance() {
::mozilla::ipc::AssertIsOnBackgroundThread();
}
void FileSystemQuotaClient::InitiateShutdown() {
::mozilla::ipc::AssertIsOnBackgroundThread();
data::FileSystemDataManager::InitiateShutdown();
}
nsCString FileSystemQuotaClient::GetShutdownStatus() const {
::mozilla::ipc::AssertIsOnBackgroundThread();
return "Not implemented"_ns;
}
bool FileSystemQuotaClient::IsShutdownCompleted() const {
::mozilla::ipc::AssertIsOnBackgroundThread();
return data::FileSystemDataManager::IsShutdownCompleted();
}
void FileSystemQuotaClient::ForceKillActors() {
::mozilla::ipc::AssertIsOnBackgroundThread();
// Hopefully not needed.
}
void FileSystemQuotaClient::FinalizeShutdown() {
::mozilla::ipc::AssertIsOnBackgroundThread();
// Empty for now.
}
} // namespace mozilla::dom::fs
|