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_manager.h" | 5 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
6 | 6 |
7 #include "content/browser/devtools/devtools_manager_impl.h" | 7 #include "content/browser/devtools/devtools_manager_impl.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" | 9 #include "content/browser/devtools/devtools_protocol_constants.h" |
10 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 10 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 171 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
172 int worker_process_id, | 172 int worker_process_id, |
173 int worker_route_id) { | 173 int worker_route_id) { |
174 WorkerId id(worker_process_id, worker_route_id); | 174 WorkerId id(worker_process_id, worker_route_id); |
175 | 175 |
176 WorkerInfoMap::iterator it = workers_.find(id); | 176 WorkerInfoMap::iterator it = workers_.find(id); |
177 if (it == workers_.end()) | 177 if (it == workers_.end()) |
178 return NULL; | 178 return NULL; |
179 | 179 |
180 WorkerInfo* info = it->second; | 180 WorkerInfo* info = it->second; |
181 if (info->state() != WORKER_UNINSPECTED) | 181 if (info->state() != WORKER_UNINSPECTED && |
182 info->state() != WORKER_PAUSED_FOR_DEBUG_ON_START) { | |
182 return info->agent_host(); | 183 return info->agent_host(); |
184 } | |
183 | 185 |
184 EmbeddedWorkerDevToolsAgentHost* agent_host = | 186 EmbeddedWorkerDevToolsAgentHost* agent_host = |
185 new EmbeddedWorkerDevToolsAgentHost(id); | 187 new EmbeddedWorkerDevToolsAgentHost(id); |
186 info->set_agent_host(agent_host); | 188 info->set_agent_host(agent_host); |
187 info->set_state(WORKER_INSPECTED); | 189 info->set_state(WORKER_INSPECTED); |
188 return agent_host; | 190 return agent_host; |
189 } | 191 } |
190 | 192 |
191 DevToolsAgentHost* | 193 DevToolsAgentHost* |
192 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( | 194 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( |
193 const ServiceWorkerIdentifier& service_worker_id) { | 195 const ServiceWorkerIdentifier& service_worker_id) { |
194 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 196 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); |
195 if (it == workers_.end()) | 197 if (it == workers_.end()) |
196 return NULL; | 198 return NULL; |
197 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); | 199 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); |
198 } | 200 } |
199 | 201 |
200 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { | 202 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() |
203 : debug_service_worker_on_start_(false) { | |
201 } | 204 } |
202 | 205 |
203 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { | 206 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { |
204 } | 207 } |
205 | 208 |
206 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( | 209 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( |
207 int worker_process_id, | 210 int worker_process_id, |
208 int worker_route_id, | 211 int worker_route_id, |
209 const SharedWorkerInstance& instance) { | 212 const SharedWorkerInstance& instance) { |
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 10 matching lines...) Expand all Loading... | |
221 | 224 |
222 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( | 225 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( |
223 int worker_process_id, | 226 int worker_process_id, |
224 int worker_route_id, | 227 int worker_route_id, |
225 const ServiceWorkerIdentifier& service_worker_id) { | 228 const ServiceWorkerIdentifier& service_worker_id) { |
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
227 const WorkerId id(worker_process_id, worker_route_id); | 230 const WorkerId id(worker_process_id, worker_route_id); |
228 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 231 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); |
229 if (it == workers_.end()) { | 232 if (it == workers_.end()) { |
230 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); | 233 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); |
234 if (debug_service_worker_on_start_) | |
235 info->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START); | |
231 workers_.set(id, info.Pass()); | 236 workers_.set(id, info.Pass()); |
232 return false; | 237 return debug_service_worker_on_start_; |
233 } | 238 } |
234 MoveToPausedState(id, it); | 239 MoveToPausedState(id, it); |
235 return true; | 240 return true; |
236 } | 241 } |
237 | 242 |
238 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 243 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
239 int worker_route_id) { | 244 int worker_route_id) { |
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
241 const WorkerId id(worker_process_id, worker_route_id); | 246 const WorkerId id(worker_process_id, worker_route_id); |
242 WorkerInfoMap::iterator it = workers_.find(id); | 247 WorkerInfoMap::iterator it = workers_.find(id); |
(...skipping 17 matching lines...) Expand all Loading... | |
260 devtools::Worker::disconnectedFromWorker::kName, NULL) | 265 devtools::Worker::disconnectedFromWorker::kName, NULL) |
261 ->Serialize(); | 266 ->Serialize(); |
262 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 267 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
263 agent_host, notification); | 268 agent_host, notification); |
264 agent_host->DetachFromWorker(); | 269 agent_host->DetachFromWorker(); |
265 break; | 270 break; |
266 } | 271 } |
267 case WORKER_TERMINATED: | 272 case WORKER_TERMINATED: |
268 NOTREACHED(); | 273 NOTREACHED(); |
269 break; | 274 break; |
270 case WORKER_PAUSED: { | 275 case WORKER_PAUSED_FOR_DEBUG_ON_START: |
yurys
2014/05/28 10:54:53
case WORKER_PAUSED_FOR_DEBUG_ON_START: can be plac
horo
2014/05/28 11:04:17
Done.
| |
276 workers_.erase(it); | |
277 break; | |
278 case WORKER_PAUSED_FOR_REATTACH: { | |
271 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); | 279 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); |
272 worker_info->set_state(WORKER_TERMINATED); | 280 worker_info->set_state(WORKER_TERMINATED); |
273 const WorkerId old_id = worker_info->agent_host()->worker_id(); | 281 const WorkerId old_id = worker_info->agent_host()->worker_id(); |
274 workers_.set(old_id, worker_info.Pass()); | 282 workers_.set(old_id, worker_info.Pass()); |
275 break; | 283 break; |
276 } | 284 } |
277 } | 285 } |
278 } | 286 } |
279 | 287 |
280 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, | 288 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, |
281 int worker_route_id) { | 289 int worker_route_id) { |
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
283 const WorkerId id(worker_process_id, worker_route_id); | 291 const WorkerId id(worker_process_id, worker_route_id); |
284 WorkerInfoMap::iterator it = workers_.find(id); | 292 WorkerInfoMap::iterator it = workers_.find(id); |
285 DCHECK(it != workers_.end()); | 293 DCHECK(it != workers_.end()); |
286 WorkerInfo* info = it->second; | 294 WorkerInfo* info = it->second; |
287 if (info->state() != WORKER_PAUSED) | 295 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { |
288 return; | 296 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id); |
289 info->agent_host()->ReattachToWorker(id); | 297 scoped_refptr<DevToolsAgentHost> agent_host( |
290 info->set_state(WORKER_INSPECTED); | 298 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id)); |
299 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(), | |
300 agent_host.get()); | |
301 } else if (info->state() == WORKER_PAUSED_FOR_REATTACH) { | |
302 info->agent_host()->ReattachToWorker(id); | |
303 info->set_state(WORKER_INSPECTED); | |
304 } | |
291 } | 305 } |
292 | 306 |
293 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( | 307 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( |
294 EmbeddedWorkerDevToolsAgentHost* agent_host) { | 308 EmbeddedWorkerDevToolsAgentHost* agent_host) { |
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
296 const WorkerId id(agent_host->worker_id()); | 310 const WorkerId id(agent_host->worker_id()); |
297 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id); | 311 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id); |
298 if (worker_info) { | 312 if (worker_info) { |
299 DCHECK_EQ(WORKER_TERMINATED, worker_info->state()); | 313 DCHECK_EQ(WORKER_TERMINATED, worker_info->state()); |
300 return; | 314 return; |
301 } | 315 } |
302 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); | 316 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); |
303 ++it) { | 317 ++it) { |
304 if (it->second->agent_host() == agent_host) { | 318 if (it->second->agent_host() == agent_host) { |
305 DCHECK_EQ(WORKER_PAUSED, it->second->state()); | 319 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state()); |
306 SendMessageToWorker( | 320 SendMessageToWorker( |
307 it->first, | 321 it->first, |
308 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); | 322 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); |
309 it->second->set_agent_host(NULL); | 323 it->second->set_agent_host(NULL); |
310 it->second->set_state(WORKER_UNINSPECTED); | 324 it->second->set_state(WORKER_UNINSPECTED); |
311 return; | 325 return; |
312 } | 326 } |
313 } | 327 } |
314 } | 328 } |
315 | 329 |
(...skipping 17 matching lines...) Expand all Loading... | |
333 break; | 347 break; |
334 } | 348 } |
335 return it; | 349 return it; |
336 } | 350 } |
337 | 351 |
338 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 352 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
339 const WorkerId& id, | 353 const WorkerId& id, |
340 const WorkerInfoMap::iterator& it) { | 354 const WorkerInfoMap::iterator& it) { |
341 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 355 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
342 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 356 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
343 info->set_state(WORKER_PAUSED); | 357 info->set_state(WORKER_PAUSED_FOR_REATTACH); |
344 workers_.set(id, info.Pass()); | 358 workers_.set(id, info.Pass()); |
345 } | 359 } |
346 | 360 |
347 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 361 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
348 workers_.clear(); | 362 workers_.clear(); |
349 } | 363 } |
350 | 364 |
351 } // namespace content | 365 } // namespace content |
OLD | NEW |