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" |
11 #include "content/browser/shared_worker/shared_worker_instance.h" | 11 #include "content/browser/shared_worker/shared_worker_instance.h" |
12 #include "content/common/devtools_messages.h" | 12 #include "content/common/devtools_messages.h" |
| 13 #include "content/common/service_worker/service_worker_types.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/worker_service.h" | 16 #include "content/public/browser/worker_service.h" |
16 #include "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 bool SendMessageToWorker( | 23 bool SendMessageToWorker( |
23 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, | 24 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, |
24 IPC::Message* message) { | 25 IPC::Message* message) { |
25 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); | 26 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); |
26 if (!host) { | 27 if (!host) { |
27 delete message; | 28 delete message; |
28 return false; | 29 return false; |
29 } | 30 } |
30 message->set_routing_id(worker_id.second); | 31 message->set_routing_id(worker_id.second); |
31 host->Send(message); | 32 host->Send(message); |
32 return true; | 33 return true; |
33 } | 34 } |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( | 38 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( |
38 const SharedWorkerInstance& instance) | 39 const SharedWorkerInstance& instance) |
39 : shared_worker_instance_(new SharedWorkerInstance(instance)), | 40 : shared_worker_instance_(new SharedWorkerInstance(instance)), |
| 41 service_worker_context_(NULL), |
| 42 service_worker_version_id_(kInvalidServiceWorkerVersionId), |
40 state_(WORKER_UNINSPECTED), | 43 state_(WORKER_UNINSPECTED), |
41 agent_host_(NULL) { | 44 agent_host_(NULL) { |
42 } | 45 } |
43 | 46 |
44 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( | 47 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( |
45 const base::FilePath& storage_partition_path, | 48 const ServiceWorkerContextCore* const service_worker_context, |
46 const GURL& service_worker_scope) | 49 int64 service_worker_version_id) |
47 : storage_partition_path_(new base::FilePath(storage_partition_path)), | 50 : service_worker_context_(service_worker_context), |
48 service_worker_scope_(new GURL(service_worker_scope)), | 51 service_worker_version_id_(service_worker_version_id), |
49 state_(WORKER_UNINSPECTED), | 52 state_(WORKER_UNINSPECTED), |
50 agent_host_(NULL) { | 53 agent_host_(NULL) { |
51 } | 54 } |
52 | 55 |
53 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( | 56 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( |
54 const SharedWorkerInstance& other) { | 57 const SharedWorkerInstance& other) { |
55 if (!shared_worker_instance_) | 58 if (!shared_worker_instance_) |
56 return false; | 59 return false; |
57 return shared_worker_instance_->Matches(other); | 60 return shared_worker_instance_->Matches(other); |
58 } | 61 } |
59 | 62 |
60 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( | 63 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( |
61 const base::FilePath& other_storage_partition_path, | 64 const ServiceWorkerContextCore* const other_service_worker_context, |
62 const GURL& other_service_worker_scope) { | 65 int64 other_service_worker_version_id) { |
63 if (!storage_partition_path_ || !service_worker_scope_) | 66 if (!service_worker_context_) |
64 return false; | 67 return false; |
65 return *storage_partition_path_ == other_storage_partition_path && | 68 return service_worker_context_ == other_service_worker_context && |
66 *service_worker_scope_ == other_service_worker_scope; | 69 service_worker_version_id_ == other_service_worker_version_id; |
67 } | 70 } |
68 | 71 |
69 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { | 72 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { |
70 } | 73 } |
71 | 74 |
72 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost | 75 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost |
73 : public IPCDevToolsAgentHost, | 76 : public IPCDevToolsAgentHost, |
74 public IPC::Listener { | 77 public IPC::Listener { |
75 public: | 78 public: |
76 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 79 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 171 |
169 EmbeddedWorkerDevToolsAgentHost* agent_host = | 172 EmbeddedWorkerDevToolsAgentHost* agent_host = |
170 new EmbeddedWorkerDevToolsAgentHost(id); | 173 new EmbeddedWorkerDevToolsAgentHost(id); |
171 info->set_agent_host(agent_host); | 174 info->set_agent_host(agent_host); |
172 info->set_state(WORKER_INSPECTED); | 175 info->set_state(WORKER_INSPECTED); |
173 return agent_host; | 176 return agent_host; |
174 } | 177 } |
175 | 178 |
176 DevToolsAgentHost* | 179 DevToolsAgentHost* |
177 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( | 180 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( |
178 const base::FilePath& storage_partition_path, | 181 const ServiceWorkerContextCore* const service_worker_context, |
179 const GURL& service_worker_scope) { | 182 int64 service_worker_version_id) { |
180 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( | 183 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( |
181 storage_partition_path, service_worker_scope); | 184 service_worker_context, service_worker_version_id); |
182 if (it == workers_.end()) | 185 if (it == workers_.end()) |
183 return NULL; | 186 return NULL; |
184 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); | 187 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); |
185 } | 188 } |
186 | 189 |
187 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { | 190 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { |
188 } | 191 } |
189 | 192 |
190 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { | 193 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { |
191 } | 194 } |
(...skipping 10 matching lines...) Expand all Loading... |
202 workers_.set(id, info.Pass()); | 205 workers_.set(id, info.Pass()); |
203 return false; | 206 return false; |
204 } | 207 } |
205 MoveToPausedState(id, it); | 208 MoveToPausedState(id, it); |
206 return true; | 209 return true; |
207 } | 210 } |
208 | 211 |
209 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( | 212 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( |
210 int worker_process_id, | 213 int worker_process_id, |
211 int worker_route_id, | 214 int worker_route_id, |
212 const base::FilePath& storage_partition_path, | 215 const ServiceWorkerContextCore* const service_worker_context, |
213 const GURL& service_worker_scope) { | 216 int64 service_worker_version_id) { |
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
215 const WorkerId id(worker_process_id, worker_route_id); | 218 const WorkerId id(worker_process_id, worker_route_id); |
216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( | 219 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( |
217 storage_partition_path, service_worker_scope); | 220 service_worker_context, service_worker_version_id); |
218 if (it == workers_.end()) { | 221 if (it == workers_.end()) { |
219 scoped_ptr<WorkerInfo> info( | 222 scoped_ptr<WorkerInfo> info( |
220 new WorkerInfo(storage_partition_path, service_worker_scope)); | 223 new WorkerInfo(service_worker_context, service_worker_version_id)); |
221 workers_.set(id, info.Pass()); | 224 workers_.set(id, info.Pass()); |
222 return false; | 225 return false; |
223 } | 226 } |
224 MoveToPausedState(id, it); | 227 MoveToPausedState(id, it); |
225 return true; | 228 return true; |
226 } | 229 } |
227 | 230 |
228 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 231 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
229 int worker_route_id) { | 232 int worker_route_id) { |
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 WorkerInfoMap::iterator it = workers_.begin(); | 312 WorkerInfoMap::iterator it = workers_.begin(); |
310 for (; it != workers_.end(); ++it) { | 313 for (; it != workers_.end(); ++it) { |
311 if (it->second->Matches(instance)) | 314 if (it->second->Matches(instance)) |
312 break; | 315 break; |
313 } | 316 } |
314 return it; | 317 return it; |
315 } | 318 } |
316 | 319 |
317 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 320 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
318 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( | 321 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( |
319 const base::FilePath& storage_partition_path, | 322 const ServiceWorkerContextCore* const service_worker_context, |
320 const GURL& service_worker_scope) { | 323 int64 service_worker_version_id) { |
321 WorkerInfoMap::iterator it = workers_.begin(); | 324 WorkerInfoMap::iterator it = workers_.begin(); |
322 for (; it != workers_.end(); ++it) { | 325 for (; it != workers_.end(); ++it) { |
323 if (it->second->Matches(storage_partition_path, service_worker_scope)) | 326 if (it->second->Matches(service_worker_context, service_worker_version_id)) |
324 break; | 327 break; |
325 } | 328 } |
326 return it; | 329 return it; |
327 } | 330 } |
328 | 331 |
329 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 332 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
330 const WorkerId& id, | 333 const WorkerId& id, |
331 const WorkerInfoMap::iterator& it) { | 334 const WorkerInfoMap::iterator& it) { |
332 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 335 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
333 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 336 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
334 info->set_state(WORKER_PAUSED); | 337 info->set_state(WORKER_PAUSED); |
335 workers_.set(id, info.Pass()); | 338 workers_.set(id, info.Pass()); |
336 } | 339 } |
337 | 340 |
338 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 341 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
339 workers_.clear(); | 342 workers_.clear(); |
340 } | 343 } |
341 | 344 |
342 } // namespace content | 345 } // namespace content |
OLD | NEW |