#include "storage/browser/file_system/obfuscated_file_util.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <tuple>
#include <utility>
#include "base/containers/queue.h"
#include "base/files/file_error_or.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/types/expected_macros.h"
#include "components/services/storage/public/cpp/buckets/bucket_init_params.h"
#include "storage/browser/file_system/file_observers.h"
#include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_operation_context.h"
#include "storage/browser/file_system/file_system_util.h"
#include "storage/browser/file_system/obfuscated_file_util_disk_delegate.h"
#include "storage/browser/file_system/obfuscated_file_util_memory_delegate.h"
#include "storage/browser/file_system/quota/quota_limit_type.h"
#include "storage/browser/file_system/sandbox_file_system_backend.h"
#include "storage/browser/file_system/sandbox_origin_database.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/common/database/database_identifier.h"
#include "storage/common/file_system/file_system_types.h"
#include "storage/common/file_system/file_system_util.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/leveldatabase/leveldb_chrome.h"
#include "url/gurl.h"
namespace storage {
namespace {
FileId;
FileInfo;
void InitFileInfo(SandboxDirectoryDatabase::FileInfo* file_info,
SandboxDirectoryDatabase::FileId parent_id,
const base::FilePath::StringType& file_name) { … }
const int64_t kPathCreationQuotaCost = …;
const int64_t kPathByteQuotaCost = …;
int64_t UsageForPath(size_t length) { … }
bool AllocateQuota(FileSystemOperationContext* context, int64_t growth) { … }
void UpdateUsage(FileSystemOperationContext* context,
const FileSystemURL& url,
int64_t growth) { … }
void TouchDirectory(SandboxDirectoryDatabase* db, FileId dir_id) { … }
enum IsolatedOriginStatus { … };
}
DatabaseKey::DatabaseKey() = default;
DatabaseKey::~DatabaseKey() = default;
DatabaseKey::DatabaseKey(const DatabaseKey& other) = default;
DatabaseKey& DatabaseKey::operator=(const DatabaseKey& other) = default;
DatabaseKey::DatabaseKey(DatabaseKey&& other) = default;
DatabaseKey& DatabaseKey::operator=(DatabaseKey&& other) = default;
DatabaseKey::DatabaseKey(const blink::StorageKey& storage_key,
const std::optional<BucketLocator>& bucket,
const std::string& type) { … }
bool DatabaseKey::operator==(const DatabaseKey& other) const { … }
bool DatabaseKey::operator!=(const DatabaseKey& other) const { … }
bool DatabaseKey::operator<(const DatabaseKey& other) const { … }
class ObfuscatedFileEnumerator final
: public FileSystemFileUtil::AbstractFileEnumerator { … };
class ObfuscatedStorageKeyEnumerator
: public ObfuscatedFileUtil::AbstractStorageKeyEnumerator { … };
const base::FilePath::CharType ObfuscatedFileUtil::kFileSystemDirectory[] = …);
ObfuscatedFileUtil::ObfuscatedFileUtil(
scoped_refptr<SpecialStoragePolicy> special_storage_policy,
const base::FilePath& profile_path,
leveldb::Env* env_override,
const std::set<std::string>& known_type_strings,
SandboxFileSystemBackendDelegate* sandbox_delegate,
bool is_incognito)
: … { … }
ObfuscatedFileUtil::~ObfuscatedFileUtil() { … }
base::File ObfuscatedFileUtil::CreateOrOpen(FileSystemOperationContext* context,
const FileSystemURL& url,
int file_flags) { … }
base::File::Error ObfuscatedFileUtil::EnsureFileExists(
FileSystemOperationContext* context,
const FileSystemURL& url,
bool* created) { … }
base::File::Error ObfuscatedFileUtil::CreateDirectory(
FileSystemOperationContext* context,
const FileSystemURL& url,
bool exclusive,
bool recursive) { … }
base::File::Error ObfuscatedFileUtil::GetFileInfo(
FileSystemOperationContext* context,
const FileSystemURL& url,
base::File::Info* file_info,
base::FilePath* platform_file_path) { … }
base::File::Error ObfuscatedFileUtil::GetLocalFilePath(
FileSystemOperationContext* context,
const FileSystemURL& url,
base::FilePath* local_path) { … }
base::File::Error ObfuscatedFileUtil::Touch(
FileSystemOperationContext* context,
const FileSystemURL& url,
const base::Time& last_access_time,
const base::Time& last_modified_time) { … }
base::File::Error ObfuscatedFileUtil::Truncate(
FileSystemOperationContext* context,
const FileSystemURL& url,
int64_t length) { … }
base::File::Error ObfuscatedFileUtil::CopyOrMoveFile(
FileSystemOperationContext* context,
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
CopyOrMoveOptionSet options,
bool copy) { … }
base::File::Error ObfuscatedFileUtil::CopyInForeignFile(
FileSystemOperationContext* context,
const base::FilePath& src_file_path,
const FileSystemURL& dest_url) { … }
base::File::Error ObfuscatedFileUtil::DeleteFile(
FileSystemOperationContext* context,
const FileSystemURL& url) { … }
base::File::Error ObfuscatedFileUtil::DeleteDirectory(
FileSystemOperationContext* context,
const FileSystemURL& url) { … }
ScopedFile ObfuscatedFileUtil::CreateSnapshotFile(
FileSystemOperationContext* context,
const FileSystemURL& url,
base::File::Error* error,
base::File::Info* file_info,
base::FilePath* platform_path) { … }
std::unique_ptr<FileSystemFileUtil::AbstractFileEnumerator>
ObfuscatedFileUtil::CreateFileEnumerator(FileSystemOperationContext* context,
const FileSystemURL& root_url,
bool recursive) { … }
bool ObfuscatedFileUtil::IsDirectoryEmpty(FileSystemOperationContext* context,
const FileSystemURL& url) { … }
base::FileErrorOr<base::FilePath>
ObfuscatedFileUtil::GetDirectoryForBucketAndType(
const BucketLocator& bucket,
const std::optional<FileSystemType>& type,
bool create) { … }
base::FileErrorOr<base::FilePath>
ObfuscatedFileUtil::GetDirectoryForStorageKeyAndType(
const blink::StorageKey& storage_key,
const std::optional<FileSystemType>& type,
bool create) { … }
bool ObfuscatedFileUtil::DeleteDirectoryForBucketAndType(
const BucketLocator& bucket_locator,
const std::optional<FileSystemType>& type) { … }
std::unique_ptr<ObfuscatedFileUtil::AbstractStorageKeyEnumerator>
ObfuscatedFileUtil::CreateStorageKeyEnumerator() { … }
void ObfuscatedFileUtil::DestroyDirectoryDatabaseForBucket(
const BucketLocator& bucket_locator,
const std::optional<FileSystemType>& type) { … }
int64_t ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) { … }
base::FileErrorOr<base::FilePath> ObfuscatedFileUtil::GetDirectoryForURL(
const FileSystemURL& url,
bool create) { … }
QuotaErrorOr<BucketLocator> ObfuscatedFileUtil::GetOrCreateDefaultBucket(
const blink::StorageKey& storage_key) { … }
base::File::Error ObfuscatedFileUtil::GetFileInfoInternal(
SandboxDirectoryDatabase* db,
FileSystemOperationContext* context,
const FileSystemURL& url,
FileId file_id,
FileInfo* local_info,
base::File::Info* file_info,
base::FilePath* platform_file_path) { … }
base::File ObfuscatedFileUtil::CreateAndOpenFile(
FileSystemOperationContext* context,
const FileSystemURL& dest_url,
FileInfo* dest_file_info,
int file_flags) { … }
base::File::Error ObfuscatedFileUtil::CreateFile(
FileSystemOperationContext* context,
const base::FilePath& src_file_path,
bool foreign_source,
const FileSystemURL& dest_url,
FileInfo* dest_file_info) { … }
base::File::Error ObfuscatedFileUtil::CommitCreateFile(
const base::FilePath& root,
const base::FilePath& local_path,
SandboxDirectoryDatabase* db,
FileInfo* dest_file_info) { … }
base::FilePath ObfuscatedFileUtil::DataPathToLocalPath(
const FileSystemURL& url,
const base::FilePath& data_path) { … }
SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase(
const FileSystemURL& url,
bool create) { … }
base::FileErrorOr<base::FilePath> ObfuscatedFileUtil::GetDirectoryForStorageKey(
const blink::StorageKey& storage_key,
bool create) { … }
base::File::Error ObfuscatedFileUtil::GetDirectoryHelper(
const base::FilePath& path,
bool create) { … }
void ObfuscatedFileUtil::InvalidateUsageCache(
FileSystemOperationContext* context,
const blink::StorageKey& storage_key,
FileSystemType type) { … }
void ObfuscatedFileUtil::MarkUsed() { … }
void ObfuscatedFileUtil::DropDatabases() { … }
void ObfuscatedFileUtil::RewriteDatabases() { … }
void ObfuscatedFileUtil::DeleteDefaultBucketForStorageKey(
const blink::StorageKey& storage_key) { … }
bool ObfuscatedFileUtil::InitOriginDatabase(const url::Origin& origin_hint,
bool create) { … }
base::File::Error ObfuscatedFileUtil::GenerateNewLocalPath(
SandboxDirectoryDatabase* db,
FileSystemOperationContext* context,
const FileSystemURL& url,
base::FilePath* root,
base::FilePath* local_path) { … }
base::File ObfuscatedFileUtil::CreateOrOpenInternal(
FileSystemOperationContext* context,
const FileSystemURL& url,
int file_flags) { … }
bool ObfuscatedFileUtil::HasIsolatedStorage(
const blink::StorageKey& storage_key) { … }
}