Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / sql / mojo / mojo_vfs.h
blobdc835938eff9b07e617e644a8fd0bc7bcd3e2856
1 // Copyright 2015 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.
5 #ifndef SQL_MOJO_MOJO_VFS_H_
6 #define SQL_MOJO_MOJO_VFS_H_
8 #include "base/macros.h"
9 #include "components/filesystem/public/interfaces/directory.mojom.h"
11 typedef struct sqlite3_vfs sqlite3_vfs;
13 namespace sql {
15 // Changes the default sqlite3 vfs to a vfs that uses proxies calls to the
16 // mojo:filesystem service. Instantiating this object transparently changes how
17 // the entire //sql/ subsystem works in the process of the caller; all paths
18 // are treated as relative to |directory|.
19 class ScopedMojoFilesystemVFS {
20 public:
21 explicit ScopedMojoFilesystemVFS(filesystem::DirectoryPtr directory);
22 ~ScopedMojoFilesystemVFS();
24 // Returns the directory of the current VFS.
25 filesystem::DirectoryPtr& GetDirectory();
27 private:
28 friend sqlite3_vfs* GetParentVFS(sqlite3_vfs* mojo_vfs);
29 friend filesystem::DirectoryPtr& GetRootDirectory(sqlite3_vfs* mojo_vfs);
31 // The default vfs at the time MojoVFS was installed. We use the to pass
32 // through things like randomness requests and per-platform sleep calls.
33 sqlite3_vfs* parent_;
35 // When we initialize the subsystem, we are given a filesystem::Directory
36 // object, which is the root directory of a mojo:filesystem. All access to
37 // various files are specified from this root directory.
38 filesystem::DirectoryPtr root_directory_;
40 DISALLOW_COPY_AND_ASSIGN(ScopedMojoFilesystemVFS);
43 } // namespace sql
45 #endif // SQL_MOJO_MOJO_VFS_H_