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 <utility> |
| 8 |
7 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
8 #include <dirent.h> | 10 #include <dirent.h> |
9 #include <sys/types.h> | 11 #include <sys/types.h> |
10 #endif | 12 #endif |
11 | 13 |
12 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
13 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
14 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
15 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 std::string filename_; | 183 std::string filename_; |
182 scoped_ptr<base::File> file_; | 184 scoped_ptr<base::File> file_; |
183 const UMALogger* uma_logger_; | 185 const UMALogger* uma_logger_; |
184 }; | 186 }; |
185 | 187 |
186 class ChromiumRandomAccessFile : public leveldb::RandomAccessFile { | 188 class ChromiumRandomAccessFile : public leveldb::RandomAccessFile { |
187 public: | 189 public: |
188 ChromiumRandomAccessFile(const std::string& fname, | 190 ChromiumRandomAccessFile(const std::string& fname, |
189 base::File file, | 191 base::File file, |
190 const UMALogger* uma_logger) | 192 const UMALogger* uma_logger) |
191 : filename_(fname), file_(file.Pass()), uma_logger_(uma_logger) {} | 193 : filename_(fname), file_(std::move(file)), uma_logger_(uma_logger) {} |
192 virtual ~ChromiumRandomAccessFile() {} | 194 virtual ~ChromiumRandomAccessFile() {} |
193 | 195 |
194 Status Read(uint64_t offset, | 196 Status Read(uint64_t offset, |
195 size_t n, | 197 size_t n, |
196 Slice* result, | 198 Slice* result, |
197 char* scratch) const override { | 199 char* scratch) const override { |
198 Status s; | 200 Status s; |
199 int r = file_.Read(offset, scratch, n); | 201 int r = file_.Read(offset, scratch, n); |
200 *result = Slice(scratch, (r < 0) ? 0 : r); | 202 *result = Slice(scratch, (r < 0) ? 0 : r); |
201 if (r < 0) { | 203 if (r < 0) { |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 761 |
760 if (error_code != base::File::FILE_OK) { | 762 if (error_code != base::File::FILE_OK) { |
761 locks_.Remove(fname); | 763 locks_.Remove(fname); |
762 result = MakeIOError(fname, FileErrorString(error_code), kLockFile, | 764 result = MakeIOError(fname, FileErrorString(error_code), kLockFile, |
763 error_code); | 765 error_code); |
764 RecordOSError(kLockFile, error_code); | 766 RecordOSError(kLockFile, error_code); |
765 return result; | 767 return result; |
766 } | 768 } |
767 | 769 |
768 ChromiumFileLock* my_lock = new ChromiumFileLock; | 770 ChromiumFileLock* my_lock = new ChromiumFileLock; |
769 my_lock->file_ = file.Pass(); | 771 my_lock->file_ = std::move(file); |
770 my_lock->name_ = fname; | 772 my_lock->name_ = fname; |
771 *lock = my_lock; | 773 *lock = my_lock; |
772 return result; | 774 return result; |
773 } | 775 } |
774 | 776 |
775 Status ChromiumEnv::UnlockFile(FileLock* lock) { | 777 Status ChromiumEnv::UnlockFile(FileLock* lock) { |
776 ChromiumFileLock* my_lock = reinterpret_cast<ChromiumFileLock*>(lock); | 778 ChromiumFileLock* my_lock = reinterpret_cast<ChromiumFileLock*>(lock); |
777 Status result; | 779 Status result; |
778 | 780 |
779 base::File::Error error_code = my_lock->file_.Unlock(); | 781 base::File::Error error_code = my_lock->file_.Unlock(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 #else | 846 #else |
845 #error "Need to determine limit to open files for this OS" | 847 #error "Need to determine limit to open files for this OS" |
846 #endif | 848 #endif |
847 } | 849 } |
848 | 850 |
849 Status ChromiumEnv::NewRandomAccessFile(const std::string& fname, | 851 Status ChromiumEnv::NewRandomAccessFile(const std::string& fname, |
850 leveldb::RandomAccessFile** result) { | 852 leveldb::RandomAccessFile** result) { |
851 int flags = base::File::FLAG_READ | base::File::FLAG_OPEN; | 853 int flags = base::File::FLAG_READ | base::File::FLAG_OPEN; |
852 base::File file(FilePath::FromUTF8Unsafe(fname), flags); | 854 base::File file(FilePath::FromUTF8Unsafe(fname), flags); |
853 if (file.IsValid()) { | 855 if (file.IsValid()) { |
854 *result = new ChromiumRandomAccessFile(fname, file.Pass(), this); | 856 *result = new ChromiumRandomAccessFile(fname, std::move(file), this); |
855 RecordOpenFilesLimit("Success"); | 857 RecordOpenFilesLimit("Success"); |
856 return Status::OK(); | 858 return Status::OK(); |
857 } | 859 } |
858 base::File::Error error_code = file.error_details(); | 860 base::File::Error error_code = file.error_details(); |
859 if (error_code == base::File::FILE_ERROR_TOO_MANY_OPENED) | 861 if (error_code == base::File::FILE_ERROR_TOO_MANY_OPENED) |
860 RecordOpenFilesLimit("TooManyOpened"); | 862 RecordOpenFilesLimit("TooManyOpened"); |
861 else | 863 else |
862 RecordOpenFilesLimit("OtherError"); | 864 RecordOpenFilesLimit("OtherError"); |
863 *result = NULL; | 865 *result = NULL; |
864 RecordOSError(kNewRandomAccessFile, error_code); | 866 RecordOSError(kNewRandomAccessFile, error_code); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 | 1078 |
1077 } // namespace leveldb_env | 1079 } // namespace leveldb_env |
1078 | 1080 |
1079 namespace leveldb { | 1081 namespace leveldb { |
1080 | 1082 |
1081 Env* Env::Default() { | 1083 Env* Env::Default() { |
1082 return leveldb_env::default_env.Pointer(); | 1084 return leveldb_env::default_env.Pointer(); |
1083 } | 1085 } |
1084 | 1086 |
1085 } // namespace leveldb | 1087 } // namespace leveldb |
OLD | NEW |