Commit b8fbad74 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

ServiceWorker: ServiceWorkerContextCoreObserver::OnRegistrationStored.

OnRegistrationStored is guaranteed to be called after a
ServiceWorkerRegistration has been persisted to ServiceWorkerStorage, so
observers can assume that methods like ServiceWorkerStorage::GetUserData
will find the registration.

Bug: 729800
Change-Id: I35181050b2f35a3b82c4f8e5a22383905b9bc482
Reviewed-on: https://chromium-review.googlesource.com/1043064
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556380}
parent 4461b89a
......@@ -768,6 +768,14 @@ int ServiceWorkerContextCore::GetVersionFailureCount(int64_t version_id) {
return it->second.count;
}
void ServiceWorkerContextCore::NotifyRegistrationStored(int64_t registration_id,
const GURL& pattern) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationStored,
registration_id, pattern);
}
void ServiceWorkerContextCore::OnStorageWiped() {
observer_list_->Notify(FROM_HERE,
&ServiceWorkerContextCoreObserver::OnStorageWiped);
......
......@@ -287,6 +287,9 @@ class CONTENT_EXPORT ServiceWorkerContextCore
// version. The count resets to zero when the worker successfully starts.
int GetVersionFailureCount(int64_t version_id);
// Called by ServiceWorkerStorage when StoreRegistration() succeeds.
void NotifyRegistrationStored(int64_t registration_id, const GURL& pattern);
URLLoaderFactoryGetter* loader_factory_getter() {
return loader_factory_getter_.get();
}
......
......@@ -91,11 +91,18 @@ class ServiceWorkerContextCoreObserver {
const std::string& uuid) {}
// Called when the ServiceWorkerContainer.register() promise is resolved.
//
// 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.
// This is called before the service worker registration is persisted to
// storage. The implementation cannot assume that the ServiceWorkerContextCore
// will find the registration at this point.
virtual void OnRegistrationCompleted(int64_t registration_id,
const GURL& pattern) {}
// Called after a service worker registration is persisted to storage.
//
// This happens after OnRegistrationCompleted(). The implementation can assume
// that ServiceWorkerContextCore will find the registration, and can safely
// add user data to the registration.
virtual void OnRegistrationStored(int64_t registration_id,
const GURL& pattern) {}
virtual void OnRegistrationDeleted(int64_t registration_id,
const GURL& pattern) {}
......
......@@ -1391,6 +1391,8 @@ void ServiceWorkerStorage::DidStoreRegistration(
deleted_version.resources_total_size_bytes);
}
context_->NotifyRegistrationStored(new_version.registration_id,
new_version.scope);
std::move(callback).Run(SERVICE_WORKER_OK);
if (!context_->GetLiveVersion(deleted_version.version_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