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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 : public IPCDevToolsAgentHost, | 73 : public IPCDevToolsAgentHost, |
74 public IPC::Listener { | 74 public IPC::Listener { |
75 public: | 75 public: |
76 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 76 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) |
77 : worker_id_(worker_id), worker_attached_(true) { | 77 : worker_id_(worker_id), worker_attached_(true) { |
78 AddRef(); | 78 AddRef(); |
79 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 79 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
80 host->AddRoute(worker_id_.second, this); | 80 host->AddRoute(worker_id_.second, this); |
81 } | 81 } |
82 | 82 |
| 83 // DevToolsAgentHost override. |
| 84 virtual bool IsWorker() OVERRIDE { return true; } |
| 85 |
83 // IPCDevToolsAgentHost implementation. | 86 // IPCDevToolsAgentHost implementation. |
84 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { | 87 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { |
85 if (worker_attached_) | 88 if (worker_attached_) |
86 SendMessageToWorker(worker_id_, message); | 89 SendMessageToWorker(worker_id_, message); |
87 else | 90 else |
88 delete message; | 91 delete message; |
89 } | 92 } |
90 virtual void OnClientAttached() OVERRIDE {} | 93 virtual void OnClientAttached() OVERRIDE {} |
91 virtual void OnClientDetached() OVERRIDE {} | 94 virtual void OnClientDetached() OVERRIDE {} |
92 | 95 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
212 const WorkerId id(worker_process_id, worker_route_id); | 215 const WorkerId id(worker_process_id, worker_route_id); |
213 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( | 216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( |
214 storage_partition_path, service_worker_scope); | 217 storage_partition_path, service_worker_scope); |
215 if (it == workers_.end()) { | 218 if (it == workers_.end()) { |
216 scoped_ptr<WorkerInfo> info( | 219 scoped_ptr<WorkerInfo> info( |
217 new WorkerInfo(storage_partition_path, service_worker_scope)); | 220 new WorkerInfo(storage_partition_path, service_worker_scope)); |
218 workers_.set(id, info.Pass()); | 221 workers_.set(id, info.Pass()); |
219 return false; | 222 return false; |
220 } | 223 } |
| 224 if (WORKER_TERMINATED != it->second->state()) { |
| 225 // WorkerDestroyed is called when EmbeddedWorkerInstance is deleted. But in |
| 226 // current code ServiceWorkerStorage::DeleteRegistration doesn't remove the |
| 227 // instance. So WorkerDestroyed could not be called correctly. |
| 228 // TODO(horo): Remove this if statement when it becomes unnecessary. |
| 229 DLOG(ERROR) << "WorkerDestroyed has not been called correctly."; |
| 230 WorkerDestroyed(it->first.first, it->first.second); |
| 231 return ServiceWorkerCreated(worker_process_id, |
| 232 worker_route_id, |
| 233 storage_partition_path, |
| 234 service_worker_scope); |
| 235 } |
221 MoveToPausedState(id, it); | 236 MoveToPausedState(id, it); |
222 return true; | 237 return true; |
223 } | 238 } |
224 | 239 |
225 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 240 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
226 int worker_route_id) { | 241 int worker_route_id) { |
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
228 const WorkerId id(worker_process_id, worker_route_id); | 243 const WorkerId id(worker_process_id, worker_route_id); |
229 WorkerInfoMap::iterator it = workers_.find(id); | 244 WorkerInfoMap::iterator it = workers_.find(id); |
230 DCHECK(it != workers_.end()); | 245 DCHECK(it != workers_.end()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 for (; it != workers_.end(); ++it) { | 334 for (; it != workers_.end(); ++it) { |
320 if (it->second->Matches(storage_partition_path, service_worker_scope)) | 335 if (it->second->Matches(storage_partition_path, service_worker_scope)) |
321 break; | 336 break; |
322 } | 337 } |
323 return it; | 338 return it; |
324 } | 339 } |
325 | 340 |
326 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 341 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
327 const WorkerId& id, | 342 const WorkerId& id, |
328 const WorkerInfoMap::iterator& it) { | 343 const WorkerInfoMap::iterator& it) { |
329 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 344 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
330 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 345 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
331 info->set_state(WORKER_PAUSED); | 346 info->set_state(WORKER_PAUSED); |
332 workers_.set(id, info.Pass()); | 347 workers_.set(id, info.Pass()); |
333 } | 348 } |
334 | 349 |
335 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 350 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
336 workers_.clear(); | 351 workers_.clear(); |
337 } | 352 } |
338 | 353 |
339 } // namespace content | 354 } // namespace content |
OLD | NEW |