| 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 #include "components/leveldb/env_mojo.h" | 5 #include "components/leveldb/env_mojo.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "third_party/leveldatabase/chromium_logger.h" | 10 #include "third_party/leveldatabase/chromium_logger.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 base::File::ErrorToString(base::File::Error(static_cast<int>(error))); | 34 base::File::ErrorToString(base::File::Error(static_cast<int>(error))); |
| 35 | 35 |
| 36 char buf[512]; | 36 char buf[512]; |
| 37 snprintf(buf, sizeof(buf), "%s (MojoFSError: %d::%s)", err_str.c_str(), | 37 snprintf(buf, sizeof(buf), "%s (MojoFSError: %d::%s)", err_str.c_str(), |
| 38 method, MethodIDToString(method)); | 38 method, MethodIDToString(method)); |
| 39 return Status::IOError(filename, buf); | 39 return Status::IOError(filename, buf); |
| 40 } | 40 } |
| 41 | 41 |
| 42 class MojoFileLock : public FileLock { | 42 class MojoFileLock : public FileLock { |
| 43 public: | 43 public: |
| 44 MojoFileLock(LevelDBFileThread::OpaqueLock* lock, const std::string& name) | 44 MojoFileLock(LevelDBMojoProxy::OpaqueLock* lock, const std::string& name) |
| 45 : fname_(name), lock_(lock) {} | 45 : fname_(name), lock_(lock) {} |
| 46 ~MojoFileLock() override { DCHECK(!lock_); } | 46 ~MojoFileLock() override { DCHECK(!lock_); } |
| 47 | 47 |
| 48 const std::string& name() const { return fname_; } | 48 const std::string& name() const { return fname_; } |
| 49 | 49 |
| 50 LevelDBFileThread::OpaqueLock* TakeLock() { | 50 LevelDBMojoProxy::OpaqueLock* TakeLock() { |
| 51 LevelDBFileThread::OpaqueLock* to_return = lock_; | 51 LevelDBMojoProxy::OpaqueLock* to_return = lock_; |
| 52 lock_ = nullptr; | 52 lock_ = nullptr; |
| 53 return to_return; | 53 return to_return; |
| 54 } | 54 } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 std::string fname_; | 57 std::string fname_; |
| 58 LevelDBFileThread::OpaqueLock* lock_; | 58 LevelDBMojoProxy::OpaqueLock* lock_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class MojoSequentialFile : public leveldb::SequentialFile { | 61 class MojoSequentialFile : public leveldb::SequentialFile { |
| 62 public: | 62 public: |
| 63 MojoSequentialFile(const std::string& fname, base::File f) | 63 MojoSequentialFile(const std::string& fname, base::File f) |
| 64 : filename_(fname), file_(std::move(f)) {} | 64 : filename_(fname), file_(std::move(f)) {} |
| 65 ~MojoSequentialFile() override {} | 65 ~MojoSequentialFile() override {} |
| 66 | 66 |
| 67 Status Read(size_t n, Slice* result, char* scratch) override { | 67 Status Read(size_t n, Slice* result, char* scratch) override { |
| 68 int bytes_read = file_.ReadAtCurrentPosNoBestEffort( | 68 int bytes_read = file_.ReadAtCurrentPosNoBestEffort( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 std::string filename_; | 120 std::string filename_; |
| 121 mutable base::File file_; | 121 mutable base::File file_; |
| 122 | 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(MojoRandomAccessFile); | 123 DISALLOW_COPY_AND_ASSIGN(MojoRandomAccessFile); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 class MojoWritableFile : public leveldb::WritableFile { | 126 class MojoWritableFile : public leveldb::WritableFile { |
| 127 public: | 127 public: |
| 128 MojoWritableFile(LevelDBFileThread::OpaqueDir* dir, | 128 MojoWritableFile(LevelDBMojoProxy::OpaqueDir* dir, |
| 129 const std::string& fname, | 129 const std::string& fname, |
| 130 base::File f, | 130 base::File f, |
| 131 scoped_refptr<LevelDBFileThread> thread) | 131 scoped_refptr<LevelDBMojoProxy> thread) |
| 132 : filename_(fname), | 132 : filename_(fname), |
| 133 file_(std::move(f)), | 133 file_(std::move(f)), |
| 134 file_type_(kOther), | 134 file_type_(kOther), |
| 135 dir_(dir), | 135 dir_(dir), |
| 136 thread_(thread) { | 136 thread_(thread) { |
| 137 base::FilePath path = base::FilePath::FromUTF8Unsafe(fname); | 137 base::FilePath path = base::FilePath::FromUTF8Unsafe(fname); |
| 138 if (path.BaseName().AsUTF8Unsafe().find("MANIFEST") == 0) | 138 if (path.BaseName().AsUTF8Unsafe().find("MANIFEST") == 0) |
| 139 file_type_ = kManifest; | 139 file_type_ = kManifest; |
| 140 else if (path.MatchesExtension(table_extension)) | 140 else if (path.MatchesExtension(table_extension)) |
| 141 file_type_ = kTable; | 141 file_type_ = kTable; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return error == filesystem::FileError::OK | 195 return error == filesystem::FileError::OK |
| 196 ? Status::OK() | 196 ? Status::OK() |
| 197 : Status::IOError(filename_, | 197 : Status::IOError(filename_, |
| 198 base::File::ErrorToString(base::File::Error( | 198 base::File::ErrorToString(base::File::Error( |
| 199 static_cast<int>(error)))); | 199 static_cast<int>(error)))); |
| 200 } | 200 } |
| 201 | 201 |
| 202 std::string filename_; | 202 std::string filename_; |
| 203 base::File file_; | 203 base::File file_; |
| 204 Type file_type_; | 204 Type file_type_; |
| 205 LevelDBFileThread::OpaqueDir* dir_; | 205 LevelDBMojoProxy::OpaqueDir* dir_; |
| 206 std::string parent_dir_; | 206 std::string parent_dir_; |
| 207 scoped_refptr<LevelDBFileThread> thread_; | 207 scoped_refptr<LevelDBMojoProxy> thread_; |
| 208 | 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(MojoWritableFile); | 209 DISALLOW_COPY_AND_ASSIGN(MojoWritableFile); |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 } // namespace | 212 } // namespace |
| 213 | 213 |
| 214 MojoEnv::MojoEnv(scoped_refptr<LevelDBFileThread> file_thread, | 214 MojoEnv::MojoEnv(scoped_refptr<LevelDBMojoProxy> file_thread, |
| 215 LevelDBFileThread::OpaqueDir* dir) | 215 LevelDBMojoProxy::OpaqueDir* dir) |
| 216 : thread_(file_thread), | 216 : thread_(file_thread), dir_(dir) {} |
| 217 dir_(dir) { | |
| 218 } | |
| 219 | 217 |
| 220 MojoEnv::~MojoEnv() { | 218 MojoEnv::~MojoEnv() { |
| 221 thread_->UnregisterDirectory(dir_); | 219 thread_->UnregisterDirectory(dir_); |
| 222 } | 220 } |
| 223 | 221 |
| 224 Status MojoEnv::NewSequentialFile(const std::string& fname, | 222 Status MojoEnv::NewSequentialFile(const std::string& fname, |
| 225 SequentialFile** result) { | 223 SequentialFile** result) { |
| 226 TRACE_EVENT1("leveldb", "MojoEnv::NewSequentialFile", "fname", fname); | 224 TRACE_EVENT1("leveldb", "MojoEnv::NewSequentialFile", "fname", fname); |
| 227 base::File f = thread_->OpenFileHandle( | 225 base::File f = thread_->OpenFileHandle( |
| 228 dir_, mojo::String::From(fname), | 226 dir_, mojo::String::From(fname), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 324 |
| 327 Status MojoEnv::RenameFile(const std::string& src, const std::string& target) { | 325 Status MojoEnv::RenameFile(const std::string& src, const std::string& target) { |
| 328 TRACE_EVENT2("leveldb", "MojoEnv::RenameFile", "src", src, "target", target); | 326 TRACE_EVENT2("leveldb", "MojoEnv::RenameFile", "src", src, "target", target); |
| 329 return FilesystemErrorToStatus(thread_->RenameFile(dir_, src, target), src, | 327 return FilesystemErrorToStatus(thread_->RenameFile(dir_, src, target), src, |
| 330 leveldb_env::kRenameFile); | 328 leveldb_env::kRenameFile); |
| 331 } | 329 } |
| 332 | 330 |
| 333 Status MojoEnv::LockFile(const std::string& fname, FileLock** lock) { | 331 Status MojoEnv::LockFile(const std::string& fname, FileLock** lock) { |
| 334 TRACE_EVENT1("leveldb", "MojoEnv::LockFile", "fname", fname); | 332 TRACE_EVENT1("leveldb", "MojoEnv::LockFile", "fname", fname); |
| 335 | 333 |
| 336 std::pair<filesystem::FileError, LevelDBFileThread::OpaqueLock*> p = | 334 std::pair<filesystem::FileError, LevelDBMojoProxy::OpaqueLock*> p = |
| 337 thread_->LockFile(dir_, mojo::String::From(fname)); | 335 thread_->LockFile(dir_, mojo::String::From(fname)); |
| 338 | 336 |
| 339 if (p.second) | 337 if (p.second) |
| 340 *lock = new MojoFileLock(p.second, fname); | 338 *lock = new MojoFileLock(p.second, fname); |
| 341 | 339 |
| 342 return FilesystemErrorToStatus(p.first, fname, leveldb_env::kLockFile); | 340 return FilesystemErrorToStatus(p.first, fname, leveldb_env::kLockFile); |
| 343 } | 341 } |
| 344 | 342 |
| 345 Status MojoEnv::UnlockFile(FileLock* lock) { | 343 Status MojoEnv::UnlockFile(FileLock* lock) { |
| 346 MojoFileLock* my_lock = reinterpret_cast<MojoFileLock*>(lock); | 344 MojoFileLock* my_lock = reinterpret_cast<MojoFileLock*>(lock); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 371 *result = NULL; | 369 *result = NULL; |
| 372 return MakeIOError(fname, "Unable to create log file", | 370 return MakeIOError(fname, "Unable to create log file", |
| 373 leveldb_env::kNewLogger, f->error_details()); | 371 leveldb_env::kNewLogger, f->error_details()); |
| 374 } else { | 372 } else { |
| 375 *result = new leveldb::ChromiumLogger(f.release()); | 373 *result = new leveldb::ChromiumLogger(f.release()); |
| 376 return Status::OK(); | 374 return Status::OK(); |
| 377 } | 375 } |
| 378 } | 376 } |
| 379 | 377 |
| 380 } // namespace leveldb | 378 } // namespace leveldb |
| OLD | NEW |