Commit 20cc7359 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

SessionStorageAreaImpl/DataMap -> Storage Service

Moves these classes into Storage Service, including unit tests. No
behavioral changes.

Bug: 1000959
Change-Id: Icf444ef0e631237340ef6705d5f883c752138823
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1960808Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#723546}
parent f72e1a14
......@@ -16,6 +16,10 @@ source_set("storage") {
"dom_storage/legacy_dom_storage_database.h",
"dom_storage/local_storage_impl.cc",
"dom_storage/local_storage_impl.h",
"dom_storage/session_storage_area_impl.cc",
"dom_storage/session_storage_area_impl.h",
"dom_storage/session_storage_data_map.cc",
"dom_storage/session_storage_data_map.h",
"dom_storage/session_storage_metadata.cc",
"dom_storage/session_storage_metadata.h",
"dom_storage/storage_area_impl.cc",
......@@ -89,6 +93,8 @@ source_set("tests") {
"dom_storage/dom_storage_database_unittest.cc",
"dom_storage/legacy_dom_storage_database_unittest.cc",
"dom_storage/local_storage_impl_unittest.cc",
"dom_storage/session_storage_area_impl_unittest.cc",
"dom_storage/session_storage_data_map_unittest.cc",
"dom_storage/session_storage_metadata_unittest.cc",
"dom_storage/storage_area_impl_unittest.cc",
"indexed_db/scopes/disjoint_range_lock_manager_unittest.cc",
......
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/dom_storage/session_storage_area_impl.h"
#include "components/services/storage/dom_storage/session_storage_area_impl.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "content/browser/dom_storage/session_storage_data_map.h"
#include "components/services/storage/dom_storage/session_storage_data_map.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/leveldatabase/env_chromium.h"
namespace content {
namespace storage {
SessionStorageAreaImpl::SessionStorageAreaImpl(
storage::SessionStorageMetadata::NamespaceEntry namespace_entry,
SessionStorageMetadata::NamespaceEntry namespace_entry,
url::Origin origin,
scoped_refptr<SessionStorageDataMap> data_map,
RegisterNewAreaMap register_new_map_callback)
......@@ -42,7 +42,7 @@ void SessionStorageAreaImpl::Bind(
}
std::unique_ptr<SessionStorageAreaImpl> SessionStorageAreaImpl::Clone(
storage::SessionStorageMetadata::NamespaceEntry namespace_entry) {
SessionStorageMetadata::NamespaceEntry namespace_entry) {
DCHECK(namespace_entry_ != namespace_entry);
return base::WrapUnique(new SessionStorageAreaImpl(
namespace_entry, origin_, shared_data_map_, register_new_map_callback_));
......@@ -156,4 +156,4 @@ void SessionStorageAreaImpl::CreateNewMap(
shared_data_map_->AddBindingReference();
}
} // namespace content
} // namespace storage
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_AREA_IMPL_H_
#define CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_AREA_IMPL_H_
#ifndef COMPONENTS_SERVICES_STORAGE_DOM_STORAGE_SESSION_STORAGE_AREA_IMPL_H_
#define COMPONENTS_SERVICES_STORAGE_DOM_STORAGE_SESSION_STORAGE_AREA_IMPL_H_
#include <vector>
......@@ -11,7 +11,6 @@
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "components/services/storage/dom_storage/session_storage_metadata.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
......@@ -19,7 +18,8 @@
#include "third_party/blink/public/mojom/dom_storage/storage_area.mojom.h"
#include "url/origin.h"
namespace content {
namespace storage {
class SessionStorageDataMap;
// This class provides session storage access to the renderer by binding to the
......@@ -38,30 +38,29 @@ class SessionStorageDataMap;
// During forking, this class is responsible for dealing with moving its
// observers from the SessionStorageDataMap's StorageArea to the new forked
// SessionStorageDataMap's StorageArea.
class CONTENT_EXPORT SessionStorageAreaImpl : public blink::mojom::StorageArea {
class SessionStorageAreaImpl : public blink::mojom::StorageArea {
public:
using RegisterNewAreaMap = base::RepeatingCallback<
scoped_refptr<storage::SessionStorageMetadata::MapData>(
storage::SessionStorageMetadata::NamespaceEntry namespace_entry,
using RegisterNewAreaMap =
base::RepeatingCallback<scoped_refptr<SessionStorageMetadata::MapData>(
SessionStorageMetadata::NamespaceEntry namespace_entry,
const url::Origin& origin)>;
// Creates a area for the given |namespace_entry|-|origin| data area. All
// StorageArea calls are delegated to the |data_map|. The
// |register_new_map_callback| is called when a shared |data_map| needs to be
// forked for the copy-on-write behavior and a new map needs to be registered.
SessionStorageAreaImpl(
storage::SessionStorageMetadata::NamespaceEntry namespace_entry,
url::Origin origin,
scoped_refptr<SessionStorageDataMap> data_map,
RegisterNewAreaMap register_new_map_callback);
SessionStorageAreaImpl(SessionStorageMetadata::NamespaceEntry namespace_entry,
url::Origin origin,
scoped_refptr<SessionStorageDataMap> data_map,
RegisterNewAreaMap register_new_map_callback);
~SessionStorageAreaImpl() override;
// Creates a shallow copy clone for the new namespace entry.
// This doesn't change the refcount of the underlying map - that operation
// must be done using
// storage::SessionStorageMetadata::RegisterShallowClonedNamespace.
// SessionStorageMetadata::RegisterShallowClonedNamespace.
std::unique_ptr<SessionStorageAreaImpl> Clone(
storage::SessionStorageMetadata::NamespaceEntry namespace_entry);
SessionStorageMetadata::NamespaceEntry namespace_entry);
void Bind(
mojo::PendingAssociatedReceiver<blink::mojom::StorageArea> receiver);
......@@ -101,7 +100,7 @@ class CONTENT_EXPORT SessionStorageAreaImpl : public blink::mojom::StorageArea {
void CreateNewMap(NewMapType map_type,
const base::Optional<std::string>& delete_all_source);
storage::SessionStorageMetadata::NamespaceEntry namespace_entry_;
SessionStorageMetadata::NamespaceEntry namespace_entry_;
url::Origin origin_;
scoped_refptr<SessionStorageDataMap> shared_data_map_;
RegisterNewAreaMap register_new_map_callback_;
......@@ -112,6 +111,6 @@ class CONTENT_EXPORT SessionStorageAreaImpl : public blink::mojom::StorageArea {
DISALLOW_COPY_AND_ASSIGN(SessionStorageAreaImpl);
};
} // namespace content
} // namespace storage
#endif // CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_AREA_IMPL_H_
#endif // COMPONENTS_SERVICES_STORAGE_DOM_STORAGE_SESSION_STORAGE_AREA_IMPL_H_
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/dom_storage/session_storage_data_map.h"
#include "components/services/storage/dom_storage/session_storage_data_map.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/services/storage/dom_storage/dom_storage_constants.h"
namespace content {
namespace storage {
// static
scoped_refptr<SessionStorageDataMap> SessionStorageDataMap::CreateFromDisk(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
storage::AsyncDomStorageDatabase* database) {
scoped_refptr<SessionStorageMetadata::MapData> map_data,
AsyncDomStorageDatabase* database) {
return base::WrapRefCounted(new SessionStorageDataMap(
listener, std::move(map_data), database, false));
}
......@@ -23,8 +23,8 @@ scoped_refptr<SessionStorageDataMap> SessionStorageDataMap::CreateFromDisk(
// static
scoped_refptr<SessionStorageDataMap> SessionStorageDataMap::CreateEmpty(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
storage::AsyncDomStorageDatabase* database) {
scoped_refptr<SessionStorageMetadata::MapData> map_data,
AsyncDomStorageDatabase* database) {
return base::WrapRefCounted(
new SessionStorageDataMap(listener, std::move(map_data), database, true));
}
......@@ -32,7 +32,7 @@ scoped_refptr<SessionStorageDataMap> SessionStorageDataMap::CreateEmpty(
// static
scoped_refptr<SessionStorageDataMap> SessionStorageDataMap::CreateClone(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
scoped_refptr<SessionStorageMetadata::MapData> map_data,
scoped_refptr<SessionStorageDataMap> clone_from) {
return base::WrapRefCounted(new SessionStorageDataMap(
listener, std::move(map_data), std::move(clone_from)));
......@@ -44,16 +44,16 @@ void SessionStorageDataMap::DidCommit(leveldb::Status status) {
SessionStorageDataMap::SessionStorageDataMap(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
storage::AsyncDomStorageDatabase* database,
scoped_refptr<SessionStorageMetadata::MapData> map_data,
AsyncDomStorageDatabase* database,
bool is_empty)
: listener_(listener),
map_data_(std::move(map_data)),
storage_area_impl_(
std::make_unique<storage::StorageAreaImpl>(database,
map_data_->KeyPrefix(),
this,
GetOptions())),
std::make_unique<StorageAreaImpl>(database,
map_data_->KeyPrefix(),
this,
GetOptions())),
storage_area_ptr_(storage_area_impl_.get()) {
if (is_empty)
storage_area_impl_->InitializeAsEmpty();
......@@ -64,7 +64,7 @@ SessionStorageDataMap::SessionStorageDataMap(
SessionStorageDataMap::SessionStorageDataMap(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
scoped_refptr<SessionStorageMetadata::MapData> map_data,
scoped_refptr<SessionStorageDataMap> forking_from)
: listener_(listener),
clone_from_data_map_(std::move(forking_from)),
......@@ -99,7 +99,7 @@ void SessionStorageDataMap::OnMapLoaded(leveldb::Status) {
}
// static
storage::StorageAreaImpl::Options SessionStorageDataMap::GetOptions() {
StorageAreaImpl::Options SessionStorageDataMap::GetOptions() {
// Delay for a moment after a value is set in anticipation
// of other values being set, so changes are batched.
constexpr const base::TimeDelta kCommitDefaultDelaySecs =
......@@ -107,15 +107,13 @@ storage::StorageAreaImpl::Options SessionStorageDataMap::GetOptions() {
// To avoid excessive IO we apply limits to the amount of data being
// written and the frequency of writes.
storage::StorageAreaImpl::Options options;
options.max_size = storage::kPerStorageAreaQuota +
storage::kPerStorageAreaOverQuotaAllowance;
StorageAreaImpl::Options options;
options.max_size = kPerStorageAreaQuota + kPerStorageAreaOverQuotaAllowance;
options.default_commit_delay = kCommitDefaultDelaySecs;
options.max_bytes_per_hour = storage::kPerStorageAreaQuota;
options.max_bytes_per_hour = kPerStorageAreaQuota;
options.max_commits_per_hour = 60;
options.cache_mode =
storage::StorageAreaImpl::CacheMode::KEYS_ONLY_WHEN_POSSIBLE;
options.cache_mode = StorageAreaImpl::CacheMode::KEYS_ONLY_WHEN_POSSIBLE;
return options;
}
} // namespace content
} // namespace storage
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATA_MAP_H_
#define CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATA_MAP_H_
#ifndef COMPONENTS_SERVICES_STORAGE_DOM_STORAGE_SESSION_STORAGE_DATA_MAP_H_
#define COMPONENTS_SERVICES_STORAGE_DOM_STORAGE_SESSION_STORAGE_DATA_MAP_H_
#include <memory>
#include <vector>
......@@ -13,31 +13,28 @@
#include "base/optional.h"
#include "components/services/storage/dom_storage/session_storage_metadata.h"
#include "components/services/storage/dom_storage/storage_area_impl.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
namespace storage {
class AsyncDomStorageDatabase;
}
namespace content {
class AsyncDomStorageDatabase;
// Holds the StorageArea for a session storage data map. Every
// namespace-origin area has a data map. To support shallow copying of the data
// (copy-on-write), a single data map can be shared between multiple namespaces.
// Thus this class is refcounted. This class has a one-to-one relationship with
// the storage::SessionStorageMetadata::MapData object, accessible from
// the SessionStorageMetadata::MapData object, accessible from
// |map_data()|.
//
// Neither this data map nor the inner StorageArea is bound to, as it needs
// to be shared between multiple connections if it is shallow-copied. However,
// it does allow it's user to keep track of the number of binding using
// |binding_count()|, |AddBindingReference()|, and |RemoveBindingReference()|.
class CONTENT_EXPORT SessionStorageDataMap final
: public storage::StorageAreaImpl::Delegate,
class SessionStorageDataMap final
: public StorageAreaImpl::Delegate,
public base::RefCounted<SessionStorageDataMap> {
public:
class CONTENT_EXPORT Listener {
class Listener {
public:
virtual ~Listener() {}
virtual void OnDataMapCreation(const std::vector<uint8_t>& map_id,
......@@ -48,24 +45,24 @@ class CONTENT_EXPORT SessionStorageDataMap final
static scoped_refptr<SessionStorageDataMap> CreateFromDisk(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
storage::AsyncDomStorageDatabase* database);
scoped_refptr<SessionStorageMetadata::MapData> map_data,
AsyncDomStorageDatabase* database);
static scoped_refptr<SessionStorageDataMap> CreateEmpty(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
storage::AsyncDomStorageDatabase* database);
scoped_refptr<SessionStorageMetadata::MapData> map_data,
AsyncDomStorageDatabase* database);
static scoped_refptr<SessionStorageDataMap> CreateClone(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data,
scoped_refptr<SessionStorageMetadata::MapData> map_data,
scoped_refptr<SessionStorageDataMap> clone_from);
Listener* listener() const { return listener_; }
storage::StorageAreaImpl* storage_area() { return storage_area_ptr_; }
StorageAreaImpl* storage_area() { return storage_area_ptr_; }
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data() {
scoped_refptr<SessionStorageMetadata::MapData> map_data() {
return map_data_.get();
}
......@@ -85,18 +82,18 @@ class CONTENT_EXPORT SessionStorageDataMap final
SessionStorageDataMap(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_entry,
storage::AsyncDomStorageDatabase* database,
scoped_refptr<SessionStorageMetadata::MapData> map_entry,
AsyncDomStorageDatabase* database,
bool is_empty);
SessionStorageDataMap(
Listener* listener,
scoped_refptr<storage::SessionStorageMetadata::MapData> map_entry,
scoped_refptr<SessionStorageMetadata::MapData> map_entry,
scoped_refptr<SessionStorageDataMap> forking_from);
~SessionStorageDataMap() override;
void OnMapLoaded(leveldb::Status status) override;
static storage::StorageAreaImpl::Options GetOptions();
static StorageAreaImpl::Options GetOptions();
Listener* listener_;
int binding_count_ = 0;
......@@ -106,18 +103,18 @@ class CONTENT_EXPORT SessionStorageDataMap final
// completes synchronously.
scoped_refptr<SessionStorageDataMap> clone_from_data_map_;
scoped_refptr<storage::SessionStorageMetadata::MapData> map_data_;
std::unique_ptr<storage::StorageAreaImpl> storage_area_impl_;
scoped_refptr<SessionStorageMetadata::MapData> map_data_;
std::unique_ptr<StorageAreaImpl> storage_area_impl_;
// Holds the same value as |storage_area_impl_|. The reason for this is that
// during destruction of the StorageAreaImpl instance we might still get
// called and need access to the StorageAreaImpl instance. The
// unique_ptr could already be null, but this field should still be valid.
// TODO(dmurph): Change delegate ownership so this doesn't have to be done.
storage::StorageAreaImpl* storage_area_ptr_;
StorageAreaImpl* storage_area_ptr_;
DISALLOW_COPY_AND_ASSIGN(SessionStorageDataMap);
};
} // namespace content
} // namespace storage
#endif // CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATA_MAP_H_
#endif // COMPONENTS_SERVICES_STORAGE_DOM_STORAGE_SESSION_STORAGE_DATA_MAP_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/dom_storage/session_storage_data_map.h"
#include "components/services/storage/dom_storage/session_storage_data_map.h"
#include <map>
#include <vector>
......@@ -23,7 +23,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace content {
namespace storage {
namespace {
......@@ -94,7 +94,7 @@ class SessionStorageDataMapTest : public testing::Test {
SessionStorageDataMapTest()
: test_origin_(url::Origin::Create(GURL("http://host1.com:1"))) {
base::RunLoop loop;
database_ = storage::AsyncDomStorageDatabase::OpenInMemory(
database_ = AsyncDomStorageDatabase::OpenInMemory(
base::nullopt, "SessionStorageDataMapTest",
base::CreateSequencedTaskRunner({base::MayBlock(), base::ThreadPool()}),
base::BindLambdaForTesting([&](leveldb::Status status) {
......@@ -104,7 +104,7 @@ class SessionStorageDataMapTest : public testing::Test {
loop.Run();
database_->database().PostTaskWithThisObject(
FROM_HERE, base::BindOnce([](const storage::DomStorageDatabase& db) {
FROM_HERE, base::BindOnce([](const DomStorageDatabase& db) {
// Should show up in first map.
leveldb::Status status =
db.Put(MakeBytes("map-1-key1"), MakeBytes("data1"));
......@@ -119,11 +119,11 @@ class SessionStorageDataMapTest : public testing::Test {
~SessionStorageDataMapTest() override = default;
std::map<std::string, std::string> GetDatabaseContents() {
std::vector<storage::DomStorageDatabase::KeyValuePair> entries;
std::vector<DomStorageDatabase::KeyValuePair> entries;
base::RunLoop loop;
database_->database().PostTaskWithThisObject(
FROM_HERE,
base::BindLambdaForTesting([&](const storage::DomStorageDatabase& db) {
base::BindLambdaForTesting([&](const DomStorageDatabase& db) {
leveldb::Status status = db.GetPrefixed({}, &entries);
ASSERT_TRUE(status.ok());
loop.Quit();
......@@ -143,7 +143,7 @@ class SessionStorageDataMapTest : public testing::Test {
base::test::TaskEnvironment task_environment_;
testing::StrictMock<MockListener> listener_;
url::Origin test_origin_;
std::unique_ptr<storage::AsyncDomStorageDatabase> database_;
std::unique_ptr<AsyncDomStorageDatabase> database_;
};
} // namespace
......@@ -156,8 +156,8 @@ TEST_F(SessionStorageDataMapTest, BasicEmptyCreation) {
scoped_refptr<SessionStorageDataMap> map =
SessionStorageDataMap::CreateFromDisk(
&listener_,
base::MakeRefCounted<storage::SessionStorageMetadata::MapData>(
1, test_origin_),
base::MakeRefCounted<SessionStorageMetadata::MapData>(1,
test_origin_),
database_.get());
bool success;
......@@ -189,8 +189,7 @@ TEST_F(SessionStorageDataMapTest, ExplicitlyEmpty) {
scoped_refptr<SessionStorageDataMap> map = SessionStorageDataMap::CreateEmpty(
&listener_,
base::MakeRefCounted<storage::SessionStorageMetadata::MapData>(
1, test_origin_),
base::MakeRefCounted<SessionStorageMetadata::MapData>(1, test_origin_),
database_.get());
bool success;
......@@ -221,8 +220,8 @@ TEST_F(SessionStorageDataMapTest, Clone) {
scoped_refptr<SessionStorageDataMap> map1 =
SessionStorageDataMap::CreateFromDisk(
&listener_,
base::MakeRefCounted<storage::SessionStorageMetadata::MapData>(
1, test_origin_),
base::MakeRefCounted<SessionStorageMetadata::MapData>(1,
test_origin_),
database_.get());
EXPECT_CALL(listener_,
......@@ -234,8 +233,8 @@ TEST_F(SessionStorageDataMapTest, Clone) {
scoped_refptr<SessionStorageDataMap> map2 =
SessionStorageDataMap::CreateClone(
&listener_,
base::MakeRefCounted<storage::SessionStorageMetadata::MapData>(
2, test_origin_),
base::MakeRefCounted<SessionStorageMetadata::MapData>(2,
test_origin_),
map1);
bool success;
......@@ -265,4 +264,4 @@ TEST_F(SessionStorageDataMapTest, Clone) {
EXPECT_EQ(3u, GetDatabaseContents().size());
}
} // namespace content
} // namespace storage
......@@ -785,12 +785,8 @@ jumbo_source_set("browser") {
"display_cutout/display_cutout_host_impl.h",
"dom_storage/dom_storage_context_wrapper.cc",
"dom_storage/dom_storage_context_wrapper.h",
"dom_storage/session_storage_area_impl.cc",
"dom_storage/session_storage_area_impl.h",
"dom_storage/session_storage_context_mojo.cc",
"dom_storage/session_storage_context_mojo.h",
"dom_storage/session_storage_data_map.cc",
"dom_storage/session_storage_data_map.h",
"dom_storage/session_storage_namespace_impl.cc",
"dom_storage/session_storage_namespace_impl.h",
"dom_storage/session_storage_namespace_impl_mojo.cc",
......
......@@ -26,7 +26,7 @@
#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 "content/browser/dom_storage/session_storage_area_impl.h"
#include "components/services/storage/dom_storage/session_storage_area_impl.h"
#include "content/browser/dom_storage/session_storage_namespace_impl_mojo.h"
#include "content/public/browser/session_storage_usage_info.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
......@@ -558,7 +558,7 @@ SessionStorageContextMojo::RegisterNewAreaMap(
void SessionStorageContextMojo::OnDataMapCreation(
const std::vector<uint8_t>& map_prefix,
SessionStorageDataMap* map) {
storage::SessionStorageDataMap* map) {
DCHECK(data_maps_.find(map_prefix) == data_maps_.end());
data_maps_.emplace(std::piecewise_construct,
std::forward_as_tuple(map_prefix),
......@@ -604,7 +604,7 @@ void SessionStorageContextMojo::OnCommitResultWithCallback(
std::move(callback).Run();
}
scoped_refptr<SessionStorageDataMap>
scoped_refptr<storage::SessionStorageDataMap>
SessionStorageContextMojo::MaybeGetExistingDataMapForId(
const std::vector<uint8_t>& map_number_as_bytes) {
auto it = data_maps_.find(map_number_as_bytes);
......@@ -658,7 +658,7 @@ void SessionStorageContextMojo::RegisterShallowClonedNamespace(
std::unique_ptr<SessionStorageNamespaceImplMojo>
SessionStorageContextMojo::CreateSessionStorageNamespaceImplMojo(
std::string namespace_id) {
SessionStorageAreaImpl::RegisterNewAreaMap map_id_callback =
storage::SessionStorageAreaImpl::RegisterNewAreaMap map_id_callback =
base::BindRepeating(&SessionStorageContextMojo::RegisterNewAreaMap,
base::Unretained(this));
......
......@@ -23,8 +23,8 @@
#include "base/trace_event/memory_dump_provider.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_data_map.h"
#include "components/services/storage/dom_storage/session_storage_metadata.h"
#include "content/browser/dom_storage/session_storage_data_map.h"
#include "content/browser/dom_storage/session_storage_namespace_impl_mojo.h"
#include "content/common/content_export.h"
#include "content/public/browser/session_storage_usage_info.h"
......@@ -47,7 +47,7 @@ struct SessionStorageUsageInfo;
// ShutdownAndDelete (on the correct task runner).
class CONTENT_EXPORT SessionStorageContextMojo
: public base::trace_event::MemoryDumpProvider,
public SessionStorageDataMap::Listener,
public storage::SessionStorageDataMap::Listener,
public SessionStorageNamespaceImplMojo::Delegate {
public:
using GetStorageUsageCallback =
......@@ -179,16 +179,16 @@ class CONTENT_EXPORT SessionStorageContextMojo
storage::SessionStorageMetadata::NamespaceEntry namespace_entry,
const url::Origin& origin);
// SessionStorageAreaImpl::Listener implementation:
// storage::SessionStorageAreaImpl::Listener implementation:
void OnDataMapCreation(const std::vector<uint8_t>& map_prefix,
SessionStorageDataMap* map) override;
storage::SessionStorageDataMap* map) override;
void OnDataMapDestruction(const std::vector<uint8_t>& map_prefix) override;
void OnCommitResult(leveldb::Status status) override;
void OnCommitResultWithCallback(base::OnceClosure callback,
leveldb::Status status);
// SessionStorageNamespaceImplMojo::Delegate implementation:
scoped_refptr<SessionStorageDataMap> MaybeGetExistingDataMapForId(
scoped_refptr<storage::SessionStorageDataMap> MaybeGetExistingDataMapForId(
const std::vector<uint8_t>& map_number_as_bytes) override;
void RegisterShallowClonedNamespace(
storage::SessionStorageMetadata::NamespaceEntry source_namespace_entry,
......@@ -281,9 +281,9 @@ class CONTENT_EXPORT SessionStorageContextMojo
std::vector<base::OnceClosure> on_database_opened_callbacks_;
// The removal of items from this map is managed by the refcounting in
// SessionStorageDataMap.
// storage::SessionStorageDataMap.
// Populated after the database is connected.
std::map<std::vector<uint8_t>, SessionStorageDataMap*> data_maps_;
std::map<std::vector<uint8_t>, storage::SessionStorageDataMap*> data_maps_;
// Populated in CreateSessionNamespace, CloneSessionNamespace, and sometimes
// RegisterShallowClonedNamespace. Items are removed in
// DeleteSessionNamespace.
......
......@@ -23,8 +23,9 @@ void SessionStorageResponse(base::OnceClosure callback, bool success) {
SessionStorageNamespaceImplMojo::SessionStorageNamespaceImplMojo(
std::string namespace_id,
SessionStorageDataMap::Listener* data_map_listener,
SessionStorageAreaImpl::RegisterNewAreaMap register_new_map_callback,
storage::SessionStorageDataMap::Listener* data_map_listener,
storage::SessionStorageAreaImpl::RegisterNewAreaMap
register_new_map_callback,
Delegate* delegate)
: namespace_id_(std::move(namespace_id)),
data_map_listener_(data_map_listener),
......@@ -67,16 +68,17 @@ void SessionStorageNamespaceImplMojo::PopulateFromMetadata(
pending_population_from_parent_namespace_.clear();
namespace_entry_ = namespace_metadata;
for (const auto& pair : namespace_entry_->second) {
scoped_refptr<SessionStorageDataMap> data_map =
scoped_refptr<storage::SessionStorageDataMap> data_map =
delegate_->MaybeGetExistingDataMapForId(
pair.second->MapNumberAsBytes());
if (!data_map) {
data_map = SessionStorageDataMap::CreateFromDisk(data_map_listener_,
pair.second, database_);
data_map = storage::SessionStorageDataMap::CreateFromDisk(
data_map_listener_, pair.second, database_);
}
origin_areas_[pair.first] = std::make_unique<SessionStorageAreaImpl>(
namespace_entry_, pair.first, std::move(data_map),
register_new_map_callback_);
origin_areas_[pair.first] =
std::make_unique<storage::SessionStorageAreaImpl>(
namespace_entry_, pair.first, std::move(data_map),
register_new_map_callback_);
}
if (!run_after_population_.empty()) {
for (base::OnceClosure& callback : run_after_population_)
......@@ -190,7 +192,7 @@ void SessionStorageNamespaceImplMojo::OpenArea(
if (it == origin_areas_.end()) {
// The area may have been purged due to lack of bindings, so check the
// metadata for the map.
scoped_refptr<SessionStorageDataMap> data_map;
scoped_refptr<storage::SessionStorageDataMap> data_map;
auto map_data_it = namespace_entry_->second.find(origin);
if (map_data_it != namespace_entry_->second.end()) {
// The map exists already, either on disk or being used by another
......@@ -200,18 +202,18 @@ void SessionStorageNamespaceImplMojo::OpenArea(
data_map =
delegate_->MaybeGetExistingDataMapForId(map_data->MapNumberAsBytes());
if (!data_map) {
data_map = SessionStorageDataMap::CreateFromDisk(data_map_listener_,
map_data, database_);
data_map = storage::SessionStorageDataMap::CreateFromDisk(
data_map_listener_, map_data, database_);
}
} else {
// The map doesn't exist yet.
data_map = SessionStorageDataMap::CreateEmpty(
data_map = storage::SessionStorageDataMap::CreateEmpty(
data_map_listener_,
register_new_map_callback_.Run(namespace_entry_, origin), database_);
}
it = origin_areas_
.emplace(std::make_pair(
origin, std::make_unique<SessionStorageAreaImpl>(
origin, std::make_unique<storage::SessionStorageAreaImpl>(
namespace_entry_, origin, std::move(data_map),
register_new_map_callback_)))
.first;
......
......@@ -12,9 +12,10 @@
#include "base/containers/flat_set.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "components/services/storage/dom_storage/session_storage_area_impl.h"
#include "components/services/storage/dom_storage/session_storage_data_map.h"
#include "components/services/storage/dom_storage/session_storage_metadata.h"
#include "content/browser/dom_storage/session_storage_area_impl.h"
#include "content/browser/dom_storage/session_storage_data_map.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/public/mojom/dom_storage/session_storage_namespace.mojom.h"
......@@ -53,7 +54,7 @@ class CONTENT_EXPORT SessionStorageNamespaceImplMojo final
: public blink::mojom::SessionStorageNamespace {
public:
using OriginAreas =
std::map<url::Origin, std::unique_ptr<SessionStorageAreaImpl>>;
std::map<url::Origin, std::unique_ptr<storage::SessionStorageAreaImpl>>;
enum class State {
// This is the default state when a namespace is first constructed. It has
......@@ -85,7 +86,8 @@ class CONTENT_EXPORT SessionStorageNamespaceImplMojo final
// purged in a call to |PurgeUnboundAreas| but the map could still be alive
// as a clone, used by another namespace.
// Returns nullptr if a data map was not found.
virtual scoped_refptr<SessionStorageDataMap> MaybeGetExistingDataMapForId(
virtual scoped_refptr<storage::SessionStorageDataMap>
MaybeGetExistingDataMapForId(
const std::vector<uint8_t>& map_number_as_bytes) = 0;
};
......@@ -95,12 +97,14 @@ class CONTENT_EXPORT SessionStorageNamespaceImplMojo final
// namespace. The |delegate| is called when the |Clone| method
// is called by mojo, as well as when the |OpenArea| method is called and the
// map id for that origin is found in our metadata. The
// |register_new_map_callback| is given to the the SessionStorageAreaImpl's,
// used per-origin, that are bound to in OpenArea.
// |register_new_map_callback| is given to the the
// storage::SessionStorageAreaImpl's, used per-origin, that are bound to in
// OpenArea.
SessionStorageNamespaceImplMojo(
std::string namespace_id,
SessionStorageDataMap::Listener* data_map_listener,
SessionStorageAreaImpl::RegisterNewAreaMap register_new_map_callback,
storage::SessionStorageDataMap::Listener* data_map_listener,
storage::SessionStorageAreaImpl::RegisterNewAreaMap
register_new_map_callback,
Delegate* delegate);
~SessionStorageNamespaceImplMojo() override;
......@@ -206,8 +210,9 @@ class CONTENT_EXPORT SessionStorageNamespaceImplMojo final
storage::SessionStorageMetadata::NamespaceEntry namespace_entry_;
storage::AsyncDomStorageDatabase* database_ = nullptr;
SessionStorageDataMap::Listener* data_map_listener_;
SessionStorageAreaImpl::RegisterNewAreaMap register_new_map_callback_;
storage::SessionStorageDataMap::Listener* data_map_listener_;
storage::SessionStorageAreaImpl::RegisterNewAreaMap
register_new_map_callback_;
Delegate* delegate_;
State state_ = State::kNotPopulated;
......
......@@ -14,10 +14,10 @@
#include "base/test/bind_test_util.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_data_map.h"
#include "components/services/storage/dom_storage/session_storage_metadata.h"
#include "components/services/storage/dom_storage/storage_area_test_util.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/dom_storage/session_storage_data_map.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "content/test/gmock_util.h"
......@@ -46,13 +46,13 @@ MATCHER(OKStatus, "Equality matcher for type OK leveldb::Status") {
return arg.ok();
}
class MockListener : public SessionStorageDataMap::Listener {
class MockListener : public storage::SessionStorageDataMap::Listener {
public:
MockListener() {}
~MockListener() override {}
MOCK_METHOD2(OnDataMapCreation,
void(const std::vector<uint8_t>& map_id,
SessionStorageDataMap* map));
storage::SessionStorageDataMap* map));
MOCK_METHOD1(OnDataMapDestruction, void(const std::vector<uint8_t>& map_id));
MOCK_METHOD1(OnCommitResult, void(leveldb::Status));
};
......@@ -142,7 +142,7 @@ class SessionStorageNamespaceImplMojoTest
SessionStorageNamespaceImplMojo* CreateSessionStorageNamespaceImplMojo(
const std::string& namespace_id) {
DCHECK(namespaces_.find(namespace_id) == namespaces_.end());
SessionStorageAreaImpl::RegisterNewAreaMap map_id_callback =
storage::SessionStorageAreaImpl::RegisterNewAreaMap map_id_callback =
base::BindRepeating(
&SessionStorageNamespaceImplMojoTest::RegisterNewAreaMap,
base::Unretained(this));
......@@ -188,7 +188,7 @@ class SessionStorageNamespaceImplMojoTest
areas_to_clone);
}
scoped_refptr<SessionStorageDataMap> MaybeGetExistingDataMapForId(
scoped_refptr<storage::SessionStorageDataMap> MaybeGetExistingDataMapForId(
const std::vector<uint8_t>& map_number_as_bytes) override {
auto it = data_maps_.find(map_number_as_bytes);
if (it == data_maps_.end())
......@@ -209,7 +209,7 @@ class SessionStorageNamespaceImplMojoTest
std::map<std::string, std::unique_ptr<SessionStorageNamespaceImplMojo>>
namespaces_;
std::map<std::vector<uint8_t>, scoped_refptr<SessionStorageDataMap>>
std::map<std::vector<uint8_t>, scoped_refptr<storage::SessionStorageDataMap>>
data_maps_;
testing::StrictMock<MockListener> listener_;
......@@ -616,7 +616,7 @@ TEST_F(SessionStorageNamespaceImplMojoTest, ReopenClonedAreaAfterPurge) {
SessionStorageNamespaceImplMojo* namespace_impl =
CreateSessionStorageNamespaceImplMojo(test_namespace_id1_);
SessionStorageDataMap* data_map;
storage::SessionStorageDataMap* data_map;
EXPECT_CALL(listener_,
OnDataMapCreation(StdStringToUint8Vector("0"), testing::_))
.WillOnce(testing::SaveArg<1>(&data_map));
......
......@@ -1556,9 +1556,7 @@ test("content_unittests") {
"../browser/devtools/protocol/tracing_handler_unittest.cc",
"../browser/devtools/protocol_unittest.cc",
"../browser/dom_storage/dom_storage_context_wrapper_unittest.cc",
"../browser/dom_storage/session_storage_area_impl_unittest.cc",
"../browser/dom_storage/session_storage_context_mojo_unittest.cc",
"../browser/dom_storage/session_storage_data_map_unittest.cc",
"../browser/dom_storage/session_storage_namespace_impl_mojo_unittest.cc",
"../browser/download/download_manager_impl_unittest.cc",
"../browser/download/save_package_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment