OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_LEVELDB_ENV_MOJO_H_ | 5 #ifndef COMPONENTS_LEVELDB_ENV_MOJO_H_ |
6 #define COMPONENTS_LEVELDB_ENV_MOJO_H_ | 6 #define COMPONENTS_LEVELDB_ENV_MOJO_H_ |
7 | 7 |
8 #include "base/id_map.h" | |
8 #include "components/filesystem/public/interfaces/directory.mojom.h" | 9 #include "components/filesystem/public/interfaces/directory.mojom.h" |
9 #include "components/leveldb/leveldb_mojo_proxy.h" | 10 #include "components/leveldb/leveldb_mojo_proxy.h" |
10 #include "third_party/leveldatabase/env_chromium.h" | 11 #include "third_party/leveldatabase/env_chromium.h" |
11 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 12 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
12 | 13 |
13 namespace leveldb { | 14 namespace leveldb { |
14 | 15 |
15 // An implementation of the leveldb operating system interaction code which | 16 // An implementation of the leveldb operating system interaction code which |
16 // proxies to a specified mojo:filesystem directory. Most of these methods are | 17 // proxies to a specified mojo:filesystem directory. Most of these methods are |
17 // synchronous and block on responses from the filesystem service. That's fine | 18 // synchronous and block on responses from the filesystem service. That's fine |
18 // since, for the most part, they merely open files or check for a file's | 19 // since, for the most part, they merely open files or check for a file's |
19 // existence. | 20 // existence. |
20 class MojoEnv : public leveldb_env::ChromiumEnv { | 21 class MojoEnv : public leveldb_env::ChromiumEnv { |
21 public: | 22 public: |
22 MojoEnv(const std::string& name, | 23 class Directory { |
23 scoped_refptr<LevelDBMojoProxy> file_thread, | 24 public: |
24 LevelDBMojoProxy::OpaqueDir* dir); | 25 ~Directory(); |
25 ~MojoEnv() override; | 26 const std::string& prefix() const { return prefix_; } |
27 | |
28 private: | |
29 friend class MojoEnv; | |
30 Directory(MojoEnv* env, std::string prefix); | |
31 MojoEnv* env_; | |
32 std::string prefix_; | |
33 }; | |
34 | |
35 explicit MojoEnv( | |
36 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | |
37 | |
38 // Registers a |directory| with the leveldb environment, returning a string | |
39 // that should be used as prefix to indicate files in that directory. | |
40 std::unique_ptr<Directory> RegisterDirectory( | |
41 filesystem::mojom::DirectoryPtr directory); | |
42 | |
43 base::SingleThreadTaskRunner* file_task_runner() const { | |
44 return thread_->task_runner(); | |
45 } | |
26 | 46 |
27 // Overridden from leveldb_env::EnvChromium: | 47 // Overridden from leveldb_env::EnvChromium: |
cmumford
2017/04/12 23:06:39
I know it was there before, but s/EnvChromium/Chro
| |
28 Status NewSequentialFile(const std::string& fname, | 48 Status NewSequentialFile(const std::string& fname, |
29 SequentialFile** result) override; | 49 SequentialFile** result) override; |
30 Status NewRandomAccessFile(const std::string& fname, | 50 Status NewRandomAccessFile(const std::string& fname, |
31 RandomAccessFile** result) override; | 51 RandomAccessFile** result) override; |
32 Status NewWritableFile(const std::string& fname, | 52 Status NewWritableFile(const std::string& fname, |
33 WritableFile** result) override; | 53 WritableFile** result) override; |
34 Status NewAppendableFile(const std::string& fname, | 54 Status NewAppendableFile(const std::string& fname, |
35 WritableFile** result) override; | 55 WritableFile** result) override; |
36 bool FileExists(const std::string& fname) override; | 56 bool FileExists(const std::string& fname) override; |
37 Status GetChildren(const std::string& dir, | 57 Status GetChildren(const std::string& dir, |
38 std::vector<std::string>* result) override; | 58 std::vector<std::string>* result) override; |
39 Status DeleteFile(const std::string& fname) override; | 59 Status DeleteFile(const std::string& fname) override; |
40 Status CreateDir(const std::string& dirname) override; | 60 Status CreateDir(const std::string& dirname) override; |
41 Status DeleteDir(const std::string& dirname) override; | 61 Status DeleteDir(const std::string& dirname) override; |
42 Status GetFileSize(const std::string& fname, uint64_t* file_size) override; | 62 Status GetFileSize(const std::string& fname, uint64_t* file_size) override; |
43 Status RenameFile(const std::string& src, const std::string& target) override; | 63 Status RenameFile(const std::string& src, const std::string& target) override; |
44 Status LockFile(const std::string& fname, FileLock** lock) override; | 64 Status LockFile(const std::string& fname, FileLock** lock) override; |
45 Status UnlockFile(FileLock* lock) override; | 65 Status UnlockFile(FileLock* lock) override; |
46 Status GetTestDirectory(std::string* path) override; | 66 Status GetTestDirectory(std::string* path) override; |
47 Status NewLogger(const std::string& fname, Logger** result) override; | 67 Status NewLogger(const std::string& fname, Logger** result) override; |
48 | 68 |
49 // For reference, we specifically don't override Schedule(), StartThread(), | 69 // For reference, we specifically don't override Schedule(), StartThread(), |
50 // NowMicros() or SleepForMicroseconds() and use the EnvChromium versions. | 70 // NowMicros() or SleepForMicroseconds() and use the EnvChromium versions. |
51 | 71 |
52 private: | 72 private: |
73 ~MojoEnv() override; | |
74 | |
75 void ParsePath(const std::string& path, | |
76 LevelDBMojoProxy::OpaqueDir** out_dir, | |
77 std::string* out_path); | |
78 void UnregisterDirectory(base::StringPiece prefix); | |
79 | |
53 scoped_refptr<LevelDBMojoProxy> thread_; | 80 scoped_refptr<LevelDBMojoProxy> thread_; |
54 LevelDBMojoProxy::OpaqueDir* dir_; | 81 IDMap<LevelDBMojoProxy::OpaqueDir*> dirs_; |
55 | 82 |
56 DISALLOW_COPY_AND_ASSIGN(MojoEnv); | 83 DISALLOW_COPY_AND_ASSIGN(MojoEnv); |
57 }; | 84 }; |
58 | 85 |
59 } // namespace leveldb | 86 } // namespace leveldb |
60 | 87 |
61 #endif // COMPONENTS_LEVELDB_ENV_MOJO_H_ | 88 #endif // COMPONENTS_LEVELDB_ENV_MOJO_H_ |
OLD | NEW |