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/bind.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_impl.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/devtools_agent_host_registry.h" |
18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
22 #include "content/public/common/process_type.h" | 23 #include "content/public/common/process_type.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
26 | 27 |
27 using content::BrowserThread; | 28 using content::BrowserThread; |
28 | 29 |
| 30 namespace content { |
| 31 |
| 32 // Called on the UI thread. |
| 33 // static |
| 34 DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( |
| 35 int worker_process_id, |
| 36 int worker_route_id) { |
| 37 return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 38 worker_process_id, |
| 39 worker_route_id); |
| 40 } |
| 41 |
29 class WorkerDevToolsManager::AgentHosts | 42 class WorkerDevToolsManager::AgentHosts |
30 : private content::NotificationObserver { | 43 : private content::NotificationObserver { |
31 public: | 44 public: |
32 static void Add(WorkerId id, WorkerDevToolsAgentHost* host) { | 45 static void Add(WorkerId id, WorkerDevToolsAgentHost* host) { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 if (!instance_) | 47 if (!instance_) |
35 instance_ = new AgentHosts(); | 48 instance_ = new AgentHosts(); |
36 instance_->map_[id] = host; | 49 instance_->map_[id] = host; |
37 } | 50 } |
38 static void Remove(WorkerId id) { | 51 static void Remove(WorkerId id) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 RemovePendingWorkerData(old_id); | 171 RemovePendingWorkerData(old_id); |
159 } | 172 } |
160 | 173 |
161 static void WorkerDestroyed(WorkerId id) { | 174 static void WorkerDestroyed(WorkerId id) { |
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
163 WorkerDevToolsAgentHost* agent = AgentHosts::GetAgentHost(id); | 176 WorkerDevToolsAgentHost* agent = AgentHosts::GetAgentHost(id); |
164 if (!agent) { | 177 if (!agent) { |
165 RemovePendingWorkerData(id); | 178 RemovePendingWorkerData(id); |
166 return; | 179 return; |
167 } | 180 } |
168 DevToolsManager::GetInstance()->ForwardToDevToolsClient(agent, | 181 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
169 DevToolsClientMsg_DispatchOnInspectorFrontend(MSG_ROUTING_NONE, | 182 agent, |
170 WebKit::WebDevToolsAgent::disconnectEventAsText().utf8())); | 183 WebKit::WebDevToolsAgent::disconnectEventAsText().utf8()); |
171 int cookie = DevToolsManager::GetInstance()->DetachClientHost(agent); | 184 int cookie = DevToolsManagerImpl::GetInstance()->DetachClientHost(agent); |
172 if (cookie == -1) { | 185 if (cookie == -1) { |
173 RemovePendingWorkerData(id); | 186 RemovePendingWorkerData(id); |
174 return; | 187 return; |
175 } | 188 } |
176 if (!instance_) | 189 if (!instance_) |
177 new DetachedClientHosts(); | 190 new DetachedClientHosts(); |
178 instance_->worker_id_to_cookie_[id] = cookie; | 191 instance_->worker_id_to_cookie_[id] = cookie; |
179 } | 192 } |
180 | 193 |
181 private: | 194 private: |
182 DetachedClientHosts() { | 195 DetachedClientHosts() { |
183 instance_ = this; | 196 instance_ = this; |
184 } | 197 } |
185 ~DetachedClientHosts() { | 198 ~DetachedClientHosts() { |
186 instance_ = NULL; | 199 instance_ = NULL; |
187 } | 200 } |
188 | 201 |
189 bool ReattachClient(WorkerId old_id, WorkerId new_id) { | 202 bool ReattachClient(WorkerId old_id, WorkerId new_id) { |
190 WorkerIdToCookieMap::iterator it = worker_id_to_cookie_.find(old_id); | 203 WorkerIdToCookieMap::iterator it = worker_id_to_cookie_.find(old_id); |
191 if (it == worker_id_to_cookie_.end()) | 204 if (it == worker_id_to_cookie_.end()) |
192 return false; | 205 return false; |
193 DevToolsAgentHost* agent = | 206 DevToolsAgentHost* agent = |
194 WorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 207 WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
195 new_id.first, | 208 new_id.first, |
196 new_id.second); | 209 new_id.second); |
197 DevToolsManager::GetInstance()->AttachClientHost( | 210 DevToolsManagerImpl::GetInstance()->AttachClientHost( |
198 it->second, | 211 it->second, |
199 agent); | 212 agent); |
200 worker_id_to_cookie_.erase(it); | 213 worker_id_to_cookie_.erase(it); |
201 if (worker_id_to_cookie_.empty()) | 214 if (worker_id_to_cookie_.empty()) |
202 delete this; | 215 delete this; |
203 return true; | 216 return true; |
204 } | 217 } |
205 | 218 |
206 static void RemovePendingWorkerData(WorkerId id) { | 219 static void RemovePendingWorkerData(WorkerId id) { |
207 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 return; | 392 return; |
380 } | 393 } |
381 } | 394 } |
382 } | 395 } |
383 NotifyWorkerDestroyedOnIOThread(worker_process_id, worker_route_id); | 396 NotifyWorkerDestroyedOnIOThread(worker_process_id, worker_route_id); |
384 } | 397 } |
385 | 398 |
386 void WorkerDevToolsManager::ForwardToDevToolsClient( | 399 void WorkerDevToolsManager::ForwardToDevToolsClient( |
387 int worker_process_id, | 400 int worker_process_id, |
388 int worker_route_id, | 401 int worker_route_id, |
389 const IPC::Message& message) { | 402 const std::string& message) { |
390 if (FindInspectedWorker(worker_process_id, worker_route_id) == | 403 if (FindInspectedWorker(worker_process_id, worker_route_id) == |
391 inspected_workers_.end()) { | 404 inspected_workers_.end()) { |
392 NOTREACHED(); | 405 NOTREACHED(); |
393 return; | 406 return; |
394 } | 407 } |
395 BrowserThread::PostTask( | 408 BrowserThread::PostTask( |
396 BrowserThread::UI, FROM_HERE, | 409 BrowserThread::UI, FROM_HERE, |
397 base::Bind( | 410 base::Bind( |
398 &ForwardToDevToolsClientOnUIThread, | 411 &ForwardToDevToolsClientOnUIThread, |
399 worker_process_id, | 412 worker_process_id, |
(...skipping 24 matching lines...) Expand all Loading... |
424 return; | 437 return; |
425 IPC::Message* msg = new IPC::Message(message); | 438 IPC::Message* msg = new IPC::Message(message); |
426 msg->set_routing_id(worker_route_id); | 439 msg->set_routing_id(worker_route_id); |
427 it->host->Send(msg); | 440 it->host->Send(msg); |
428 } | 441 } |
429 | 442 |
430 // static | 443 // static |
431 void WorkerDevToolsManager::ForwardToDevToolsClientOnUIThread( | 444 void WorkerDevToolsManager::ForwardToDevToolsClientOnUIThread( |
432 int worker_process_id, | 445 int worker_process_id, |
433 int worker_route_id, | 446 int worker_route_id, |
434 const IPC::Message& message) { | 447 const std::string& message) { |
435 WorkerDevToolsAgentHost* agent_host = AgentHosts::GetAgentHost(WorkerId( | 448 WorkerDevToolsAgentHost* agent_host = AgentHosts::GetAgentHost(WorkerId( |
436 worker_process_id, | 449 worker_process_id, |
437 worker_route_id)); | 450 worker_route_id)); |
438 if (!agent_host) | 451 if (!agent_host) |
439 return; | 452 return; |
440 DevToolsManager::GetInstance()->ForwardToDevToolsClient(agent_host, message); | 453 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(agent_host, |
| 454 message); |
441 } | 455 } |
442 | 456 |
443 // static | 457 // static |
444 void WorkerDevToolsManager::SaveAgentRuntimeStateOnUIThread( | 458 void WorkerDevToolsManager::SaveAgentRuntimeStateOnUIThread( |
445 int worker_process_id, | 459 int worker_process_id, |
446 int worker_route_id, | 460 int worker_route_id, |
447 const std::string& state) { | 461 const std::string& state) { |
448 WorkerDevToolsAgentHost* agent_host = AgentHosts::GetAgentHost(WorkerId( | 462 WorkerDevToolsAgentHost* agent_host = AgentHosts::GetAgentHost(WorkerId( |
449 worker_process_id, | 463 worker_process_id, |
450 worker_route_id)); | 464 worker_route_id)); |
451 if (!agent_host) | 465 if (!agent_host) |
452 return; | 466 return; |
453 DevToolsManager::GetInstance()->SaveAgentRuntimeState(agent_host, state); | 467 DevToolsManagerImpl::GetInstance()->SaveAgentRuntimeState(agent_host, state); |
454 } | 468 } |
455 | 469 |
456 // static | 470 // static |
457 void WorkerDevToolsManager::NotifyWorkerDestroyedOnIOThread( | 471 void WorkerDevToolsManager::NotifyWorkerDestroyedOnIOThread( |
458 int worker_process_id, | 472 int worker_process_id, |
459 int worker_route_id) { | 473 int worker_route_id) { |
460 BrowserThread::PostTask( | 474 BrowserThread::PostTask( |
461 BrowserThread::UI, FROM_HERE, | 475 BrowserThread::UI, FROM_HERE, |
462 base::Bind( | 476 base::Bind( |
463 &WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread, | 477 &WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread, |
464 worker_process_id, | 478 worker_process_id, |
465 worker_route_id)); | 479 worker_route_id)); |
466 } | 480 } |
467 | 481 |
468 // static | 482 // static |
469 void WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread( | 483 void WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread( |
470 int worker_process_id, | 484 int worker_process_id, |
471 int worker_route_id) { | 485 int worker_route_id) { |
472 WorkerDevToolsAgentHost* host = | 486 WorkerDevToolsAgentHost* host = |
473 AgentHosts::GetAgentHost(WorkerId(worker_process_id, worker_route_id)); | 487 AgentHosts::GetAgentHost(WorkerId(worker_process_id, worker_route_id)); |
474 if (host) | 488 if (host) |
475 host->WorkerDestroyed(); | 489 host->WorkerDestroyed(); |
476 } | 490 } |
477 | 491 |
478 // static | 492 // static |
479 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { | 493 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { |
480 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) | 494 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) |
481 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); | 495 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); |
482 } | 496 } |
| 497 |
| 498 } // namespace |
OLD | NEW |