chromium/components/services/storage/dom_storage/session_storage_impl.cc

// Copyright 2017 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/dom_storage/session_storage_impl.h"

#include <inttypes.h>

#include <utility>

#include "base/barrier_closure.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "components/services/storage/dom_storage/async_dom_storage_database.h"
#include "components/services/storage/dom_storage/dom_storage_database.h"
#include "components/services/storage/dom_storage/session_storage_area_impl.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"

namespace storage {

namespace {
// After this many consecutive commit errors we'll throw away the entire
// database.
const int kSessionStorageCommitErrorThreshold =;

// Limits on the cache size and number of areas in memory, over which the areas
// are purged.
#if BUILDFLAG(IS_ANDROID)
const unsigned kMaxSessionStorageAreaCount = 10;
const size_t kMaxSessionStorageCacheSize = 2 * 1024 * 1024;
#else
const unsigned kMaxSessionStorageAreaCount =;
const size_t kMaxSessionStorageCacheSize =;
#endif

enum class SessionStorageCachePurgeReason {};

void RecordSessionStorageCachePurgedHistogram(
    SessionStorageCachePurgeReason reason,
    size_t purged_size_kib) {}

void SessionStorageErrorResponse(base::OnceClosure callback,
                                 leveldb::Status status) {}

}  // namespace

SessionStorageImpl::SessionStorageImpl(
    const base::FilePath& partition_directory,
    scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
    scoped_refptr<base::SequencedTaskRunner> memory_dump_task_runner,
    BackingMode backing_mode,
    std::string database_name,
    mojo::PendingReceiver<mojom::SessionStorageControl> receiver)
    :{}

SessionStorageImpl::~SessionStorageImpl() {}

void SessionStorageImpl::BindNamespace(
    const std::string& namespace_id,
    mojo::PendingReceiver<blink::mojom::SessionStorageNamespace> receiver,
    BindNamespaceCallback callback) {}

void SessionStorageImpl::BindStorageArea(
    const blink::StorageKey& storage_key,
    const std::string& namespace_id,
    mojo::PendingReceiver<blink::mojom::StorageArea> receiver,
    BindStorageAreaCallback callback) {}

void SessionStorageImpl::CreateNamespace(const std::string& namespace_id) {}

void SessionStorageImpl::CloneNamespace(
    const std::string& clone_from_namespace_id,
    const std::string& clone_to_namespace_id,
    mojom::SessionStorageCloneType clone_type) {}

void SessionStorageImpl::DeleteNamespace(const std::string& namespace_id,
                                         bool should_persist) {}

void SessionStorageImpl::Flush() {}

void SessionStorageImpl::GetUsage(GetUsageCallback callback) {}

void SessionStorageImpl::DeleteStorage(const blink::StorageKey& storage_key,
                                       const std::string& namespace_id,
                                       DeleteStorageCallback callback) {}

void SessionStorageImpl::CleanUpStorage(CleanUpStorageCallback callback) {}

void SessionStorageImpl::ShutDown(base::OnceClosure callback) {}

void SessionStorageImpl::PurgeMemory() {}

void SessionStorageImpl::PurgeUnusedAreasIfNeeded() {}

void SessionStorageImpl::ScavengeUnusedNamespaces(
    ScavengeUnusedNamespacesCallback callback) {}

bool SessionStorageImpl::OnMemoryDump(
    const base::trace_event::MemoryDumpArgs& args,
    base::trace_event::ProcessMemoryDump* pmd) {}

void SessionStorageImpl::PretendToConnectForTesting() {}

void SessionStorageImpl::FlushAreaForTesting(
    const std::string& namespace_id,
    const blink::StorageKey& storage_key) {}

void SessionStorageImpl::SetDatabaseOpenCallbackForTesting(
    base::OnceClosure callback) {}

scoped_refptr<SessionStorageMetadata::MapData>
SessionStorageImpl::RegisterNewAreaMap(
    SessionStorageMetadata::NamespaceEntry namespace_entry,
    const blink::StorageKey& storage_key) {}

void SessionStorageImpl::OnDataMapCreation(
    const std::vector<uint8_t>& map_prefix,
    SessionStorageDataMap* map) {}

void SessionStorageImpl::OnDataMapDestruction(
    const std::vector<uint8_t>& map_prefix) {}

void SessionStorageImpl::OnCommitResult(leveldb::Status status) {}

void SessionStorageImpl::OnCommitResultWithCallback(base::OnceClosure callback,
                                                    leveldb::Status status) {}

scoped_refptr<SessionStorageDataMap>
SessionStorageImpl::MaybeGetExistingDataMapForId(
    const std::vector<uint8_t>& map_number_as_bytes) {}

void SessionStorageImpl::RegisterShallowClonedNamespace(
    SessionStorageMetadata::NamespaceEntry source_namespace_entry,
    const std::string& new_namespace_id,
    const SessionStorageNamespaceImpl::StorageKeyAreas& clone_from_areas) {}

std::unique_ptr<SessionStorageNamespaceImpl>
SessionStorageImpl::CreateSessionStorageNamespaceImpl(
    std::string namespace_id) {}

void SessionStorageImpl::DoDatabaseDelete(const std::string& namespace_id) {}

void SessionStorageImpl::RunWhenConnected(base::OnceClosure callback) {}

void SessionStorageImpl::InitiateConnection(bool in_memory_only) {}

SessionStorageImpl::ValueAndStatus::ValueAndStatus() = default;

SessionStorageImpl::ValueAndStatus::ValueAndStatus(ValueAndStatus&&) = default;

SessionStorageImpl::ValueAndStatus::~ValueAndStatus() = default;

SessionStorageImpl::KeyValuePairsAndStatus::KeyValuePairsAndStatus() = default;

SessionStorageImpl::KeyValuePairsAndStatus::KeyValuePairsAndStatus(
    KeyValuePairsAndStatus&&) = default;

SessionStorageImpl::KeyValuePairsAndStatus::~KeyValuePairsAndStatus() = default;

void SessionStorageImpl::OnDatabaseOpened(leveldb::Status status) {}

void SessionStorageImpl::OnGotDatabaseMetadata(
    ValueAndStatus version,
    KeyValuePairsAndStatus namespaces,
    ValueAndStatus next_map_id) {}

SessionStorageImpl::MetadataParseResult
SessionStorageImpl::ParseDatabaseVersion(
    ValueAndStatus version,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* migration_tasks) {}

SessionStorageImpl::MetadataParseResult SessionStorageImpl::ParseNamespaces(
    KeyValuePairsAndStatus namespaces,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask> migration_tasks) {}

SessionStorageImpl::MetadataParseResult SessionStorageImpl::ParseNextMapId(
    ValueAndStatus next_map_id) {}

void SessionStorageImpl::OnConnectionFinished() {}

void SessionStorageImpl::PurgeAllNamespaces() {}

void SessionStorageImpl::DeleteAndRecreateDatabase(const char* histogram_name) {}

void SessionStorageImpl::OnDBDestroyed(bool recreate_in_memory,
                                       leveldb::Status status) {}

void SessionStorageImpl::OnShutdownComplete() {}

void SessionStorageImpl::GetStatistics(size_t* total_cache_size,
                                       size_t* unused_area_count) {}

void SessionStorageImpl::LogDatabaseOpenResult(OpenResult result) {}

}  // namespace storage