#include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
#include <stddef.h>
#include <iterator>
#include <utility>
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/uuid.h"
#include "chrome/browser/sync_file_system/file_change.h"
#include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
#include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
#include "chrome/browser/sync_file_system/syncable_file_system_util.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/file_system/copy_or_move_hook_delegate.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_backend.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_operation_runner.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/test/mock_blob_util.h"
#include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_special_storage_policy.h"
#include "storage/browser/test/test_file_system_options.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/gurl.h"
#include "url/origin.h"
File;
FileSystemContext;
FileSystemOperationRunner;
FileSystemURL;
FileSystemURLSet;
QuotaManager;
ScopedTextBlob;
namespace sync_file_system {
namespace {
template <typename R>
void AssignAndQuit(base::TaskRunner* original_task_runner,
base::OnceClosure quit_closure,
R* result_out,
R result) { … }
template <typename R, typename CallbackType>
R RunOnThread(base::SingleThreadTaskRunner* task_runner,
const base::Location& location,
base::OnceCallback<void(CallbackType callback)> task) { … }
void RunOnThread(base::SingleThreadTaskRunner* task_runner,
const base::Location& location,
base::OnceClosure task) { … }
void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { … }
void VerifySameTaskRunner(
base::SingleThreadTaskRunner* runner1,
base::SingleThreadTaskRunner* runner2) { … }
void OnCreateSnapshotFileAndVerifyData(
const std::string& expected_data,
CannedSyncableFileSystem::StatusCallback callback,
base::File::Error result,
const base::File::Info& file_info,
const base::FilePath& platform_path,
scoped_refptr<storage::ShareableFileReference> ) { … }
void OnCreateSnapshotFile(
base::File::Info* file_info_out,
base::FilePath* platform_path_out,
CannedSyncableFileSystem::StatusCallback callback,
base::File::Error result,
const base::File::Info& file_info,
const base::FilePath& platform_path,
scoped_refptr<storage::ShareableFileReference> file_ref) { … }
class DirectoryHelper { … };
class WriteHelper { … };
void DidGetUsageAndQuota(storage::StatusCallback callback,
int64_t* usage_out,
int64_t* quota_out,
blink::mojom::QuotaStatusCode status,
int64_t usage,
int64_t quota) { … }
void EnsureLastTaskRuns(base::SingleThreadTaskRunner* runner) { … }
}
CannedSyncableFileSystem::CannedSyncableFileSystem(
const GURL& origin,
bool in_memory_file_system,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
: … { … }
CannedSyncableFileSystem::~CannedSyncableFileSystem() = default;
void CannedSyncableFileSystem::SetUp() { … }
void CannedSyncableFileSystem::TearDown() { … }
FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const { … }
File::Error CannedSyncableFileSystem::OpenFileSystem() { … }
void CannedSyncableFileSystem::AddSyncStatusObserver(
LocalFileSyncStatus::Observer* observer) { … }
void CannedSyncableFileSystem::RemoveSyncStatusObserver(
LocalFileSyncStatus::Observer* observer) { … }
SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
LocalFileSyncContext* sync_context) { … }
File::Error CannedSyncableFileSystem::CreateDirectory(
const FileSystemURL& url) { … }
File::Error CannedSyncableFileSystem::CreateFile(const FileSystemURL& url) { … }
File::Error CannedSyncableFileSystem::Copy(
const FileSystemURL& src_url, const FileSystemURL& dest_url) { … }
File::Error CannedSyncableFileSystem::Move(
const FileSystemURL& src_url, const FileSystemURL& dest_url) { … }
File::Error CannedSyncableFileSystem::TruncateFile(const FileSystemURL& url,
int64_t size) { … }
File::Error CannedSyncableFileSystem::TouchFile(
const FileSystemURL& url,
const base::Time& last_access_time,
const base::Time& last_modified_time) { … }
File::Error CannedSyncableFileSystem::Remove(
const FileSystemURL& url, bool recursive) { … }
File::Error CannedSyncableFileSystem::FileExists(
const FileSystemURL& url) { … }
File::Error CannedSyncableFileSystem::DirectoryExists(
const FileSystemURL& url) { … }
File::Error CannedSyncableFileSystem::VerifyFile(
const FileSystemURL& url,
const std::string& expected_data) { … }
File::Error CannedSyncableFileSystem::GetMetadataAndPlatformPath(
const FileSystemURL& url,
base::File::Info* info,
base::FilePath* platform_path) { … }
File::Error CannedSyncableFileSystem::ReadDirectory(
const storage::FileSystemURL& url,
FileEntryList* entries) { … }
int64_t CannedSyncableFileSystem::Write(
const FileSystemURL& url,
std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { … }
int64_t CannedSyncableFileSystem::WriteString(const FileSystemURL& url,
const std::string& data) { … }
File::Error CannedSyncableFileSystem::DeleteFileSystem() { … }
blink::mojom::QuotaStatusCode CannedSyncableFileSystem::GetUsageAndQuota(
int64_t* usage,
int64_t* quota) { … }
void CannedSyncableFileSystem::GetChangedURLsInTracker(
FileSystemURLSet* urls) { … }
void CannedSyncableFileSystem::ClearChangeForURLInTracker(
const FileSystemURL& url) { … }
void CannedSyncableFileSystem::GetChangesForURLInTracker(
const FileSystemURL& url,
FileChangeList* changes) { … }
SyncFileSystemBackend* CannedSyncableFileSystem::backend() { … }
FileSystemOperationRunner* CannedSyncableFileSystem::operation_runner() { … }
void CannedSyncableFileSystem::OnSyncEnabled(const FileSystemURL& url) { … }
void CannedSyncableFileSystem::OnWriteEnabled(const FileSystemURL& url) { … }
void CannedSyncableFileSystem::DoOpenFileSystem(
OpenFileSystemCallback callback) { … }
void CannedSyncableFileSystem::DoCreateDirectory(const FileSystemURL& url,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoCreateFile(const FileSystemURL& url,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoCopy(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoMove(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoTruncateFile(const FileSystemURL& url,
int64_t size,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoTouchFile(const FileSystemURL& url,
const base::Time& last_access_time,
const base::Time& last_modified_time,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoRemove(const FileSystemURL& url,
bool recursive,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoFileExists(const FileSystemURL& url,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoDirectoryExists(const FileSystemURL& url,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoVerifyFile(const FileSystemURL& url,
const std::string& expected_data,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoGetMetadataAndPlatformPath(
const FileSystemURL& url,
base::File::Info* info,
base::FilePath* platform_path,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoReadDirectory(const FileSystemURL& url,
FileEntryList* entries,
StatusCallback callback) { … }
void CannedSyncableFileSystem::DoWrite(
const FileSystemURL& url,
std::unique_ptr<storage::BlobDataHandle> blob_data_handle,
WriteCallback callback) { … }
void CannedSyncableFileSystem::DoWriteString(const FileSystemURL& url,
const std::string& data,
WriteCallback callback) { … }
void CannedSyncableFileSystem::DoGetUsageAndQuota(
int64_t* usage,
int64_t* quota,
storage::StatusCallback callback) { … }
void CannedSyncableFileSystem::DidOpenFileSystem(
base::SingleThreadTaskRunner* original_task_runner,
base::OnceClosure quit_closure,
const storage::FileSystemURL& root,
const std::string& name,
File::Error result) { … }
void CannedSyncableFileSystem::DidInitializeFileSystemContext(
base::OnceClosure quit_closure,
SyncStatusCode status) { … }
void CannedSyncableFileSystem::InitializeSyncStatusObserver() { … }
}