OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/embedded_worker_devtools_manager.h" | 5 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
6 | 6 |
7 #include "content/browser/devtools/devtools_manager_impl.h" | 7 #include "content/browser/devtools/devtools_manager_impl.h" |
8 #include "content/browser/devtools/devtools_protocol.h" | 8 #include "content/browser/devtools/devtools_protocol.h" |
9 #include "content/browser/devtools/devtools_protocol_constants.h" | 9 #include "content/browser/devtools/devtools_protocol_constants.h" |
10 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 10 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 | 83 |
84 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { | 84 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { |
85 } | 85 } |
86 | 86 |
87 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost | 87 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost |
88 : public IPCDevToolsAgentHost, | 88 : public IPCDevToolsAgentHost, |
89 public IPC::Listener { | 89 public IPC::Listener { |
90 public: | 90 public: |
91 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 91 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) |
92 : worker_id_(worker_id), worker_attached_(false) { | 92 : worker_id_(worker_id), worker_attached_(false) { |
93 AttachToWorker(); | 93 WorkerCreated(); |
94 } | 94 } |
95 | 95 |
96 // DevToolsAgentHost override. | 96 // DevToolsAgentHost override. |
97 virtual bool IsWorker() const OVERRIDE { return true; } | 97 virtual bool IsWorker() const OVERRIDE { return true; } |
98 | 98 |
99 // IPCDevToolsAgentHost implementation. | 99 // IPCDevToolsAgentHost implementation. |
100 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { | 100 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { |
101 if (worker_attached_) | 101 if (worker_attached_) |
102 SendMessageToWorker(worker_id_, message); | 102 SendMessageToWorker(worker_id_, message); |
103 else | 103 else |
(...skipping 28 matching lines...) Expand all Loading... | |
132 AttachToWorker(); | 132 AttachToWorker(); |
133 Reattach(state_); | 133 Reattach(state_); |
134 } | 134 } |
135 | 135 |
136 void DetachFromWorker() { | 136 void DetachFromWorker() { |
137 if (!worker_attached_) | 137 if (!worker_attached_) |
138 return; | 138 return; |
139 worker_attached_ = false; | 139 worker_attached_ = false; |
140 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 140 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
141 host->RemoveRoute(worker_id_.second); | 141 host->RemoveRoute(worker_id_.second); |
142 } | |
143 | |
144 void WorkerCreated() { | |
145 AddRef(); | |
146 } | |
147 | |
148 void WorkerDestroyed() { | |
142 Release(); | 149 Release(); |
143 } | 150 } |
144 | 151 |
145 WorkerId worker_id() const { return worker_id_; } | 152 WorkerId worker_id() const { return worker_id_; } |
146 | 153 |
147 private: | 154 private: |
148 virtual ~EmbeddedWorkerDevToolsAgentHost() { | 155 virtual ~EmbeddedWorkerDevToolsAgentHost() { |
149 CHECK(!worker_attached_); | 156 CHECK(!worker_attached_); |
150 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( | 157 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( |
151 this); | 158 this); |
152 } | 159 } |
153 | 160 |
154 void OnDispatchOnInspectorFrontend(const std::string& message) { | 161 void OnDispatchOnInspectorFrontend(const std::string& message) { |
155 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, | 162 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, |
156 message); | 163 message); |
157 } | 164 } |
158 | 165 |
159 void OnSaveAgentRuntimeState(const std::string& state) { state_ = state; } | 166 void OnSaveAgentRuntimeState(const std::string& state) { state_ = state; } |
160 | 167 |
161 void AttachToWorker() { | 168 void AttachToWorker() { |
162 if (worker_attached_) | 169 if (worker_attached_) |
163 return; | 170 return; |
164 worker_attached_ = true; | 171 worker_attached_ = true; |
165 AddRef(); | |
166 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 172 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
167 host->AddRoute(worker_id_.second, this); | 173 host->AddRoute(worker_id_.second, this); |
168 } | 174 } |
169 | 175 |
170 WorkerId worker_id_; | 176 WorkerId worker_id_; |
171 bool worker_attached_; | 177 bool worker_attached_; |
172 std::string state_; | 178 std::string state_; |
173 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); | 179 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); |
174 }; | 180 }; |
175 | 181 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 return true; | 257 return true; |
252 } | 258 } |
253 | 259 |
254 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 260 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
255 int worker_route_id) { | 261 int worker_route_id) { |
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
257 const WorkerId id(worker_process_id, worker_route_id); | 263 const WorkerId id(worker_process_id, worker_route_id); |
258 WorkerInfoMap::iterator it = workers_.find(id); | 264 WorkerInfoMap::iterator it = workers_.find(id); |
259 DCHECK(it != workers_.end()); | 265 DCHECK(it != workers_.end()); |
260 WorkerInfo* info = it->second; | 266 WorkerInfo* info = it->second; |
267 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host(); | |
261 switch (info->state()) { | 268 switch (info->state()) { |
262 case WORKER_UNINSPECTED: | 269 case WORKER_UNINSPECTED: |
263 case WORKER_PAUSED_FOR_DEBUG_ON_START: | 270 case WORKER_PAUSED_FOR_DEBUG_ON_START: |
264 workers_.erase(it); | 271 workers_.erase(it); |
265 break; | 272 break; |
266 case WORKER_INSPECTED: { | 273 case WORKER_INSPECTED: { |
267 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host(); | |
268 info->set_state(WORKER_TERMINATED); | 274 info->set_state(WORKER_TERMINATED); |
269 if (!agent_host->IsAttached()) { | 275 if (agent_host->IsAttached()) { |
276 // Client host is debugging this worker agent host. | |
277 std::string notification = | |
278 DevToolsProtocol::CreateNotification( | |
279 devtools::Worker::disconnectedFromWorker::kName, NULL) | |
280 ->Serialize(); | |
281 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | |
282 agent_host, notification); | |
270 agent_host->DetachFromWorker(); | 283 agent_host->DetachFromWorker(); |
271 return; | |
272 } | 284 } |
273 // Client host is debugging this worker agent host. | |
274 std::string notification = | |
275 DevToolsProtocol::CreateNotification( | |
276 devtools::Worker::disconnectedFromWorker::kName, NULL) | |
277 ->Serialize(); | |
278 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | |
279 agent_host, notification); | |
280 agent_host->DetachFromWorker(); | |
281 break; | 285 break; |
282 } | 286 } |
283 case WORKER_TERMINATED: | 287 case WORKER_TERMINATED: |
284 NOTREACHED(); | 288 NOTREACHED(); |
285 break; | 289 break; |
286 case WORKER_PAUSED_FOR_REATTACH: { | 290 case WORKER_PAUSED_FOR_REATTACH: { |
287 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); | 291 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); |
288 worker_info->set_state(WORKER_TERMINATED); | 292 worker_info->set_state(WORKER_TERMINATED); |
289 const WorkerId old_id = worker_info->agent_host()->worker_id(); | 293 const WorkerId old_id = worker_info->agent_host()->worker_id(); |
290 workers_.set(old_id, worker_info.Pass()); | 294 workers_.set(old_id, worker_info.Pass()); |
291 break; | 295 break; |
292 } | 296 } |
293 } | 297 } |
298 if (agent_host) | |
299 agent_host->WorkerDestroyed(); | |
294 } | 300 } |
295 | 301 |
296 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, | 302 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, |
297 int worker_route_id) { | 303 int worker_route_id) { |
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
299 const WorkerId id(worker_process_id, worker_route_id); | 305 const WorkerId id(worker_process_id, worker_route_id); |
300 WorkerInfoMap::iterator it = workers_.find(id); | 306 WorkerInfoMap::iterator it = workers_.find(id); |
301 DCHECK(it != workers_.end()); | 307 DCHECK(it != workers_.end()); |
302 WorkerInfo* info = it->second; | 308 WorkerInfo* info = it->second; |
303 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { | 309 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 } | 368 } |
363 return it; | 369 return it; |
364 } | 370 } |
365 | 371 |
366 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 372 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
367 const WorkerId& id, | 373 const WorkerId& id, |
368 const WorkerInfoMap::iterator& it) { | 374 const WorkerInfoMap::iterator& it) { |
369 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 375 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
370 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 376 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
371 info->set_state(WORKER_PAUSED_FOR_REATTACH); | 377 info->set_state(WORKER_PAUSED_FOR_REATTACH); |
378 if (EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host()) | |
379 agent_host->WorkerCreated(); | |
dgozman
2014/07/21 13:41:16
Why do we call WorkerCreated from within MoveToPau
vkuzkokov
2014/08/05 16:00:50
MoveToPausedState is renamed to WorkerRestarted
| |
372 workers_.set(id, info.Pass()); | 380 workers_.set(id, info.Pass()); |
373 } | 381 } |
374 | 382 |
375 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 383 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
376 workers_.clear(); | 384 workers_.clear(); |
377 } | 385 } |
378 | 386 |
379 } // namespace content | 387 } // namespace content |
OLD | NEW |