chromium/components/services/storage/indexed_db/leveldb/fake_leveldb_factory.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/services/storage/indexed_db/leveldb/fake_leveldb_factory.h"

#include <mutex>
#include <optional>
#include <string>
#include <thread>
#include <utility>

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "components/services/storage/indexed_db/leveldb/leveldb_state.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/slice.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"

namespace content {
namespace {
class FlakyIterator;

// FlakyDB is a leveldb::DB wrapper that will flake in a predictable pattern
// given a queue of |flake_points|. After a flake, the database will continue
// operating as normal.
class FlakyDB : public leveldb::DB {};

// FlakyIterator calls its parent's FlakePointForNextOperation method to
// determine the validity at any position. Because an iterator maintains state,
// it stores the current result from FlakePointForNextOperation in the
// current_flake_ variable. This is reset & optionally set during a Seek*, Next,
// or Prev call. LevelDB iterators are not thread-safe.
class FlakyIterator : public leveldb::Iterator {};

leveldb::Iterator* FlakyDB::NewIterator(const leveldb::ReadOptions& options) {}

class BrokenIterator : public leveldb::Iterator {};

// BrokenDB is a fake leveldb::DB that will return a given error status on every
// method call, or no-op if there is nothing to return.
class BrokenDB : public leveldb::DB {};

// BreakOnCallbackDB is a leveldb::DB wrapper that will return a given error
// status or fail every method call after the |Break| method is called. This is
// thread-safe, just like leveldb::DB.
class BreakOnCallbackDB : public leveldb::DB {};

}  // namespace

// static
std::unique_ptr<leveldb::DB> FakeLevelDBFactory::CreateFlakyDB(
    std::unique_ptr<leveldb::DB> db,
    std::queue<FlakePoint> flake_points) {}

// static
std::pair<std::unique_ptr<leveldb::DB>,
          base::OnceCallback<void(leveldb::Status)>>
FakeLevelDBFactory::CreateBreakableDB(std::unique_ptr<leveldb::DB> db) {}

// static
scoped_refptr<LevelDBState> FakeLevelDBFactory::GetBrokenLevelDB(
    leveldb::Status error_to_return,
    const base::FilePath& reported_file_path) {}

}  // namespace content