Commit 07e56664 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

DOMStorage: Replace raw operator new usage in Blink code.

This CL makes the blink::CachedStorageArea constructor public and
removes the Create*() factory functions. The functions recently became
identical, with the exception of the blink::CacheStorageArea::AreaType
value passed to the constructor.

This small refactoring removes one layer of indirection, as well as the
use of the bare new operator in the factory functions.

Change-Id: I0e6606f3021771c712a79878d681290c3862acc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038035
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739025}
parent 9f343a40
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -60,28 +61,6 @@ base::OnceCallback<void(bool)> MakeSuccessCallback( ...@@ -60,28 +61,6 @@ base::OnceCallback<void(bool)> MakeSuccessCallback(
} // namespace } // namespace
// static
scoped_refptr<CachedStorageArea> CachedStorageArea::CreateForLocalStorage(
scoped_refptr<const SecurityOrigin> origin,
mojo::PendingRemote<mojom::blink::StorageArea> area,
scoped_refptr<base::SingleThreadTaskRunner> ipc_runner,
StorageNamespace* storage_namespace) {
return base::AdoptRef(new CachedStorageArea(
AreaType::kLocalStorage, std::move(origin), std::move(area),
std::move(ipc_runner), storage_namespace));
}
// static
scoped_refptr<CachedStorageArea> CachedStorageArea::CreateForSessionStorage(
scoped_refptr<const SecurityOrigin> origin,
mojo::PendingRemote<mojom::blink::StorageArea> area,
scoped_refptr<base::SingleThreadTaskRunner> ipc_runner,
StorageNamespace* storage_namespace) {
return base::AdoptRef(new CachedStorageArea(
AreaType::kSessionStorage, std::move(origin), std::move(area),
std::move(ipc_runner), storage_namespace));
}
unsigned CachedStorageArea::GetLength() { unsigned CachedStorageArea::GetLength() {
EnsureLoaded(); EnsureLoaded();
return map_->GetLength(); return map_->GetLength();
......
...@@ -55,16 +55,16 @@ class MODULES_EXPORT CachedStorageArea ...@@ -55,16 +55,16 @@ class MODULES_EXPORT CachedStorageArea
WebScopedVirtualTimePauser::VirtualTaskDuration duration) = 0; WebScopedVirtualTimePauser::VirtualTaskDuration duration) = 0;
}; };
static scoped_refptr<CachedStorageArea> CreateForLocalStorage( enum class AreaType {
scoped_refptr<const SecurityOrigin> origin, kSessionStorage,
mojo::PendingRemote<mojom::blink::StorageArea> area, kLocalStorage,
scoped_refptr<base::SingleThreadTaskRunner> ipc_runner, };
StorageNamespace* storage_namespace);
static scoped_refptr<CachedStorageArea> CreateForSessionStorage( CachedStorageArea(AreaType type,
scoped_refptr<const SecurityOrigin> origin, scoped_refptr<const SecurityOrigin> origin,
mojo::PendingRemote<mojom::blink::StorageArea> area, mojo::PendingRemote<mojom::blink::StorageArea> area,
scoped_refptr<base::SingleThreadTaskRunner> ipc_runner, scoped_refptr<base::SingleThreadTaskRunner> ipc_runner,
StorageNamespace* storage_namespace); StorageNamespace* storage_namespace);
// These correspond to blink::Storage. // These correspond to blink::Storage.
unsigned GetLength(); unsigned GetLength();
...@@ -92,17 +92,6 @@ class MODULES_EXPORT CachedStorageArea ...@@ -92,17 +92,6 @@ class MODULES_EXPORT CachedStorageArea
mojo::Remote<mojom::blink::StorageArea>& RemoteArea() { return remote_area_; } mojo::Remote<mojom::blink::StorageArea>& RemoteArea() { return remote_area_; }
private: private:
enum class AreaType {
kSessionStorage,
kLocalStorage,
};
CachedStorageArea(AreaType type,
scoped_refptr<const SecurityOrigin> origin,
mojo::PendingRemote<mojom::blink::StorageArea> area,
scoped_refptr<base::SingleThreadTaskRunner> ipc_runner,
StorageNamespace* storage_namespace);
friend class RefCounted<CachedStorageArea>; friend class RefCounted<CachedStorageArea>;
~CachedStorageArea() override; ~CachedStorageArea() override;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/modules/storage/cached_storage_area.h" #include "third_party/blink/renderer/modules/storage/cached_storage_area.h"
#include "base/memory/scoped_refptr.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/renderer/modules/storage/testing/fake_area_source.h" #include "third_party/blink/renderer/modules/storage/testing/fake_area_source.h"
...@@ -29,15 +30,12 @@ class CachedStorageAreaTest : public testing::Test { ...@@ -29,15 +30,12 @@ class CachedStorageAreaTest : public testing::Test {
const String kRemoteSource = kPageUrl2.GetString() + "\n" + kRemoteSourceId; const String kRemoteSource = kPageUrl2.GetString() + "\n" + kRemoteSourceId;
void SetUp() override { void SetUp() override {
if (IsSessionStorage()) { const CachedStorageArea::AreaType area_type =
cached_area_ = CachedStorageArea::CreateForSessionStorage( IsSessionStorage() ? CachedStorageArea::AreaType::kSessionStorage
kOrigin, mock_storage_area_.GetInterfaceRemote(), : CachedStorageArea::AreaType::kLocalStorage;
scheduler::GetSingleThreadTaskRunnerForTesting(), nullptr); cached_area_ = base::MakeRefCounted<CachedStorageArea>(
} else { area_type, kOrigin, mock_storage_area_.GetInterfaceRemote(),
cached_area_ = CachedStorageArea::CreateForLocalStorage( scheduler::GetSingleThreadTaskRunnerForTesting(), nullptr);
kOrigin, mock_storage_area_.GetInterfaceRemote(),
scheduler::GetSingleThreadTaskRunnerForTesting(), nullptr);
}
source_area_ = MakeGarbageCollected<FakeAreaSource>(kPageUrl); source_area_ = MakeGarbageCollected<FakeAreaSource>(kPageUrl);
source_area_id_ = cached_area_->RegisterSource(source_area_); source_area_id_ = cached_area_->RegisterSource(source_area_);
source_ = kPageUrl.GetString() + "\n" + source_area_id_; source_ = kPageUrl.GetString() + "\n" + source_area_id_;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
...@@ -101,14 +102,16 @@ scoped_refptr<CachedStorageArea> StorageNamespace::GetCachedArea( ...@@ -101,14 +102,16 @@ scoped_refptr<CachedStorageArea> StorageNamespace::GetCachedArea(
mojo::PendingRemote<mojom::blink::StorageArea> area_remote; mojo::PendingRemote<mojom::blink::StorageArea> area_remote;
EnsureConnected(); EnsureConnected();
namespace_->OpenArea(origin, area_remote.InitWithNewPipeAndPassReceiver()); namespace_->OpenArea(origin, area_remote.InitWithNewPipeAndPassReceiver());
result = CachedStorageArea::CreateForSessionStorage( result = base::MakeRefCounted<CachedStorageArea>(
origin, std::move(area_remote), controller_->IPCTaskRunner(), this); CachedStorageArea::AreaType::kSessionStorage, origin,
std::move(area_remote), controller_->IPCTaskRunner(), this);
} else { } else {
mojo::PendingRemote<mojom::blink::StorageArea> area_remote; mojo::PendingRemote<mojom::blink::StorageArea> area_remote;
controller_->storage_partition_service()->OpenLocalStorage( controller_->storage_partition_service()->OpenLocalStorage(
origin, area_remote.InitWithNewPipeAndPassReceiver()); origin, area_remote.InitWithNewPipeAndPassReceiver());
result = CachedStorageArea::CreateForLocalStorage( result = base::MakeRefCounted<CachedStorageArea>(
origin, std::move(area_remote), controller_->IPCTaskRunner(), this); CachedStorageArea::AreaType::kLocalStorage, origin,
std::move(area_remote), controller_->IPCTaskRunner(), this);
} }
cached_areas_.insert(std::move(origin), result); cached_areas_.insert(std::move(origin), result);
return result; return result;
......
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