Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3472)

Unified Diff: content/renderer/service_worker/embedded_worker_instance_client_impl.h

Issue 2313653002: ServiceWorker: Exchange InterfaceProviders when starting worker thread (Closed)
Patch Set: Indent Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/service_worker/embedded_worker_instance_client_impl.h
diff --git a/content/renderer/service_worker/embedded_worker_instance_client_impl.h b/content/renderer/service_worker/embedded_worker_instance_client_impl.h
index 64d163fe24886f1686f58118c265f9b5c3a1ccf7..979af728bf1f5b80d2142b362fa82b5fb90dbd87 100644
--- a/content/renderer/service_worker/embedded_worker_instance_client_impl.h
+++ b/content/renderer/service_worker/embedded_worker_instance_client_impl.h
@@ -5,11 +5,14 @@
#ifndef CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_CLIENT_IMPL_H_
#define CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_CLIENT_IMPL_H_
+#include "base/bind.h"
#include "base/id_map.h"
#include "base/optional.h"
#include "content/common/service_worker/embedded_worker.mojom.h"
#include "content/renderer/service_worker/embedded_worker_dispatcher.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+#include "services/shell/public/cpp/interface_provider.h"
namespace content {
@@ -25,20 +28,37 @@ class EmbeddedWorkerInstanceClientImpl
mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request);
~EmbeddedWorkerInstanceClientImpl() override;
+ // If you call this method on a different thread from the main thread, this
+ // method will use PostTask to the main thread. |callback| will be invoked
+ // on the same thread with the caller of this method after
+ // |ptr| is bound to a remote interface.
+ template <typename Interface>
+ void GetInterfaceOnMainThread(mojo::InterfaceRequest<Interface> request,
+ const base::Closure& callback);
+
// Called from ServiceWorkerContextClient. Must call on the main thread.
void StopWorkerCompleted();
private:
// Implementation of mojo interface
- void StartWorker(mojom::EmbeddedWorkerStartWorkerParamsPtr params) override;
+ void StartWorker(
+ mojom::EmbeddedWorkerStartWorkerParamsPtr params,
+ shell::mojom::InterfaceProviderPtr remote_interfaces) override;
void StopWorker(const StopWorkerCallback& callback) override;
// Handler of connection error bound to |binding_|
void OnError();
+ // This method should be called on the main thread.
+ template <typename Interface>
+ void GetInterface(mojo::InterfaceRequest<Interface> request);
+
+ base::WeakPtr<EmbeddedWorkerInstanceClientImpl> AsWeakPtr();
+
EmbeddedWorkerDispatcher* dispatcher_;
- // This object will be bound to the main thread.
+ // These objects are bound to the main thread.
mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_;
+ shell::InterfaceProvider remote_interfaces_;
// This is valid before StartWorker is called. After that, this object
// will be passed to ServiceWorkerContextClient.
@@ -47,11 +67,39 @@ class EmbeddedWorkerInstanceClientImpl
base::Optional<int> embedded_worker_id_;
EmbeddedWorkerDispatcher::WorkerWrapper* wrapper_;
+ // For cross thread
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
+
// Stores callbacks
StopWorkerCallback stop_callback_;
+ base::WeakPtrFactory<EmbeddedWorkerInstanceClientImpl> weak_factory;
+
DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceClientImpl);
};
+template <typename Interface>
+void EmbeddedWorkerInstanceClientImpl::GetInterfaceOnMainThread(
nhiroki 2016/09/06 01:38:05 Do we really need to make this thread-safe? At lea
shimazu 2016/09/21 07:00:51 Done.
+ mojo::InterfaceRequest<Interface> request,
+ const base::Closure& callback) {
+ if (!main_thread_task_runner_->BelongsToCurrentThread()) {
+ main_thread_task_runner_->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&EmbeddedWorkerInstanceClientImpl::GetInterface<Interface>,
+ AsWeakPtr(), base::Passed(&request)),
+ callback);
+ return;
+ }
+ GetInterface(std::move(request));
+ if (callback)
+ callback.Run();
+}
+
+template <typename Interface>
+void EmbeddedWorkerInstanceClientImpl::GetInterface(
+ mojo::InterfaceRequest<Interface> request) {
+ remote_interfaces_.GetInterface(std::move(request));
+}
+
} // namespace content
#endif //

Powered by Google App Engine
This is Rietveld 408576698