chromium/components/services/storage/dom_storage/session_storage_metadata.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/services/storage/dom_storage/session_storage_metadata.h"

#include <string_view>

#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "components/services/storage/dom_storage/async_dom_storage_database.h"
#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
#include "url/gurl.h"

namespace storage {

namespace {

// Example layout of the database:
// | key                                    | value              |
// |----------------------------------------|--------------------|
// | map-1-a                                | b (a = b in map 1) |
// | ...                                    |                    |
// | namespace-<36 char guid 1>-StorageKey1 | 1 (mapid)          |
// | namespace-<36 char guid 1>-StorageKey2 | 2                  |
// | namespace-<36 char guid 2>-StorageKey1 | 1 (shallow copy)   |
// | namespace-<36 char guid 2>-StorageKey2 | 2 (shallow copy)   |
// | namespace-<36 char guid 3>-StorageKey1 | 3 (deep copy)      |
// | namespace-<36 char guid 3>-StorageKey2 | 2 (shallow copy)   |
// | next-map-id                            | 4                  |
// | version                                | 1                  |
// Example area key:
//   namespace-dabc53e1_8291_4de5_824f_dab8aa69c846-https://example.com/
//
// All number values (map numbers and the version) are string conversions of
// numbers. Map keys are converted to UTF-8 and the values stay as UTF-16.

// This is "map-" (without the quotes).
constexpr const uint8_t kMapIdPrefixBytes[] =;

constexpr const size_t kNamespacePrefixLength =;
constexpr const uint8_t kNamespaceStorageKeySeperatorByte =;
constexpr const size_t kNamespaceStorageKeySeperatorLength =;
constexpr const size_t kPrefixBeforeStorageKeyLength =;

std::string_view Uint8VectorToStringView(const std::vector<uint8_t>& bytes) {}

bool ValueToNumber(const std::vector<uint8_t>& value, int64_t* out) {}

std::vector<uint8_t> NumberToValue(int64_t map_number) {}

}  // namespace

constexpr const int64_t SessionStorageMetadata::kMinSessionStorageSchemaVersion;
constexpr const int64_t
    SessionStorageMetadata::kLatestSessionStorageSchemaVersion;
constexpr const int64_t SessionStorageMetadata::kInvalidDatabaseVersion;
constexpr const int64_t SessionStorageMetadata::kInvalidMapId;
constexpr const uint8_t SessionStorageMetadata::kDatabaseVersionBytes[];
constexpr const uint8_t SessionStorageMetadata::kNamespacePrefixBytes[];
constexpr const uint8_t SessionStorageMetadata::kNextMapIdKeyBytes[];

SessionStorageMetadata::MapData::MapData(int64_t map_number,
                                         blink::StorageKey storage_key)
    :{}
SessionStorageMetadata::MapData::~MapData() = default;

SessionStorageMetadata::SessionStorageMetadata() {}

SessionStorageMetadata::~SessionStorageMetadata() {}

std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>
SessionStorageMetadata::SetupNewDatabase() {}

bool SessionStorageMetadata::ParseDatabaseVersion(
    std::optional<std::vector<uint8_t>> value,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* upgrade_tasks) {}

bool SessionStorageMetadata::ParseNamespaces(
    std::vector<DomStorageDatabase::KeyValuePair> values,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* upgrade_tasks) {}

void SessionStorageMetadata::ParseNextMapId(
    const std::vector<uint8_t>& map_id) {}

// static
std::vector<uint8_t> SessionStorageMetadata::LatestDatabaseVersionAsVector() {}

scoped_refptr<SessionStorageMetadata::MapData>
SessionStorageMetadata::RegisterNewMap(
    NamespaceEntry namespace_entry,
    const blink::StorageKey& storage_key,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* save_tasks) {}

void SessionStorageMetadata::RegisterShallowClonedNamespace(
    NamespaceEntry source_namespace,
    NamespaceEntry destination_namespace,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* save_tasks) {}

void SessionStorageMetadata::DeleteNamespace(
    const std::string& namespace_id,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* save_tasks) {}

void SessionStorageMetadata::DeleteArea(
    const std::string& namespace_id,
    const blink::StorageKey& storage_key,
    std::vector<AsyncDomStorageDatabase::BatchDatabaseTask>* save_tasks) {}

SessionStorageMetadata::NamespaceEntry
SessionStorageMetadata::GetOrCreateNamespaceEntry(
    const std::string& namespace_id) {}

// static
std::vector<uint8_t> SessionStorageMetadata::GetNamespacePrefix(
    const std::string& namespace_id) {}

// static
std::vector<uint8_t> SessionStorageMetadata::GetAreaKey(
    const std::string& namespace_id,
    const blink::StorageKey& storage_key) {}

// static
std::vector<uint8_t> SessionStorageMetadata::GetMapPrefix(int64_t map_number) {}

// static
std::vector<uint8_t> SessionStorageMetadata::GetMapPrefix(
    const std::vector<uint8_t>& map_number_as_bytes) {}

}  // namespace storage