OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/devtools/embedded_worker_devtools_agent_host.h" | 5 #include "content/browser/devtools/embedded_worker_devtools_agent_host.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/devtools/devtools_protocol.h" | 8 #include "content/browser/devtools/devtools_protocol.h" |
9 #include "content/browser/devtools/devtools_protocol_constants.h" | |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
11 #include "content/browser/service_worker/service_worker_version.h" | 10 #include "content/browser/service_worker/service_worker_version.h" |
12 #include "content/browser/shared_worker/shared_worker_service_impl.h" | 11 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
13 #include "content/common/devtools_messages.h" | 12 #include "content/common/devtools_messages.h" |
14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 | 17 |
19 namespace { | 18 namespace { |
(...skipping 17 matching lines...) Expand all Loading... | |
37 } | 36 } |
38 | 37 |
39 } | 38 } |
40 | 39 |
41 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( | 40 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( |
42 WorkerId worker_id, | 41 WorkerId worker_id, |
43 const SharedWorkerInstance& shared_worker) | 42 const SharedWorkerInstance& shared_worker) |
44 : shared_worker_(new SharedWorkerInstance(shared_worker)), | 43 : shared_worker_(new SharedWorkerInstance(shared_worker)), |
45 state_(WORKER_UNINSPECTED), | 44 state_(WORKER_UNINSPECTED), |
46 worker_id_(worker_id) { | 45 worker_id_(worker_id) { |
46 InitWorkerDomainClient(); | |
47 WorkerCreated(); | 47 WorkerCreated(); |
48 } | 48 } |
49 | 49 |
50 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( | 50 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( |
51 WorkerId worker_id, | 51 WorkerId worker_id, |
52 const ServiceWorkerIdentifier& service_worker, | 52 const ServiceWorkerIdentifier& service_worker, |
53 bool debug_service_worker_on_start) | 53 bool debug_service_worker_on_start) |
54 : service_worker_(new ServiceWorkerIdentifier(service_worker)), | 54 : service_worker_(new ServiceWorkerIdentifier(service_worker)), |
55 state_(WORKER_UNINSPECTED), | 55 state_(WORKER_UNINSPECTED), |
56 worker_id_(worker_id) { | 56 worker_id_(worker_id) { |
57 if (debug_service_worker_on_start) | 57 if (debug_service_worker_on_start) |
58 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START; | 58 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START; |
59 InitWorkerDomainClient(); | |
59 WorkerCreated(); | 60 WorkerCreated(); |
60 } | 61 } |
61 | 62 |
63 void EmbeddedWorkerDevToolsAgentHost::InitWorkerDomainClient() { | |
64 worker_domain_client_.reset(new devtools::worker::Client( | |
65 base::Bind(&EmbeddedWorkerDevToolsAgentHost::SendMessageToClient, | |
66 base::Unretained(this)))); | |
67 } | |
68 | |
62 bool EmbeddedWorkerDevToolsAgentHost::IsWorker() const { | 69 bool EmbeddedWorkerDevToolsAgentHost::IsWorker() const { |
63 return true; | 70 return true; |
64 } | 71 } |
65 | 72 |
66 DevToolsAgentHost::Type EmbeddedWorkerDevToolsAgentHost::GetType() { | 73 DevToolsAgentHost::Type EmbeddedWorkerDevToolsAgentHost::GetType() { |
67 return shared_worker_ ? TYPE_SHARED_WORKER : TYPE_SERVICE_WORKER; | 74 return shared_worker_ ? TYPE_SHARED_WORKER : TYPE_SERVICE_WORKER; |
68 } | 75 } |
69 | 76 |
70 std::string EmbeddedWorkerDevToolsAgentHost::GetTitle() { | 77 std::string EmbeddedWorkerDevToolsAgentHost::GetTitle() { |
71 if (shared_worker_ && shared_worker_->name().length()) | 78 if (shared_worker_ && shared_worker_->name().length()) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; | 171 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; |
165 worker_id_ = worker_id; | 172 worker_id_ = worker_id; |
166 WorkerCreated(); | 173 WorkerCreated(); |
167 } | 174 } |
168 | 175 |
169 void EmbeddedWorkerDevToolsAgentHost::WorkerDestroyed() { | 176 void EmbeddedWorkerDevToolsAgentHost::WorkerDestroyed() { |
170 DCHECK_NE(WORKER_TERMINATED, state_); | 177 DCHECK_NE(WORKER_TERMINATED, state_); |
171 if (state_ == WORKER_INSPECTED) { | 178 if (state_ == WORKER_INSPECTED) { |
172 DCHECK(IsAttached()); | 179 DCHECK(IsAttached()); |
173 // Client host is debugging this worker agent host. | 180 // Client host is debugging this worker agent host. |
174 std::string notification = | 181 worker_domain_client_->DisconnectedFromWorker( |
dgozman
2014/11/20 14:38:07
Let's create worker domain client right here to lo
vkuzkokov
2014/11/20 15:05:07
Done.
| |
175 DevToolsProtocol::CreateNotification( | 182 devtools::worker::DisconnectedFromWorkerParams::Create()); |
176 devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); | |
177 SendMessageToClient(notification); | |
178 DetachFromWorker(); | 183 DetachFromWorker(); |
179 } | 184 } |
180 state_ = WORKER_TERMINATED; | 185 state_ = WORKER_TERMINATED; |
181 Release(); // Balanced in WorkerCreated() | 186 Release(); // Balanced in WorkerCreated() |
182 } | 187 } |
183 | 188 |
184 bool EmbeddedWorkerDevToolsAgentHost::Matches( | 189 bool EmbeddedWorkerDevToolsAgentHost::Matches( |
185 const SharedWorkerInstance& other) { | 190 const SharedWorkerInstance& other) { |
186 return shared_worker_ && shared_worker_->Matches(other); | 191 return shared_worker_ && shared_worker_->Matches(other); |
187 } | 192 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 | 228 |
224 ProcessChunkedMessageFromAgent(message, total_size); | 229 ProcessChunkedMessageFromAgent(message, total_size); |
225 } | 230 } |
226 | 231 |
227 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( | 232 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( |
228 const std::string& state) { | 233 const std::string& state) { |
229 saved_agent_state_ = state; | 234 saved_agent_state_ = state; |
230 } | 235 } |
231 | 236 |
232 } // namespace content | 237 } // namespace content |
OLD | NEW |