| 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 <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/strings/string_util.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "third_party/leveldatabase/chromium_logger.h" | 13 #include "third_party/leveldatabase/chromium_logger.h" |
| 13 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 14 | 15 |
| 15 namespace leveldb { | 16 namespace leveldb { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const base::FilePath::CharType table_extension[] = FILE_PATH_LITERAL(".ldb"); | 20 const base::FilePath::CharType table_extension[] = FILE_PATH_LITERAL(".ldb"); |
| 20 | 21 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 MojoWritableFile(LevelDBMojoProxy::OpaqueDir* dir, | 131 MojoWritableFile(LevelDBMojoProxy::OpaqueDir* dir, |
| 131 const std::string& fname, | 132 const std::string& fname, |
| 132 base::File f, | 133 base::File f, |
| 133 scoped_refptr<LevelDBMojoProxy> thread) | 134 scoped_refptr<LevelDBMojoProxy> thread) |
| 134 : filename_(fname), | 135 : filename_(fname), |
| 135 file_(std::move(f)), | 136 file_(std::move(f)), |
| 136 file_type_(kOther), | 137 file_type_(kOther), |
| 137 dir_(dir), | 138 dir_(dir), |
| 138 thread_(thread) { | 139 thread_(thread) { |
| 139 base::FilePath path = base::FilePath::FromUTF8Unsafe(fname); | 140 base::FilePath path = base::FilePath::FromUTF8Unsafe(fname); |
| 140 if (path.BaseName().AsUTF8Unsafe().find("MANIFEST") == 0) | 141 if (base::StartsWith(path.BaseName().AsUTF8Unsafe(), "MANIFEST", |
| 142 base::CompareCase::SENSITIVE)) { |
| 141 file_type_ = kManifest; | 143 file_type_ = kManifest; |
| 142 else if (path.MatchesExtension(table_extension)) | 144 } else if (path.MatchesExtension(table_extension)) { |
| 143 file_type_ = kTable; | 145 file_type_ = kTable; |
| 146 } |
| 144 parent_dir_ = | 147 parent_dir_ = |
| 145 base::FilePath::FromUTF8Unsafe(fname).DirName().AsUTF8Unsafe(); | 148 base::FilePath::FromUTF8Unsafe(fname).DirName().AsUTF8Unsafe(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 ~MojoWritableFile() override {} | 151 ~MojoWritableFile() override {} |
| 149 | 152 |
| 150 leveldb::Status Append(const leveldb::Slice& data) override { | 153 leveldb::Status Append(const leveldb::Slice& data) override { |
| 151 size_t bytes_written = file_.WriteAtCurrentPos( | 154 size_t bytes_written = file_.WriteAtCurrentPos( |
| 152 data.data(), static_cast<int>(data.size())); | 155 data.data(), static_cast<int>(data.size())); |
| 153 if (bytes_written != data.size()) { | 156 if (bytes_written != data.size()) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 *result = NULL; | 375 *result = NULL; |
| 373 return MakeIOError(fname, "Unable to create log file", | 376 return MakeIOError(fname, "Unable to create log file", |
| 374 leveldb_env::kNewLogger, f->error_details()); | 377 leveldb_env::kNewLogger, f->error_details()); |
| 375 } else { | 378 } else { |
| 376 *result = new leveldb::ChromiumLogger(f.release()); | 379 *result = new leveldb::ChromiumLogger(f.release()); |
| 377 return Status::OK(); | 380 return Status::OK(); |
| 378 } | 381 } |
| 379 } | 382 } |
| 380 | 383 |
| 381 } // namespace leveldb | 384 } // namespace leveldb |
| OLD | NEW |