| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <dirent.h> | 10 #include <dirent.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
| 24 #include "third_party/leveldatabase/chromium_logger.h" | 25 #include "third_party/leveldatabase/chromium_logger.h" |
| 25 #include "third_party/leveldatabase/src/include/leveldb/options.h" | 26 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
| 26 #include "third_party/re2/src/re2/re2.h" | 27 #include "third_party/re2/src/re2/re2.h" |
| 27 | 28 |
| 28 using base::FilePath; | 29 using base::FilePath; |
| 29 using leveldb::FileLock; | 30 using leveldb::FileLock; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 NOTREACHED(); | 372 NOTREACHED(); |
| 372 return "Unknown"; | 373 return "Unknown"; |
| 373 } | 374 } |
| 374 | 375 |
| 375 Status MakeIOError(Slice filename, | 376 Status MakeIOError(Slice filename, |
| 376 const std::string& message, | 377 const std::string& message, |
| 377 MethodID method, | 378 MethodID method, |
| 378 base::File::Error error) { | 379 base::File::Error error) { |
| 379 DCHECK_LT(error, 0); | 380 DCHECK_LT(error, 0); |
| 380 char buf[512]; | 381 char buf[512]; |
| 381 snprintf(buf, sizeof(buf), "%s (ChromeMethodBFE: %d::%s::%d)", | 382 base::snprintf(buf, sizeof(buf), "%s (ChromeMethodBFE: %d::%s::%d)", |
| 382 message.c_str(), method, MethodIDToString(method), -error); | 383 message.c_str(), method, MethodIDToString(method), -error); |
| 383 return Status::IOError(filename, buf); | 384 return Status::IOError(filename, buf); |
| 384 } | 385 } |
| 385 | 386 |
| 386 Status MakeIOError(Slice filename, | 387 Status MakeIOError(Slice filename, |
| 387 const std::string& message, | 388 const std::string& message, |
| 388 MethodID method) { | 389 MethodID method) { |
| 389 char buf[512]; | 390 char buf[512]; |
| 390 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(), | 391 base::snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_st
r(), |
| 391 method, MethodIDToString(method)); | 392 method, MethodIDToString(method)); |
| 392 return Status::IOError(filename, buf); | 393 return Status::IOError(filename, buf); |
| 393 } | 394 } |
| 394 | 395 |
| 395 ErrorParsingResult ParseMethodAndError(const leveldb::Status& status, | 396 ErrorParsingResult ParseMethodAndError(const leveldb::Status& status, |
| 396 MethodID* method_param, | 397 MethodID* method_param, |
| 397 base::File::Error* error) { | 398 base::File::Error* error) { |
| 398 const std::string status_string = status.ToString(); | 399 const std::string status_string = status.ToString(); |
| 399 int method; | 400 int method; |
| 400 if (RE2::PartialMatch(status_string.c_str(), "ChromeMethodOnly: (\\d+)", | 401 if (RE2::PartialMatch(status_string.c_str(), "ChromeMethodOnly: (\\d+)", |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 Retrier retrier(kRenameFile, this); | 683 Retrier retrier(kRenameFile, this); |
| 683 base::File::Error error = base::File::FILE_OK; | 684 base::File::Error error = base::File::FILE_OK; |
| 684 do { | 685 do { |
| 685 if (base::ReplaceFile(src_file_path, destination, &error)) | 686 if (base::ReplaceFile(src_file_path, destination, &error)) |
| 686 return result; | 687 return result; |
| 687 } while (retrier.ShouldKeepTrying(error)); | 688 } while (retrier.ShouldKeepTrying(error)); |
| 688 | 689 |
| 689 DCHECK(error != base::File::FILE_OK); | 690 DCHECK(error != base::File::FILE_OK); |
| 690 RecordOSError(kRenameFile, error); | 691 RecordOSError(kRenameFile, error); |
| 691 char buf[100]; | 692 char buf[100]; |
| 692 snprintf(buf, | 693 base::snprintf(buf, |
| 693 sizeof(buf), | 694 sizeof(buf), |
| 694 "Could not rename file: %s", | 695 "Could not rename file: %s", |
| 695 FileErrorString(error)); | 696 FileErrorString(error)); |
| 696 return MakeIOError(src, buf, kRenameFile, error); | 697 return MakeIOError(src, buf, kRenameFile, error); |
| 697 } | 698 } |
| 698 | 699 |
| 699 Status ChromiumEnv::LockFile(const std::string& fname, FileLock** lock) { | 700 Status ChromiumEnv::LockFile(const std::string& fname, FileLock** lock) { |
| 700 *lock = NULL; | 701 *lock = NULL; |
| 701 Status result; | 702 Status result; |
| 702 int flags = base::File::FLAG_OPEN_ALWAYS | | 703 int flags = base::File::FLAG_OPEN_ALWAYS | |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 | 1052 |
| 1052 } // namespace leveldb_env | 1053 } // namespace leveldb_env |
| 1053 | 1054 |
| 1054 namespace leveldb { | 1055 namespace leveldb { |
| 1055 | 1056 |
| 1056 Env* Env::Default() { | 1057 Env* Env::Default() { |
| 1057 return leveldb_env::default_env.Pointer(); | 1058 return leveldb_env::default_env.Pointer(); |
| 1058 } | 1059 } |
| 1059 | 1060 |
| 1060 } // namespace leveldb | 1061 } // namespace leveldb |
| OLD | NEW |