// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef SQL_SANDBOXED_VFS_FILE_H_ #define SQL_SANDBOXED_VFS_FILE_H_ #include "base/dcheck_is_on.h" #include "base/files/file.h" #include "base/files/file_path.h" #include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr_exclusion.h" #include "third_party/sqlite/sqlite3.h" namespace sql { // The file types associated with a SQLite database. enum class SandboxedVfsFileType { … }; class SandboxedVfs; // SQLite VFS file implementation that works in a sandboxed process. // // An instance is created when SQLite calls into SandboxedVfs::Open(). The // instance is deleted by a call to SandboxedVfsFile::Close(). // // The SQLite VFS API includes a complex locking strategy documented in // https://www.sqlite.org/lockingv3.html // // This implementation uses a simplified locking strategy, where we grab an // exclusive lock when entering any of the modes that prepare for a transition // to EXCLUSIVE. (These modes are RESERVED and PENDING). This approach is easy // to implement on top of base::File's locking primitives, at the cost of some // false contention, which makes us slower under high concurrency. // // SQLite's built-in VFSes use the OS support for locking a range of bytes in // the file, rather locking than the whole file. class SandboxedVfsFile { … }; // sqlite3_file "subclass" that bridges to a SandboxedVfsFile instance. struct SandboxedVfsFileSqliteBridge { … }; } // namespace sql #endif // SQL_SANDBOXED_VFS_FILE_H_