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( ...@@ -368,10 +368,10 @@ void ServiceWorkerRegistry::StoreRegistration(
version->cross_origin_embedder_policy().value(); version->cross_origin_embedder_policy().value();
} }
auto resources = std::make_unique<ResourceList>(); ResourceList resources;
version->script_cache_map()->GetResources(resources.get()); version->script_cache_map()->GetResources(&resources);
if (resources->empty()) { if (resources.empty()) {
RunSoon(FROM_HERE, RunSoon(FROM_HERE,
base::BindOnce(std::move(callback), base::BindOnce(std::move(callback),
blink::ServiceWorkerStatusCode::kErrorFailed)); blink::ServiceWorkerStatusCode::kErrorFailed));
...@@ -379,7 +379,7 @@ void ServiceWorkerRegistry::StoreRegistration( ...@@ -379,7 +379,7 @@ void ServiceWorkerRegistry::StoreRegistration(
} }
uint64_t resources_total_size_bytes = 0; uint64_t resources_total_size_bytes = 0;
for (const auto& resource : *resources) { for (const auto& resource : resources) {
DCHECK_GE(resource->size_bytes, 0); DCHECK_GE(resource->size_bytes, 0);
resources_total_size_bytes += resource->size_bytes; resources_total_size_bytes += resource->size_bytes;
} }
......
...@@ -328,7 +328,7 @@ void ServiceWorkerStorage::GetAllRegistrations( ...@@ -328,7 +328,7 @@ void ServiceWorkerStorage::GetAllRegistrations(
void ServiceWorkerStorage::StoreRegistrationData( void ServiceWorkerStorage::StoreRegistrationData(
storage::mojom::ServiceWorkerRegistrationDataPtr registration_data, storage::mojom::ServiceWorkerRegistrationDataPtr registration_data,
std::unique_ptr<ResourceList> resources, ResourceList resources,
StoreRegistrationDataCallback callback) { StoreRegistrationDataCallback callback) {
DCHECK_EQ(state_, STORAGE_STATE_INITIALIZED); DCHECK_EQ(state_, STORAGE_STATE_INITIALIZED);
...@@ -1366,13 +1366,12 @@ void ServiceWorkerStorage::WriteRegistrationInDB( ...@@ -1366,13 +1366,12 @@ void ServiceWorkerStorage::WriteRegistrationInDB(
ServiceWorkerDatabase* database, ServiceWorkerDatabase* database,
scoped_refptr<base::SequencedTaskRunner> original_task_runner, scoped_refptr<base::SequencedTaskRunner> original_task_runner,
storage::mojom::ServiceWorkerRegistrationDataPtr registration, storage::mojom::ServiceWorkerRegistrationDataPtr registration,
std::unique_ptr<ResourceList> resources, ResourceList resources,
WriteRegistrationCallback callback) { WriteRegistrationCallback callback) {
DCHECK(database); DCHECK(database);
DCHECK(resources);
ServiceWorkerDatabase::DeletedVersion deleted_version; ServiceWorkerDatabase::DeletedVersion deleted_version;
ServiceWorkerDatabase::Status status = ServiceWorkerDatabase::Status status =
database->WriteRegistration(*registration, *resources, &deleted_version); database->WriteRegistration(*registration, resources, &deleted_version);
original_task_runner->PostTask( original_task_runner->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(callback), registration->script.GetOrigin(), base::BindOnce(std::move(callback), registration->script.GetOrigin(),
......
...@@ -145,7 +145,7 @@ class CONTENT_EXPORT ServiceWorkerStorage { ...@@ -145,7 +145,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
// Stores |registration_data| and |resources| on persistent storage. // Stores |registration_data| and |resources| on persistent storage.
void StoreRegistrationData( void StoreRegistrationData(
storage::mojom::ServiceWorkerRegistrationDataPtr registration_data, storage::mojom::ServiceWorkerRegistrationDataPtr registration_data,
std::unique_ptr<ResourceList> resources, ResourceList resources,
StoreRegistrationDataCallback callback); StoreRegistrationDataCallback callback);
// Updates the state of the registration's stored version to active. // Updates the state of the registration's stored version to active.
...@@ -448,7 +448,7 @@ class CONTENT_EXPORT ServiceWorkerStorage { ...@@ -448,7 +448,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
ServiceWorkerDatabase* database, ServiceWorkerDatabase* database,
scoped_refptr<base::SequencedTaskRunner> original_task_runner, scoped_refptr<base::SequencedTaskRunner> original_task_runner,
storage::mojom::ServiceWorkerRegistrationDataPtr registration, storage::mojom::ServiceWorkerRegistrationDataPtr registration,
std::unique_ptr<ResourceList> resources, ResourceList resources,
WriteRegistrationCallback callback); WriteRegistrationCallback callback);
static void FindForClientUrlInDB( static void FindForClientUrlInDB(
ServiceWorkerDatabase* database, ServiceWorkerDatabase* database,
......
...@@ -160,12 +160,8 @@ void ServiceWorkerStorageControlImpl::StoreRegistration( ...@@ -160,12 +160,8 @@ void ServiceWorkerStorageControlImpl::StoreRegistration(
storage::mojom::ServiceWorkerRegistrationDataPtr registration, storage::mojom::ServiceWorkerRegistrationDataPtr registration,
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> resources, std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> resources,
StoreRegistrationCallback callback) { StoreRegistrationCallback callback) {
// TODO(bashi): Change the signature of
// ServiceWorkerStorage::StoreRegistrationData() to take a const reference.
storage_->StoreRegistrationData( storage_->StoreRegistrationData(
std::move(registration), std::move(registration), std::move(resources),
std::make_unique<ServiceWorkerStorage::ResourceList>(
std::move(resources)),
base::BindOnce(&ServiceWorkerStorageControlImpl::DidStoreRegistration, base::BindOnce(&ServiceWorkerStorageControlImpl::DidStoreRegistration,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); 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