sandboxed_vfs_delegate.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/services/storage/sandboxed_vfs_delegate.h"
  5. #include <cstdint>
  6. #include <utility>
  7. #include "base/files/file.h"
  8. #include "base/files/file_error_or.h"
  9. #include "base/files/file_path.h"
  10. #include "components/services/storage/public/cpp/filesystem/filesystem_proxy.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace storage {
  13. SandboxedVfsDelegate::SandboxedVfsDelegate(
  14. std::unique_ptr<FilesystemProxy> filesystem)
  15. : filesystem_(std::move(filesystem)) {}
  16. SandboxedVfsDelegate::~SandboxedVfsDelegate() = default;
  17. base::File SandboxedVfsDelegate::OpenFile(const base::FilePath& file_path,
  18. int sqlite_requested_flags) {
  19. base::FileErrorOr<base::File> result = filesystem_->OpenFile(
  20. file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
  21. base::File::FLAG_WRITE);
  22. if (result.is_error())
  23. return base::File();
  24. return std::move(result.value());
  25. }
  26. int SandboxedVfsDelegate::DeleteFile(const base::FilePath& file_path,
  27. bool sync_dir) {
  28. if (!filesystem_->DeleteFile(file_path))
  29. return SQLITE_IOERR_DELETE;
  30. return SQLITE_OK;
  31. }
  32. absl::optional<sql::SandboxedVfs::PathAccessInfo>
  33. SandboxedVfsDelegate::GetPathAccess(const base::FilePath& file_path) {
  34. absl::optional<FilesystemProxy::PathAccessInfo> info =
  35. filesystem_->GetPathAccess(file_path);
  36. if (!info)
  37. return absl::nullopt;
  38. sql::SandboxedVfs::PathAccessInfo access;
  39. access.can_read = info->can_read;
  40. access.can_write = info->can_write;
  41. return access;
  42. }
  43. bool SandboxedVfsDelegate::SetFileLength(const base::FilePath& file_path,
  44. base::File& file,
  45. size_t size) {
  46. return filesystem_->SetOpenedFileLength(&file, static_cast<uint64_t>(size));
  47. }
  48. } // namespace storage