#include "storage/browser/file_system/sandbox_file_system_backend_delegate.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_error_or.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/types/expected_macros.h"
#include "storage/browser/file_system/async_file_util_adapter.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_url.h"
#include "storage/browser/file_system/file_system_usage_cache.h"
#include "storage/browser/file_system/file_system_util.h"
#include "storage/browser/file_system/obfuscated_file_util.h"
#include "storage/browser/file_system/obfuscated_file_util_memory_delegate.h"
#include "storage/browser/file_system/quota/quota_backend_impl.h"
#include "storage/browser/file_system/quota/quota_reservation.h"
#include "storage/browser/file_system/quota/quota_reservation_manager.h"
#include "storage/browser/file_system/sandbox_file_stream_reader.h"
#include "storage/browser/file_system/sandbox_file_stream_writer.h"
#include "storage/browser/file_system/sandbox_file_system_backend.h"
#include "storage/browser/file_system/sandbox_quota_observer.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/common/file_system/file_system_util.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/gurl.h"
namespace storage {
namespace {
int64_t kMinimumStatsCollectionIntervalHours = …;
const char kTemporaryDirectoryName[] = …;
const char kPersistentDirectoryName[] = …;
const char kSyncableDirectoryName[] = …;
const base::FilePath::CharType* const kRestrictedNames[] = …;
const base::FilePath::CharType kRestrictedChars[] = …;
std::set<std::string> GetKnownTypeStrings() { … }
class SandboxObfuscatedStorageKeyEnumerator
: public SandboxFileSystemBackendDelegate::StorageKeyEnumerator { … };
base::File::Error OpenSandboxFileSystemOnFileTaskRunner(
ObfuscatedFileUtil* file_util,
const BucketLocator& bucket_locator,
FileSystemType type,
OpenFileSystemMode mode) { … }
void DidOpenFileSystem(
base::WeakPtr<SandboxFileSystemBackendDelegate> delegate,
base::OnceClosure quota_callback,
base::OnceCallback<void(base::File::Error error)> callback,
base::File::Error error) { … }
template <typename T>
void DeleteSoon(base::SequencedTaskRunner* runner, T* ptr) { … }
}
std::string SandboxFileSystemBackendDelegate::GetTypeString(
FileSystemType type) { … }
SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate(
scoped_refptr<QuotaManagerProxy> quota_manager_proxy,
scoped_refptr<base::SequencedTaskRunner> file_task_runner,
const base::FilePath& profile_path,
scoped_refptr<SpecialStoragePolicy> special_storage_policy,
const FileSystemOptions& file_system_options,
leveldb::Env* env_override)
: … { … }
SandboxFileSystemBackendDelegate::~SandboxFileSystemBackendDelegate() { … }
SandboxFileSystemBackendDelegate::StorageKeyEnumerator*
SandboxFileSystemBackendDelegate::CreateStorageKeyEnumerator() { … }
base::FilePath
SandboxFileSystemBackendDelegate::GetBaseDirectoryForStorageKeyAndType(
const blink::StorageKey& storage_key,
FileSystemType type,
bool create) { … }
base::FilePath
SandboxFileSystemBackendDelegate::GetBaseDirectoryForBucketAndType(
const BucketLocator& bucket_locator,
FileSystemType type,
bool create) { … }
void SandboxFileSystemBackendDelegate::OpenFileSystem(
const BucketLocator& bucket_locator,
FileSystemType type,
OpenFileSystemMode mode,
ResolveURLCallback callback,
const GURL& root_url) { … }
std::unique_ptr<FileSystemOperationContext>
SandboxFileSystemBackendDelegate::CreateFileSystemOperationContext(
const FileSystemURL& url,
FileSystemContext* context,
base::File::Error* error_code) const { … }
std::unique_ptr<FileStreamReader>
SandboxFileSystemBackendDelegate::CreateFileStreamReader(
const FileSystemURL& url,
int64_t offset,
const base::Time& expected_modification_time,
FileSystemContext* context) const { … }
std::unique_ptr<FileStreamWriter>
SandboxFileSystemBackendDelegate::CreateFileStreamWriter(
const FileSystemURL& url,
int64_t offset,
FileSystemContext* context,
FileSystemType type) const { … }
void SandboxFileSystemBackendDelegate::DeleteCachedDefaultBucket(
const blink::StorageKey& storage_key) { … }
base::File::Error
SandboxFileSystemBackendDelegate::DeleteBucketDataOnFileTaskRunner(
FileSystemContext* file_system_context,
QuotaManagerProxy* proxy,
const BucketLocator& bucket_locator,
FileSystemType type) { … }
void SandboxFileSystemBackendDelegate::PerformStorageCleanupOnFileTaskRunner(
FileSystemContext* context,
QuotaManagerProxy* proxy,
FileSystemType type) { … }
std::vector<blink::StorageKey>
SandboxFileSystemBackendDelegate::GetStorageKeysForTypeOnFileTaskRunner(
FileSystemType type) { … }
int64_t SandboxFileSystemBackendDelegate::GetBucketUsageOnFileTaskRunner(
FileSystemContext* file_system_context,
const BucketLocator& bucket_locator,
FileSystemType type) { … }
scoped_refptr<QuotaReservation>
SandboxFileSystemBackendDelegate::CreateQuotaReservationOnFileTaskRunner(
const blink::StorageKey& storage_key,
FileSystemType type) { … }
void SandboxFileSystemBackendDelegate::AddFileUpdateObserver(
FileSystemType type,
FileUpdateObserver* observer,
base::SequencedTaskRunner* task_runner) { … }
void SandboxFileSystemBackendDelegate::AddFileChangeObserver(
FileSystemType type,
FileChangeObserver* observer,
base::SequencedTaskRunner* task_runner) { … }
void SandboxFileSystemBackendDelegate::AddFileAccessObserver(
FileSystemType type,
FileAccessObserver* observer,
base::SequencedTaskRunner* task_runner) { … }
const UpdateObserverList* SandboxFileSystemBackendDelegate::GetUpdateObservers(
FileSystemType type) const { … }
const ChangeObserverList* SandboxFileSystemBackendDelegate::GetChangeObservers(
FileSystemType type) const { … }
const AccessObserverList* SandboxFileSystemBackendDelegate::GetAccessObservers(
FileSystemType type) const { … }
void SandboxFileSystemBackendDelegate::RegisterQuotaUpdateObserver(
FileSystemType type) { … }
void SandboxFileSystemBackendDelegate::InvalidateUsageCache(
const blink::StorageKey& storage_key,
FileSystemType type) { … }
void SandboxFileSystemBackendDelegate::StickyInvalidateUsageCache(
const blink::StorageKey& storage_key,
FileSystemType type) { … }
FileSystemFileUtil* SandboxFileSystemBackendDelegate::sync_file_util() { … }
bool SandboxFileSystemBackendDelegate::IsAccessValid(
const FileSystemURL& url) const { … }
bool SandboxFileSystemBackendDelegate::IsAllowedScheme(const GURL& url) const { … }
base::FileErrorOr<base::FilePath>
SandboxFileSystemBackendDelegate::GetUsageCachePathForStorageKeyAndType(
const blink::StorageKey& storage_key,
FileSystemType type) { … }
base::FileErrorOr<base::FilePath>
SandboxFileSystemBackendDelegate::GetUsageCachePathForStorageKeyAndType(
ObfuscatedFileUtil* sandbox_file_util,
const blink::StorageKey& storage_key,
FileSystemType type) { … }
base::FileErrorOr<base::FilePath>
SandboxFileSystemBackendDelegate::GetUsageCachePathForBucketAndType(
const BucketLocator& bucket_locator,
FileSystemType type) { … }
base::FileErrorOr<base::FilePath>
SandboxFileSystemBackendDelegate::GetUsageCachePathForBucketAndType(
ObfuscatedFileUtil* sandbox_file_util,
const BucketLocator& bucket_locator,
FileSystemType type) { … }
int64_t SandboxFileSystemBackendDelegate::RecalculateBucketUsage(
FileSystemContext* context,
const BucketLocator& bucket_locator,
FileSystemType type) { … }
void SandboxFileSystemBackendDelegate::CollectOpenFileSystemMetrics(
base::File::Error error_code) { … }
ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { … }
base::WeakPtr<ObfuscatedFileUtilMemoryDelegate>
SandboxFileSystemBackendDelegate::memory_file_util_delegate() { … }
std::unique_ptr<ObfuscatedFileUtil> ObfuscatedFileUtil::CreateForTesting(
scoped_refptr<SpecialStoragePolicy> special_storage_policy,
const base::FilePath& profile_path,
leveldb::Env* env_override,
bool is_incognito) { … }
}