OLD | NEW |
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2011 The LevelDB 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. See the AUTHORS file for names of contributors. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
4 | 4 |
5 #include "third_party/leveldatabase/env_chromium.h" | 5 #include "third_party/leveldatabase/env_chromium.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
10 #include <dirent.h> | 11 #include <dirent.h> |
11 #include <sys/types.h> | 12 #include <sys/types.h> |
12 #endif | 13 #endif |
13 | 14 |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 uma_logger_->RecordErrorAt(kSequentialFileSkip); | 175 uma_logger_->RecordErrorAt(kSequentialFileSkip); |
175 return MakeIOError(filename_, base::File::ErrorToString(error), | 176 return MakeIOError(filename_, base::File::ErrorToString(error), |
176 kSequentialFileSkip, error); | 177 kSequentialFileSkip, error); |
177 } else { | 178 } else { |
178 return Status::OK(); | 179 return Status::OK(); |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
182 private: | 183 private: |
183 std::string filename_; | 184 std::string filename_; |
184 scoped_ptr<base::File> file_; | 185 std::unique_ptr<base::File> file_; |
185 const UMALogger* uma_logger_; | 186 const UMALogger* uma_logger_; |
186 }; | 187 }; |
187 | 188 |
188 class ChromiumRandomAccessFile : public leveldb::RandomAccessFile { | 189 class ChromiumRandomAccessFile : public leveldb::RandomAccessFile { |
189 public: | 190 public: |
190 ChromiumRandomAccessFile(const std::string& fname, | 191 ChromiumRandomAccessFile(const std::string& fname, |
191 base::File file, | 192 base::File file, |
192 const UMALogger* uma_logger) | 193 const UMALogger* uma_logger) |
193 : filename_(fname), file_(std::move(file)), uma_logger_(uma_logger) {} | 194 : filename_(fname), file_(std::move(file)), uma_logger_(uma_logger) {} |
194 virtual ~ChromiumRandomAccessFile() {} | 195 virtual ~ChromiumRandomAccessFile() {} |
(...skipping 30 matching lines...) Expand all Loading... |
225 leveldb::Status Append(const leveldb::Slice& data) override; | 226 leveldb::Status Append(const leveldb::Slice& data) override; |
226 leveldb::Status Close() override; | 227 leveldb::Status Close() override; |
227 leveldb::Status Flush() override; | 228 leveldb::Status Flush() override; |
228 leveldb::Status Sync() override; | 229 leveldb::Status Sync() override; |
229 | 230 |
230 private: | 231 private: |
231 enum Type { kManifest, kTable, kOther }; | 232 enum Type { kManifest, kTable, kOther }; |
232 leveldb::Status SyncParent(); | 233 leveldb::Status SyncParent(); |
233 | 234 |
234 std::string filename_; | 235 std::string filename_; |
235 scoped_ptr<base::File> file_; | 236 std::unique_ptr<base::File> file_; |
236 const UMALogger* uma_logger_; | 237 const UMALogger* uma_logger_; |
237 Type file_type_; | 238 Type file_type_; |
238 std::string parent_dir_; | 239 std::string parent_dir_; |
239 bool make_backup_; | 240 bool make_backup_; |
240 }; | 241 }; |
241 | 242 |
242 ChromiumWritableFile::ChromiumWritableFile(const std::string& fname, | 243 ChromiumWritableFile::ChromiumWritableFile(const std::string& fname, |
243 base::File* f, | 244 base::File* f, |
244 const UMALogger* uma_logger, | 245 const UMALogger* uma_logger, |
245 bool make_backup) | 246 bool make_backup) |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } | 803 } |
803 } | 804 } |
804 *path = test_directory_.AsUTF8Unsafe(); | 805 *path = test_directory_.AsUTF8Unsafe(); |
805 mu_.Release(); | 806 mu_.Release(); |
806 return Status::OK(); | 807 return Status::OK(); |
807 } | 808 } |
808 | 809 |
809 Status ChromiumEnv::NewLogger(const std::string& fname, | 810 Status ChromiumEnv::NewLogger(const std::string& fname, |
810 leveldb::Logger** result) { | 811 leveldb::Logger** result) { |
811 FilePath path = FilePath::FromUTF8Unsafe(fname); | 812 FilePath path = FilePath::FromUTF8Unsafe(fname); |
812 scoped_ptr<base::File> f(new base::File( | 813 std::unique_ptr<base::File> f(new base::File( |
813 path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); | 814 path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); |
814 if (!f->IsValid()) { | 815 if (!f->IsValid()) { |
815 *result = NULL; | 816 *result = NULL; |
816 RecordOSError(kNewLogger, f->error_details()); | 817 RecordOSError(kNewLogger, f->error_details()); |
817 return MakeIOError(fname, "Unable to create log file", kNewLogger, | 818 return MakeIOError(fname, "Unable to create log file", kNewLogger, |
818 f->error_details()); | 819 f->error_details()); |
819 } else { | 820 } else { |
820 *result = new leveldb::ChromiumLogger(f.release()); | 821 *result = new leveldb::ChromiumLogger(f.release()); |
821 return Status::OK(); | 822 return Status::OK(); |
822 } | 823 } |
823 } | 824 } |
824 | 825 |
825 Status ChromiumEnv::NewSequentialFile(const std::string& fname, | 826 Status ChromiumEnv::NewSequentialFile(const std::string& fname, |
826 leveldb::SequentialFile** result) { | 827 leveldb::SequentialFile** result) { |
827 FilePath path = FilePath::FromUTF8Unsafe(fname); | 828 FilePath path = FilePath::FromUTF8Unsafe(fname); |
828 scoped_ptr<base::File> f( | 829 std::unique_ptr<base::File> f( |
829 new base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ)); | 830 new base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ)); |
830 if (!f->IsValid()) { | 831 if (!f->IsValid()) { |
831 *result = NULL; | 832 *result = NULL; |
832 RecordOSError(kNewSequentialFile, f->error_details()); | 833 RecordOSError(kNewSequentialFile, f->error_details()); |
833 return MakeIOError(fname, "Unable to create sequential file", | 834 return MakeIOError(fname, "Unable to create sequential file", |
834 kNewSequentialFile, f->error_details()); | 835 kNewSequentialFile, f->error_details()); |
835 } else { | 836 } else { |
836 *result = new ChromiumSequentialFile(fname, f.release(), this); | 837 *result = new ChromiumSequentialFile(fname, f.release(), this); |
837 return Status::OK(); | 838 return Status::OK(); |
838 } | 839 } |
(...skipping 26 matching lines...) Expand all Loading... |
865 *result = NULL; | 866 *result = NULL; |
866 RecordOSError(kNewRandomAccessFile, error_code); | 867 RecordOSError(kNewRandomAccessFile, error_code); |
867 return MakeIOError(fname, FileErrorString(error_code), kNewRandomAccessFile, | 868 return MakeIOError(fname, FileErrorString(error_code), kNewRandomAccessFile, |
868 error_code); | 869 error_code); |
869 } | 870 } |
870 | 871 |
871 Status ChromiumEnv::NewWritableFile(const std::string& fname, | 872 Status ChromiumEnv::NewWritableFile(const std::string& fname, |
872 leveldb::WritableFile** result) { | 873 leveldb::WritableFile** result) { |
873 *result = NULL; | 874 *result = NULL; |
874 FilePath path = FilePath::FromUTF8Unsafe(fname); | 875 FilePath path = FilePath::FromUTF8Unsafe(fname); |
875 scoped_ptr<base::File> f(new base::File( | 876 std::unique_ptr<base::File> f(new base::File( |
876 path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); | 877 path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); |
877 if (!f->IsValid()) { | 878 if (!f->IsValid()) { |
878 RecordErrorAt(kNewWritableFile); | 879 RecordErrorAt(kNewWritableFile); |
879 return MakeIOError(fname, "Unable to create writable file", | 880 return MakeIOError(fname, "Unable to create writable file", |
880 kNewWritableFile, f->error_details()); | 881 kNewWritableFile, f->error_details()); |
881 } else { | 882 } else { |
882 *result = new ChromiumWritableFile(fname, f.release(), this, make_backup_); | 883 *result = new ChromiumWritableFile(fname, f.release(), this, make_backup_); |
883 return Status::OK(); | 884 return Status::OK(); |
884 } | 885 } |
885 } | 886 } |
886 | 887 |
887 Status ChromiumEnv::NewAppendableFile(const std::string& fname, | 888 Status ChromiumEnv::NewAppendableFile(const std::string& fname, |
888 leveldb::WritableFile** result) { | 889 leveldb::WritableFile** result) { |
889 *result = NULL; | 890 *result = NULL; |
890 FilePath path = FilePath::FromUTF8Unsafe(fname); | 891 FilePath path = FilePath::FromUTF8Unsafe(fname); |
891 scoped_ptr<base::File> f(new base::File( | 892 std::unique_ptr<base::File> f(new base::File( |
892 path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND)); | 893 path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND)); |
893 if (!f->IsValid()) { | 894 if (!f->IsValid()) { |
894 RecordErrorAt(kNewAppendableFile); | 895 RecordErrorAt(kNewAppendableFile); |
895 return MakeIOError(fname, "Unable to create appendable file", | 896 return MakeIOError(fname, "Unable to create appendable file", |
896 kNewAppendableFile, f->error_details()); | 897 kNewAppendableFile, f->error_details()); |
897 } | 898 } |
898 *result = new ChromiumWritableFile(fname, f.release(), this, make_backup_); | 899 *result = new ChromiumWritableFile(fname, f.release(), this, make_backup_); |
899 return Status::OK(); | 900 return Status::OK(); |
900 } | 901 } |
901 | 902 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 | 1079 |
1079 } // namespace leveldb_env | 1080 } // namespace leveldb_env |
1080 | 1081 |
1081 namespace leveldb { | 1082 namespace leveldb { |
1082 | 1083 |
1083 Env* Env::Default() { | 1084 Env* Env::Default() { |
1084 return leveldb_env::default_env.Pointer(); | 1085 return leveldb_env::default_env.Pointer(); |
1085 } | 1086 } |
1086 | 1087 |
1087 } // namespace leveldb | 1088 } // namespace leveldb |
OLD | NEW |