Commit a6d9c824 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Slim down semantics of provider host's "associated registration".

This should really just be the registration of the controller. Slim down
some of the meaning so it's more like that.

Bug: 866353
Change-Id: I98a412dd4456e5600125ea7fccb44d6e0e049faf
Reviewed-on: https://chromium-review.googlesource.com/1149439Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577829}
parent 2eec4dd7
...@@ -362,6 +362,7 @@ void ServiceWorkerControlleeRequestHandler:: ...@@ -362,6 +362,7 @@ void ServiceWorkerControlleeRequestHandler::
url_job_.get(), "Info", "No Provider"); url_job_.get(), "Info", "No Provider");
return; return;
} }
provider_host_->AddMatchingRegistration(registration.get());
if (!context_) { if (!context_) {
url_job_->FallbackToNetwork(); url_job_->FallbackToNetwork();
...@@ -416,14 +417,6 @@ void ServiceWorkerControlleeRequestHandler:: ...@@ -416,14 +417,6 @@ void ServiceWorkerControlleeRequestHandler::
scoped_refptr<ServiceWorkerVersion> active_version = scoped_refptr<ServiceWorkerVersion> active_version =
registration->active_version(); registration->active_version();
if (!active_version) { if (!active_version) {
// Although there is no active version, a registration exists, so associate
// it, so it can be used for .ready.
// TODO(falken): There's no need to associate the registration just for
// .ready. Change this to AddMatchingRegistration instead, and call it
// unconditionally if there is a |provider_host_|.
provider_host_->AssociateRegistration(registration.get(),
false /* notify_controllerchange */);
url_job_->FallbackToNetwork(); url_job_->FallbackToNetwork();
TRACE_EVENT_ASYNC_END1( TRACE_EVENT_ASYNC_END1(
"ServiceWorker", "ServiceWorker",
......
...@@ -279,13 +279,14 @@ TEST_F(ServiceWorkerControlleeRequestHandlerTest, InstallingRegistration) { ...@@ -279,13 +279,14 @@ TEST_F(ServiceWorkerControlleeRequestHandlerTest, InstallingRegistration) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// The handler should have fallen back to network and destroyed the job. The // The handler should have fallen back to network and destroyed the job. The
// registration should be associated with the provider host, although it is // registration should not be associated with the provider host, since it is
// not controlled since there is no active version. // not controlled. However it should be a matching registration so it can be
// used for .ready and claim().
EXPECT_FALSE(job); EXPECT_FALSE(job);
EXPECT_EQ(registration_.get(), provider_host_->associated_registration()); EXPECT_FALSE(provider_host_->associated_registration());
EXPECT_EQ(version_.get(), provider_host_->installing_version());
EXPECT_FALSE(version_->HasControllee()); EXPECT_FALSE(version_->HasControllee());
EXPECT_FALSE(provider_host_->controller()); EXPECT_FALSE(provider_host_->controller());
EXPECT_EQ(registration_.get(), provider_host_->MatchRegistration());
} }
// Test to not regress crbug/414118. // Test to not regress crbug/414118.
......
...@@ -503,9 +503,10 @@ void ServiceWorkerProviderHost::AssociateRegistration( ...@@ -503,9 +503,10 @@ void ServiceWorkerProviderHost::AssociateRegistration(
DCHECK(registration); DCHECK(registration);
DCHECK(!associated_registration_); DCHECK(!associated_registration_);
DCHECK(allow_association_); DCHECK(allow_association_);
DCHECK(base::ContainsKey(matching_registrations_,
registration->pattern().spec().size()));
associated_registration_ = registration; associated_registration_ = registration;
AddMatchingRegistration(registration);
SetControllerVersionAttribute(registration->active_version(), SetControllerVersionAttribute(registration->active_version(),
notify_controllerchange); notify_controllerchange);
} }
......
...@@ -200,12 +200,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -200,12 +200,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// Returns this provider's controller. The controller is typically the same as // Returns this provider's controller. The controller is typically the same as
// active_version() but can differ in the following cases: // active_version() but can differ in the following cases:
// (1) The client was created before the registration existed or had an active // (1) The client had a controller but NotifyControllerLost() was called due
// version (in spec language, it is not "using" the registration). // to an exceptional circumstance.
// (2) The client had a controller but NotifyControllerLost() was called due // (2) During algorithms such as the update, skipWaiting(), and claim() steps,
// to an exceptional circumstance (here also it is not "using" the
// registration).
// (3) During algorithms such as the update, skipWaiting(), and claim() steps,
// the active version and controller may temporarily differ. For example, to // the active version and controller may temporarily differ. For example, to
// perform skipWaiting(), the registration's active version is updated first // perform skipWaiting(), the registration's active version is updated first
// and then the provider host's controlling version is updated to match it. // and then the provider host's controlling version is updated to match it.
...@@ -221,20 +218,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -221,20 +218,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
: nullptr; : nullptr;
} }
ServiceWorkerVersion* waiting_version() const { // Returns the associated registration. This is typically the registration of
return associated_registration_.get() // the controller() if it exists. It may also exist when controller() is null
? associated_registration_->waiting_version() // after NotifyControllerLost().
: nullptr;
}
ServiceWorkerVersion* installing_version() const {
return associated_registration_.get()
? associated_registration_->installing_version()
: nullptr;
}
// Returns the associated registration. The provider host listens to this
// registration to resolve the .ready promise and set its controller.
ServiceWorkerRegistration* associated_registration() const { ServiceWorkerRegistration* associated_registration() const {
// Only clients can have an associated registration. // Only clients can have an associated registration.
DCHECK(!associated_registration_ || IsProviderForClient()); DCHECK(!associated_registration_ || IsProviderForClient());
...@@ -315,14 +301,13 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -315,14 +301,13 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// Can only be called when IsProviderForClient() is true. // Can only be called when IsProviderForClient() is true.
blink::mojom::ServiceWorkerClientType client_type() const; blink::mojom::ServiceWorkerClientType client_type() const;
// For service worker clients. Associates to |registration| to listen for its // For service worker clients. Associates to |registration| to set the
// version change events and sets the controller. If |notify_controllerchange| // controller. If |notify_controllerchange| is true, instructs the renderer to
// is true, instructs the renderer to dispatch a 'controllerchange' event. // dispatch a 'controllerchange' event.
void AssociateRegistration(ServiceWorkerRegistration* registration, void AssociateRegistration(ServiceWorkerRegistration* registration,
bool notify_controllerchange); bool notify_controllerchange);
// For service worker clients. Clears the associated registration and stops // For service worker clients. Clears the controller.
// listening to it.
void DisassociateRegistration(); void DisassociateRegistration();
// Returns a handler for a request. May return nullptr if the request doesn't // Returns a handler for a request. May return nullptr if the request doesn't
...@@ -415,6 +400,16 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -415,6 +400,16 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// After this is called, is_execution_ready() returns true. // After this is called, is_execution_ready() returns true.
void CompleteSharedWorkerPreparation(); void CompleteSharedWorkerPreparation();
// For service worker clients. The host keeps track of all the prospective
// longest-matching registrations, in order to resolve .ready or respond to
// claim() attempts.
//
// This is subtle: it doesn't keep all registrations (e.g., from storage) in
// memory, but just the ones that are possibly the longest-matching one. The
// best match from storage is added at load time. That match can't uninstall
// while this host is a controllee, so all the other stored registrations can
// be ignored. Only a newly installed registration can claim it, and new
// installing registrations are added as matches.
void AddMatchingRegistration(ServiceWorkerRegistration* registration); void AddMatchingRegistration(ServiceWorkerRegistration* registration);
void RemoveMatchingRegistration(ServiceWorkerRegistration* registration); void RemoveMatchingRegistration(ServiceWorkerRegistration* registration);
...@@ -513,8 +508,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -513,8 +508,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
void SetControllerVersionAttribute(ServiceWorkerVersion* version, void SetControllerVersionAttribute(ServiceWorkerVersion* version,
bool notify_controllerchange); bool notify_controllerchange);
void SendAssociateRegistrationMessage();
// Syncs matching registrations with live registrations. // Syncs matching registrations with live registrations.
void SyncMatchingRegistrations(); void SyncMatchingRegistrations();
...@@ -614,6 +607,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -614,6 +607,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
GURL document_url_; GURL document_url_;
GURL topmost_frame_url_; GURL topmost_frame_url_;
// The registration of |controller_|, if it exists. This might also be
// set even if |controller_| is null due to NotifyControllerLost.
scoped_refptr<ServiceWorkerRegistration> associated_registration_; scoped_refptr<ServiceWorkerRegistration> associated_registration_;
// Keyed by registration scope URL length. // Keyed by registration scope URL length.
......
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