Commit 4daa1195 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

ServiceWorker: Rename OnRegistrationStored -> OnRegistrationCompleted.

For historical reasons, OnRegistrationStored() is called when the
promise returned by ServiceWorkerContainer.register() is resolved, which
happens before the registration is written to disk. This means
OnRegistrationStored() implementations cannot assume that
ServiceWorkerContextCore will be able to retrieve the registration.

This CL renames the method to a more appropriate name. A follow-up CL
will add an OnRegistrationStored() method, which will be called when the
registration is written to the database.

TBR=benwells

Bug: 729800
Change-Id: If273b3008ff55e4d5cd8f5be9e0e6090da2e5390
Reviewed-on: https://chromium-review.googlesource.com/1039083
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555550}
parent c0f801e2
...@@ -532,8 +532,8 @@ void InstallableManager::OnDidCheckHasServiceWorker( ...@@ -532,8 +532,8 @@ void InstallableManager::OnDidCheckHasServiceWorker(
case content::ServiceWorkerCapability::NO_SERVICE_WORKER: case content::ServiceWorkerCapability::NO_SERVICE_WORKER:
InstallableTask& task = task_queue_.Current(); InstallableTask& task = task_queue_.Current();
if (task.params.wait_for_worker) { if (task.params.wait_for_worker) {
// Wait for ServiceWorkerContextObserver::OnRegistrationStored. Set the // Wait for ServiceWorkerContextObserver::OnRegistrationCompleted. Set
// param |wait_for_worker| to false so we only wait once per task. // the param |wait_for_worker| to false so we only wait once per task.
task.params.wait_for_worker = false; task.params.wait_for_worker = false;
OnWaitingForServiceWorker(); OnWaitingForServiceWorker();
task_queue_.PauseCurrent(); task_queue_.PauseCurrent();
...@@ -597,7 +597,7 @@ void InstallableManager::OnIconFetched(const GURL icon_url, ...@@ -597,7 +597,7 @@ void InstallableManager::OnIconFetched(const GURL icon_url,
WorkOnTask(); WorkOnTask();
} }
void InstallableManager::OnRegistrationStored(const GURL& pattern) { void InstallableManager::OnRegistrationCompleted(const GURL& pattern) {
// If the scope doesn't match we keep waiting. // If the scope doesn't match we keep waiting.
if (!content::ServiceWorkerContext::ScopeMatches(pattern, if (!content::ServiceWorkerContext::ScopeMatches(pattern,
manifest().start_url)) { manifest().start_url)) {
......
...@@ -192,7 +192,7 @@ class InstallableManager ...@@ -192,7 +192,7 @@ class InstallableManager
const SkBitmap& bitmap); const SkBitmap& bitmap);
// content::ServiceWorkerContextObserver overrides // content::ServiceWorkerContextObserver overrides
void OnRegistrationStored(const GURL& pattern) override; void OnRegistrationCompleted(const GURL& pattern) override;
// content::WebContentsObserver overrides // content::WebContentsObserver overrides
void DidFinishNavigation(content::NavigationHandle* handle) override; void DidFinishNavigation(content::NavigationHandle* handle) override;
......
...@@ -220,7 +220,7 @@ cr.define('serviceworker', function() { ...@@ -220,7 +220,7 @@ cr.define('serviceworker', function() {
update(); update();
} }
function onRegistrationStored(scope) { function onRegistrationCompleted(scope) {
update(); update();
} }
...@@ -258,7 +258,7 @@ cr.define('serviceworker', function() { ...@@ -258,7 +258,7 @@ cr.define('serviceworker', function() {
onErrorReported: onErrorReported, onErrorReported: onErrorReported,
onConsoleMessageReported: onConsoleMessageReported, onConsoleMessageReported: onConsoleMessageReported,
onVersionStateChanged: onVersionStateChanged, onVersionStateChanged: onVersionStateChanged,
onRegistrationStored: onRegistrationStored, onRegistrationCompleted: onRegistrationCompleted,
onRegistrationDeleted: onRegistrationDeleted, onRegistrationDeleted: onRegistrationDeleted,
}; };
}); });
......
...@@ -550,11 +550,10 @@ void ServiceWorkerContextCore::RegistrationComplete( ...@@ -550,11 +550,10 @@ void ServiceWorkerContextCore::RegistrationComplete(
DCHECK(registration); DCHECK(registration);
std::move(callback).Run(status, status_message, registration->id()); std::move(callback).Run(status, status_message, registration->id());
// TODO(falken): At this point the registration promise is resolved, but we // At this point the registration promise is resolved, but we haven't
// haven't persisted anything to storage yet. So we should either call // persisted anything to storage yet.
// OnRegistrationStored somewhere else or change its name.
observer_list_->Notify( observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationStored, FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationCompleted,
registration->id(), pattern); registration->id(), pattern);
} }
......
...@@ -89,8 +89,13 @@ class ServiceWorkerContextCoreObserver { ...@@ -89,8 +89,13 @@ class ServiceWorkerContextCoreObserver {
blink::mojom::ServiceWorkerProviderType type) {} blink::mojom::ServiceWorkerProviderType type) {}
virtual void OnControlleeRemoved(int64_t version_id, virtual void OnControlleeRemoved(int64_t version_id,
const std::string& uuid) {} const std::string& uuid) {}
virtual void OnRegistrationStored(int64_t registration_id, // Called when the ServiceWorkerContainer.register() promise is resolved.
const GURL& pattern) {} //
// This is called before the service worker registration is persisted to disk.
// The caller cannot assume that the ServiceWorkerContextCore will find the
// registration at this point.
virtual void OnRegistrationCompleted(int64_t registration_id,
const GURL& pattern) {}
virtual void OnRegistrationDeleted(int64_t registration_id, virtual void OnRegistrationDeleted(int64_t registration_id,
const GURL& pattern) {} const GURL& pattern) {}
......
...@@ -111,7 +111,7 @@ class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { ...@@ -111,7 +111,7 @@ class RejectActivateTestHelper : public EmbeddedWorkerTestHelper {
}; };
enum NotificationType { enum NotificationType {
REGISTRATION_STORED, REGISTRATION_COMPLETED,
REGISTRATION_DELETED, REGISTRATION_DELETED,
STORAGE_RECOVERED, STORAGE_RECOVERED,
}; };
...@@ -138,10 +138,10 @@ class ServiceWorkerContextTest : public ServiceWorkerContextCoreObserver, ...@@ -138,10 +138,10 @@ class ServiceWorkerContextTest : public ServiceWorkerContextCoreObserver,
void TearDown() override { helper_.reset(); } void TearDown() override { helper_.reset(); }
// ServiceWorkerContextCoreObserver overrides. // ServiceWorkerContextCoreObserver overrides.
void OnRegistrationStored(int64_t registration_id, void OnRegistrationCompleted(int64_t registration_id,
const GURL& pattern) override { const GURL& pattern) override {
NotificationLog log; NotificationLog log;
log.type = REGISTRATION_STORED; log.type = REGISTRATION_COMPLETED;
log.pattern = pattern; log.pattern = pattern;
log.registration_id = registration_id; log.registration_id = registration_id;
notifications_.push_back(log); notifications_.push_back(log);
...@@ -229,7 +229,7 @@ TEST_F(ServiceWorkerContextTest, Register) { ...@@ -229,7 +229,7 @@ TEST_F(ServiceWorkerContextTest, Register) {
EXPECT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId, registration_id); EXPECT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId, registration_id);
ASSERT_EQ(1u, notifications_.size()); ASSERT_EQ(1u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(registration_id, notifications_[0].registration_id); EXPECT_EQ(registration_id, notifications_[0].registration_id);
...@@ -278,7 +278,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { ...@@ -278,7 +278,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
EXPECT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId, registration_id); EXPECT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId, registration_id);
ASSERT_EQ(1u, notifications_.size()); ASSERT_EQ(1u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(registration_id, notifications_[0].registration_id); EXPECT_EQ(registration_id, notifications_[0].registration_id);
...@@ -326,7 +326,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { ...@@ -326,7 +326,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
EXPECT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId, registration_id); EXPECT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId, registration_id);
ASSERT_EQ(1u, notifications_.size()); ASSERT_EQ(1u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(registration_id, notifications_[0].registration_id); EXPECT_EQ(registration_id, notifications_[0].registration_id);
...@@ -369,7 +369,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) { ...@@ -369,7 +369,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_EQ(2u, notifications_.size()); ASSERT_EQ(2u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(registration_id, notifications_[0].registration_id); EXPECT_EQ(registration_id, notifications_[0].registration_id);
EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type);
...@@ -474,16 +474,16 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { ...@@ -474,16 +474,16 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_EQ(6u, notifications_.size()); ASSERT_EQ(6u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(registration_id1, notifications_[0].registration_id); EXPECT_EQ(registration_id1, notifications_[0].registration_id);
EXPECT_EQ(origin1_p1, notifications_[0].pattern); EXPECT_EQ(origin1_p1, notifications_[0].pattern);
EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[1].type);
EXPECT_EQ(origin1_p2, notifications_[1].pattern); EXPECT_EQ(origin1_p2, notifications_[1].pattern);
EXPECT_EQ(registration_id2, notifications_[1].registration_id); EXPECT_EQ(registration_id2, notifications_[1].registration_id);
EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[2].type);
EXPECT_EQ(origin2_p1, notifications_[2].pattern); EXPECT_EQ(origin2_p1, notifications_[2].pattern);
EXPECT_EQ(registration_id3, notifications_[2].registration_id); EXPECT_EQ(registration_id3, notifications_[2].registration_id);
EXPECT_EQ(REGISTRATION_STORED, notifications_[3].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[3].type);
EXPECT_EQ(origin3_p1, notifications_[3].pattern); EXPECT_EQ(origin3_p1, notifications_[3].pattern);
EXPECT_EQ(registration_id4, notifications_[3].registration_id); EXPECT_EQ(registration_id4, notifications_[3].registration_id);
EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type);
...@@ -529,10 +529,10 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { ...@@ -529,10 +529,10 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
EXPECT_EQ(old_registration_id, new_registration_id); EXPECT_EQ(old_registration_id, new_registration_id);
ASSERT_EQ(2u, notifications_.size()); ASSERT_EQ(2u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(old_registration_id, notifications_[0].registration_id); EXPECT_EQ(old_registration_id, notifications_[0].registration_id);
EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[1].type);
EXPECT_EQ(pattern, notifications_[1].pattern); EXPECT_EQ(pattern, notifications_[1].pattern);
EXPECT_EQ(new_registration_id, notifications_[1].registration_id); EXPECT_EQ(new_registration_id, notifications_[1].registration_id);
} }
...@@ -571,10 +571,10 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { ...@@ -571,10 +571,10 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
EXPECT_EQ(old_registration_id, new_registration_id); EXPECT_EQ(old_registration_id, new_registration_id);
ASSERT_EQ(2u, notifications_.size()); ASSERT_EQ(2u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(old_registration_id, notifications_[0].registration_id); EXPECT_EQ(old_registration_id, notifications_[0].registration_id);
EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[1].type);
EXPECT_EQ(pattern, notifications_[1].pattern); EXPECT_EQ(pattern, notifications_[1].pattern);
EXPECT_EQ(old_registration_id, notifications_[1].registration_id); EXPECT_EQ(old_registration_id, notifications_[1].registration_id);
} }
...@@ -754,11 +754,11 @@ TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { ...@@ -754,11 +754,11 @@ TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
EXPECT_EQ(3, context()->GetNewServiceWorkerHandleId()); EXPECT_EQ(3, context()->GetNewServiceWorkerHandleId());
ASSERT_EQ(3u, notifications_.size()); ASSERT_EQ(3u, notifications_.size());
EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[0].type);
EXPECT_EQ(pattern, notifications_[0].pattern); EXPECT_EQ(pattern, notifications_[0].pattern);
EXPECT_EQ(registration_id, notifications_[0].registration_id); EXPECT_EQ(registration_id, notifications_[0].registration_id);
EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type);
EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); EXPECT_EQ(REGISTRATION_COMPLETED, notifications_[2].type);
EXPECT_EQ(pattern, notifications_[2].pattern); EXPECT_EQ(pattern, notifications_[2].pattern);
EXPECT_EQ(registration_id, notifications_[2].registration_id); EXPECT_EQ(registration_id, notifications_[2].registration_id);
} }
......
...@@ -362,8 +362,9 @@ void ServiceWorkerContextWatcher::OnControlleeRemoved(int64_t version_id, ...@@ -362,8 +362,9 @@ void ServiceWorkerContextWatcher::OnControlleeRemoved(int64_t version_id,
SendVersionInfo(*version); SendVersionInfo(*version);
} }
void ServiceWorkerContextWatcher::OnRegistrationStored(int64_t registration_id, void ServiceWorkerContextWatcher::OnRegistrationCompleted(
const GURL& pattern) { int64_t registration_id,
const GURL& pattern) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
SendRegistrationInfo(registration_id, pattern, SendRegistrationInfo(registration_id, pattern,
ServiceWorkerRegistrationInfo::IS_NOT_DELETED); ServiceWorkerRegistrationInfo::IS_NOT_DELETED);
......
...@@ -112,8 +112,8 @@ class CONTENT_EXPORT ServiceWorkerContextWatcher ...@@ -112,8 +112,8 @@ class CONTENT_EXPORT ServiceWorkerContextWatcher
blink::mojom::ServiceWorkerProviderType type) override; blink::mojom::ServiceWorkerProviderType type) override;
void OnControlleeRemoved(int64_t version_id, void OnControlleeRemoved(int64_t version_id,
const std::string& uuid) override; const std::string& uuid) override;
void OnRegistrationStored(int64_t registration_id, void OnRegistrationCompleted(int64_t registration_id,
const GURL& pattern) override; const GURL& pattern) override;
void OnRegistrationDeleted(int64_t registration_id, void OnRegistrationDeleted(int64_t registration_id,
const GURL& pattern) override; const GURL& pattern) override;
......
...@@ -242,10 +242,11 @@ ResourceContext* ServiceWorkerContextWrapper::resource_context() { ...@@ -242,10 +242,11 @@ ResourceContext* ServiceWorkerContextWrapper::resource_context() {
return resource_context_; return resource_context_;
} }
void ServiceWorkerContextWrapper::OnRegistrationStored(int64_t registration_id, void ServiceWorkerContextWrapper::OnRegistrationCompleted(
const GURL& pattern) { int64_t registration_id,
const GURL& pattern) {
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnRegistrationStored(pattern); observer.OnRegistrationCompleted(pattern);
} }
void ServiceWorkerContextWrapper::AddObserver( void ServiceWorkerContextWrapper::AddObserver(
......
...@@ -98,8 +98,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -98,8 +98,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
} }
// ServiceWorkerContextCoreObserver implementation: // ServiceWorkerContextCoreObserver implementation:
void OnRegistrationStored(int64_t registration_id, void OnRegistrationCompleted(int64_t registration_id,
const GURL& pattern) override; const GURL& pattern) override;
// ServiceWorkerContext implementation: // ServiceWorkerContext implementation:
void AddObserver(ServiceWorkerContextObserver* observer) override; void AddObserver(ServiceWorkerContextObserver* observer) override;
......
...@@ -306,11 +306,11 @@ class ServiceWorkerInternalsUI::PartitionObserver ...@@ -306,11 +306,11 @@ class ServiceWorkerInternalsUI::PartitionObserver
web_ui_->CallJavascriptFunctionUnsafe( web_ui_->CallJavascriptFunctionUnsafe(
"serviceworker.onConsoleMessageReported", ConvertToRawPtrVector(args)); "serviceworker.onConsoleMessageReported", ConvertToRawPtrVector(args));
} }
void OnRegistrationStored(int64_t registration_id, void OnRegistrationCompleted(int64_t registration_id,
const GURL& pattern) override { const GURL& pattern) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
web_ui_->CallJavascriptFunctionUnsafe("serviceworker.onRegistrationStored", web_ui_->CallJavascriptFunctionUnsafe(
Value(pattern.spec())); "serviceworker.onRegistrationCompleted", Value(pattern.spec()));
} }
void OnRegistrationDeleted(int64_t registration_id, void OnRegistrationDeleted(int64_t registration_id,
const GURL& pattern) override { const GURL& pattern) override {
......
...@@ -12,7 +12,11 @@ namespace content { ...@@ -12,7 +12,11 @@ namespace content {
class ServiceWorkerContextObserver { class ServiceWorkerContextObserver {
public: public:
// Called when a service worker has been registered with scope |pattern|. // Called when a service worker has been registered with scope |pattern|.
virtual void OnRegistrationStored(const GURL& pattern) {} //
// This is called when the ServiceWorkerContainer.register() promise is
// resolved, which happens before the service worker registration is persisted
// to disk.
virtual void OnRegistrationCompleted(const GURL& pattern) {}
protected: protected:
virtual ~ServiceWorkerContextObserver() {} virtual ~ServiceWorkerContextObserver() {}
......
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