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 @@
#include <inttypes.h>
#include "base/bind_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
......@@ -60,28 +61,6 @@ base::OnceCallback<void(bool)> MakeSuccessCallback(
} // 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() {
EnsureLoaded();
return map_->GetLength();
......
......@@ -55,12 +55,12 @@ class MODULES_EXPORT CachedStorageArea
WebScopedVirtualTimePauser::VirtualTaskDuration duration) = 0;
};
static scoped_refptr<CachedStorageArea> CreateForLocalStorage(
scoped_refptr<const SecurityOrigin> origin,
mojo::PendingRemote<mojom::blink::StorageArea> area,
scoped_refptr<base::SingleThreadTaskRunner> ipc_runner,
StorageNamespace* storage_namespace);
static scoped_refptr<CachedStorageArea> CreateForSessionStorage(
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,
......@@ -92,17 +92,6 @@ class MODULES_EXPORT CachedStorageArea
mojo::Remote<mojom::blink::StorageArea>& RemoteArea() { return remote_area_; }
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>;
~CachedStorageArea() override;
......
......@@ -4,6 +4,7 @@
#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 "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/renderer/modules/storage/testing/fake_area_source.h"
......@@ -29,15 +30,12 @@ class CachedStorageAreaTest : public testing::Test {
const String kRemoteSource = kPageUrl2.GetString() + "\n" + kRemoteSourceId;
void SetUp() override {
if (IsSessionStorage()) {
cached_area_ = CachedStorageArea::CreateForSessionStorage(
kOrigin, mock_storage_area_.GetInterfaceRemote(),
scheduler::GetSingleThreadTaskRunnerForTesting(), nullptr);
} else {
cached_area_ = CachedStorageArea::CreateForLocalStorage(
kOrigin, mock_storage_area_.GetInterfaceRemote(),
const CachedStorageArea::AreaType area_type =
IsSessionStorage() ? CachedStorageArea::AreaType::kSessionStorage
: CachedStorageArea::AreaType::kLocalStorage;
cached_area_ = base::MakeRefCounted<CachedStorageArea>(
area_type, kOrigin, mock_storage_area_.GetInterfaceRemote(),
scheduler::GetSingleThreadTaskRunnerForTesting(), nullptr);
}
source_area_ = MakeGarbageCollected<FakeAreaSource>(kPageUrl);
source_area_id_ = cached_area_->RegisterSource(source_area_);
source_ = kPageUrl.GetString() + "\n" + source_area_id_;
......
......@@ -29,6 +29,7 @@
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/features.h"
......@@ -101,14 +102,16 @@ scoped_refptr<CachedStorageArea> StorageNamespace::GetCachedArea(
mojo::PendingRemote<mojom::blink::StorageArea> area_remote;
EnsureConnected();
namespace_->OpenArea(origin, area_remote.InitWithNewPipeAndPassReceiver());
result = CachedStorageArea::CreateForSessionStorage(
origin, std::move(area_remote), controller_->IPCTaskRunner(), this);
result = base::MakeRefCounted<CachedStorageArea>(
CachedStorageArea::AreaType::kSessionStorage, origin,
std::move(area_remote), controller_->IPCTaskRunner(), this);
} else {
mojo::PendingRemote<mojom::blink::StorageArea> area_remote;
controller_->storage_partition_service()->OpenLocalStorage(
origin, area_remote.InitWithNewPipeAndPassReceiver());
result = CachedStorageArea::CreateForLocalStorage(
origin, std::move(area_remote), controller_->IPCTaskRunner(), this);
result = base::MakeRefCounted<CachedStorageArea>(
CachedStorageArea::AreaType::kLocalStorage, origin,
std::move(area_remote), controller_->IPCTaskRunner(), this);
}
cached_areas_.insert(std::move(origin), 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