| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/debugger/worker_devtools_manager.h" | 5 #include "content/browser/debugger/worker_devtools_manager.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/tuple.h" | 10 #include "base/bind.h" |
| 11 #include "content/browser/debugger/devtools_agent_host.h" | 11 #include "content/browser/debugger/devtools_agent_host.h" |
| 12 #include "content/browser/debugger/devtools_manager.h" | 12 #include "content/browser/debugger/devtools_manager.h" |
| 13 #include "content/browser/debugger/worker_devtools_message_filter.h" | 13 #include "content/browser/debugger/worker_devtools_message_filter.h" |
| 14 #include "content/browser/worker_host/worker_process_host.h" | 14 #include "content/browser/worker_host/worker_process_host.h" |
| 15 #include "content/browser/worker_host/worker_service.h" | 15 #include "content/browser/worker_host/worker_service.h" |
| 16 #include "content/common/devtools_messages.h" | 16 #include "content/common/devtools_messages.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 class WorkerDevToolsManager::WorkerDevToolsAgentHost | 89 class WorkerDevToolsManager::WorkerDevToolsAgentHost |
| 90 : public DevToolsAgentHost { | 90 : public DevToolsAgentHost { |
| 91 public: | 91 public: |
| 92 explicit WorkerDevToolsAgentHost(WorkerId worker_id) | 92 explicit WorkerDevToolsAgentHost(WorkerId worker_id) |
| 93 : worker_id_(worker_id) { | 93 : worker_id_(worker_id) { |
| 94 AgentHosts::Add(worker_id, this); | 94 AgentHosts::Add(worker_id, this); |
| 95 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
| 96 BrowserThread::IO, | 96 BrowserThread::IO, |
| 97 FROM_HERE, | 97 FROM_HERE, |
| 98 NewRunnableFunction( | 98 base::Bind( |
| 99 &RegisterAgent, | 99 &RegisterAgent, |
| 100 worker_id.first, | 100 worker_id.first, |
| 101 worker_id.second)); | 101 worker_id.second)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void WorkerDestroyed() { | 104 void WorkerDestroyed() { |
| 105 NotifyCloseListener(); | 105 NotifyCloseListener(); |
| 106 delete this; | 106 delete this; |
| 107 } | 107 } |
| 108 | 108 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 int worker_route_id, | 123 int worker_route_id, |
| 124 const IPC::Message& message) { | 124 const IPC::Message& message) { |
| 125 WorkerDevToolsManager::GetInstance()->ForwardToWorkerDevToolsAgent( | 125 WorkerDevToolsManager::GetInstance()->ForwardToWorkerDevToolsAgent( |
| 126 worker_process_id, worker_route_id, message); | 126 worker_process_id, worker_route_id, message); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // DevToolsAgentHost implementation. | 129 // DevToolsAgentHost implementation. |
| 130 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { | 130 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { |
| 131 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
| 132 BrowserThread::IO, FROM_HERE, | 132 BrowserThread::IO, FROM_HERE, |
| 133 NewRunnableFunction( | 133 base::Bind( |
| 134 &WorkerDevToolsAgentHost::ForwardToWorkerDevToolsAgent, | 134 &WorkerDevToolsAgentHost::ForwardToWorkerDevToolsAgent, |
| 135 worker_id_.first, | 135 worker_id_.first, |
| 136 worker_id_.second, | 136 worker_id_.second, |
| 137 *message)); | 137 *message)); |
| 138 } | 138 } |
| 139 virtual void NotifyClientClosing() OVERRIDE {} | 139 virtual void NotifyClientClosing() OVERRIDE {} |
| 140 virtual int GetRenderProcessId() OVERRIDE { return -1; } | 140 virtual int GetRenderProcessId() OVERRIDE { return -1; } |
| 141 | 141 |
| 142 WorkerId worker_id_; | 142 WorkerId worker_id_; |
| 143 | 143 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 agent); | 192 agent); |
| 193 worker_id_to_cookie_.erase(it); | 193 worker_id_to_cookie_.erase(it); |
| 194 if (worker_id_to_cookie_.empty()) | 194 if (worker_id_to_cookie_.empty()) |
| 195 delete this; | 195 delete this; |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 | 198 |
| 199 static void RemovePendingWorkerData(WorkerId id) { | 199 static void RemovePendingWorkerData(WorkerId id) { |
| 200 BrowserThread::PostTask( | 200 BrowserThread::PostTask( |
| 201 BrowserThread::IO, FROM_HERE, | 201 BrowserThread::IO, FROM_HERE, |
| 202 NewRunnableFunction(RemoveInspectedWorkerDataOnIOThread, id)); | 202 base::Bind(RemoveInspectedWorkerDataOnIOThread, id)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 static void RemoveInspectedWorkerDataOnIOThread(WorkerId id) { | 205 static void RemoveInspectedWorkerDataOnIOThread(WorkerId id) { |
| 206 WorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(id); | 206 WorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(id); |
| 207 } | 207 } |
| 208 | 208 |
| 209 static DetachedClientHosts* instance_; | 209 static DetachedClientHosts* instance_; |
| 210 typedef std::map<WorkerId, int> WorkerIdToCookieMap; | 210 typedef std::map<WorkerId, int> WorkerIdToCookieMap; |
| 211 WorkerIdToCookieMap worker_id_to_cookie_; | 211 WorkerIdToCookieMap worker_id_to_cookie_; |
| 212 }; | 212 }; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return; | 290 return; |
| 291 | 291 |
| 292 WorkerId worker_id(worker->id(), worker_route_id); | 292 WorkerId worker_id(worker->id(), worker_route_id); |
| 293 terminated_workers_.push_back(TerminatedInspectedWorker( | 293 terminated_workers_.push_back(TerminatedInspectedWorker( |
| 294 worker_id, | 294 worker_id, |
| 295 it->worker_url, | 295 it->worker_url, |
| 296 it->worker_name)); | 296 it->worker_name)); |
| 297 inspected_workers_.erase(it); | 297 inspected_workers_.erase(it); |
| 298 BrowserThread::PostTask( | 298 BrowserThread::PostTask( |
| 299 BrowserThread::UI, FROM_HERE, | 299 BrowserThread::UI, FROM_HERE, |
| 300 NewRunnableFunction( | 300 base::Bind(DetachedClientHosts::WorkerDestroyed, worker_id)); |
| 301 DetachedClientHosts::WorkerDestroyed, | |
| 302 worker_id)); | |
| 303 } | 301 } |
| 304 | 302 |
| 305 void WorkerDevToolsManager::WorkerContextStarted(WorkerProcessHost* process, | 303 void WorkerDevToolsManager::WorkerContextStarted(WorkerProcessHost* process, |
| 306 int worker_route_id) { | 304 int worker_route_id) { |
| 307 WorkerId new_worker_id(process->id(), worker_route_id); | 305 WorkerId new_worker_id(process->id(), worker_route_id); |
| 308 PausedWorkers::iterator it = paused_workers_.find(new_worker_id); | 306 PausedWorkers::iterator it = paused_workers_.find(new_worker_id); |
| 309 if (it == paused_workers_.end()) | 307 if (it == paused_workers_.end()) |
| 310 return; | 308 return; |
| 311 | 309 |
| 312 BrowserThread::PostTask( | 310 BrowserThread::PostTask( |
| 313 BrowserThread::UI, FROM_HERE, | 311 BrowserThread::UI, FROM_HERE, |
| 314 NewRunnableFunction( | 312 base::Bind( |
| 315 DetachedClientHosts::WorkerReloaded, | 313 DetachedClientHosts::WorkerReloaded, |
| 316 it->second, | 314 it->second, |
| 317 new_worker_id)); | 315 new_worker_id)); |
| 318 paused_workers_.erase(it); | 316 paused_workers_.erase(it); |
| 319 } | 317 } |
| 320 | 318 |
| 321 void WorkerDevToolsManager::RemoveInspectedWorkerData( | 319 void WorkerDevToolsManager::RemoveInspectedWorkerData( |
| 322 const WorkerId& id) { | 320 const WorkerId& id) { |
| 323 for (TerminatedInspectedWorkers::iterator it = terminated_workers_.begin(); | 321 for (TerminatedInspectedWorkers::iterator it = terminated_workers_.begin(); |
| 324 it != terminated_workers_.end(); ++it) { | 322 it != terminated_workers_.end(); ++it) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 int worker_process_id, | 380 int worker_process_id, |
| 383 int worker_route_id, | 381 int worker_route_id, |
| 384 const IPC::Message& message) { | 382 const IPC::Message& message) { |
| 385 if (FindInspectedWorker(worker_process_id, worker_route_id) == | 383 if (FindInspectedWorker(worker_process_id, worker_route_id) == |
| 386 inspected_workers_.end()) { | 384 inspected_workers_.end()) { |
| 387 NOTREACHED(); | 385 NOTREACHED(); |
| 388 return; | 386 return; |
| 389 } | 387 } |
| 390 BrowserThread::PostTask( | 388 BrowserThread::PostTask( |
| 391 BrowserThread::UI, FROM_HERE, | 389 BrowserThread::UI, FROM_HERE, |
| 392 NewRunnableFunction( | 390 base::Bind( |
| 393 ForwardToDevToolsClientOnUIThread, | 391 ForwardToDevToolsClientOnUIThread, |
| 394 worker_process_id, | 392 worker_process_id, |
| 395 worker_route_id, | 393 worker_route_id, |
| 396 message)); | 394 message)); |
| 397 } | 395 } |
| 398 | 396 |
| 399 void WorkerDevToolsManager::SaveAgentRuntimeState(int worker_process_id, | 397 void WorkerDevToolsManager::SaveAgentRuntimeState(int worker_process_id, |
| 400 int worker_route_id, | 398 int worker_route_id, |
| 401 const std::string& state) { | 399 const std::string& state) { |
| 402 BrowserThread::PostTask( | 400 BrowserThread::PostTask( |
| 403 BrowserThread::UI, FROM_HERE, | 401 BrowserThread::UI, FROM_HERE, |
| 404 NewRunnableFunction( | 402 base::Bind( |
| 405 SaveAgentRuntimeStateOnUIThread, | 403 SaveAgentRuntimeStateOnUIThread, |
| 406 worker_process_id, | 404 worker_process_id, |
| 407 worker_route_id, | 405 worker_route_id, |
| 408 state)); | 406 state)); |
| 409 } | 407 } |
| 410 | 408 |
| 411 void WorkerDevToolsManager::ForwardToWorkerDevToolsAgent( | 409 void WorkerDevToolsManager::ForwardToWorkerDevToolsAgent( |
| 412 int worker_process_id, | 410 int worker_process_id, |
| 413 int worker_route_id, | 411 int worker_route_id, |
| 414 const IPC::Message& message) { | 412 const IPC::Message& message) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 return; | 445 return; |
| 448 DevToolsManager::GetInstance()->SaveAgentRuntimeState(agent_host, state); | 446 DevToolsManager::GetInstance()->SaveAgentRuntimeState(agent_host, state); |
| 449 } | 447 } |
| 450 | 448 |
| 451 // static | 449 // static |
| 452 void WorkerDevToolsManager::NotifyWorkerDestroyedOnIOThread( | 450 void WorkerDevToolsManager::NotifyWorkerDestroyedOnIOThread( |
| 453 int worker_process_id, | 451 int worker_process_id, |
| 454 int worker_route_id) { | 452 int worker_route_id) { |
| 455 BrowserThread::PostTask( | 453 BrowserThread::PostTask( |
| 456 BrowserThread::UI, FROM_HERE, | 454 BrowserThread::UI, FROM_HERE, |
| 457 NewRunnableFunction( | 455 base::Bind( |
| 458 &WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread, | 456 &WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread, |
| 459 worker_process_id, | 457 worker_process_id, |
| 460 worker_route_id)); | 458 worker_route_id)); |
| 461 } | 459 } |
| 462 | 460 |
| 463 // static | 461 // static |
| 464 void WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread( | 462 void WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread( |
| 465 int worker_process_id, | 463 int worker_process_id, |
| 466 int worker_route_id) { | 464 int worker_route_id) { |
| 467 WorkerDevToolsAgentHost* host = | 465 WorkerDevToolsAgentHost* host = |
| 468 AgentHosts::GetAgentHost(WorkerId(worker_process_id, worker_route_id)); | 466 AgentHosts::GetAgentHost(WorkerId(worker_process_id, worker_route_id)); |
| 469 if (host) | 467 if (host) |
| 470 host->WorkerDestroyed(); | 468 host->WorkerDestroyed(); |
| 471 } | 469 } |
| 472 | 470 |
| 473 // static | 471 // static |
| 474 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { | 472 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { |
| 475 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) | 473 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) |
| 476 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); | 474 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); |
| 477 } | 475 } |
| 478 | 476 |
| OLD | NEW |