Commit 48c46560 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Workaround for duplicate service worker controllees notifications

With this CL, the ServiceWorkerContextAdapter drops duplicate
OnControlleeAdded or OnControlleeRemoved notifications from the
ServiceWorkerContextObserver interface.

Bug: 993029, 1015692
Change-Id: I482a7d9db93cf6f8abd6475f7b0256f0f53857cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354528Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799272}
parent 68319bd3
......@@ -267,6 +267,43 @@ void ServiceWorkerContextAdapter::OnVersionStoppedRunning(int64_t version_id) {
observer.OnVersionStoppedRunning(version_id);
}
void ServiceWorkerContextAdapter::OnControlleeAdded(
int64_t version_id,
const std::string& client_uuid,
const content::ServiceWorkerClientInfo& client_info) {
// If |client_uuid| is already marked as a client of |version_id|, the
// notification is dropped.
bool inserted =
service_worker_clients_[version_id].insert(client_uuid).second;
if (!inserted)
return;
for (auto& observer : observer_list_)
observer.OnControlleeAdded(version_id, client_uuid, client_info);
}
void ServiceWorkerContextAdapter::OnControlleeRemoved(
int64_t version_id,
const std::string& client_uuid) {
// If |client_uuid| is not already marked as a client of |version_id|, the
// notification is dropped.
auto it = service_worker_clients_.find(version_id);
if (it == service_worker_clients_.end())
return;
size_t removed = it->second.erase(client_uuid);
if (!removed)
return;
// If a service worker no longer has any clients, it is removed entirely from
// |service_worker_clients_|.
if (it->second.empty())
service_worker_clients_.erase(it);
for (auto& observer : observer_list_)
observer.OnControlleeRemoved(version_id, client_uuid);
}
void ServiceWorkerContextAdapter::OnNoControllees(int64_t version_id,
const GURL& scope) {
for (auto& observer : observer_list_)
......
......@@ -100,6 +100,12 @@ class ServiceWorkerContextAdapter
int64_t version_id,
const content::ServiceWorkerRunningInfo& running_info) override;
void OnVersionStoppedRunning(int64_t version_id) override;
void OnControlleeAdded(
int64_t version_id,
const std::string& client_uuid,
const content::ServiceWorkerClientInfo& client_info) override;
void OnControlleeRemoved(int64_t version_id,
const std::string& client_uuid) override;
void OnNoControllees(int64_t version_id, const GURL& scope) override;
void OnReportConsoleMessage(int64_t version_id,
const GURL& scope,
......@@ -124,6 +130,15 @@ class ServiceWorkerContextAdapter
base::flat_map<int64_t /*version_id*/, std::unique_ptr<RunningServiceWorker>>
running_service_workers_;
// Tracks the OnControlleeAdded and OnControlleeRemoved notification for each
// service worker, with the goal of cleaning up duplicate notifications for
// observers of this class.
// TODO(1015692): Fix the underlying code in content/browser/service_worker so
// that duplicate notifications are no longer sent.
base::flat_map<int64_t /*version_id*/,
base::flat_set<std::string /*client_uuid*/>>
service_worker_clients_;
#if DCHECK_IS_ON()
// Keeps track of service worker whose render process exited early.
base::flat_set<int64_t> stopped_service_workers_;
......
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