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