Commit 54204cc0 authored by Nidhi Jaju's avatar Nidhi Jaju Committed by Commit Bot

Stop wrapping ResourceList with std::unique_ptr

In the Service Worker Storage, |resources| is wrapped with
std::unique_ptr, however this requires additional memory allocation.
However, unique_ptr is not needed to move the ownership, hence it
is removed and the vector |resources| is passed directly using
std::move.

Bug: 1055677
Change-Id: I9f3e01c8052dd7f4a3d66da6a48e402d78304ec1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214768
Commit-Queue: Nidhi Jaju <nidhijaju@google.com>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771667}
parent e05bfc85
......@@ -368,10 +368,10 @@ void ServiceWorkerRegistry::StoreRegistration(
version->cross_origin_embedder_policy().value();
}
auto resources = std::make_unique<ResourceList>();
version->script_cache_map()->GetResources(resources.get());
ResourceList resources;
version->script_cache_map()->GetResources(&resources);
if (resources->empty()) {
if (resources.empty()) {
RunSoon(FROM_HERE,
base::BindOnce(std::move(callback),
blink::ServiceWorkerStatusCode::kErrorFailed));
......@@ -379,7 +379,7 @@ void ServiceWorkerRegistry::StoreRegistration(
}
uint64_t resources_total_size_bytes = 0;
for (const auto& resource : *resources) {
for (const auto& resource : resources) {
DCHECK_GE(resource->size_bytes, 0);
resources_total_size_bytes += resource->size_bytes;
}
......
......@@ -328,7 +328,7 @@ void ServiceWorkerStorage::GetAllRegistrations(
void ServiceWorkerStorage::StoreRegistrationData(
storage::mojom::ServiceWorkerRegistrationDataPtr registration_data,
std::unique_ptr<ResourceList> resources,
ResourceList resources,
StoreRegistrationDataCallback callback) {
DCHECK_EQ(state_, STORAGE_STATE_INITIALIZED);
......@@ -1366,13 +1366,12 @@ void ServiceWorkerStorage::WriteRegistrationInDB(
ServiceWorkerDatabase* database,
scoped_refptr<base::SequencedTaskRunner> original_task_runner,
storage::mojom::ServiceWorkerRegistrationDataPtr registration,
std::unique_ptr<ResourceList> resources,
ResourceList resources,
WriteRegistrationCallback callback) {
DCHECK(database);
DCHECK(resources);
ServiceWorkerDatabase::DeletedVersion deleted_version;
ServiceWorkerDatabase::Status status =
database->WriteRegistration(*registration, *resources, &deleted_version);
database->WriteRegistration(*registration, resources, &deleted_version);
original_task_runner->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), registration->script.GetOrigin(),
......
......@@ -145,7 +145,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
// Stores |registration_data| and |resources| on persistent storage.
void StoreRegistrationData(
storage::mojom::ServiceWorkerRegistrationDataPtr registration_data,
std::unique_ptr<ResourceList> resources,
ResourceList resources,
StoreRegistrationDataCallback callback);
// Updates the state of the registration's stored version to active.
......@@ -448,7 +448,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
ServiceWorkerDatabase* database,
scoped_refptr<base::SequencedTaskRunner> original_task_runner,
storage::mojom::ServiceWorkerRegistrationDataPtr registration,
std::unique_ptr<ResourceList> resources,
ResourceList resources,
WriteRegistrationCallback callback);
static void FindForClientUrlInDB(
ServiceWorkerDatabase* database,
......
......@@ -160,12 +160,8 @@ void ServiceWorkerStorageControlImpl::StoreRegistration(
storage::mojom::ServiceWorkerRegistrationDataPtr registration,
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> resources,
StoreRegistrationCallback callback) {
// TODO(bashi): Change the signature of
// ServiceWorkerStorage::StoreRegistrationData() to take a const reference.
storage_->StoreRegistrationData(
std::move(registration),
std::make_unique<ServiceWorkerStorage::ResourceList>(
std::move(resources)),
std::move(registration), std::move(resources),
base::BindOnce(&ServiceWorkerStorageControlImpl::DidStoreRegistration,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
......
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