 Chromium Code Reviews
 Chromium Code Reviews Issue 2722293002:
  Fix lifetime of leveldb::MojoEnv instances.  (Closed)
    
  
    Issue 2722293002:
  Fix lifetime of leveldb::MojoEnv instances.  (Closed) 
  | Index: components/leveldb/env_mojo.h | 
| diff --git a/components/leveldb/env_mojo.h b/components/leveldb/env_mojo.h | 
| index d784803324321735652be12bd77c44540a4ae91b..12d1fd8f589c1a1432c20a2b6430b9d455922aa2 100644 | 
| --- a/components/leveldb/env_mojo.h | 
| +++ b/components/leveldb/env_mojo.h | 
| @@ -5,6 +5,7 @@ | 
| #ifndef COMPONENTS_LEVELDB_ENV_MOJO_H_ | 
| #define COMPONENTS_LEVELDB_ENV_MOJO_H_ | 
| +#include "base/id_map.h" | 
| #include "components/filesystem/public/interfaces/directory.mojom.h" | 
| #include "components/leveldb/leveldb_mojo_proxy.h" | 
| #include "third_party/leveldatabase/env_chromium.h" | 
| @@ -19,10 +20,29 @@ namespace leveldb { | 
| // existence. | 
| class MojoEnv : public leveldb_env::ChromiumEnv { | 
| public: | 
| - MojoEnv(const std::string& name, | 
| - scoped_refptr<LevelDBMojoProxy> file_thread, | 
| - LevelDBMojoProxy::OpaqueDir* dir); | 
| - ~MojoEnv() override; | 
| + class Directory { | 
| + public: | 
| + ~Directory(); | 
| + const std::string& prefix() const { return prefix_; } | 
| + | 
| + private: | 
| + friend class MojoEnv; | 
| + Directory(MojoEnv* env, std::string prefix); | 
| + MojoEnv* env_; | 
| + std::string prefix_; | 
| + }; | 
| + | 
| + explicit MojoEnv( | 
| + scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 
| + | 
| + // Registers a |directory| with the leveldb environment, returning a string | 
| + // that should be used as prefix to indicate files in that directory. | 
| + std::unique_ptr<Directory> RegisterDirectory( | 
| + filesystem::mojom::DirectoryPtr directory); | 
| + | 
| + base::SingleThreadTaskRunner* file_task_runner() const { | 
| + return thread_->task_runner(); | 
| + } | 
| // Overridden from leveldb_env::EnvChromium: | 
| 
cmumford
2017/04/12 23:06:39
I know it was there before, but s/EnvChromium/Chro
 | 
| Status NewSequentialFile(const std::string& fname, | 
| @@ -50,8 +70,15 @@ class MojoEnv : public leveldb_env::ChromiumEnv { | 
| // NowMicros() or SleepForMicroseconds() and use the EnvChromium versions. | 
| private: | 
| + ~MojoEnv() override; | 
| + | 
| + void ParsePath(const std::string& path, | 
| + LevelDBMojoProxy::OpaqueDir** out_dir, | 
| + std::string* out_path); | 
| + void UnregisterDirectory(base::StringPiece prefix); | 
| + | 
| scoped_refptr<LevelDBMojoProxy> thread_; | 
| - LevelDBMojoProxy::OpaqueDir* dir_; | 
| + IDMap<LevelDBMojoProxy::OpaqueDir*> dirs_; | 
| DISALLOW_COPY_AND_ASSIGN(MojoEnv); | 
| }; |