| 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/devtools/worker_devtools_manager.h" | 5 #include "content/browser/devtools/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 "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "content/browser/devtools/devtools_manager_impl.h" | 12 #include "content/browser/devtools/devtools_manager_impl.h" |
| 13 #include "content/browser/devtools/devtools_protocol.h" | 13 #include "content/browser/devtools/devtools_protocol.h" |
| 14 #include "content/browser/devtools/devtools_protocol_constants.h" | 14 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 15 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 15 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
| 16 #include "content/browser/devtools/shared_worker_devtools_manager.h" | |
| 17 #include "content/browser/devtools/worker_devtools_message_filter.h" | 16 #include "content/browser/devtools/worker_devtools_message_filter.h" |
| 18 #include "content/browser/worker_host/worker_service_impl.h" | 17 #include "content/browser/worker_host/worker_service_impl.h" |
| 19 #include "content/common/devtools_messages.h" | 18 #include "content/common/devtools_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
| 22 #include "content/public/common/process_type.h" | 21 #include "content/public/common/process_type.h" |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 | 24 |
| 26 // Called on the UI thread. | 25 // Called on the UI thread. |
| 27 // static | 26 // static |
| 28 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( | 27 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( |
| 29 int worker_process_id, | 28 int worker_process_id, |
| 30 int worker_route_id) { | 29 int worker_route_id) { |
| 31 if (WorkerService::EmbeddedSharedWorkerEnabled()) { | 30 return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 32 return SharedWorkerDevToolsManager::GetInstance() | 31 worker_process_id, |
| 33 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 32 worker_route_id); |
| 34 } else { | |
| 35 return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( | |
| 36 worker_process_id, worker_route_id); | |
| 37 } | |
| 38 } | 33 } |
| 39 | 34 |
| 40 namespace { | 35 namespace { |
| 41 | 36 |
| 42 typedef std::map<WorkerDevToolsManager::WorkerId, | 37 typedef std::map<WorkerDevToolsManager::WorkerId, |
| 43 WorkerDevToolsManager::WorkerDevToolsAgentHost*> AgentHosts; | 38 WorkerDevToolsManager::WorkerDevToolsAgentHost*> AgentHosts; |
| 44 base::LazyInstance<AgentHosts>::Leaky g_agent_map = LAZY_INSTANCE_INITIALIZER; | 39 base::LazyInstance<AgentHosts>::Leaky g_agent_map = LAZY_INSTANCE_INITIALIZER; |
| 45 base::LazyInstance<AgentHosts>::Leaky g_orphan_map = LAZY_INSTANCE_INITIALIZER; | 40 base::LazyInstance<AgentHosts>::Leaky g_orphan_map = LAZY_INSTANCE_INITIALIZER; |
| 46 | 41 |
| 47 } // namespace | 42 } // namespace |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 worker_url(url), | 200 worker_url(url), |
| 206 worker_name(name) {} | 201 worker_name(name) {} |
| 207 WorkerProcessHost* const host; | 202 WorkerProcessHost* const host; |
| 208 int const route_id; | 203 int const route_id; |
| 209 GURL worker_url; | 204 GURL worker_url; |
| 210 base::string16 worker_name; | 205 base::string16 worker_name; |
| 211 }; | 206 }; |
| 212 | 207 |
| 213 // static | 208 // static |
| 214 WorkerDevToolsManager* WorkerDevToolsManager::GetInstance() { | 209 WorkerDevToolsManager* WorkerDevToolsManager::GetInstance() { |
| 215 DCHECK(!WorkerService::EmbeddedSharedWorkerEnabled()); | |
| 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 217 return Singleton<WorkerDevToolsManager>::get(); | 211 return Singleton<WorkerDevToolsManager>::get(); |
| 218 } | 212 } |
| 219 | 213 |
| 220 // static | 214 // static |
| 221 DevToolsAgentHost* WorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 215 DevToolsAgentHost* WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 222 int worker_process_id, | 216 int worker_process_id, |
| 223 int worker_route_id) { | 217 int worker_route_id) { |
| 224 DCHECK(!WorkerService::EmbeddedSharedWorkerEnabled()); | |
| 225 WorkerId id(worker_process_id, worker_route_id); | 218 WorkerId id(worker_process_id, worker_route_id); |
| 226 AgentHosts::iterator it = g_agent_map.Get().find(id); | 219 AgentHosts::iterator it = g_agent_map.Get().find(id); |
| 227 if (it == g_agent_map.Get().end()) | 220 if (it == g_agent_map.Get().end()) |
| 228 return new WorkerDevToolsAgentHost(id); | 221 return new WorkerDevToolsAgentHost(id); |
| 229 return it->second; | 222 return it->second; |
| 230 } | 223 } |
| 231 | 224 |
| 232 WorkerDevToolsManager::WorkerDevToolsManager() { | 225 WorkerDevToolsManager::WorkerDevToolsManager() { |
| 233 } | 226 } |
| 234 | 227 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); | 437 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); |
| 445 } | 438 } |
| 446 | 439 |
| 447 WorkerDevToolsManager::WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() { | 440 WorkerDevToolsManager::WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() { |
| 448 DetachedClientHosts::RemovePendingWorkerData(worker_id_); | 441 DetachedClientHosts::RemovePendingWorkerData(worker_id_); |
| 449 g_agent_map.Get().erase(worker_id_); | 442 g_agent_map.Get().erase(worker_id_); |
| 450 g_orphan_map.Get().erase(worker_id_); | 443 g_orphan_map.Get().erase(worker_id_); |
| 451 } | 444 } |
| 452 | 445 |
| 453 } // namespace content | 446 } // namespace content |
| OLD | NEW |