| 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_impl.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_service_impl.h" | 14 #include "content/browser/worker_host/worker_service_impl.h" |
| 15 #include "content/common/devtools_messages.h" | 15 #include "content/common/devtools_messages.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/child_process_data.h" | 17 #include "content/public/browser/child_process_data.h" |
| 18 #include "content/public/browser/devtools_agent_host_registry.h" | 18 #include "content/public/browser/devtools_agent_host_registry.h" |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 #include "content/public/browser/notification_service.h" | |
| 22 #include "content/public/browser/notification_types.h" | |
| 23 #include "content/public/common/process_type.h" | 19 #include "content/public/common/process_type.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 27 | 23 |
| 28 using content::BrowserThread; | 24 using content::BrowserThread; |
| 29 | 25 |
| 30 namespace content { | 26 namespace content { |
| 31 | 27 |
| 32 // Called on the UI thread. | 28 // Called on the UI thread. |
| 33 // static | 29 // static |
| 34 DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( | 30 DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( |
| 35 int worker_process_id, | 31 int worker_process_id, |
| 36 int worker_route_id) { | 32 int worker_route_id) { |
| 37 return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 33 return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 38 worker_process_id, | 34 worker_process_id, |
| 39 worker_route_id); | 35 worker_route_id); |
| 40 } | 36 } |
| 41 | 37 |
| 42 class WorkerDevToolsManager::AgentHosts | 38 class WorkerDevToolsManager::AgentHosts { |
| 43 : private content::NotificationObserver { | |
| 44 public: | 39 public: |
| 45 static void Add(WorkerId id, WorkerDevToolsAgentHost* host) { | 40 static void Add(WorkerId id, WorkerDevToolsAgentHost* host) { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 47 if (!instance_) | 42 if (!instance_) |
| 48 instance_ = new AgentHosts(); | 43 instance_ = new AgentHosts(); |
| 49 instance_->map_[id] = host; | 44 instance_->map_[id] = host; |
| 50 } | 45 } |
| 51 static void Remove(WorkerId id) { | 46 static void Remove(WorkerId id) { |
| 52 DCHECK(instance_); | 47 DCHECK(instance_); |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 return NULL; | 60 return NULL; |
| 66 Instances& map = instance_->map_; | 61 Instances& map = instance_->map_; |
| 67 Instances::iterator it = map.find(id); | 62 Instances::iterator it = map.find(id); |
| 68 if (it == map.end()) | 63 if (it == map.end()) |
| 69 return NULL; | 64 return NULL; |
| 70 return it->second; | 65 return it->second; |
| 71 } | 66 } |
| 72 | 67 |
| 73 private: | 68 private: |
| 74 AgentHosts() { | 69 AgentHosts() { |
| 75 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | |
| 76 content::NotificationService::AllSources()); | |
| 77 } | 70 } |
| 78 ~AgentHosts() {} | 71 ~AgentHosts() {} |
| 79 | 72 |
| 80 // content::NotificationObserver implementation. | |
| 81 virtual void Observe(int type, | |
| 82 const content::NotificationSource&, | |
| 83 const content::NotificationDetails&) OVERRIDE; | |
| 84 | |
| 85 static AgentHosts* instance_; | 73 static AgentHosts* instance_; |
| 86 typedef std::map<WorkerId, WorkerDevToolsAgentHost*> Instances; | 74 typedef std::map<WorkerId, WorkerDevToolsAgentHost*> Instances; |
| 87 Instances map_; | 75 Instances map_; |
| 88 content::NotificationRegistrar registrar_; | |
| 89 }; | 76 }; |
| 90 | 77 |
| 91 WorkerDevToolsManager::AgentHosts* | 78 WorkerDevToolsManager::AgentHosts* |
| 92 WorkerDevToolsManager::AgentHosts::instance_ = NULL; | 79 WorkerDevToolsManager::AgentHosts::instance_ = NULL; |
| 93 | 80 |
| 94 | 81 |
| 95 struct WorkerDevToolsManager::TerminatedInspectedWorker { | 82 struct WorkerDevToolsManager::TerminatedInspectedWorker { |
| 96 TerminatedInspectedWorker(WorkerId id, const GURL& url, const string16& name) | 83 TerminatedInspectedWorker(WorkerId id, const GURL& url, const string16& name) |
| 97 : old_worker_id(id), | 84 : old_worker_id(id), |
| 98 worker_url(url), | 85 worker_url(url), |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 215 } |
| 229 | 216 |
| 230 static DetachedClientHosts* instance_; | 217 static DetachedClientHosts* instance_; |
| 231 typedef std::map<WorkerId, int> WorkerIdToCookieMap; | 218 typedef std::map<WorkerId, int> WorkerIdToCookieMap; |
| 232 WorkerIdToCookieMap worker_id_to_cookie_; | 219 WorkerIdToCookieMap worker_id_to_cookie_; |
| 233 }; | 220 }; |
| 234 | 221 |
| 235 WorkerDevToolsManager::DetachedClientHosts* | 222 WorkerDevToolsManager::DetachedClientHosts* |
| 236 WorkerDevToolsManager::DetachedClientHosts::instance_ = NULL; | 223 WorkerDevToolsManager::DetachedClientHosts::instance_ = NULL; |
| 237 | 224 |
| 238 | |
| 239 void WorkerDevToolsManager::AgentHosts::Observe( | |
| 240 int type, | |
| 241 const content::NotificationSource&, | |
| 242 const content::NotificationDetails&) { | |
| 243 DCHECK(type == content::NOTIFICATION_APP_TERMINATING); | |
| 244 Instances copy(map_); | |
| 245 for (Instances::iterator it = copy.begin(); it != copy.end(); ++it) | |
| 246 it->second->WorkerDestroyed(); | |
| 247 DCHECK(!instance_); | |
| 248 } | |
| 249 | |
| 250 struct WorkerDevToolsManager::InspectedWorker { | 225 struct WorkerDevToolsManager::InspectedWorker { |
| 251 InspectedWorker(WorkerProcessHost* host, int route_id, const GURL& url, | 226 InspectedWorker(WorkerProcessHost* host, int route_id, const GURL& url, |
| 252 const string16& name) | 227 const string16& name) |
| 253 : host(host), | 228 : host(host), |
| 254 route_id(route_id), | 229 route_id(route_id), |
| 255 worker_url(url), | 230 worker_url(url), |
| 256 worker_name(name) {} | 231 worker_name(name) {} |
| 257 WorkerProcessHost* const host; | 232 WorkerProcessHost* const host; |
| 258 int const route_id; | 233 int const route_id; |
| 259 GURL worker_url; | 234 GURL worker_url; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 host->WorkerDestroyed(); | 464 host->WorkerDestroyed(); |
| 490 } | 465 } |
| 491 | 466 |
| 492 // static | 467 // static |
| 493 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { | 468 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { |
| 494 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) | 469 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) |
| 495 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); | 470 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); |
| 496 } | 471 } |
| 497 | 472 |
| 498 } // namespace | 473 } // namespace |
| OLD | NEW |