OLD | NEW |
1 // Copyright (c) 2013 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 5 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 virtual void DidCreateNewFile(const std::string& fname) = 0; | 98 virtual void DidCreateNewFile(const std::string& fname) = 0; |
99 virtual bool DoesDirNeedSync(const std::string& fname) = 0; | 99 virtual bool DoesDirNeedSync(const std::string& fname) = 0; |
100 virtual void DidSyncDir(const std::string& fname) = 0; | 100 virtual void DidSyncDir(const std::string& fname) = 0; |
101 }; | 101 }; |
102 | 102 |
103 class ChromiumEnv : public leveldb::Env, | 103 class ChromiumEnv : public leveldb::Env, |
104 public UMALogger, | 104 public UMALogger, |
105 public RetrierProvider, | 105 public RetrierProvider, |
106 public WriteTracker { | 106 public WriteTracker { |
107 public: | 107 public: |
| 108 ChromiumEnv(); |
| 109 |
108 typedef void(ScheduleFunc)(void*); | 110 typedef void(ScheduleFunc)(void*); |
109 | 111 |
110 static bool MakeBackup(const std::string& fname); | 112 static bool MakeBackup(const std::string& fname); |
111 static base::FilePath CreateFilePath(const std::string& file_path); | 113 static base::FilePath CreateFilePath(const std::string& file_path); |
112 static const char* FileErrorString(::base::File::Error error); | 114 static const char* FileErrorString(::base::File::Error error); |
113 static bool HasTableExtension(const base::FilePath& path); | 115 static bool HasTableExtension(const base::FilePath& path); |
114 virtual ~ChromiumEnv(); | 116 virtual ~ChromiumEnv(); |
115 | 117 |
116 virtual bool FileExists(const std::string& fname); | 118 virtual bool FileExists(const std::string& fname); |
117 virtual leveldb::Status GetChildren(const std::string& dir, | 119 virtual leveldb::Status GetChildren(const std::string& dir, |
118 std::vector<std::string>* result); | 120 std::vector<std::string>* result); |
119 virtual leveldb::Status DeleteFile(const std::string& fname); | 121 virtual leveldb::Status DeleteFile(const std::string& fname); |
120 virtual leveldb::Status CreateDir(const std::string& name); | 122 virtual leveldb::Status CreateDir(const std::string& name); |
121 virtual leveldb::Status DeleteDir(const std::string& name); | 123 virtual leveldb::Status DeleteDir(const std::string& name); |
122 virtual leveldb::Status GetFileSize(const std::string& fname, uint64_t* size); | 124 virtual leveldb::Status GetFileSize(const std::string& fname, uint64_t* size); |
123 virtual leveldb::Status RenameFile(const std::string& src, | 125 virtual leveldb::Status RenameFile(const std::string& src, |
124 const std::string& dst); | 126 const std::string& dst); |
125 virtual leveldb::Status LockFile(const std::string& fname, | 127 virtual leveldb::Status LockFile(const std::string& fname, |
126 leveldb::FileLock** lock); | 128 leveldb::FileLock** lock); |
127 virtual leveldb::Status UnlockFile(leveldb::FileLock* lock); | 129 virtual leveldb::Status UnlockFile(leveldb::FileLock* lock); |
128 virtual void Schedule(ScheduleFunc*, void* arg); | 130 virtual void Schedule(ScheduleFunc*, void* arg); |
129 virtual void StartThread(void (*function)(void* arg), void* arg); | 131 virtual void StartThread(void (*function)(void* arg), void* arg); |
130 virtual leveldb::Status GetTestDirectory(std::string* path); | 132 virtual leveldb::Status GetTestDirectory(std::string* path); |
131 virtual uint64_t NowMicros(); | 133 virtual uint64_t NowMicros(); |
132 virtual void SleepForMicroseconds(int micros); | 134 virtual void SleepForMicroseconds(int micros); |
| 135 virtual leveldb::Status NewSequentialFile(const std::string& fname, |
| 136 leveldb::SequentialFile** result); |
| 137 virtual leveldb::Status NewRandomAccessFile( |
| 138 const std::string& fname, |
| 139 leveldb::RandomAccessFile** result); |
| 140 virtual leveldb::Status NewWritableFile(const std::string& fname, |
| 141 leveldb::WritableFile** result); |
| 142 virtual leveldb::Status NewLogger(const std::string& fname, |
| 143 leveldb::Logger** result); |
133 | 144 |
134 protected: | 145 protected: |
135 ChromiumEnv(); | |
136 | |
137 virtual void DidCreateNewFile(const std::string& fname); | |
138 virtual bool DoesDirNeedSync(const std::string& fname); | |
139 virtual void DidSyncDir(const std::string& fname); | 146 virtual void DidSyncDir(const std::string& fname); |
140 virtual base::File::Error GetDirectoryEntries( | |
141 const base::FilePath& dir_param, | |
142 std::vector<base::FilePath>* result) const = 0; | |
143 virtual void RecordErrorAt(MethodID method) const; | |
144 virtual void RecordOSError(MethodID method, int saved_errno) const; | |
145 virtual void RecordOSError(MethodID method, | |
146 base::File::Error error) const; | |
147 base::HistogramBase* GetMaxFDHistogram(const std::string& type) const; | |
148 base::HistogramBase* GetOSErrorHistogram(MethodID method, int limit) const; | |
149 | 147 |
150 std::string name_; | 148 std::string name_; |
151 bool make_backup_; | 149 bool make_backup_; |
152 | 150 |
153 private: | 151 private: |
| 152 virtual void DidCreateNewFile(const std::string& fname); |
| 153 virtual bool DoesDirNeedSync(const std::string& fname); |
| 154 virtual void RecordErrorAt(MethodID method) const; |
| 155 virtual void RecordOSError(MethodID method, int saved_errno) const; |
| 156 virtual void RecordOSError(MethodID method, |
| 157 base::File::Error error) const; |
| 158 void RecordOpenFilesLimit(const std::string& type); |
| 159 base::HistogramBase* GetMaxFDHistogram(const std::string& type) const; |
| 160 base::HistogramBase* GetOSErrorHistogram(MethodID method, int limit) const; |
| 161 |
154 // File locks may not be exclusive within a process (e.g. on POSIX). Track | 162 // File locks may not be exclusive within a process (e.g. on POSIX). Track |
155 // locks held by the ChromiumEnv to prevent access within the process. | 163 // locks held by the ChromiumEnv to prevent access within the process. |
156 class LockTable { | 164 class LockTable { |
157 public: | 165 public: |
158 bool Insert(const std::string& fname) { | 166 bool Insert(const std::string& fname) { |
159 leveldb::MutexLock l(&mu_); | 167 leveldb::MutexLock l(&mu_); |
160 return locked_files_.insert(fname).second; | 168 return locked_files_.insert(fname).second; |
161 } | 169 } |
162 bool Remove(const std::string& fname) { | 170 bool Remove(const std::string& fname) { |
163 leveldb::MutexLock l(&mu_); | 171 leveldb::MutexLock l(&mu_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void (*function)(void*); | 212 void (*function)(void*); |
205 }; | 213 }; |
206 typedef std::deque<BGItem> BGQueue; | 214 typedef std::deque<BGItem> BGQueue; |
207 BGQueue queue_; | 215 BGQueue queue_; |
208 LockTable locks_; | 216 LockTable locks_; |
209 }; | 217 }; |
210 | 218 |
211 } // namespace leveldb_env | 219 } // namespace leveldb_env |
212 | 220 |
213 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 221 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
OLD | NEW |