OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" | 5 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/child/scoped_child_process_reference.h" | 10 #include "content/child/scoped_child_process_reference.h" |
11 #include "content/common/service_worker/embedded_worker_messages.h" | 11 #include "content/common/service_worker/embedded_worker_messages.h" |
12 #include "content/public/common/content_client.h" | 12 #include "content/public/common/content_client.h" |
13 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h" | 13 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h" |
14 #include "content/renderer/service_worker/service_worker_context_client.h" | 14 #include "content/renderer/service_worker/service_worker_context_client.h" |
15 #include "services/service_manager/public/cpp/interface_registry.h" | |
16 #include "third_party/WebKit/public/web/WebEmbeddedWorker.h" | 15 #include "third_party/WebKit/public/web/WebEmbeddedWorker.h" |
17 #include "third_party/WebKit/public/web/WebEmbeddedWorkerStartData.h" | 16 #include "third_party/WebKit/public/web/WebEmbeddedWorkerStartData.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 // static | 20 // static |
22 void EmbeddedWorkerInstanceClientImpl::Create( | 21 void EmbeddedWorkerInstanceClientImpl::Create( |
23 EmbeddedWorkerDispatcher* dispatcher, | 22 EmbeddedWorkerDispatcher* dispatcher, |
24 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request) { | 23 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request) { |
25 // This won't be leaked because the lifetime will be managed internally. | 24 // This won't be leaked because the lifetime will be managed internally. |
26 new EmbeddedWorkerInstanceClientImpl(dispatcher, std::move(request)); | 25 new EmbeddedWorkerInstanceClientImpl(dispatcher, std::move(request)); |
27 } | 26 } |
28 | 27 |
29 void EmbeddedWorkerInstanceClientImpl::ExposeInterfacesToBrowser( | |
30 service_manager::InterfaceRegistry* interface_registry) { | |
31 DCHECK(renderer_request_.is_pending()); | |
32 interface_registry->Bind( | |
33 std::move(renderer_request_), service_manager::Identity(), | |
34 service_manager::InterfaceProviderSpec(), service_manager::Identity(), | |
35 service_manager::InterfaceProviderSpec()); | |
36 } | |
37 | |
38 void EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted() { | 28 void EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted() { |
39 DCHECK(embedded_worker_id_); | 29 DCHECK(embedded_worker_id_); |
40 DCHECK(stop_callback_); | 30 DCHECK(stop_callback_); |
41 dispatcher_->UnregisterWorker(embedded_worker_id_.value()); | 31 dispatcher_->UnregisterWorker(embedded_worker_id_.value()); |
42 embedded_worker_id_.reset(); | 32 embedded_worker_id_.reset(); |
43 stop_callback_.Run(); | 33 stop_callback_.Run(); |
44 TRACE_EVENT0("ServiceWorker", | 34 TRACE_EVENT0("ServiceWorker", |
45 "EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted"); | 35 "EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted"); |
46 stop_callback_.Reset(); | 36 stop_callback_.Reset(); |
47 wrapper_ = nullptr; | 37 wrapper_ = nullptr; |
48 } | 38 } |
49 | 39 |
50 void EmbeddedWorkerInstanceClientImpl::StartWorker( | 40 void EmbeddedWorkerInstanceClientImpl::StartWorker( |
51 const EmbeddedWorkerStartParams& params, | 41 const EmbeddedWorkerStartParams& params, |
52 service_manager::mojom::InterfaceProviderPtr browser_interfaces, | 42 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request) { |
53 service_manager::mojom::InterfaceProviderRequest renderer_request) { | |
54 DCHECK(ChildThreadImpl::current()); | 43 DCHECK(ChildThreadImpl::current()); |
55 DCHECK(!wrapper_); | 44 DCHECK(!wrapper_); |
56 TRACE_EVENT0("ServiceWorker", | 45 TRACE_EVENT0("ServiceWorker", |
57 "EmbeddedWorkerInstanceClientImpl::StartWorker"); | 46 "EmbeddedWorkerInstanceClientImpl::StartWorker"); |
58 embedded_worker_id_ = params.embedded_worker_id; | 47 embedded_worker_id_ = params.embedded_worker_id; |
59 remote_interfaces_.Bind(std::move(browser_interfaces)); | |
60 renderer_request_ = std::move(renderer_request); | |
61 | 48 |
62 std::unique_ptr<EmbeddedWorkerDispatcher::WorkerWrapper> wrapper = | 49 std::unique_ptr<EmbeddedWorkerDispatcher::WorkerWrapper> wrapper = |
63 dispatcher_->StartWorkerContext( | 50 dispatcher_->StartWorkerContext( |
64 params, base::MakeUnique<ServiceWorkerContextClient>( | 51 params, |
65 params.embedded_worker_id, | 52 base::MakeUnique<ServiceWorkerContextClient>( |
66 params.service_worker_version_id, params.scope, | 53 params.embedded_worker_id, params.service_worker_version_id, |
67 params.script_url, params.worker_devtools_agent_route_id, | 54 params.scope, params.script_url, |
68 std::move(temporal_self_))); | 55 params.worker_devtools_agent_route_id, |
| 56 std::move(dispatcher_request), std::move(temporal_self_))); |
69 wrapper_ = wrapper.get(); | 57 wrapper_ = wrapper.get(); |
70 dispatcher_->RegisterWorker(params.embedded_worker_id, std::move(wrapper)); | 58 dispatcher_->RegisterWorker(params.embedded_worker_id, std::move(wrapper)); |
71 } | 59 } |
72 | 60 |
73 void EmbeddedWorkerInstanceClientImpl::StopWorker( | 61 void EmbeddedWorkerInstanceClientImpl::StopWorker( |
74 const StopWorkerCallback& callback) { | 62 const StopWorkerCallback& callback) { |
75 DCHECK(ChildThreadImpl::current()); | 63 DCHECK(ChildThreadImpl::current()); |
76 DCHECK(embedded_worker_id_); | 64 DCHECK(embedded_worker_id_); |
77 // StopWorker is possible to be called twice or before StartWorker(). | 65 // StopWorker is possible to be called twice or before StartWorker(). |
78 if (stop_callback_ || !wrapper_) | 66 if (stop_callback_ || !wrapper_) |
(...skipping 16 matching lines...) Expand all Loading... |
95 } | 83 } |
96 | 84 |
97 EmbeddedWorkerInstanceClientImpl::~EmbeddedWorkerInstanceClientImpl() {} | 85 EmbeddedWorkerInstanceClientImpl::~EmbeddedWorkerInstanceClientImpl() {} |
98 | 86 |
99 void EmbeddedWorkerInstanceClientImpl::OnError() { | 87 void EmbeddedWorkerInstanceClientImpl::OnError() { |
100 // Removes myself if it's owned by myself. | 88 // Removes myself if it's owned by myself. |
101 temporal_self_.reset(); | 89 temporal_self_.reset(); |
102 } | 90 } |
103 | 91 |
104 } // namespace content | 92 } // namespace content |
OLD | NEW |