| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/indexed_db/leveldb/leveldb_database.h" | 5 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
| 6 | 6 |
| 7 #include <cerrno> | 7 #include <cerrno> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 public: | 120 public: |
| 121 explicit LockImpl(leveldb::Env* env, leveldb::FileLock* lock) | 121 explicit LockImpl(leveldb::Env* env, leveldb::FileLock* lock) |
| 122 : env_(env), lock_(lock) {} | 122 : env_(env), lock_(lock) {} |
| 123 virtual ~LockImpl() { env_->UnlockFile(lock_); } | 123 virtual ~LockImpl() { env_->UnlockFile(lock_); } |
| 124 private: | 124 private: |
| 125 leveldb::Env* env_; | 125 leveldb::Env* env_; |
| 126 leveldb::FileLock* lock_; | 126 leveldb::FileLock* lock_; |
| 127 | 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(LockImpl); | 128 DISALLOW_COPY_AND_ASSIGN(LockImpl); |
| 129 }; | 129 }; |
| 130 } | 130 } // namespace |
| 131 | 131 |
| 132 scoped_ptr<LevelDBLock> LevelDBDatabase::LockForTesting( | 132 scoped_ptr<LevelDBLock> LevelDBDatabase::LockForTesting( |
| 133 const base::FilePath& file_name) { | 133 const base::FilePath& file_name) { |
| 134 leveldb::Env* env = leveldb::IDBEnv(); | 134 leveldb::Env* env = leveldb::IDBEnv(); |
| 135 base::FilePath lock_path = file_name.AppendASCII("LOCK"); | 135 base::FilePath lock_path = file_name.AppendASCII("LOCK"); |
| 136 leveldb::FileLock* lock = NULL; | 136 leveldb::FileLock* lock = NULL; |
| 137 leveldb::Status status = env->LockFile(lock_path.AsUTF8Unsafe(), &lock); | 137 leveldb::Status status = env->LockFile(lock_path.AsUTF8Unsafe(), &lock); |
| 138 if (!status.ok()) | 138 if (!status.ok()) |
| 139 return scoped_ptr<LevelDBLock>(); | 139 return scoped_ptr<LevelDBLock>(); |
| 140 DCHECK(lock); | 140 DCHECK(lock); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 base::LinearHistogram::FactoryGet( | 183 base::LinearHistogram::FactoryGet( |
| 184 method_histogram_name, | 184 method_histogram_name, |
| 185 1, | 185 1, |
| 186 leveldb_env::kNumEntries, | 186 leveldb_env::kNumEntries, |
| 187 leveldb_env::kNumEntries + 1, | 187 leveldb_env::kNumEntries + 1, |
| 188 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(method); | 188 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(method); |
| 189 | 189 |
| 190 std::string error_histogram_name(histogram_name); | 190 std::string error_histogram_name(histogram_name); |
| 191 | 191 |
| 192 if (result == leveldb_env::METHOD_AND_PFE) { | 192 if (result == leveldb_env::METHOD_AND_PFE) { |
| 193 DCHECK(error < 0); | 193 DCHECK_LT(error, 0); |
| 194 error_histogram_name.append(std::string(".PFE.") + | 194 error_histogram_name.append(std::string(".PFE.") + |
| 195 leveldb_env::MethodIDToString(method)); | 195 leveldb_env::MethodIDToString(method)); |
| 196 base::LinearHistogram::FactoryGet( | 196 base::LinearHistogram::FactoryGet( |
| 197 error_histogram_name, | 197 error_histogram_name, |
| 198 1, | 198 1, |
| 199 -base::File::FILE_ERROR_MAX, | 199 -base::File::FILE_ERROR_MAX, |
| 200 -base::File::FILE_ERROR_MAX + 1, | 200 -base::File::FILE_ERROR_MAX + 1, |
| 201 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(-error); | 201 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(-error); |
| 202 } else if (result == leveldb_env::METHOD_AND_ERRNO) { | 202 } else if (result == leveldb_env::METHOD_AND_ERRNO) { |
| 203 error_histogram_name.append(std::string(".Errno.") + | 203 error_histogram_name.append(std::string(".Errno.") + |
| 204 leveldb_env::MethodIDToString(method)); | 204 leveldb_env::MethodIDToString(method)); |
| 205 base::LinearHistogram::FactoryGet( | 205 base::LinearHistogram::FactoryGet( |
| 206 error_histogram_name, | 206 error_histogram_name, |
| 207 1, | 207 1, |
| 208 ERANGE + 1, | 208 ERANGE + 1, |
| 209 ERANGE + 2, | 209 ERANGE + 2, |
| 210 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(error); | 210 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(error); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 static void ParseAndHistogramCorruptionDetails( | 214 static void ParseAndHistogramCorruptionDetails( |
| 215 const std::string& histogram_name, | 215 const std::string& histogram_name, |
| 216 const leveldb::Status& status) { | 216 const leveldb::Status& status) { |
| 217 int error = leveldb_env::GetCorruptionCode(status); | 217 int error = leveldb_env::GetCorruptionCode(status); |
| 218 DCHECK(error >= 0); | 218 DCHECK_GE(error, 0); |
| 219 std::string corruption_histogram_name(histogram_name); | 219 std::string corruption_histogram_name(histogram_name); |
| 220 corruption_histogram_name.append(".Corruption"); | 220 corruption_histogram_name.append(".Corruption"); |
| 221 const int kNumPatterns = leveldb_env::GetNumCorruptionCodes(); | 221 const int kNumPatterns = leveldb_env::GetNumCorruptionCodes(); |
| 222 base::LinearHistogram::FactoryGet( | 222 base::LinearHistogram::FactoryGet( |
| 223 corruption_histogram_name, | 223 corruption_histogram_name, |
| 224 1, | 224 1, |
| 225 kNumPatterns, | 225 kNumPatterns, |
| 226 kNumPatterns + 1, | 226 kNumPatterns + 1, |
| 227 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(error); | 227 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(error); |
| 228 } | 228 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 389 |
| 390 private: | 390 private: |
| 391 friend class content::LevelDBDatabase; | 391 friend class content::LevelDBDatabase; |
| 392 explicit IteratorImpl(scoped_ptr<leveldb::Iterator> iterator); | 392 explicit IteratorImpl(scoped_ptr<leveldb::Iterator> iterator); |
| 393 void CheckStatus(); | 393 void CheckStatus(); |
| 394 | 394 |
| 395 scoped_ptr<leveldb::Iterator> iterator_; | 395 scoped_ptr<leveldb::Iterator> iterator_; |
| 396 | 396 |
| 397 DISALLOW_COPY_AND_ASSIGN(IteratorImpl); | 397 DISALLOW_COPY_AND_ASSIGN(IteratorImpl); |
| 398 }; | 398 }; |
| 399 } | 399 } // namespace |
| 400 | 400 |
| 401 IteratorImpl::IteratorImpl(scoped_ptr<leveldb::Iterator> it) | 401 IteratorImpl::IteratorImpl(scoped_ptr<leveldb::Iterator> it) |
| 402 : iterator_(it.Pass()) {} | 402 : iterator_(it.Pass()) {} |
| 403 | 403 |
| 404 void IteratorImpl::CheckStatus() { | 404 void IteratorImpl::CheckStatus() { |
| 405 const leveldb::Status& s = iterator_->status(); | 405 const leveldb::Status& s = iterator_->status(); |
| 406 if (!s.ok()) | 406 if (!s.ok()) |
| 407 LOG(ERROR) << "LevelDB iterator error: " << s.ToString(); | 407 LOG(ERROR) << "LevelDB iterator error: " << s.ToString(); |
| 408 } | 408 } |
| 409 | 409 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 void LevelDBDatabase::Compact(const base::StringPiece& start, | 463 void LevelDBDatabase::Compact(const base::StringPiece& start, |
| 464 const base::StringPiece& stop) { | 464 const base::StringPiece& stop) { |
| 465 const leveldb::Slice start_slice = MakeSlice(start); | 465 const leveldb::Slice start_slice = MakeSlice(start); |
| 466 const leveldb::Slice stop_slice = MakeSlice(stop); | 466 const leveldb::Slice stop_slice = MakeSlice(stop); |
| 467 db_->CompactRange(&start_slice, &stop_slice); | 467 db_->CompactRange(&start_slice, &stop_slice); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } | 470 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } |
| 471 | 471 |
| 472 } // namespace content | 472 } // namespace content |
| OLD | NEW |