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