Commit d0f11a30 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert ServiceWorkerWorkerClient(Registry) to new Mojo types

This CL converts ServiceWorkerWorkerClient{Ptr, PtrInfo, Request},
ServiceWorkerWorkerClientRegistry{Ptr, PtrInfo, Request} in content
to the new Mojo types, and uses
pending_remote<ServiceWorkerWorkerClient> and
pending_receiver<ServiceWorkerWorkerClientRegistry> in
service_worker_provider.mojom.

Bug: 955171, 978694
Change-Id: I28a4efa171d65aa966d4afbd45f194868d8de789
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1765095
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690216}
parent da4fe11a
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
#include "content/common/child_process.mojom.h" #include "content/common/child_process.mojom.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "ipc/ipc_message.h" #include "ipc/ipc_message.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/remote_set.h" #include "mojo/public/cpp/bindings/remote_set.h"
#include "mojo/public/cpp/bindings/shared_remote.h" #include "mojo/public/cpp/bindings/shared_remote.h"
...@@ -167,10 +168,10 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl ...@@ -167,10 +168,10 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl
private: private:
class Factory; class Factory;
// - |service_worker_client_request| is bound to |this| to receive // - |service_worker_client_receiver| receives OnControllerChanged()
// OnControllerChanged() notifications. // notifications.
// - |service_worker_worker_client_registry_info| is a host pointer to // - |service_worker_worker_client_registry| is used to register new
// register a new ServiceWorkerWorkerClient, which is needed when creating a // ServiceWorkerWorkerClients, which is needed when creating a
// nested worker. // nested worker.
// //
// Regarding the rest of params, see the comments on Create(). // Regarding the rest of params, see the comments on Create().
...@@ -178,10 +179,10 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl ...@@ -178,10 +179,10 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl
blink::mojom::RendererPreferences renderer_preferences, blink::mojom::RendererPreferences renderer_preferences,
mojo::PendingReceiver<blink::mojom::RendererPreferenceWatcher> mojo::PendingReceiver<blink::mojom::RendererPreferenceWatcher>
watcher_receiver, watcher_receiver,
blink::mojom::ServiceWorkerWorkerClientRequest mojo::PendingReceiver<blink::mojom::ServiceWorkerWorkerClient>
service_worker_client_request, service_worker_client_receiver,
blink::mojom::ServiceWorkerWorkerClientRegistryPtrInfo mojo::PendingRemote<blink::mojom::ServiceWorkerWorkerClientRegistry>
service_worker_worker_client_registry_info, service_worker_worker_client_registry,
mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost> mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost>
service_worker_container_host, service_worker_container_host,
std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info, std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info,
...@@ -196,10 +197,10 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl ...@@ -196,10 +197,10 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl
~WebWorkerFetchContextImpl() override; ~WebWorkerFetchContextImpl() override;
scoped_refptr<WebWorkerFetchContextImpl> CloneForNestedWorkerInternal( scoped_refptr<WebWorkerFetchContextImpl> CloneForNestedWorkerInternal(
blink::mojom::ServiceWorkerWorkerClientRequest mojo::PendingReceiver<blink::mojom::ServiceWorkerWorkerClient>
service_worker_client_request, service_worker_client_receiver,
blink::mojom::ServiceWorkerWorkerClientRegistryPtrInfo mojo::PendingRemote<blink::mojom::ServiceWorkerWorkerClientRegistry>
service_worker_worker_client_registry_ptr_info, service_worker_worker_client_registry,
mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost> mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost>
service_worker_container_host, service_worker_container_host,
std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info, std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info,
...@@ -218,18 +219,19 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl ...@@ -218,18 +219,19 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl
// Implements blink::mojom::RendererPreferenceWatcher. // Implements blink::mojom::RendererPreferenceWatcher.
void NotifyUpdate(blink::mojom::RendererPreferencesPtr new_prefs) override; void NotifyUpdate(blink::mojom::RendererPreferencesPtr new_prefs) override;
// |binding_| and |service_worker_worker_client_registry_| may be null if this // |receiver_| and |service_worker_worker_client_registry_| may be null if
// context can't use service workers. See comments for Create(). // this context can't use service workers. See comments for Create().
mojo::Binding<blink::mojom::ServiceWorkerWorkerClient> binding_; mojo::Receiver<blink::mojom::ServiceWorkerWorkerClient> receiver_{this};
blink::mojom::ServiceWorkerWorkerClientRegistryPtr mojo::Remote<blink::mojom::ServiceWorkerWorkerClientRegistry>
service_worker_worker_client_registry_; service_worker_worker_client_registry_;
// Bound to |this| on the worker thread. // Bound to |this| on the worker thread.
blink::mojom::ServiceWorkerWorkerClientRequest service_worker_client_request_; mojo::PendingReceiver<blink::mojom::ServiceWorkerWorkerClient>
service_worker_client_receiver_;
// Consumed on the worker thread to create // Consumed on the worker thread to create
// |service_worker_worker_client_registry_|. // |service_worker_worker_client_registry_|.
blink::mojom::ServiceWorkerWorkerClientRegistryPtrInfo mojo::PendingRemote<blink::mojom::ServiceWorkerWorkerClientRegistry>
service_worker_worker_client_registry_info_; pending_service_worker_worker_client_registry_;
// Consumed on the worker thread to create |service_worker_container_host_|. // Consumed on the worker thread to create |service_worker_container_host_|.
mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost> mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost>
pending_service_worker_container_host_; pending_service_worker_container_host_;
......
...@@ -183,18 +183,22 @@ void ServiceWorkerProviderContext::SetWebServiceWorkerProvider( ...@@ -183,18 +183,22 @@ void ServiceWorkerProviderContext::SetWebServiceWorkerProvider(
} }
void ServiceWorkerProviderContext::RegisterWorkerClient( void ServiceWorkerProviderContext::RegisterWorkerClient(
blink::mojom::ServiceWorkerWorkerClientPtr client) { mojo::PendingRemote<blink::mojom::ServiceWorkerWorkerClient>
pending_client) {
DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
client.set_connection_error_handler(base::BindOnce( mojo::Remote<blink::mojom::ServiceWorkerWorkerClient> client(
std::move(pending_client));
client.set_disconnect_handler(base::BindOnce(
&ServiceWorkerProviderContext::UnregisterWorkerFetchContext, &ServiceWorkerProviderContext::UnregisterWorkerFetchContext,
base::Unretained(this), client.get())); base::Unretained(this), client.get()));
worker_clients_.push_back(std::move(client)); worker_clients_.push_back(std::move(client));
} }
void ServiceWorkerProviderContext::CloneWorkerClientRegistry( void ServiceWorkerProviderContext::CloneWorkerClientRegistry(
blink::mojom::ServiceWorkerWorkerClientRegistryRequest request) { mojo::PendingReceiver<blink::mojom::ServiceWorkerWorkerClientRegistry>
receiver) {
DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
worker_client_registry_bindings_.AddBinding(this, std::move(request)); worker_client_registry_receivers_.Add(this, std::move(receiver));
} }
mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost> mojo::PendingRemote<blink::mojom::ServiceWorkerContainerHost>
...@@ -254,9 +258,8 @@ void ServiceWorkerProviderContext::UnregisterWorkerFetchContext( ...@@ -254,9 +258,8 @@ void ServiceWorkerProviderContext::UnregisterWorkerFetchContext(
DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
base::EraseIf( base::EraseIf(
worker_clients_, worker_clients_,
[client](const blink::mojom::ServiceWorkerWorkerClientPtr& client_ptr) { [client](const mojo::Remote<blink::mojom::ServiceWorkerWorkerClient>&
return client_ptr.get() == client; remote_client) { return remote_client.get() == client; });
});
} }
void ServiceWorkerProviderContext::SetController( void ServiceWorkerProviderContext::SetController(
......
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h" #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h" #include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h" #include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom.h" #include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom.h"
...@@ -141,9 +142,11 @@ class CONTENT_EXPORT ServiceWorkerProviderContext ...@@ -141,9 +142,11 @@ class CONTENT_EXPORT ServiceWorkerProviderContext
// blink::mojom::ServiceWorkerWorkerClientRegistry: // blink::mojom::ServiceWorkerWorkerClientRegistry:
void RegisterWorkerClient( void RegisterWorkerClient(
blink::mojom::ServiceWorkerWorkerClientPtr client) override; mojo::PendingRemote<blink::mojom::ServiceWorkerWorkerClient>
pending_client) override;
void CloneWorkerClientRegistry( void CloneWorkerClientRegistry(
blink::mojom::ServiceWorkerWorkerClientRegistryRequest request) override; mojo::PendingReceiver<blink::mojom::ServiceWorkerWorkerClientRegistry>
receiver) override;
// Returns a remote to this context's container host. This can return null // Returns a remote to this context's container host. This can return null
// after OnNetworkProviderDestroyed() is called (in which case |this| will be // after OnNetworkProviderDestroyed() is called (in which case |this| will be
...@@ -274,18 +277,19 @@ class CONTENT_EXPORT ServiceWorkerProviderContext ...@@ -274,18 +277,19 @@ class CONTENT_EXPORT ServiceWorkerProviderContext
// and therefore doesn't support navigator.serviceWorker. // and therefore doesn't support navigator.serviceWorker.
base::WeakPtr<WebServiceWorkerProviderImpl> web_service_worker_provider_; base::WeakPtr<WebServiceWorkerProviderImpl> web_service_worker_provider_;
// Keeps ServiceWorkerWorkerClient pointers of dedicated or shared workers // Remotes for dedicated or shared workers which are associated with the
// which are associated with the ServiceWorkerProviderContext. // ServiceWorkerProviderContext.
// - If this ServiceWorkerProviderContext is for a Document, then // - If this ServiceWorkerProviderContext is for a Document, then
// |worker_clients| contains all its dedicated workers. // |worker_clients| contains all its dedicated workers.
// - If this ServiceWorkerProviderContext is for a SharedWorker (technically // - If this ServiceWorkerProviderContext is for a SharedWorker (technically
// speaking, for its shadow page), then |worker_clients| has one element: // speaking, for its shadow page), then |worker_clients| has one element:
// the shared worker. // the shared worker.
std::vector<blink::mojom::ServiceWorkerWorkerClientPtr> worker_clients_; std::vector<mojo::Remote<blink::mojom::ServiceWorkerWorkerClient>>
worker_clients_;
// For adding new ServiceWorkerWorkerClients. // For adding new ServiceWorkerWorkerClients.
mojo::BindingSet<blink::mojom::ServiceWorkerWorkerClientRegistry> mojo::ReceiverSet<blink::mojom::ServiceWorkerWorkerClientRegistry>
worker_client_registry_bindings_; worker_client_registry_receivers_;
// Used in |subresource_loader_factory_| to get the connection to the // Used in |subresource_loader_factory_| to get the connection to the
// controller service worker. // controller service worker.
......
...@@ -77,8 +77,9 @@ interface ServiceWorkerWorkerClient { ...@@ -77,8 +77,9 @@ interface ServiceWorkerWorkerClient {
// nested workers. // nested workers.
interface ServiceWorkerWorkerClientRegistry { interface ServiceWorkerWorkerClientRegistry {
// Adds a new ServiceWorkerWorkerClient. // Adds a new ServiceWorkerWorkerClient.
RegisterWorkerClient(ServiceWorkerWorkerClient client); RegisterWorkerClient(pending_remote<ServiceWorkerWorkerClient> client);
// Clones this host. // Clones this host.
CloneWorkerClientRegistry(ServiceWorkerWorkerClientRegistry& host); CloneWorkerClientRegistry(
pending_receiver<ServiceWorkerWorkerClientRegistry> host);
}; };
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