Chromium Code Reviews| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 string16 worker_name; | 54 string16 worker_name; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 | 57 |
| 58 class WorkerDevToolsManager::WorkerDevToolsAgentHost | 58 class WorkerDevToolsManager::WorkerDevToolsAgentHost |
| 59 : public IPCDevToolsAgentHost { | 59 : public IPCDevToolsAgentHost { |
| 60 public: | 60 public: |
| 61 explicit WorkerDevToolsAgentHost(WorkerId worker_id) | 61 explicit WorkerDevToolsAgentHost(WorkerId worker_id) |
| 62 : has_worker_id_(false) { | 62 : has_worker_id_(false) { |
| 63 SetWorkerId(worker_id, false); | 63 SetWorkerId(worker_id, false); |
| 64 AddRef(); // Balanced in ResetWorkerId. | |
| 65 } | 64 } |
| 66 | 65 |
| 67 void SetWorkerId(WorkerId worker_id, bool reattach) { | 66 void SetWorkerId(WorkerId worker_id, bool reattach) { |
| 68 worker_id_ = worker_id; | 67 worker_id_ = worker_id; |
| 68 if (!has_worker_id_) | |
| 69 AddRef(); // Balanced in ResetWorkerId. | |
| 69 has_worker_id_ = true; | 70 has_worker_id_ = true; |
| 70 g_agent_map.Get()[worker_id_] = this; | 71 g_agent_map.Get()[worker_id_] = this; |
| 71 | 72 |
| 72 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
| 73 BrowserThread::IO, | 74 BrowserThread::IO, |
| 74 FROM_HERE, | 75 FROM_HERE, |
| 75 base::Bind( | 76 base::Bind( |
| 76 &ConnectToWorker, | 77 &ConnectToWorker, |
| 77 worker_id.first, | 78 worker_id.first, |
| 78 worker_id.second)); | 79 worker_id.second)); |
| 79 | 80 |
| 80 if (reattach) | 81 if (reattach) |
| 81 Reattach(state_); | 82 Reattach(state_); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void ResetWorkerId() { | 85 void ResetWorkerId() { |
| 85 g_agent_map.Get().erase(worker_id_); | 86 g_agent_map.Get().erase(worker_id_); |
| 86 has_worker_id_ = false; | 87 has_worker_id_ = false; |
| 87 Release(); | 88 Release(); // Balanced in SetWorkerId. |
| 88 } | 89 } |
| 89 | 90 |
| 90 void SaveAgentRuntimeState(const std::string& state) { | 91 void SaveAgentRuntimeState(const std::string& state) { |
| 91 state_ = state; | 92 state_ = state; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void ConnectionFailed() { | 95 void ConnectionFailed() { |
| 95 NotifyCloseListener(); | 96 NotifyCloseListener(); |
| 96 // Object can be deleted here. | 97 // Object can be deleted here. |
| 97 } | 98 } |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 virtual ~WorkerDevToolsAgentHost() { | 101 virtual ~WorkerDevToolsAgentHost(); |
| 101 g_agent_map.Get().erase(worker_id_); | |
|
yurys
2013/04/15 05:24:18
Why did this move?
Vladislav Kaznacheev
2013/04/15 13:10:27
Because I needed to call a method from DetachedCli
| |
| 102 g_orphan_map.Get().erase(worker_id_); | |
| 103 } | |
| 104 | 102 |
| 105 static void ConnectToWorker( | 103 static void ConnectToWorker( |
| 106 int worker_process_id, | 104 int worker_process_id, |
| 107 int worker_route_id) { | 105 int worker_route_id) { |
| 108 WorkerDevToolsManager::GetInstance()->ConnectDevToolsAgentHostToWorker( | 106 WorkerDevToolsManager::GetInstance()->ConnectDevToolsAgentHostToWorker( |
| 109 worker_process_id, worker_route_id); | 107 worker_process_id, worker_route_id); |
| 110 } | 108 } |
| 111 | 109 |
| 112 static void ForwardToWorkerDevToolsAgent( | 110 static void ForwardToWorkerDevToolsAgent( |
| 113 int worker_process_id, | 111 int worker_process_id, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 } | 171 } |
| 174 | 172 |
| 175 // Client host is debugging this worker agent host. | 173 // Client host is debugging this worker agent host. |
| 176 devtools_manager->DispatchOnInspectorFrontend( | 174 devtools_manager->DispatchOnInspectorFrontend( |
| 177 agent, | 175 agent, |
| 178 WebDevToolsAgent::workerDisconnectedFromWorkerEvent().utf8()); | 176 WebDevToolsAgent::workerDisconnectedFromWorkerEvent().utf8()); |
| 179 g_orphan_map.Get()[id] = agent; | 177 g_orphan_map.Get()[id] = agent; |
| 180 agent->ResetWorkerId(); | 178 agent->ResetWorkerId(); |
| 181 } | 179 } |
| 182 | 180 |
| 183 private: | |
| 184 DetachedClientHosts() {} | |
| 185 ~DetachedClientHosts() {} | |
| 186 | |
| 187 static void RemovePendingWorkerData(WorkerId id) { | 181 static void RemovePendingWorkerData(WorkerId id) { |
|
yurys
2013/04/15 05:24:18
Why do you need this method to be public?
| |
| 188 BrowserThread::PostTask( | 182 BrowserThread::PostTask( |
| 189 BrowserThread::IO, FROM_HERE, | 183 BrowserThread::IO, FROM_HERE, |
| 190 base::Bind(&RemoveInspectedWorkerDataOnIOThread, id)); | 184 base::Bind(&RemoveInspectedWorkerDataOnIOThread, id)); |
| 191 } | 185 } |
| 192 | 186 |
| 187 private: | |
| 188 DetachedClientHosts() {} | |
| 189 ~DetachedClientHosts() {} | |
| 190 | |
| 193 static void RemoveInspectedWorkerDataOnIOThread(WorkerId id) { | 191 static void RemoveInspectedWorkerDataOnIOThread(WorkerId id) { |
| 194 WorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(id); | 192 WorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(id); |
| 195 } | 193 } |
| 196 }; | 194 }; |
| 197 | 195 |
| 198 struct WorkerDevToolsManager::InspectedWorker { | 196 struct WorkerDevToolsManager::InspectedWorker { |
| 199 InspectedWorker(WorkerProcessHost* host, int route_id, const GURL& url, | 197 InspectedWorker(WorkerProcessHost* host, int route_id, const GURL& url, |
| 200 const string16& name) | 198 const string16& name) |
| 201 : host(host), | 199 : host(host), |
| 202 route_id(route_id), | 200 route_id(route_id), |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 if (it != g_agent_map.Get().end()) | 432 if (it != g_agent_map.Get().end()) |
| 435 it->second->ConnectionFailed(); | 433 it->second->ConnectionFailed(); |
| 436 } | 434 } |
| 437 | 435 |
| 438 // static | 436 // static |
| 439 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { | 437 void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { |
| 440 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) | 438 if (WorkerProcessHost* process = FindWorkerProcess(id.first)) |
| 441 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); | 439 process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); |
| 442 } | 440 } |
| 443 | 441 |
| 442 WorkerDevToolsManager::WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() { | |
| 443 DetachedClientHosts::RemovePendingWorkerData(worker_id_); | |
| 444 g_agent_map.Get().erase(worker_id_); | |
| 445 g_orphan_map.Get().erase(worker_id_); | |
| 446 } | |
| 447 | |
| 444 } // namespace content | 448 } // namespace content |
| OLD | NEW |