Commit baacc5e7 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Add "Get" prefix for ServiceWorkerStorage::New{Registration,Version,Resource}Id()

This is a follow-up CL of crrev.com/c/2041678. Having a verb for
these methods is better as these will become mojo methods.

Bug: 1046335
Change-Id: I945b2da96754d6f29b8451ddd9194f9fd781757b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2048623
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740526}
parent a1ef034b
......@@ -72,7 +72,7 @@ ServiceWorkerRegistry::~ServiceWorkerRegistry() = default;
void ServiceWorkerRegistry::CreateNewRegistration(
blink::mojom::ServiceWorkerRegistrationOptions options,
NewRegistrationCallback callback) {
storage()->NewRegistrationId(base::BindOnce(
storage()->GetNewRegistrationId(base::BindOnce(
&ServiceWorkerRegistry::DidGetNewRegistrationId,
weak_factory_.GetWeakPtr(), std::move(options), std::move(callback)));
}
......@@ -82,7 +82,7 @@ scoped_refptr<ServiceWorkerVersion> ServiceWorkerRegistry::CreateNewVersion(
const GURL& script_url,
blink::mojom::ScriptType script_type) {
DCHECK(registration);
int64_t version_id = storage()->NewVersionId();
int64_t version_id = storage()->GetNewVersionId();
if (version_id == blink::mojom::kInvalidServiceWorkerVersionId)
return nullptr;
return base::MakeRefCounted<ServiceWorkerVersion>(
......
......@@ -115,7 +115,7 @@ void ServiceWorkerScriptLoaderFactory::CreateLoaderAndStart(
switch (it->second.result) {
case ServiceWorkerSingleScriptUpdateChecker::Result::kIdentical:
// Case D.1:
context_->storage()->NewResourceId(base::BindOnce(
context_->storage()->GetNewResourceId(base::BindOnce(
&ServiceWorkerScriptLoaderFactory::CopyScript,
weak_factory_.GetWeakPtr(), it->first, it->second.old_resource_id,
base::BindOnce(
......@@ -143,7 +143,7 @@ void ServiceWorkerScriptLoaderFactory::CreateLoaderAndStart(
// Case D.3:
// Assign a new resource ID for the script from network.
context_->storage()->NewResourceId(base::BindOnce(
context_->storage()->GetNewResourceId(base::BindOnce(
&ServiceWorkerScriptLoaderFactory::OnResourceIdAssignedForNewScriptLoader,
weak_factory_.GetWeakPtr(), std::move(receiver), routing_id, request_id,
options, resource_request, std::move(client), traffic_annotation));
......
......@@ -485,7 +485,7 @@ ServiceWorkerStorage::CreateResponseMetadataWriter(int64_t resource_id) {
void ServiceWorkerStorage::CreateNewResponseWriter(
ResponseWriterCreationCallback callback) {
int64_t resource_id = NewResourceIdInternal();
int64_t resource_id = NewResourceId();
if (resource_id == ServiceWorkerConsts::kInvalidServiceWorkerResourceId) {
std::move(callback).Run(resource_id, nullptr);
} else {
......@@ -850,21 +850,21 @@ void ServiceWorkerStorage::DiskCacheImplDoneWithDisk() {
}
}
void ServiceWorkerStorage::NewRegistrationId(
void ServiceWorkerStorage::GetNewRegistrationId(
base::OnceCallback<void(int64_t registration_id)> callback) {
std::move(callback).Run(NewRegistrationIdInternal());
std::move(callback).Run(NewRegistrationId());
}
int64_t ServiceWorkerStorage::NewVersionId() {
int64_t ServiceWorkerStorage::GetNewVersionId() {
if (state_ == STORAGE_STATE_DISABLED)
return blink::mojom::kInvalidServiceWorkerVersionId;
DCHECK_EQ(STORAGE_STATE_INITIALIZED, state_);
return next_version_id_++;
}
void ServiceWorkerStorage::NewResourceId(
void ServiceWorkerStorage::GetNewResourceId(
base::OnceCallback<void(int64_t resource_id)> callback) {
std::move(callback).Run(NewResourceIdInternal());
std::move(callback).Run(NewResourceId());
}
void ServiceWorkerStorage::Disable() {
......@@ -1229,7 +1229,7 @@ void ServiceWorkerStorage::ClearSessionOnlyOrigins() {
session_only_origins));
}
int64_t ServiceWorkerStorage::NewRegistrationIdInternal() {
int64_t ServiceWorkerStorage::NewRegistrationId() {
if (state_ == STORAGE_STATE_DISABLED) {
return blink::mojom::kInvalidServiceWorkerRegistrationId;
}
......@@ -1237,7 +1237,7 @@ int64_t ServiceWorkerStorage::NewRegistrationIdInternal() {
return next_registration_id_++;
}
int64_t ServiceWorkerStorage::NewResourceIdInternal() {
int64_t ServiceWorkerStorage::NewResourceId() {
if (state_ == STORAGE_STATE_DISABLED)
return ServiceWorkerConsts::kInvalidServiceWorkerResourceId;
DCHECK_EQ(STORAGE_STATE_INITIALIZED, state_);
......
......@@ -269,12 +269,12 @@ class CONTENT_EXPORT ServiceWorkerStorage {
// NOTE: Currently this method is synchronous but intentionally uses async
// style because ServiceWorkerStorage will be accessed via mojo calls soon.
// See crbug.com/1046335 for details.
void NewRegistrationId(
void GetNewRegistrationId(
base::OnceCallback<void(int64_t registration_id)> callback);
// Returns a new version id which is guaranteed to be unique in the storage.
// Returns kInvalidServiceWorkerVersionId if the storage is disabled.
int64_t NewVersionId();
int64_t GetNewVersionId();
// Returns a new resource id which is guaranteed to be unique in the storage.
// Returns ServiceWorkerConsts::kInvalidServiceWorkerResourceId if the storage
......@@ -283,8 +283,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
// and doesn't have to take a callback. Using a callback is a preparation
// for using ServiceWorkerStorage via a mojo interface.
// See crbug.com/1046335 for details.
// TODO(bashi): Change to GetNewResourceId().
void NewResourceId(base::OnceCallback<void(int64_t resource_id)> callback);
void GetNewResourceId(base::OnceCallback<void(int64_t resource_id)> callback);
void Disable();
bool IsDisabled() const;
......@@ -428,8 +427,8 @@ class CONTENT_EXPORT ServiceWorkerStorage {
void ClearSessionOnlyOrigins();
int64_t NewRegistrationIdInternal();
int64_t NewResourceIdInternal();
int64_t NewRegistrationId();
int64_t NewResourceId();
// Static cross-thread helpers.
static void CollectStaleResourcesFromDB(
......
......@@ -665,11 +665,11 @@ TEST_F(ServiceWorkerStorageTest, DisabledStorage) {
// Next available ids should be invalid.
EXPECT_EQ(blink::mojom::kInvalidServiceWorkerRegistrationId,
storage()->NewRegistrationIdInternal());
storage()->NewRegistrationId());
EXPECT_EQ(blink::mojom::kInvalidServiceWorkerVersionId,
storage()->NewVersionId());
storage()->GetNewVersionId());
EXPECT_EQ(ServiceWorkerConsts::kInvalidServiceWorkerResourceId,
storage()->NewRegistrationIdInternal());
storage()->NewRegistrationId());
}
TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) {
......@@ -1606,7 +1606,7 @@ TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) {
// Make an updated registration.
scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
registration_.get(), script_, blink::mojom::ScriptType::kClassic,
storage()->NewVersionId(), context()->AsWeakPtr());
storage()->GetNewVersionId(), context()->AsWeakPtr());
live_version->SetStatus(ServiceWorkerVersion::NEW);
registration_->SetWaitingVersion(live_version);
std::vector<ResourceRecord> records;
......@@ -1653,7 +1653,7 @@ TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration_NoLiveVersion) {
// Make an updated registration.
scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
registration_.get(), script_, blink::mojom::ScriptType::kClassic,
storage()->NewVersionId(), context()->AsWeakPtr());
storage()->GetNewVersionId(), context()->AsWeakPtr());
live_version->SetStatus(ServiceWorkerVersion::NEW);
registration_->SetWaitingVersion(live_version);
std::vector<ResourceRecord> records;
......
......@@ -502,7 +502,7 @@ std::unique_ptr<ServiceWorkerResponseWriter> CreateNewResponseWriterSync(
int64_t GetNewResourceIdSync(ServiceWorkerStorage* storage) {
base::RunLoop run_loop;
int64_t resource_id;
storage->NewResourceId(
storage->GetNewResourceId(
base::BindLambdaForTesting([&](int64_t new_resource_id) {
DCHECK_NE(new_resource_id,
ServiceWorkerConsts::kInvalidServiceWorkerResourceId);
......
......@@ -197,7 +197,7 @@ void WriteToDiskCacheAsync(
std::unique_ptr<ServiceWorkerResponseWriter> CreateNewResponseWriterSync(
ServiceWorkerStorage* storage);
// Calls ServiceWorkerStorage::NewResourceId() synchronously.
// Calls ServiceWorkerStorage::GetNewResourceId() synchronously.
int64_t GetNewResourceIdSync(ServiceWorkerStorage* storage);
// A test implementation of ServiceWorkerResponseReader.
......
......@@ -246,7 +246,7 @@ void ServiceWorkerUpdateChecker::CheckOneScript(const GURL& url,
DCHECK_NE(ServiceWorkerConsts::kInvalidServiceWorkerResourceId, resource_id)
<< "All the target scripts should be stored in the storage.";
version_to_update_->context()->storage()->NewResourceId(base::BindOnce(
version_to_update_->context()->storage()->GetNewResourceId(base::BindOnce(
&ServiceWorkerUpdateChecker::OnResourceIdAssignedForOneScriptCheck,
weak_factory_.GetWeakPtr(), url, resource_id));
}
......
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