diff --git a/DEPS b/DEPS index b2982369bed364..90d5fd55b9acf6 100644 --- a/DEPS +++ b/DEPS @@ -1012,7 +1012,7 @@ deps = { }, 'src/third_party/leveldatabase/src': - Var('chromium_git') + '/external/leveldb.git' + '@' + 'fe4494804f5e3a2e25485d32aeb0eb7d2f25732e', + Var('chromium_git') + '/external/leveldb.git' + '@' + '9ce30510d482f5b2fa2965201453f0fc914f700c', 'src/third_party/libFuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git' + '@' + Var('libfuzzer_revision'), diff --git a/components/services/leveldb/env_mojo.cc b/components/services/leveldb/env_mojo.cc index fc656fefc05270..86bbf050ff4668 100644 --- a/components/services/leveldb/env_mojo.cc +++ b/components/services/leveldb/env_mojo.cc @@ -18,6 +18,10 @@ #include "third_party/leveldatabase/chromium_logger.h" #include "third_party/leveldatabase/src/include/leveldb/status.h" +#if defined(OS_WIN) && defined(DeleteFile) +#undef DeleteFile +#endif + using leveldb_env::UMALogger; namespace leveldb { diff --git a/components/services/leveldb/env_mojo.h b/components/services/leveldb/env_mojo.h index 9748900cff2738..362c3d9a1bfb18 100644 --- a/components/services/leveldb/env_mojo.h +++ b/components/services/leveldb/env_mojo.h @@ -8,11 +8,18 @@ #include #include +#include "build/build_config.h" #include "components/services/filesystem/public/interfaces/directory.mojom.h" #include "components/services/leveldb/leveldb_mojo_proxy.h" #include "third_party/leveldatabase/env_chromium.h" #include "third_party/leveldatabase/src/include/leveldb/env.h" +#if defined(OS_WIN) && defined(DeleteFile) +// See comment in env.h. +#undef DeleteFile +#define ENV_MOJO_DELETEFILE_UNDEFINED +#endif // defined(OS_WIN) && defined(DeleteFile) + namespace leveldb { class MojoRetrierProvider { @@ -87,4 +94,9 @@ class MojoEnv : public Env, } // namespace leveldb +// Redefine DeleteFile if necessary. +#if defined(OS_WIN) && defined(ENV_MOJO_DELETEFILE_UNDEFINED) +#define DeleteFile DeleteFileW +#endif + #endif // COMPONENTS_SERVICES_LEVELDB_ENV_MOJO_H_ diff --git a/third_party/leveldatabase/BUILD.gn b/third_party/leveldatabase/BUILD.gn index 16a557291b6d37..3d32c4ad1d89c0 100644 --- a/third_party/leveldatabase/BUILD.gn +++ b/third_party/leveldatabase/BUILD.gn @@ -13,17 +13,6 @@ config("leveldb_config") { "src", "src/include", ] - - if (is_win) { - # windows.h #defines DeleteFile to DeleteFileW on Unicode builds. This - # definition is in effect in a large part of Chromium's compilation units. - # leveldb::Env has a DeleteFile method, which becomes DeleteFileW when the - # definition is in effect. - # - # Define the macro everywhere, to avoid reasoning about which headers bring - # windows.h in. - defines += [ "DeleteFile=DeleteFileW" ] - } } leveldb_sources = [ diff --git a/third_party/leveldatabase/README.chromium b/third_party/leveldatabase/README.chromium index 06f2ffecb8a347..9402317ede79ff 100644 --- a/third_party/leveldatabase/README.chromium +++ b/third_party/leveldatabase/README.chromium @@ -1,7 +1,7 @@ Name: LevelDB: A Fast Persistent Key-Value Store Short Name: leveldb URL: https://github.com/google/leveldb.git -Version: 1.20.git.7b945f200339aa47c24788d3ee9910c09c513843 +Version: 1.20.git.9ce30510d482f5b2fa2965201453f0fc914f700c License: New BSD License File: src/LICENSE Security Critical: yes diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc index b43fbcad4c6778..6f5c1ab5338b27 100644 --- a/third_party/leveldatabase/env_chromium.cc +++ b/third_party/leveldatabase/env_chromium.cc @@ -42,6 +42,13 @@ #include "third_party/leveldatabase/src/include/leveldb/options.h" #include "third_party/re2/src/re2/re2.h" +#if defined(OS_WIN) +#undef DeleteFile +#define base_DeleteFile base::DeleteFileW +#else // defined(OS_WIN) +#define base_DeleteFile base::DeleteFile +#endif // defined(OS_WIN) + using base::FilePath; using base::trace_event::MemoryAllocatorDump; using base::trace_event::MemoryDumpArgs; @@ -869,7 +876,7 @@ void ChromiumEnv::DeleteBackupFiles(const FilePath& dir) { FILE_PATH_LITERAL("*.bak")); for (base::FilePath fname = dir_reader.Next(); !fname.empty(); fname = dir_reader.Next()) { - histogram->AddBoolean(base::DeleteFile(fname, false)); + histogram->AddBoolean(base_DeleteFile(fname, false)); } } @@ -903,7 +910,7 @@ Status ChromiumEnv::DeleteFile(const std::string& fname) { Status result; FilePath fname_filepath = FilePath::FromUTF8Unsafe(fname); // TODO(jorlow): Should we assert this is a file? - if (!base::DeleteFile(fname_filepath, false)) { + if (!base_DeleteFile(fname_filepath, false)) { result = MakeIOError(fname, "Could not delete file.", kDeleteFile); RecordErrorAt(kDeleteFile); } @@ -927,7 +934,7 @@ Status ChromiumEnv::CreateDir(const std::string& name) { Status ChromiumEnv::DeleteDir(const std::string& name) { Status result; // TODO(jorlow): Should we assert this is a directory? - if (!base::DeleteFile(FilePath::FromUTF8Unsafe(name), false)) { + if (!base_DeleteFile(FilePath::FromUTF8Unsafe(name), false)) { result = MakeIOError(name, "Could not delete directory.", kDeleteDir); RecordErrorAt(kDeleteDir); } diff --git a/third_party/leveldatabase/env_chromium.h b/third_party/leveldatabase/env_chromium.h index dfed32effc50f7..1927050c402e0c 100644 --- a/third_party/leveldatabase/env_chromium.h +++ b/third_party/leveldatabase/env_chromium.h @@ -19,6 +19,8 @@ #include "base/gtest_prod_util.h" #include "base/macros.h" #include "base/metrics/histogram.h" +#include "base/synchronization/condition_variable.h" +#include "build/build_config.h" #include "leveldb/cache.h" #include "leveldb/db.h" #include "leveldb/env.h" @@ -26,6 +28,12 @@ #include "port/port_chromium.h" #include "util/mutexlock.h" +#if defined(OS_WIN) && defined(DeleteFile) +// See comment in env.h. +#undef DeleteFile +#define ENV_CHROMIUM_DELETEFILE_UNDEFINED +#endif // defined(OS_WIN) && defined(DeleteFile) + namespace base { namespace trace_event { class MemoryAllocatorDump; @@ -369,4 +377,9 @@ LEVELDB_EXPORT leveldb::Slice MakeSlice(const base::StringPiece& s); } // namespace leveldb_env +// Redefine DeleteFile if necessary. +#if defined(OS_WIN) && defined(ENV_CHROMIUM_DELETEFILE_UNDEFINED) +#define DeleteFile DeleteFileW +#endif + #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ diff --git a/third_party/leveldatabase/env_chromium_unittest.cc b/third_party/leveldatabase/env_chromium_unittest.cc index b0818d977b2ec2..9c9ea6bf0402f3 100644 --- a/third_party/leveldatabase/env_chromium_unittest.cc +++ b/third_party/leveldatabase/env_chromium_unittest.cc @@ -18,6 +18,7 @@ #include "base/test/scoped_task_environment.h" #include "base/test/test_suite.h" #include "base/trace_event/process_memory_dump.h" +#include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/leveldatabase/env_chromium.h" #include "third_party/leveldatabase/leveldb_chrome.h" @@ -27,6 +28,10 @@ #define FPL FILE_PATH_LITERAL +#if defined(OS_WIN) && defined(DeleteFile) +#undef DeleteFile +#endif + using base::trace_event::MemoryDumpArgs; using base::trace_event::MemoryDumpLevelOfDetail; using base::trace_event::ProcessMemoryDump; diff --git a/third_party/leveldatabase/leveldb_chrome.cc b/third_party/leveldatabase/leveldb_chrome.cc index 5c15aabc98eb20..e84aacdb1d95e7 100644 --- a/third_party/leveldatabase/leveldb_chrome.cc +++ b/third_party/leveldatabase/leveldb_chrome.cc @@ -21,10 +21,18 @@ #include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_provider.h" #include "base/trace_event/process_memory_dump.h" +#include "build/build_config.h" #include "third_party/leveldatabase/env_chromium.h" #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" #include "util/mutexlock.h" +#if defined(OS_WIN) +#undef DeleteFile +#define base_DeleteFile base::DeleteFileW +#else // defined(OS_WIN) +#define base_DeleteFile base::DeleteFile +#endif // defined(OS_WIN) + using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; using base::trace_event::MemoryAllocatorDump; using base::trace_event::MemoryDumpArgs; @@ -365,7 +373,7 @@ leveldb::Status DeleteDB(const base::FilePath& db_path, // TODO(cmumford): To be fully safe this implementation should acquire a lock // as there is some daylight in between DestroyDB and DeleteFile. - if (!base::DeleteFile(db_path, true)) { + if (!base_DeleteFile(db_path, true)) { // Only delete the directory when when DestroyDB is successful. This is // because DestroyDB checks for database locks, and will fail if in use. return leveldb::Status::IOError(db_path.AsUTF8Unsafe(), "Error deleting"); diff --git a/third_party/leveldatabase/port/port_chromium.cc b/third_party/leveldatabase/port/port_chromium.cc index b84c6e0e4c00e7..570035d23f39aa 100644 --- a/third_party/leveldatabase/port/port_chromium.cc +++ b/third_party/leveldatabase/port/port_chromium.cc @@ -6,48 +6,12 @@ #include -#include "base/threading/platform_thread.h" #include "third_party/crc32c/src/include/crc32c/crc32c.h" #include "third_party/snappy/src/snappy.h" -#include "util/logging.h" namespace leveldb { namespace port { -Mutex::Mutex() = default; - -Mutex::~Mutex() = default; - -void Mutex::Lock() { - mu_.Acquire(); -} - -void Mutex::Unlock() { - mu_.Release(); -} - -void Mutex::AssertHeld() { - mu_.AssertAcquired(); -} - -CondVar::CondVar(Mutex* mu) - : cv_(&mu->mu_) { -} - -CondVar::~CondVar() = default; - -void CondVar::Wait() { - cv_.Wait(); -} - -void CondVar::Signal(){ - cv_.Signal(); -} - -void CondVar::SignalAll() { - cv_.Broadcast(); -} - bool Snappy_Compress(const char* input, size_t input_length, std::string* output) { diff --git a/third_party/leveldatabase/port/port_chromium.h b/third_party/leveldatabase/port/port_chromium.h index f37cf52c44fa91..6a9f74e4ae9d65 100644 --- a/third_party/leveldatabase/port/port_chromium.h +++ b/third_party/leveldatabase/port/port_chromium.h @@ -7,16 +7,13 @@ #ifndef STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_ #define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_ -#include -#include - +#include +#include // NOLINT #include +#include // NOLINT #include -#include "base/atomicops.h" #include "base/macros.h" -#include "base/synchronization/condition_variable.h" -#include "base/synchronization/lock.h" #include "base/thread_annotations.h" #include "build/build_config.h" @@ -28,56 +25,41 @@ static const bool kLittleEndian = true; class LOCKABLE Mutex { public: - Mutex(); - ~Mutex(); - void Lock() EXCLUSIVE_LOCK_FUNCTION(); - void Unlock() UNLOCK_FUNCTION(); - void AssertHeld() ASSERT_EXCLUSIVE_LOCK(); + Mutex() = default; + ~Mutex() = default; - private: - base::Lock mu_; + Mutex(const Mutex&) = delete; + Mutex& operator=(const Mutex&) = delete; - friend class CondVar; - DISALLOW_COPY_AND_ASSIGN(Mutex); -}; - -class CondVar { - public: - explicit CondVar(Mutex* mu); - ~CondVar(); - void Wait(); - void Signal(); - void SignalAll(); + void Lock() EXCLUSIVE_LOCK_FUNCTION() { mu_.lock(); } + void Unlock() UNLOCK_FUNCTION() { mu_.unlock(); } + void AssertHeld() ASSERT_EXCLUSIVE_LOCK() {} private: - base::ConditionVariable cv_; - - DISALLOW_COPY_AND_ASSIGN(CondVar); + friend class CondVar; + std::mutex mu_; }; -class AtomicPointer { +// Thinly wraps std::condition_variable. +class CondVar { public: - AtomicPointer() = default; - ~AtomicPointer() = default; + explicit CondVar(Mutex* mu) : mu_(mu) { assert(mu != nullptr); } + ~CondVar() = default; - explicit AtomicPointer(void* p) : rep_(reinterpret_cast(p)) {} + CondVar(const CondVar&) = delete; + CondVar& operator=(const CondVar&) = delete; - inline void* Acquire_Load() const { - return reinterpret_cast(base::subtle::Acquire_Load(&rep_)); - } - inline void Release_Store(void* v) { - base::subtle::Release_Store(&rep_, reinterpret_cast(v)); - } - inline void* NoBarrier_Load() const { - return reinterpret_cast(base::subtle::NoBarrier_Load(&rep_)); - } - inline void NoBarrier_Store(void* v) { - base::subtle::NoBarrier_Store(&rep_, reinterpret_cast(v)); + void Wait() { + std::unique_lock lock(mu_->mu_, std::adopt_lock); + cv_.wait(lock); + lock.release(); } + void Signal() { cv_.notify_one(); } + void SignalAll() { cv_.notify_all(); } private: - using Rep = base::subtle::AtomicWord; - Rep rep_; + std::condition_variable cv_; + Mutex* const mu_; }; bool Snappy_Compress(const char* input, size_t input_length,