| 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 <deque> | 5 #include <deque> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
| 20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "chromium_logger.h" |
| 22 #include "leveldb/env.h" | 23 #include "leveldb/env.h" |
| 23 #include "leveldb/slice.h" | 24 #include "leveldb/slice.h" |
| 24 #include "port/port.h" | 25 #include "port/port.h" |
| 25 #include "util/logging.h" | 26 #include "util/logging.h" |
| 26 | 27 |
| 27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 28 #include <io.h> | 29 #include <io.h> |
| 29 #include "base/win/win_util.h" | 30 #include "base/win/win_util.h" |
| 30 #endif | 31 #endif |
| 31 | 32 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 &test_directory_)) { | 417 &test_directory_)) { |
| 417 mu_.Release(); | 418 mu_.Release(); |
| 418 return Status::IOError("Could not create temp directory."); | 419 return Status::IOError("Could not create temp directory."); |
| 419 } | 420 } |
| 420 } | 421 } |
| 421 *path = FilePathToString(test_directory_); | 422 *path = FilePathToString(test_directory_); |
| 422 mu_.Release(); | 423 mu_.Release(); |
| 423 return Status::OK(); | 424 return Status::OK(); |
| 424 } | 425 } |
| 425 | 426 |
| 426 class ChromiumLogger : public Logger { | 427 virtual Status NewLogger(const std::string& fname, Logger** result) { |
| 427 public: | 428 FILE* f = fopen_internal(fname.c_str(), "w"); |
| 428 ChromiumLogger(const std::string& filename) : filename_(filename) { | 429 if (f == NULL) { |
| 430 *result = NULL; |
| 431 return Status::IOError(fname, strerror(errno)); |
| 432 } else { |
| 433 *result = new ChromiumLogger(f); |
| 434 return Status::OK(); |
| 429 } | 435 } |
| 430 | |
| 431 virtual void Logv(const char* format, va_list ap) { | |
| 432 VLOG(5) << "LevelDB: " << filename_ << " " << base::StringPrintV(format, a
p); | |
| 433 } | |
| 434 | |
| 435 private: | |
| 436 std::string filename_; | |
| 437 }; | |
| 438 | |
| 439 virtual Status NewLogger(const std::string& fname, Logger** result) { | |
| 440 *result = new ChromiumLogger(fname); | |
| 441 return Status::OK(); | |
| 442 } | 436 } |
| 443 | 437 |
| 444 virtual uint64_t NowMicros() { | 438 virtual uint64_t NowMicros() { |
| 445 return ::base::TimeTicks::Now().ToInternalValue(); | 439 return ::base::TimeTicks::Now().ToInternalValue(); |
| 446 } | 440 } |
| 447 | 441 |
| 448 virtual void SleepForMicroseconds(int micros) { | 442 virtual void SleepForMicroseconds(int micros) { |
| 449 // Round up to the next millisecond. | 443 // Round up to the next millisecond. |
| 450 ::base::PlatformThread::Sleep(::base::TimeDelta::FromMicroseconds(micros)); | 444 ::base::PlatformThread::Sleep(::base::TimeDelta::FromMicroseconds(micros)); |
| 451 } | 445 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 ::base::LazyInstance<ChromiumEnv>::Leaky | 540 ::base::LazyInstance<ChromiumEnv>::Leaky |
| 547 default_env = LAZY_INSTANCE_INITIALIZER; | 541 default_env = LAZY_INSTANCE_INITIALIZER; |
| 548 | 542 |
| 549 } | 543 } |
| 550 | 544 |
| 551 Env* Env::Default() { | 545 Env* Env::Default() { |
| 552 return default_env.Pointer(); | 546 return default_env.Pointer(); |
| 553 } | 547 } |
| 554 | 548 |
| 555 } | 549 } |
| OLD | NEW |