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 "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "third_party/leveldatabase/chromium_logger.h" | 8 #include "third_party/leveldatabase/chromium_logger.h" |
9 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 9 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 method, MethodIDToString(method)); | 36 method, MethodIDToString(method)); |
37 return Status::IOError(filename, buf); | 37 return Status::IOError(filename, buf); |
38 } | 38 } |
39 | 39 |
40 class MojoFileLock : public FileLock { | 40 class MojoFileLock : public FileLock { |
41 public: | 41 public: |
42 MojoFileLock(LevelDBFileThread::OpaqueLock* lock, const std::string& name) | 42 MojoFileLock(LevelDBFileThread::OpaqueLock* lock, const std::string& name) |
43 : fname_(name), lock_(lock) {} | 43 : fname_(name), lock_(lock) {} |
44 ~MojoFileLock() override { DCHECK(!lock_); } | 44 ~MojoFileLock() override { DCHECK(!lock_); } |
45 | 45 |
46 const std::string& name() { return fname_; } | 46 const std::string& name() const { return fname_; } |
47 | 47 |
48 LevelDBFileThread::OpaqueLock* TakeLock() { | 48 LevelDBFileThread::OpaqueLock* TakeLock() { |
49 LevelDBFileThread::OpaqueLock* to_return = lock_; | 49 LevelDBFileThread::OpaqueLock* to_return = lock_; |
50 lock_ = nullptr; | 50 lock_ = nullptr; |
51 return to_return; | 51 return to_return; |
52 } | 52 } |
53 | 53 |
54 private: | 54 private: |
55 std::string fname_; | 55 std::string fname_; |
56 LevelDBFileThread::OpaqueLock* lock_; | 56 LevelDBFileThread::OpaqueLock* lock_; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 leveldb::Status Sync() override { | 170 leveldb::Status Sync() override { |
171 TRACE_EVENT0("leveldb", "MojoWritableFile::Sync"); | 171 TRACE_EVENT0("leveldb", "MojoWritableFile::Sync"); |
172 | 172 |
173 if (!file_.Flush()) { | 173 if (!file_.Flush()) { |
174 base::File::Error error = LastFileError(); | 174 base::File::Error error = LastFileError(); |
175 return MakeIOError(filename_, base::File::ErrorToString(error), | 175 return MakeIOError(filename_, base::File::ErrorToString(error), |
176 leveldb_env::kWritableFileSync, error); | 176 leveldb_env::kWritableFileSync, error); |
177 } | 177 } |
178 | 178 |
179 // TODO(erg): In the leveldb_env::ChromiumEnv, there is a whole system | |
180 // which makes backups of the data here. crbug.com/587185 | |
181 | |
182 // leveldb's implicit contract for Sync() is that if this instance is for a | 179 // leveldb's implicit contract for Sync() is that if this instance is for a |
183 // manifest file then the directory is also sync'ed. See leveldb's | 180 // manifest file then the directory is also sync'ed. See leveldb's |
184 // env_posix.cc. | 181 // env_posix.cc. |
185 if (file_type_ == kManifest) | 182 if (file_type_ == kManifest) |
186 return SyncParent(); | 183 return SyncParent(); |
187 | 184 |
188 return Status::OK(); | 185 return Status::OK(); |
189 } | 186 } |
190 | 187 |
191 private: | 188 private: |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 *result = NULL; | 369 *result = NULL; |
373 return MakeIOError(fname, "Unable to create log file", | 370 return MakeIOError(fname, "Unable to create log file", |
374 leveldb_env::kNewLogger, f->error_details()); | 371 leveldb_env::kNewLogger, f->error_details()); |
375 } else { | 372 } else { |
376 *result = new leveldb::ChromiumLogger(f.release()); | 373 *result = new leveldb::ChromiumLogger(f.release()); |
377 return Status::OK(); | 374 return Status::OK(); |
378 } | 375 } |
379 } | 376 } |
380 | 377 |
381 } // namespace leveldb | 378 } // namespace leveldb |
OLD | NEW |