| 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 "components/filesystem/public/interfaces/directory.mojom.h" | 8 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 9 #include "components/leveldb/leveldb_mojo_proxy.h" | 9 #include "components/leveldb/leveldb_mojo_proxy.h" |
| 10 #include "third_party/leveldatabase/env_chromium.h" | |
| 11 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 10 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 12 | 11 |
| 13 namespace leveldb { | 12 namespace leveldb { |
| 14 | 13 |
| 15 // An implementation of the leveldb operating system interaction code which | 14 // An implementation of the leveldb operating system interaction code which |
| 16 // proxies to a specified mojo:filesystem directory. Most of these methods are | 15 // 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 | 16 // 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 | 17 // since, for the most part, they merely open files or check for a file's |
| 19 // existence. | 18 // existence. |
| 20 class MojoEnv : public leveldb_env::ChromiumEnv { | 19 class MojoEnv : public leveldb::Env { |
| 21 public: | 20 public: |
| 22 MojoEnv(const std::string& name, | 21 MojoEnv(scoped_refptr<LevelDBMojoProxy> file_thread, |
| 23 scoped_refptr<LevelDBMojoProxy> file_thread, | |
| 24 LevelDBMojoProxy::OpaqueDir* dir); | 22 LevelDBMojoProxy::OpaqueDir* dir); |
| 25 ~MojoEnv() override; | 23 ~MojoEnv() override; |
| 26 | 24 |
| 27 // Overridden from leveldb_env::EnvChromium: | 25 // Overridden from leveldb::Env: |
| 28 Status NewSequentialFile(const std::string& fname, | 26 Status NewSequentialFile(const std::string& fname, |
| 29 SequentialFile** result) override; | 27 SequentialFile** result) override; |
| 30 Status NewRandomAccessFile(const std::string& fname, | 28 Status NewRandomAccessFile(const std::string& fname, |
| 31 RandomAccessFile** result) override; | 29 RandomAccessFile** result) override; |
| 32 Status NewWritableFile(const std::string& fname, | 30 Status NewWritableFile(const std::string& fname, |
| 33 WritableFile** result) override; | 31 WritableFile** result) override; |
| 34 Status NewAppendableFile(const std::string& fname, | 32 Status NewAppendableFile(const std::string& fname, |
| 35 WritableFile** result) override; | 33 WritableFile** result) override; |
| 36 bool FileExists(const std::string& fname) override; | 34 bool FileExists(const std::string& fname) override; |
| 37 Status GetChildren(const std::string& dir, | 35 Status GetChildren(const std::string& dir, |
| 38 std::vector<std::string>* result) override; | 36 std::vector<std::string>* result) override; |
| 39 Status DeleteFile(const std::string& fname) override; | 37 Status DeleteFile(const std::string& fname) override; |
| 40 Status CreateDir(const std::string& dirname) override; | 38 Status CreateDir(const std::string& dirname) override; |
| 41 Status DeleteDir(const std::string& dirname) override; | 39 Status DeleteDir(const std::string& dirname) override; |
| 42 Status GetFileSize(const std::string& fname, uint64_t* file_size) override; | 40 Status GetFileSize(const std::string& fname, uint64_t* file_size) override; |
| 43 Status RenameFile(const std::string& src, const std::string& target) override; | 41 Status RenameFile(const std::string& src, const std::string& target) override; |
| 44 Status LockFile(const std::string& fname, FileLock** lock) override; | 42 Status LockFile(const std::string& fname, FileLock** lock) override; |
| 45 Status UnlockFile(FileLock* lock) override; | 43 Status UnlockFile(FileLock* lock) override; |
| 46 Status GetTestDirectory(std::string* path) override; | 44 Status GetTestDirectory(std::string* path) override; |
| 47 Status NewLogger(const std::string& fname, Logger** result) override; | 45 Status NewLogger(const std::string& fname, Logger** result) override; |
| 48 | 46 |
| 49 // For reference, we specifically don't override Schedule(), StartThread(), | 47 uint64_t NowMicros() override; |
| 50 // NowMicros() or SleepForMicroseconds() and use the EnvChromium versions. | 48 void SleepForMicroseconds(int micros) override; |
| 49 void Schedule(void (*function)(void* arg), void* arg) override; |
| 50 void StartThread(void (*function)(void* arg), void* arg) override; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 scoped_refptr<LevelDBMojoProxy> thread_; | 53 scoped_refptr<LevelDBMojoProxy> thread_; |
| 54 LevelDBMojoProxy::OpaqueDir* dir_; | 54 LevelDBMojoProxy::OpaqueDir* dir_; |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(MojoEnv); | 56 DISALLOW_COPY_AND_ASSIGN(MojoEnv); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace leveldb | 59 } // namespace leveldb |
| 60 | 60 |
| 61 #endif // COMPONENTS_LEVELDB_ENV_MOJO_H_ | 61 #endif // COMPONENTS_LEVELDB_ENV_MOJO_H_ |
| OLD | NEW |